Ini ni ada Animasi yang ke 2,,cara kerjanya hampis sama dengan yang pertama..Namun, Kali ini kita akan mencoba membuat sebuah permainan...
Ikuti langkah berikut :
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
#include<dos.h>
delay (int a);
delay (int a)
{
for (int x=0; x<a*100; x++)
{
for (int y=0; y<a*100; y++)
{}
}
}
void animasi()
{
_setcursortype(_NOCURSOR);
//kiri delay
textcolor(4);
gotoxy(29,11);cprintf(">");
delay(100);
textcolor(6);
gotoxy(30,11);cprintf(">");
delay(100); //smkin gd nile na smkn lmbat
textcolor(7);
gotoxy(31,11);cprintf(">");
//tengah-tengah
textcolor(3);
gotoxy(33,11);cprintf("Program Animasi");
//kanan delay
textcolor(4);
gotoxy(49,11);cprintf("<");
delay(100);
textcolor(6);
gotoxy(50,11);cprintf("<");
delay(100);
textcolor(7);
gotoxy(51,11);cprintf("<");
//mulai stikom bali
sleep(2);
textcolor(1);
gotoxy(44,13);cprintf("I");
delay(100);
textcolor(0);
gotoxy(44,13);cprintf(" ");
textcolor(2);
gotoxy(43,13);cprintf("L");
delay(100);
textcolor(0);
gotoxy(43,13);cprintf(" ");
textcolor(3);
gotoxy(42,13);cprintf("A");
delay(100);
textcolor(0);
gotoxy(42,13);cprintf(" ");
textcolor(4);
gotoxy(41,13);cprintf("B");
delay(100);
textcolor(0);
gotoxy(41,13);cprintf(" ");
textcolor(5);
gotoxy(39,13);cprintf("M");
delay(100);
textcolor(0);
gotoxy(39,13);cprintf(" ");
textcolor(6);
gotoxy(38,13);cprintf("O");
delay(100);
textcolor(0);
gotoxy(38,13);cprintf(" ");
textcolor(7);
gotoxy(37,13);cprintf("K");
delay(100);
textcolor(0);
gotoxy(37,13);cprintf(" ");
textcolor(8);
gotoxy(36,13);cprintf("I");
delay(100);
textcolor(0);
gotoxy(36,13);cprintf(" ");
textcolor(9);
gotoxy(35,13);cprintf("T");
delay(100);
textcolor(0);
gotoxy(35,13);cprintf(" ");
textcolor(10);
gotoxy(34,13);cprintf("S");
delay(100);
textcolor(0);
gotoxy(34,13);cprintf(" ");
//balik
gotoxy(34,13);cprintf("S");
delay(100);
textcolor(10);
gotoxy(34,13);cprintf("S");
textcolor(15);
gotoxy(35,13);cprintf("T");
delay(100);
textcolor(9);
gotoxy(35,13);cprintf("T");
textcolor(15);
gotoxy(36,13);cprintf("I");
delay(100);
textcolor(8);
gotoxy(36,13);cprintf("I");
textcolor(15);
gotoxy(37,13);cprintf("K");
delay(100);
textcolor(7);
gotoxy(37,13);cprintf("K");
textcolor(15);
gotoxy(38,13);cprintf("O");
delay(100);
textcolor(6);
gotoxy(38,13);cprintf("O");
textcolor(15);
gotoxy(39,13);cprintf("M");
delay(100);
textcolor(5);
gotoxy(39,13);cprintf("M");
textcolor(15);
gotoxy(41,13);cprintf("B");
delay(100);
textcolor(4);
gotoxy(41,13);cprintf("B");
textcolor(15);
gotoxy(42,13);cprintf("A");
delay(100);
textcolor(3);
gotoxy(42,13);cprintf("A");
textcolor(15);
gotoxy(43,13);cprintf("L");
delay(100);
textcolor(2);
gotoxy(43,13);cprintf("L");
textcolor(15);
gotoxy(44,13);cprintf("I");
delay(100);
textcolor(1);
gotoxy(44,13);cprintf("I");
textcolor(15);
sleep(5);
clrscr();
delay(100);
clrscr();
//Nama & Nim
textcolor(1);gotoxy(33,11);cprintf("N");
delay(100);
textcolor(2);gotoxy(33,11);cprintf("N");
delay(100);
textcolor(2);gotoxy(34,11);cprintf("A");
delay(100);
textcolor(3);gotoxy(34,11);cprintf("A");
delay(100);
textcolor(3);gotoxy(35,11);cprintf("M");
delay(100);
textcolor(4);gotoxy(35,11);cprintf("M");
delay(100);
textcolor(4);gotoxy(36,11);cprintf("A");
delay(100);
textcolor(5);gotoxy(36,11);cprintf("A");
delay(100);
textcolor(5);gotoxy(38,11);cprintf(":");
delay(100);
textcolor(6);gotoxy(38,11);cprintf(":");
delay(100);
textcolor(1);gotoxy(40,11);cprintf("I");
delay(100);
textcolor(2);gotoxy(40,11);cprintf("I");
delay(100);
textcolor(1);gotoxy(41,11);cprintf(" ");
delay(100);
textcolor(2);gotoxy(41,11);cprintf(" ");
delay(100);
textcolor(1);gotoxy(42,11);cprintf("P");
delay(100);
textcolor(2);gotoxy(42,11);cprintf("P");
delay(100);
textcolor(1);gotoxy(43,11);cprintf("T");
delay(100);
textcolor(2);gotoxy(43,11);cprintf("T");
delay(100);
textcolor(1);gotoxy(44,11);cprintf(" ");
delay(100);
textcolor(2);gotoxy(44,11);cprintf(" ");
delay(100);
textcolor(1);gotoxy(45,11);cprintf("Agus Suyasa");
delay(100);
textcolor(1);gotoxy(33,13);cprintf("N");
delay(100);
textcolor(2);gotoxy(33,13);cprintf("N");
delay(100);
textcolor(2);gotoxy(34,13);cprintf("I");
delay(100);
textcolor(3);gotoxy(34,13);cprintf("I");
delay(100);
textcolor(3);gotoxy(35,13);cprintf("M");
delay(100);
textcolor(4);gotoxy(35,13);cprintf("M");
delay(100);
textcolor(5);gotoxy(38,13);cprintf(":");
delay(100);
textcolor(6);gotoxy(38,13);cprintf(":");
delay(100);
textcolor(1);gotoxy(40,13);cprintf("1");
delay(100);
textcolor(2);gotoxy(40,13);cprintf("1");
delay(100);
textcolor(1);gotoxy(41,13);cprintf("0");
delay(100);
textcolor(2);gotoxy(41,13);cprintf("0");
delay(100);
textcolor(1);gotoxy(42,13);cprintf("0");
delay(100);
textcolor(2);gotoxy(42,13);cprintf("0");
delay(100);
textcolor(1);gotoxy(43,13);cprintf("0");
delay(100);
textcolor(2);gotoxy(43,13);cprintf("0");
delay(100);
textcolor(1);gotoxy(44,13);cprintf("1");
delay(100);
textcolor(2);gotoxy(44,13);cprintf("1");
delay(100);
textcolor(1);gotoxy(45,13);cprintf("0");
delay(100);
textcolor(2);gotoxy(45,13);cprintf("0");
delay(100);
textcolor(1);gotoxy(46,13);cprintf("2");
delay(100);
textcolor(2);gotoxy(46,13);cprintf("2");
delay(100);
textcolor(1);gotoxy(47,13);cprintf("3");
delay(100);
textcolor(2);gotoxy(47,13);cprintf("3");
delay(100);
textcolor(1);gotoxy(48,13);cprintf("2");
delay(100);
textcolor(2);gotoxy(48,13);cprintf("2");
delay(100);
sleep(5);
}
void tunggu(void)
{
long int i;
for(i=0; i<6e7; i++);
}
main()
{
animasi();
int x,y,bil;
int A[5];
char jwb;
char tmbl;
clrscr();
awal:
//lintasan mobil
textcolor(15);
cprintf("Jalur yang dilalui mobil");cout<<endl;
cout<<endl<<endl;
cout<<setw(29)<<"depan"<<"\n"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(45)<<"_______________| |_______________"<<endl;
cout<<setw(30)<<endl;
cout<<setw(51)<<"kiri X kanan"<<endl;
cout<<setw(45)<<"_______________ _______________"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl;
cout<<setw(30)<<"| |"<<endl<<endl;
cout<<setw(30)<<"belakang"<<"\n"<<endl;
cout<<endl;
textcolor(90);
cprintf("Keterangan : X = posisi awal mobil");cout<<endl;
cout<<endl;
cprintf("tekan huruf [n/N] untuk melanjutkan....");
cin>>tmbl;
clrscr();
if(tmbl=='n' || tmbl=='N')
goto next;
else
cout<<"error!!!";
goto keluar;
next:
textcolor(15);
cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");cout<<endl;
textcolor(15);
cprintf("ketik 0x dahulu kemudian masukan salah satu karakter yang ada di bawah ini");cout<<endl;
cprintf("(hanya boleh memasukan satu digit)dari data yang ada");cout<<endl;
cprintf("Silahkan memilih angka/huruf yang anda inginkan:");cout<<"\n"<<endl;
cprintf(" 0");cout<<endl;
cprintf(" 1");cout<<endl;
cprintf(" 2");cout<<endl;
cprintf(" 3");cout<<endl;
cprintf(" 4");cout<<endl;
cprintf(" 5");cout<<endl;
cprintf(" 6");cout<<endl;
cprintf(" 7");cout<<endl;
cprintf(" 8");cout<<endl;
cprintf(" 9");cout<<endl;
cprintf(" a/A");cout<<endl;
cprintf(" b/B");cout<<endl;
cprintf(" c/C");cout<<endl;
cprintf(" d/D");cout<<endl;
cprintf(" e/E");cout<<endl;
cprintf(" f/F");cout<<endl;
cout<<"\nSilahkan ketikan 0x lalu ketikan karakter.Contoh(0xf)!!!"<<endl;
cin>>bil;
if(bil>7 && bil<=15 )
{
bil=bil-8;
A[1]=1;
}
else
{
A[1]=0;
}
if(bil>3 && bil<=7 )
{
bil=bil-4;
A[2]=1;
}
else
{
A[2]=0;
}
if(bil>1 && bil<=3)
{
bil=bil-2;
A[3]=1;
}
else
{
A[3]=0;
}
if(bil>0 && bil<=1)
{
bil=bil-1;
A[4]=1;
}
else
{
A[4]=0;
}
clrscr();
//lintasan ketika memulai permainan
textcolor(30);
cprintf("Arah gerak mobil adalah : ");cout<<endl<<endl;
cprintf("**************************");
cout<<"\n\n";
cout<<setw(29)<<"depan"<<"\n"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(29)<<"| |"<<endl;
cout<<setw(44)<<"_______________| |_______________"<<endl;
cout<<setw(29)<<endl;
cout<<setw(52)<<"kiri kanan"<<endl;
cout<<setw(43)<<"_______________ _______________"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl;
cout<<setw(28)<<"| |"<<endl<<endl;
cout<<setw(30)<<"belakang"<<"\n"<<endl;
int i;
//A[1]=depan
if(A[1]==1)
{
i=0;
do
{
x=27; y=16-i;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27; y=16-i;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<10);
}
else
{
cout<<"";
}
//A[2]=belakang
if(A[2]==1)
{
i=0;
do
{
x=27; y=16+i;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27; y=16+i;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<10);
}
else
{
cout<<"";
}
//A[3]=kiri
if(A[3]==1)
{
i=0;
do
{
x=27-i; y=16;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27-i; y=16;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<19);
}
else
{
cout<<"";
}
//A[4]=kanan
if(A[4]==1)
{
i=0;
do
{
x=27+i; y=16;
gotoxy(x,y);
textcolor(30);
cprintf("X");
tunggu();
x=27+i; y=16;
gotoxy(x,y);
cout<<" ";
tunggu();
i++;
}
while(i<19);
}
else
{
cout<<"";
}
x=1;
y=25;
gotoxy(x,y);
textcolor(13);
cout<<endl;
cprintf("*****************************************************************");
cout<<endl;
textcolor(13);
cprintf("apakah anda ingin mencoba lagi [y/t]??? ");
cin>>jwb;
cout<<endl;
textcolor(13);
cprintf("********************************************************************");
clrscr();
if(jwb=='y' || jwb=='Y')
goto awal;
keluar:
getch();
}
Paste Source Code di atas,,jika ada masalah...
Silahkan Komen atau kirim permasalahan ke "Contact Me"
Thax
Posting Komentar