08-18-2010, 04:50 PM
Here is a game I made in C++, it is a basic tic-tac-toe game...
Stay Frosty. -NULL
Code:
#include <iostream>
using namespace std;
int main()
{
system("title Tic-Tac-Toe");
startall:
char a='a', b='b', c='c', d='d', e='e', f='f', g='g', h='h', i='i', go, gt;
int ac=0, bc=0, cc=0, dc=0, ec=0, fc=0, gc=0, hc=0, ic=0, pc=1;
mainp1:
if (a == 'X' && b == 'X' && c == 'X')
{
goto win1;
}
if (a == 'X' && e == 'X' && i == 'X')
{
goto win1;
}
if (a == 'X' && d == 'X' && g == 'X')
{
goto win1;
}
if (b == 'X' && e == 'X' && h == 'X')
{
goto win1;
}
if (d == 'X' && e == 'X' && f == 'X')
{
goto win1;
}
if (g == 'X' && h == 'X' && i == 'X')
{
goto win1;
}
if (g == 'X' && e == 'X' && c == 'X')
{
goto win1;
}
if (c == 'X' && f == 'X' && i == 'X')
{
goto win1;
}
if (a == 'O' && b == 'O' && c == 'O')
{
goto win;
}
if (a == 'O' && e == 'O' && i == 'O')
{
goto win;
}
if (a == 'O' && d == 'O' && g == 'O')
{
goto win;
}
if (b == 'O' && e == 'O' && h == 'O')
{
goto win;
}
if (d == 'O' && e == 'O' && f == 'O')
{
goto win;
}
if (g == 'O' && h == 'O' && i == 'O')
{
goto win;
}
if (g == 'O' && e == 'O' && c == 'O')
{
goto win;
}
if (c == 'O' && f == 'O' && i == 'O')
{
goto win;
}
if (ac == 1 && bc == 1 && cc == 1 && dc == 1 && ec == 1 && fc == 1 && gc == 1 && hc == 1 && ic == 1)
{
goto lose;
}
system("cls");
pc++;
cout << " " << a << " | " << b << " | " << c << endl;
cout << " " << "-----------" << endl;
cout << " " << d << " | " << e << " | " << f << endl;
cout << " " << "-----------" << endl;
cout << " " << g << " | " << h << " | " << i << endl << endl;
cout << "Player one: ";
cin >> go;
if (go == a)
{
if (ac == 1)
{
goto Invalidmove1;
}
else
{
a = 'X';
ac = 1;
goto mainp2;
}
}
if (go == b)
{
if (bc == 1)
{
goto Invalidmove1;
}
else
{
b = 'X';
bc = 1;
goto mainp2;
}
}
if (go == c)
{
if (cc == 1)
{
goto Invalidmove1;
}
else
{
c = 'X';
cc = 1;
goto mainp2;
}
}
if (go == d)
{
if (dc == 1)
{
goto Invalidmove1;
}
else
{
d = 'X';
dc = 1;
goto mainp2;
}
}
if (go == e)
{
if (ec == 1)
{
goto Invalidmove1;
}
else
{
e = 'X';
ec = 1;
goto mainp2;
}
}
if (go == f)
{
if (fc == 1)
{
goto Invalidmove1;
}
else
{
f = 'X';
fc = 1;
goto mainp2;
}
}
if (go == g)
{
if (gc == 1)
{
goto Invalidmove1;
}
else
{
g = 'X';
gc = 1;
goto mainp2;
}
}
if (go == h)
{
if (hc == 1)
{
goto Invalidmove1;
}
else
{
h = 'X';
hc = 1;
goto mainp2;
}
}
if (go == i)
{
if (ic == 1)
{
goto Invalidmove1;
}
else
{
i = 'X';
ic = 1;
goto mainp2;
}
}
else
{
goto Invalidmove1;
}
Invalidmove1:
cout << endl << endl << endl;
cout << "Move was invalid\n";
cout << "Press enter to continue\n";
system("pause");
goto mainp1;
mainp2:
if (a == 'X' && b == 'X' && c == 'X')
{
goto win1;
}
if (a == 'X' && e == 'X' && i == 'X')
{
goto win1;
}
if (a == 'X' && d == 'X' && g == 'X')
{
goto win1;
}
if (b == 'X' && e == 'X' && h == 'X')
{
goto win1;
}
if (d == 'X' && e == 'X' && f == 'X')
{
goto win1;
}
if (g == 'X' && h == 'X' && i == 'X')
{
goto win1;
}
if (g == 'X' && e == 'X' && c == 'X')
{
goto win1;
}
if (c == 'X' && f == 'X' && i == 'X')
{
goto win1;
}
if (a == 'O' && b == 'O' && c == 'O')
{
goto win;
}
if (a == 'O' && e == 'O' && i == 'O')
{
goto win;
}
if (a == 'O' && d == 'O' && g == 'O')
{
goto win;
}
if (b == 'O' && e == 'O' && h == 'O')
{
goto win;
}
if (d == 'O' && e == 'O' && f == 'O')
{
goto win;
}
if (g == 'O' && h == 'O' && i == 'O')
{
goto win;
}
if (g == 'O' && e == 'O' && c == 'O')
{
goto win;
}
if (c == 'O' && f == 'O' && i == 'O')
{
goto win;
}
if (ac == 1 && bc == 1 && cc == 1 && dc == 1 && ec == 1 && fc == 1 && gc == 1 && hc == 1 && ic == 1)
{
goto lose;
}
system("cls");
pc--;
cout << " " << a << " | " << b << " | " << c << endl;
cout << " " << "-----------" << endl;
cout << " " << d << " | " << e << " | " << f << endl;
cout << " " << "-----------" << endl;
cout << " " << g << " | " << h << " | " << i << endl << endl;
cout << "Player two: ";
cin >> gt;
if (gt == a)
{
if (ac == 1)
{
goto Invalidmove2;
}
else
{
a = 'O';
ac = 1;
goto mainp1;
}
}
if (gt == b)
{
if (bc == 1)
{
goto Invalidmove2;
}
else
{
b = 'O';
bc = 1;
goto mainp1;
}
}
if (gt == c)
{
if (cc == 1)
{
goto Invalidmove2;
}
else
{
c = 'O';
cc = 1;
goto mainp1;
}
}
if (gt == d)
{
if (dc == 1)
{
goto Invalidmove2;
}
else
{
d = 'O';
dc = 1;
goto mainp1;
}
}
if (gt == e)
{
if (ec == 1)
{
goto Invalidmove2;
}
else
{
e = 'O';
ec = 1;
goto mainp1;
}
}
if (gt == f)
{
if (fc == 1)
{
goto Invalidmove2;
}
else
{
f = 'O';
fc = 1;
goto mainp1;
}
}
if (gt == g)
{
if (gc == 1)
{
goto Invalidmove2;
}
else
{
g = 'O';
gc = 1;
goto mainp1;
}
}
if (gt == h)
{
if (hc == 1)
{
goto Invalidmove2;
}
else
{
h = 'O';
hc = 1;
goto mainp1;
}
}
if (gt == i)
{
if (ic == 1)
{
goto Invalidmove2;
}
else
{
i = 'O';
ic = 1;
goto mainp1;
}
}
else
{
goto Invalidmove2;
}
Invalidmove2:
cout << endl << endl << endl;
cout << "Move was invalid\n";
cout << "Press enter to continue\n";
system("pause");
goto mainp2;
win:
char ta;
system("cls");
cout << "Player 2: YOU WON!! Congrats.\n";
cout << "Try again? (y/n): ";
cin >> ta;
if (ta == 'y' || ta == 'Y')
{
goto startall;
}
else
{
return 0;
}
win1:
char tb;
system("cls");
cout << "Player 1: YOU WON!! Congrats.\n";
cout << "Try again? (y/n): ";
cin >> ta;
if (tb == 'y' || tb == 'Y')
{
goto startall;
}
else
{
return 0;
}
lose:
char ta2;
system("cls");
cout << "You lost...\n";
cout << "Try again? (y/n): ";
cin >> ta2;
if (ta2 == 'y' || ta == 'Y')
{
goto startall;
}
else
{
return 0;
}
}