Solved

Help understanding class using a simple game

Posted on 1998-03-11
1
180 Views
Last Modified: 2010-04-10
I am trying to make a tic tac toe program using the members listed . Please help me pick it apart my Mentor is
on holiday and I have nowhere else to turn.

enum Player { x, o, empty };

class Board
{
      public:
      int Board (column, row)

            typedef BoardSize [column] [row]

       void Place (Player,column,row)
                  cout << " Please enter your marker " << flush;
                  cin >> char Player
                  cout << " Please enter a column " <<
                          << " and row to place your marker " << flush;
                  cin >> int column, int row;
                              if (Board [column], [row] = empty ){
                                    cout << P << " is entered at " << Board [ column ], [row]<<endl;
                                    else cout << " That space is full " << endl;



       int Win (Player)
                  while Board [column], [row] = Player;
                              ++row;
                                    if row = 3;
                                    cout << Player << " wins " << endl;
              else if Board [column], [row] = Player;
                               ++column;
                                    if column = 3;
                                    cout << Player << " wins " << endl;
              else if Board [column], [row] = Player;
                              ++column, ++row;
                                     if column && row = 3;
                                     cout << Player << " wins " << endl;


       int StaleMate(Player)
              if Board [], [] != empty && Win() = 0;
              cout << " The match is a Stalemate " << endl;


             }


              int main()
              {
                  const int column = 3;
                  const int row = 3;
                   Player x;
                   Player o;

              return 0;
              }
0
Comment
Question by:chasa
1 Comment
 
LVL 3

Accepted Solution

by:
q2guo earned 200 total points
ID: 1183374
I modified you code a bit.  It 's still far from perfect, but it should get you started in the right direction.
------------------------------------------------------------


#include <iostream.h>

enum Player { x, o, empty };

class Board
{

int column;
int row;
int *grid;

public:
    int Board(int, int);
    ~Board() { delete grid; }
    void Place(void);
    int Win(void);
    void Print_result(void);
    int isBoardFull();
}

Board::Board(int column, int row)
{
    grid = new int [column*row];
    for (int i=0; i < column*row; i++) {
     // initialize board
    }
}

int Board::Print_result(Player)
    if (Player == o) cout << "O wins" <<endl;
    else if (Player == x) cout << "x wins" <<endl;
    else cout << " The match is a Stalemate " << endl;
}

int Board::isBoardFull()
{
   // return 1 is board is full
}

int Board::Win(void)
{
    while Board [column], [row] = Player;
    ++row;
    if row = 3;
    cout << Player << " wins " << endl;
      else if Board [column], [row] = Player;
    ++column;
    if column = 3;
    cout << Player << " wins " << endl;
      else if Board [column], [row] = Player;
    ++column, ++row;
    if column && row = 3;
    cout << Player << " wins " << endl;
}

void Board::Place ()
{
    cout << " Please enter your marker " << flush;
    cin >> char Player
    cout << " Please enter a column " <<
      << " and row to place your marker " << flush;
    cin >> int column, int row;
    if (Board [column], [row] = empty ){
    cout << P << " is entered at " << Board [ column ], [row]<<endl;
    else cout << " That space is full " << endl;
}

int main()
{
    const int column = 3;
    const int row = 3;
    Player player1 = x;
    Player player2 = o;
    Board b(column, row);

    while (!(b.isBoardFull()))
    {



    }
    b.Print_result(Win());

    return 0;
}
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question