Game ini dapat diimajinasikan dengan lorong" untuk keluar...
Game ini dapat dijalankan dengan Turbo C...
Berikut adalah source code nya...
//memasukkan header file
#include "constream.h"
#include "dos.h"
#include "string.h"
constream disp; //membuat object bernamaa disp
void main() {
int array[12][12] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
{1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0},
{1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
{1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}; //untuk mengisi angka2 ke dalam array
int i, j, x, y, tekan; // mendeklarasikan variable
x = 0, y = 2;
disp.clrscr();
disp< <<"Mulai ->"; //mencetak kata mulai di koordinat 19,8
disp<
do {
for(i = 0; i < 12; i++) {
for(j = 0; j < 12; j++) {
disp< if(array[i][j]) cout<<"#";
else cout<<".";
}
}// looping untuk mencetak map
disp< tekan = getch(); // mengetahui penekanan di keyboard
disp<
// validasi gerak
switch(tekan) {
case 72: if(y > 0 && !array[y - 1][x]) y--; break;
case 75: if(x > 0 && !array[y][x - 1]) x--; break;
case 77: if(x < 11 && !array[y][x + 1]) x++; break;
case 80: if(y < 11 && !array[y + 1][x]) y++; break;
}
} while(tekan != 27 && (x != 11 || y != 4)); // program berhenti apabila tekan ESC atau berhasil mencapai titik finish
//mencetak map
for(i = 0; i < 12; i++) {
for(j = 0; j < 12; j++) {
disp< if(array[i][j]) cout<<"#"; else cout<<".";
}
}
disp< disp< if(x == 11 && y == 4) cout<<"Anda HEBAT!"; //apabila finish, cetak ini
else cout<<" Anda CUPU "; // apabila tidak finish, cetak ini
disp< getch(); //untuk menampilkan layar output.
}
Untuk program selengkapnya, silahkan download DI SINI...
Semoga bermanfaat...
: )
Game ini dapat dijalankan dengan Turbo C...
Berikut adalah source code nya...
//memasukkan header file
#include "constream.h"
#include "dos.h"
#include "string.h"
constream disp; //membuat object bernamaa disp
void main() {
int array[12][12] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
{1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0},
{1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1},
{1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}; //untuk mengisi angka2 ke dalam array
int i, j, x, y, tekan; // mendeklarasikan variable
x = 0, y = 2;
disp.clrscr();
disp<
disp<
do {
for(i = 0; i < 12; i++) {
for(j = 0; j < 12; j++) {
disp<
else cout<<".";
}
}// looping untuk mencetak map
disp<
disp<
// validasi gerak
switch(tekan) {
case 72: if(y > 0 && !array[y - 1][x]) y--; break;
case 75: if(x > 0 && !array[y][x - 1]) x--; break;
case 77: if(x < 11 && !array[y][x + 1]) x++; break;
case 80: if(y < 11 && !array[y + 1][x]) y++; break;
}
} while(tekan != 27 && (x != 11 || y != 4)); // program berhenti apabila tekan ESC atau berhasil mencapai titik finish
//mencetak map
for(i = 0; i < 12; i++) {
for(j = 0; j < 12; j++) {
disp<
}
}
disp<
else cout<<" Anda CUPU "; // apabila tidak finish, cetak ini
disp<
}
Untuk program selengkapnya, silahkan download DI SINI...
Semoga bermanfaat...
: )