Tictactoe problem

This is a discussion on Tictactoe problem within the Windows Programming forums, part of the Platform Specific Boards category; I have just started with MFC again after being away from programming for a bit. And I've encountered exactly the ...

  1. #1
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537

    Tictactoe problem

    I have just started with MFC again after being away from programming for a bit. And I've encountered exactly the same problem I had the first time I tried to write tictactoe!! The area that can be clicked is seeming smaller than the area drawn, hence clicking on the right or on the bottom of the game does nothing.

    This is my OnPaint code, which has the mapmode calls where I think the problem may lie.

    Code:
    void TTTWin::OnPaint( )
    {
    	CPaintDC dc( this );
    
    	CRect rect;
    	GetClientRect( &rect );
    	dc.SetMapMode( MM_ANISOTROPIC );
    	dc.SetWindowExt( 300, 300 );
    	dc.SetViewportExt( rect.Width( ), rect.Height( ) );
    
    	dc.MoveTo( 100, 5 );
    	dc.LineTo( 100, 295 );
    	dc.MoveTo( 200, 5 );
    	dc.LineTo( 200, 295 );
    	dc.MoveTo( 5, 100 );
    	dc.LineTo( 295, 100 );
    	dc.MoveTo( 5, 200 );
    	dc.LineTo( 295, 200 );
    
    	for( int i = 0; i < 9; i++ )
    	{
    		switch( game.mark[ i ] )
    		{
    		case game.OH:
    			game.drawOH( dc, game.squares[ i ] );
    			break;
    
    		case game.EX:
    			game.drawEX( dc, game.squares[ i ] );
    			break;
    
    		case game.EMPTY:
    			break;
    
    		default:
    			MessageBox( "Cannot draw piece", ERROR );
    			break;
    		}
    	}
    }
    The TicTacToe constructore which initialises the rectangles looks like this:

    Code:
    TicTacToe::TicTacToe( )
    {
    	theApp = new TTTApp( );
    	
    	squares[ 0 ].SetRect( 0, 0, 100, 100 );
    	squares[ 1 ].SetRect( 100, 0, 200, 100 );
    	squares[ 2 ].SetRect( 200, 0, 300, 100 );
    	squares[ 3 ].SetRect( 0, 100, 100, 200 );
    	squares[ 4 ].SetRect( 100, 100, 200, 200 );
    	squares[ 5 ].SetRect( 200, 100, 300, 200 );
    	squares[ 6 ].SetRect( 0, 200, 100, 300 );
    	squares[ 7 ].SetRect( 100, 200, 200, 300 );
    	squares[ 8 ].SetRect( 200, 200, 300, 300 );
    
    	for( int i = 0; i < 9; i++ )
    	{
    		mark[ i ] = EMPTY;
    	}
    
    	lastGo = EX;
    }
    Really hope to get this one explained to me, cant believe I reached exactly the same problem I had 4 years ago when I did it for the first time!!
    Couldn't think of anything interesting, cool or funny - sorry.

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    8
    Well, I may or may not be considered qualified to reply on this since I program mostly in straight C and have never used MFC...

    If you are just starting out though, why not use static (text) controls with SS_NOTIFY or buttons for the graphic portion of your tic-tac-toe game? I'm guessing simpler is better until you get a working game going.

    Cheers, Mac
    Last edited by MacFromOK; 04-08-2005 at 09:04 PM.

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Well graphical part itself isn't to hard, just a few lines inside rectangles. I just cant see why the window is drawn 400x400, I set the mapping mode to 300x300, yet the clicking only seems to be detected in the first 300x300 pixels. This is why I think its something to do with the mapping mode...
    Couldn't think of anything interesting, cool or funny - sorry.

  4. #4
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    ok I've narrowed it down to the fact that in OnLButtonDown I will receive the device coordinates which may vary depending on window size, etc. How can I convert these to logical coordinates inside a 300x300 range?

    I've tried using CClientDc inside OnLButtonDown and converting them but the values seem unaffected??? Am I missing something in the code?


    Code:
    void TTTWin::OnLButtonDown( UINT nFlags, CPoint point )
    {
    
    	CClientDC dc( this );
    	dc.SetWindowExt( 300, 300 );
    	dc.DPtoLP( &point );
    
    	for( int i = 0; i < 9; i++ )
    	{
    		if( game.mark[ i ] == game.EMPTY && game.squares[ i ].PtInRect( point ) )
    		{
    .
    .
    .
    .
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. TicTacToe board problem
    By Overlord in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2006, 11:17 PM
  4. tictactoe symbol entering problem
    By ademkiv in forum C Programming
    Replies: 1
    Last Post: 03-21-2006, 10:53 AM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21