Tic tac toe

I am trying to make a tic tac toe game (like many people have) and I'm having trouble. I have a function boardstatus that is supposed to hold the values of all board spaces (ie A1, A2, A3, B1, B2 etc). I want the function to be able to return the value of each board square by calling it boardsquare(A1) for instance, and then it will return the character value (X, O or blank).

I just would like some ideas what to do. It seems like a simple problem but I'm not getting it. I also will need a way for these board statuses to be changed based on user input. How will I do that?

Note: This code is NOT finished at all and has many holes, so please don't bother correcting that. I'm mainly concerned with the relationship between boardprint and boardstatus. I'm really just looking for ideas, I don't expect you to completely rewrite my code unless you want to :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  #include <iostream>
#include <cstdio>

using namespace std;

int checkwin();
void boardprint();

char player1_mark;
char player2_mark;

int boardstatus( int x )
{
    
    enum squarestatus {
    SS_BLANK,
    SS_O,
    SS_X,
    };
    
//This code below doesn't work obviously but I hope you can understand
//what I'm trying to do.

    squarestatus x = SS_BLANK;
    
    return x;
    
}

int main()
{



    do
    {
        cout << "Player 1, choose X or O: ";
        cin >> player1_mark;
        cin.clear();
        cin.sync();
        if ( player1_mark == 'X' )
        {
            player2_mark = 'O';
        }
        else if (player1_mark == 'O' )
        {
            player2_mark = 'X';
        }
        else
        {
            cout << "Invalid character. Please try again." << endl;
        }
    } while ( player1_mark != 'X' && player1_mark != 'O');


}

void boardprint()
{
	system('cls');
	cout << "\n\n\tTic Tac Toe\n\n";

	cout << "Player 1 (" << player1_mark << ")  -  Player 2 (" << player2_mark << ")" << endl << endl;
	cout << endl;

	cout << "     |     |     " << endl;
	cout << "  " << boardstatus(A1) << "  |  " << boardstatus(A2) << "  |  " << boardstatus(A3) << endl;

	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;

	cout << "  " << boardstatus(B1) << "  |  " << boardstatus(B2) << "  |  " << boardstatus(B3) << endl;

	cout << "_____|_____|_____" << endl;
	cout << "     |     |     " << endl;

	cout << "  " << boardstatus(C1) << "  |  " << boardstatus(C2) << "  |  " << boardstatus(C3) << endl;

	cout << "     |     |     " << endl << endl;
}

Last edited on
Topic archived. No new replies allowed.