Membuat Program Game Tic Tac Toe menggunakan Borland C++

Membuat Program Game Tic Tac Toe
menggunakan Borland C++

1.       Buka aplikasi Borland C++ pada PC/Laptop anda.
2.       Klik File, New, Project
3.       Untuk codingnya adalah sebagai berikut :
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
main()
{
int z, baris, kolom;
char a, b, c, d, e, f, g, h, i, ulang;
cout << "\t"  << "===========" << endl;
cout << "\t""TIC TAC TOE" << endl;
cout << "\t"  << "===========" << endl;
cout << "\n\n""Apakah Anda Ingin Bermain?\nPlay [p]\nExit [e]\n";
cin >> ulang;
if(ulang=='p')
{
clrscr();
goto mulai;
}
else
{
return 0;
}
cout << "\t" "TIC TAC TOE" << endl << endl;
mulai:
a = ' ';
b = ' ';
c = ' ';
d = ' ';
e = ' ';
f = ' ';
g = ' ';
h = ' ';
i = ' ';
z=1;
while(z<=10)
{
clrscr();
lanjut:
cout <<"\tGAME TIC TAC TOE" << endl << endl;
cout << "\t"  << " =============" << 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;
cout << "\t"  << " =============" << endl << endl;
if(z==10)
{
clrscr();
cout <<"\tGAME TIC TAC TOE" << endl << endl;
cout << "\t"  << " =============" << endl;
cout << "\t" << " | " << a << " | " << b
<< " | " << c << " | " << endl;
cout << "\t"  << " =============" <<
cout << "\t" << " | " << d << " | " << e
<< " | " << f << " | " << endl;
cout << "\t"  << " =============" <<
cout << "\t" << " | " << g << " | " << h
<< " | " << i << " | " << endl;
cout << "\t"  << " =============" << endl << endl;
cout << "Draw" << endl << endl;
cout << "Apakah Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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 Anda 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;
}
getch();
}

4.       Selamat mencoba kawan..

http://fitrifebriani26.blogspot.com

Komentar

  1. The Hotel Casino & Spa - Mapyro
    Discover & Plan 양산 출장샵 a Trip to The 거제 출장안마 Hotel 논산 출장안마 Casino & Spa 포항 출장안마 in Washington, D.C. from $55. Book 용인 출장샵 online or call (866) 744-7655.

    BalasHapus

Posting Komentar

Postingan populer dari blog ini

Membuat Program Penginapan Hotel menggunakan Microsoft Visual Basic 2010 Express

Membuat Program Penjualan Barang menggunakan Microsoft Visual Basic 2010 Express

Membuat Program Data Hotel menggunakan Microsoft Visual Basic 2010 Express