Pages

Minggu, 06 Januari 2013



TUGAS KTI PROGRAM GAME

Game mencari jalan keluar

Listing program

#include <iostream.h>
#include <conio.h>
#define xmap 20
#define ymap 20
int main()
{
int x,y,posisix,posisiy,batas;
char input;
char *arah[4];
batas=0;
*arah="G0!";
int map[xmap][ymap]= {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,
1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,
1,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,0,0,0,1,
1,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,
1,1,0,1,1,0,0,0,0,1,0,0,1,1,1,1,0,1,0,1,
1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,1,0,1,
1,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,0,1,0,1,
1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,
1,0,1,1,0,0,1,0,1,0,1,1,0,1,0,0,0,1,0,1,
1,0,1,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,0,1,
1,0,1,1,1,0,0,0,1,0,0,1,0,1,0,1,0,1,0,1,
1,0,0,0,0,1,0,0,1,0,0,1,0,1,1,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,0,0,0,1,0,0,0,1,0,1,
1,0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1,
1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,3,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
};
while(1){cout<<"(Menemukan Jalan Keluar)\n";



for (x=0;x<xmap;x++){
for (y=0;y<ymap;y++){
if (map[x][y]==1){
if (x==0){
cout<<"===";
}
else if (x==xmap-1){
cout<<"===";
}
else {cout<<"|||";}
}
else if (map[x][y]==2){
cout<<*arah;
posisix=x;
posisiy=y;
}
else if (map[x][y]==3){
cout<<"EXIT";
}
else {cout<<"   ";}
}
cout<<" "<<endl;
}
cout<<"\n\"w\" \"a\" \"s\" \"d\" untuk menggerakkan]";
cout<<endl<<"posisi x = "<<posisix<<endl<<"posisi y = "<<posisiy;
input=getch();
if(input=='s'){
if (map[posisix+1][posisiy]==0 || map[posisix+1][posisiy]==3){
map[posisix][posisiy]=0;
map[posisix+1][posisiy]=2;
*arah=" v ";
}
}
else if(input=='d'){
if (map[posisix][posisiy+1]==0 || map[posisix][posisiy+1]==3){
map[posisix][posisiy]=0;
map[posisix][posisiy+1]=2;
*arah=" --> ";
}
}
else if(input=='a'){
if (map[posisix][posisiy-1]==0 || map[posisix][posisiy-1]==3){
map[posisix][posisiy]=0;
map[posisix][posisiy-1]=2;
*arah=" <-- ";
}
}
else if(input=='w'){
if (map[posisix-1][posisiy]==0 || map[posisix-1][posisiy]==3){
map[posisix][posisiy]=0;
map[posisix-1][posisiy]=2;
*arah=" ^ ";
}
}
clrscr();
}
}






Output Program

 
 
 
 
 



Game tebak-tebakan

Listing program


uses crt;
var
x,tebakan,jumlah : integer;
lagi : char;
begin
randomize;
lagi:='Y';
while(lagi='Y') or (lagi='y') do
begin
clrscr;
writeln('Silahkan Anda Tebak Angka Berapakah Yg Akan Keluar Dari 0-60');


x:= random(60);

jumlah:=0;
tebakan:=-1;
while (tebakan <> x) do

begin

tebakan:=0;
gotoXY(1,30);
Textcolor(LightGreen);
write('masukan nilai tebakan anda : ');readln(tebakan);
gotoXY(1,30);DelLine;

if tebakan < x then
begin
Textcolor(Yellow);
 gotoXY(1,8);
 writeln(tebakan:4,'======> anda belum beruntung, nilai masih kurang besar!!');
end;

if tebakan > x then
begin
Textcolor(LightRed);
gotoXY(1,8);writeln(tebakan:4,'======> anda belum beruntung, nilai masih kurang kecil!!');
end;

jumlah:=jumlah+1;

end;

GotoXY(1,8);
Textcolor(Blink);
writeln(tebakan:4,'======> benar, ',jumlah,'kali anda menebak !!');
GotoXY(1,22);
Textcolor(Blink);
write('Menebak yang lain lagi (Y/T)?');
readln(lagi);
end;
end.


Output Program
 
 

 

 

 

 

Blogger news

Blogroll

About