Thread: Gui Class With Tic Tac Toe

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    2

    Gui Class With Tic Tac Toe

    I would like to use the GUIMOUSECLICK FUNCTION so that when the first player click on the board to make a move it will draw an x or o. How do i do this
    Code:
    #include <lvp\gui_top.h>
    
    class GuiClass
    {
    	public:
       			GuiClass();
                void GuiMouseClick(int x, int y);
                void GuiPaint();
                void GetMousePos();
                void CheckWin();
                void NextPlayer();
                void PlayGame();
                bool checkEmpty(int a,int b);
                String Title();
                char board[3][3];
                int i,j,turn;
                char play;
       private:
       			int LastX;
                int LastY;
    };
    
    GuiClass::GuiClass()
    {
         //initializes matrix to empty then sets player turn to 'O'
    	  for (i = 0; i < 3; i++)
        		for (j = 0; j < 3; j++)
        			board[i][j] = '\0';
         turn = 1;
         play = 'O';
    }
    void GuiClass::NextPlayer()
    {
    	//Controls the player turn
    	if (turn == 1)
    		{
    			turn = 2;
    			play = 'X';
    		}
    	else
    		{
    			turn = 1;
    			play = 'O';
    		}
    }
    
    
    void GuiClass::PlayGame()
    {
       GetMousePos();
       //CheckWin ();
       //NextPlayer ();
    }
    
    bool GuiClass::checkEmpty (int a, int b)
    {
        	if (board[a][b] == '\0')
        		return true;
        	else
        		return false;
    }
    
    void GuiClass::GetMousePos()
    {
    	bool empty;
       empty = checkEmpty(i,j);
       if (empty == true)
       	board[i][j] = play;
       else
       	{
          	gotoxy(310,100); DrawText("Already occupied!");
            // NextPlayer();
          }
    }
    
    void GuiClass::CheckWin()
    {
    	if((board[0][0] == play && board[1][0] == play && board[2][0] == play) ||
       	(board[0][1] == play && board[1][1] == play && board[2][1] == play) ||
       	(board[0][2] == play && board[1][2] == play && board[2][2] == play) ||
       	(board[0][0] == play && board[0][1] == play && board[0][2] == play) ||
       	(board[1][0] == play && board[1][1] == play && board[1][2] == play) ||
       	(board[2][0] == play && board[2][1] == play && board[2][2] == play) ||
       	(board[0][0] == play && board[1][1] == play && board[2][2] == play) ||
       	(board[0][2] == play && board[1][1] == play && board[2][0] == play))
    DrawText("Player"); //x; DrawText("Wins!");
    }
    
    
    String GuiClass::Title()
    {
     	return("Tic Tac Toe~~!!!");
    }
    
    void GuiClass::GuiMouseClick(int x, int y)
    {
    	LastX = x;
       LastY = y;
    }
    
    void GuiClass::GuiPaint()
    {
    	Line(350,150,350,350); Line(450,150,450,350);
       Line(255,290,550,290); Line(255,210,550,210);
       gotoxy(210,100); DrawText("Player 1:");
       gotoxy(510,100); DrawText("Player 2:");
    }
    
    int main()
    {
       GuiClass Start;
       Start.PlayGame();
    	return 0;
    }
    #include <lvp\gui_bot.h>
    Last edited by xxYukoxx; 05-30-2003 at 03:28 PM.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    2
    so can any1 give me any ideas i really need this for my school project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  2. A Tic Tac Toe game
    By Rusty_chainsaw in forum C++ Programming
    Replies: 1
    Last Post: 04-12-2006, 06:16 AM
  3. Tic Tac Toe... so close...
    By SlayerBlade in forum C Programming
    Replies: 14
    Last Post: 10-10-2005, 08:58 PM
  4. Tic Tac Toe AI help please...
    By Rune Hunter in forum Game Programming
    Replies: 12
    Last Post: 11-05-2004, 04:24 PM
  5. tic tac toe
    By holden in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-09-2004, 09:59 AM