Struktur game paling mudah menggunakan C++ yang aku buat.
Apa yang diperlukan:
- Apa-apa C++ compiler
- 2 Player
Copy dan pastekan code tersebut pada mana-mana compiler:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<ctype.h>
void main()
{
char p1Symbol,p2Symbol,symbol;
char mainSymbol[3][3]={" "};
char nameP1[11], nameP2[11],name[11];
int count = 2, row, columme;
cout<<"Please input your nick name"<
cout<<"Player 1: ";
cin.getline(nameP1,10);
cout<<"Player 2: ";
cin.getline(nameP2,10);
cout<<"Please input your symbol"<
cout<
cin>>p1Symbol;
cout<
cin>>p2Symbol;
while (count<=11)
{
if (count%2==0)
{ symbol=p1Symbol;
strcpy(name,nameP1);
}
else
{ symbol=p2Symbol;
strcpy(name,nameP2);
}
for (int b = 0 ; b < 3 ; b++)
{
cout<
cout<
for (int a = 0 ; a < 3 ; a++ )
{
cout<<"| "<
}
cout<<"|"<
}
cout<
cout<
cout<<"Row : ";
cin>>row;
cout<<"Columme : ";
cin>>columme;
for (int b=0;b<3;b++)
for (int a=0;a<3;a++)
if(columme-1 == b)
{ if (row-1 == a)
mainSymbol[b][a]=symbol;
}
for (int a=0;a<3;a++)
{
if (mainSymbol[a][0]==mainSymbol[a][1]&&mainSymbol[a][1]==mainSymbol[a][2])
{
if (mainSymbol[a][0]==p1Symbol)
{ cout<
count=11;
}
if (mainSymbol[a][0] == p2Symbol)
{ cout<
count=11;
}
}
else if (mainSymbol[0][a]==mainSymbol[1][a]&&mainSymbol[1][a]==mainSymbol[2][a])
{
if (mainSymbol[2][a]==p1Symbol)
{ cout<
count=11;
}
if (mainSymbol [2][a] == p2Symbol)
{ cout<
count=11;
}
}
}
if (mainSymbol[0][0]==mainSymbol[1][1]&&mainSymbol[1][1]==mainSymbol[2][2])
{
if (mainSymbol[2][2]==p1Symbol)
{ cout<
count=11;
}
if (mainSymbol[2][2] == p2Symbol)
{ cout<
count=11;
}
}
else if (mainSymbol[0][2]==mainSymbol[1][1]&&mainSymbol[1][1]==mainSymbol[2][0])
{
if (mainSymbol[2][0] == p1Symbol)
{ cout<
count=11;
}
if (mainSymbol[2][0] == p2Symbol)
{ cout<
count=11;
}
}
count++;
}
for (int b = 0 ; b < 3 ; b++)
{
cout<
cout<
for (int a = 0 ; a < 3 ; a++ )
{
cout<<"| "<
}
cout<<"|"<
}
cout<
getch();
return ;
}
Screen shoot game tersebut
Subscribe to:
Post Comments (Atom)
0 Response to "Program Game paling mudah"
Post a Comment