Selasa, 15 November 2011

anak ikan mencari makan


#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="mulai";
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,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,
1,0,0,0,2,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,
1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,1,1,
1,0,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,1,0,1,
1,0,0,1,0,1,0,3,0,0,0,0,0,1,0,0,1,0,0,1,
1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,
1,0,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,
1,0,0,1,0,1,0,0,0,1,0,3,0,0,0,0,0,0,0,1,
1,3,0,1,0,1,0,0,0,1,1,1,1,1,1,1,0,1,0,1,
1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,3,0,1,0,1,
1,0,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,0,1,
1,0,0,1,0,1,1,0,0,1,3,0,0,0,0,0,0,1,0,1,
1,3,0,1,0,0,0,1,0,1,1,1,1,1,1,1,0,1,0,1,
1,0,0,1,3,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,
1,0,3,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,0,1,
1,0,0,1,0,1,0,0,0,1,0,0,0,3,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
};
while(1){
cout<<"ANAK IKAN MENCARI MAKAN (";
cout<<"Mustaqim Alfarabi | 09071002001)\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<<"000";
}
else {cout<<"   ";}
}
cout<<" "<<endl;
}
cout<<"\n\"w\" \"a\" \"s\" \"d\" untuk menggerakkan , 000 = makanan";
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=".|.";
}
}
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();
}
}

1 komentar: