Also, there's no computer player. It just shows the spaces and if you get 3 in a row you win lol. But is the code good
for what its doing? Thanks!
- Code: Select all
#include <iostream>
using namespace std;
bool breakloop = false;
int exitg = 1;
char a1 = 'I';
char a2 = 'I';
char a3 = 'I';
char b1 = 'I';
char b2 = 'I';
char b3 = 'I';
char c1 = 'I';
char c2 = 'I';
char c3 = 'I';
char x = 8;
int y = 0;
int graphics()
{
cout << "a "; cout << a1; cout << a2; cout << a3 << endl;
cout << "b "; cout << b1; cout << b2; cout << b3 << endl;
cout << "c "; cout << c1; cout << c2; cout << c3 << endl;
cout << " \n"; //spacer
cout << " 1"; cout << "2"; cout << "3" << endl;
cout << "\n";
}
void game()
{
if (x == 'a' && y == 1) { a1 = 'x'; }
if (x == 'a' && y == 2) { a2 = 'x'; }
if (x == 'a' && y == 3) { a3 = 'x'; }
if (x == 'b' && y == 1) { b1 = 'x'; }
if (x == 'b' && y == 2) { b2 = 'x'; }
if (x == 'b' && y == 3) { b3 = 'x'; }
if (x == 'c' && y == 1) { c1 = 'x'; }
if (x == 'c' && y == 2) { c2 = 'x'; }
if (x == 'c' && y == 3) { c3 = 'x'; }
}
void test()
{
if (a1 == 'x' && a2 == 'x' && a3 == 'x') { breakloop = true; }
if (b1 == 'x' && b2 == 'x' && b3 == 'x') { breakloop = true; }
if (c1 == 'x' && c2 == 'x' && c3 == 'x') { breakloop = true; }
if (a1 == 'x' && b2 == 'x' && c3 == 'x') { breakloop = true; }
if (a1 == 'x' && b1 == 'x' && c1 == 'x') { breakloop = true; }
if (a2 == 'x' && b2 == 'x' && c2 == 'x') { breakloop = true; }
if (a3 == 'x' && b3 == 'x' && c3 == 'x') { breakloop = true; }
}
int main()
{
while (exitg < 2)
{
graphics();
cout << "Your turn. Enter X coordinate (letter): ";
cin >> x;
system("cls");
cout << "Enter Y coordinate (number): ";
cin >> y;
system("cls");
game();
//graphics();
test();
if (breakloop == true)
{
break;
}
}
cout << "You won!";
int thing = 5;
cin >> thing;
}
