Saya hanya iseng-iseng membuat Game Tic Tac Toe dari bahasa pemrograman c++, berikut merupakan hasilnya:
#include <iostream.h>
#include <conio.h>
main()
{
int pass, bu, z, baris, kolom;
char a, b, c, d, e, f, g, h, i, ulang;
cout << "ORIGINAL BY :" << endl;
cout << "NAMA : IFAN MUHAMMAD LUHTFI" << endl;
cout << "NPM : 5520111037" << endl;
cout << "KELAS : IF 11 A" << endl << endl;
bu = 0;
do
{
cout << "Password : ";
cin >> pass;
if(pass == 123)
{
mulai:
a = ' ';
b = ' ';
c = ' ';
d = ' ';
e = ' ';
f = ' ';
g = ' ';
h = ' ';
i = ' ';
z=1;
while(z<=10)
{
clrscr();
lanjut:
cout << "ORIGINAL BY :" << endl;
cout << "NAMA : IFAN MUHAMMAD LUHTFI" << endl;
cout << "NPM : 5520111037" << endl;
cout << "KELAS : IF 11 A" << endl << endl;
cout << "GAME TIC TAC TOE 2 PLAYER" << endl << endl;
cout << "\t" << " " << a << " | "
<< b << " | " << c << " " << endl;
cout << "\t" << "-----------" << endl;
cout << "\t" << " " << d << " | "
<< e << " | " << f << " " << endl;
cout << "\t" << "-----------" << endl;
cout << "\t" << " " << g << " | "
<< h << " | " << i << " " << endl <<
endl;
if(z==10)
{
clrscr();
cout << "ORIGINAL BY :" << endl;
cout << "NAMA : IFAN MUHAMMAD LUHTFI" << endl;
cout << "NPM : 5520111037" << endl;
cout << "KELAS : IF 11 A" << endl << endl;
cout << "GAME TIC TAC TOE 2 PLAYER" << endl << endl;
cout << "\t" << " " << a << " |
" << b << " | " << c << " " << endl;
cout << "\t" << "-----------" << endl;
cout << "\t" << " " << d << " |
" << e << " | " << f << " " << endl;
cout << "\t" << "-----------" << endl;
cout << "\t" << " " << g << " |
" << h << " | " << i << " " << endl
<< endl;
cout << "Draw" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
if(((a=='X')&&(b=='X'))&&(c=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((d=='X')&&(e=='X'))&&(f=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((g=='X')&&(h=='X'))&&(i=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((a=='X')&&(d=='X'))&&(g=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((b=='X')&&(e=='X'))&&(h=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((c=='X')&&(f=='X'))&&(i=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((a=='X')&&(e=='X'))&&(i=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((c=='X')&&(e=='X'))&&(g=='X'))
{
cout << "Player 1 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((a=='O')&&(b=='O'))&&(c=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((d=='O')&&(e=='O'))&&(f=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((g=='O')&&(h=='O'))&&(i=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((a=='O')&&(d=='O'))&&(g=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((b=='O')&&(e=='O'))&&(h=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((c=='O')&&(f=='O'))&&(i=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((a=='O')&&(e=='O'))&&(i=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
else if(((c=='O')&&(e=='O'))&&(g=='O'))
{
cout << "Player 2 Menang" << endl << endl;
cout << "Apakah Ingin Main Lagi [y/n] ? ";
cin >> ulang;
if(ulang=='y')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
}
if(z % 2 == 1)
{
cout << "Player 1 [X]";
}
else
{
cout << "Player 2 [O]";
}
cout << endl << endl << "Masukan Baris [V] [1..3] : ";
cin >> baris;
if(baris>3)
{
cout << "Bilangan Diluar Jangkauan" << endl;
cout << "Masukan Angka 1 Sampai 3";
getch();
clrscr();
goto lanjut;
}
cout << "Masukan kolom [>] [1..3] : ";
cin >> kolom;
if(kolom>3)
{
cout << "Bilangan Diluar Jangkauan" << endl;
cout << "Masukan Angka 1 Sampai 3";
getch();
clrscr();
goto lanjut;
}
if((baris==1)&&(kolom==1))
{
if(a!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
a = 'X';
}
else
{
a = 'O';
}
}
}
else if((baris==1)&&(kolom==2))
{
if(b!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
b = 'X';
}
else
{
b = 'O';
}
}
}
else if((baris==1)&&(kolom==3))
{
if(c!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
c = 'X';
}
else
{
c = 'O';
}
}
}
else if((baris==2)&&(kolom==1))
{
if(d!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
d = 'X';
}
else
{
d = 'O';
}
}
}
else if((baris==2)&&(kolom==2))
{
if(e!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
e = 'X';
}
else
{
e = 'O';
}
}
}
else if((baris==2)&&(kolom==3))
{
if(f!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
f = 'X';
}
else
{
f = 'O';
}
}
}
else if((baris==3)&&(kolom==1))
{
if(g!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
g = 'X';
}
else
{
g = 'O';
}
}
}
else if((baris==3)&&(kolom==2))
{
if(h!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
h = 'X';
}
else
{
h = 'O';
}
}
}
else if((baris==3)&&(kolom==3))
{
if(i!=' ')
{
z--;
cout << endl << "Sudah Diisi";
getch();
}
else
{
if(z % 2 == 1)
{
i = 'X';
}
else
{
i = 'O';
}
}
}
z++;
clrscr();
goto lanjut;
}
}
else
{
bu++;
cout << "Password Salah" << endl << endl;
}
if(bu==3)
{
cout << "Program Di Blokir.. Hahaha.. :D";
}
}
while((pass != 123)&&(bu < 3));
getch();
}
0 komentar:
Posting Komentar