LESSON 12 HELP

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

LESSON 12 HELP

Post by leroy109109109 » July 11th, 2012, 4:17 pm

Hey i have been having a bit of a problem with lesson 12 iv'e gotten up to the end game function but when try to play the play the game the 'X' icon always comes out as an 'Xwins' icon any ideas as to what i've done wrong? :|

simplicity
Posts: 18
Joined: July 10th, 2012, 6:55 pm

Re: LESSON 12 HELP

Post by simplicity » July 11th, 2012, 5:33 pm

leroy109109109 wrote:Hey i have been having a bit of a problem with lesson 12 iv'e gotten up to the end game function but when try to play the play the game the 'X' icon always comes out as an 'Xwins' icon any ideas as to what i've done wrong? :|
Can you post your code. It can be any number of errors that can be causing it.

leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

Re: LESSON 12 HELP

Post by leroy109109109 » July 11th, 2012, 6:26 pm

Ok ill try

leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

Re: LESSON 12 HELP

Post by leroy109109109 » July 11th, 2012, 6:27 pm

#pragma once

#include "D3DGraphics.h"
#include "Keyboard.h"

class Game
{
public:
Game( HWND hWnd,const KeyboardServer& kServer );
void Go();
private:
enum XOState
{
EMPTY,
X,
O
};
private:
void ComposeFrame();
void DrawGrid(int x, int y);
void DrawX(int x, int y);
void DrawO(int x, int y);
void DrawCursor( int x, int y);

void SetSquareState( int index,XOState state);
XOState GetSquareState( int index);
void SetSquareState(int ix,int iy,XOState state);
XOState GetSquareState( int ix, int iy );
void DoUserInput();
void EndTurn();
XOState CheckForVictory();
void DrawToilet(int x,int y);
void DrawTie(int x,int y);
void DrawOwin(int x,int y);
void DrawXwin(int x,int y);
void DrawEndScreen(int x,int y,XOState state);
/********************************/
/* User Functions */


/********************************/
private:
D3DGraphics gfx;
KeyboardClient kbd;
/********************************/
/* User Variables */
XOState s0;
XOState s1;
XOState s2;
XOState s3;
XOState s4;
XOState s5;
XOState s6;
XOState s7;
XOState s8;
bool keysPressedLastFrame;
int cursorX;
int cursorY;
XOState activePlayer;
/********************************/
};

simplicity
Posts: 18
Joined: July 10th, 2012, 6:55 pm

Re: LESSON 12 HELP

Post by simplicity » July 11th, 2012, 6:29 pm

leroy109109109 wrote:Ok ill try
Paste it in the code function please. There is a tag called code.

Also post your game.cpp code.

leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

Re: LESSON 12 HELP

Post by leroy109109109 » July 11th, 2012, 6:30 pm

kk

Code: Select all

void Game::EndTurn()
{
	if(activePlayer == X)
	{
      activePlayer = O;
	}
	else
	{
		activePlayer = X;
	}
}
Last edited by leroy109109109 on July 12th, 2012, 12:16 pm, edited 1 time in total.

leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

Re: LESSON 12 HELP

Post by leroy109109109 » July 11th, 2012, 6:37 pm

K here it is(my code) in the attachment.

Code: Select all

void Game::DoUserInput()
{
if(!keysPressedLastFrame)
{
if(kbd.RightIsPressed() )
  {
    keysPressedLastFrame = true;
    cursorX++;
	if(cursorX > 2)
	{
		cursorX = 2;
	}
  }
  if(kbd.LeftIsPressed() )
  {
	keysPressedLastFrame = true;
	cursorX--;
	if(cursorX < 0)
	{
		cursorX = 0;
	}
  }
  if(kbd.DownIsPressed() )
  {
    keysPressedLastFrame = true;
	cursorY++;
	if(cursorY > 2)
	{
		cursorY = 2;
	}
  }
  
  if(kbd.UpIsPressed() )
  {
    keysPressedLastFrame = true;
    cursorY--;
	if(cursorY < 0)
	{
		cursorY = 0;
	}
  }
}
Last edited by leroy109109109 on July 12th, 2012, 12:18 pm, edited 1 time in total.

leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

Re: LESSON 12 HELP

Post by leroy109109109 » July 11th, 2012, 6:39 pm

I put it in an attachment because i couldn't paste it since it was two many words

not sure if the attachment is working though(sorta new to this)

Code: Select all

Game::XOState Game::CheckForVictory()
{
	if (s0 == s1 && s1 == s2 && s0 != EMPTY)
	{
	   return s0;
	}
	else if (s3 == s4 && s4 == s5 && s3 != EMPTY)
	{
	   return s0;
	}
	else if (s6 == s7 && s7 == s8 && s6 != EMPTY)
	{
	   return s0;
	}

	else if (s0 == s3 && s3 == s6 && s0 != EMPTY)
	{
	   return s0;
	}
	else if (s1 == s4 && s4 == s7 && s1 != EMPTY)
	{
	   return s1;
	}
	else if (s2 == s5 && s5 == s8 && s2 != EMPTY)
	{
	   return s2;
	}
	else if (s0 == s4 && s4 == s8 && s0 != EMPTY)
	{
	   return s0;
	}
	else if (s2 == s4 && s4 == s6 && s2 != EMPTY)
	{
	   return s2;
	}
	else
	{
		return EMPTY;
	}
}

leroy109109109
Posts: 11
Joined: July 11th, 2012, 2:34 pm

Re: LESSON 12 HELP

Post by leroy109109109 » July 12th, 2012, 12:20 pm

Code: Select all

void Game::ComposeFrame()
{
   const int baseX = 250;
   const int baseY = 150;
   const int squareSize = 100;
    
   XOState victoryState = CheckForVictory();
	if(victoryState == EMPTY)
	{
    DoUserInput( );
	DrawCursor(baseX + cursorX * squareSize,baseY + cursorY * squareSize);
	}
		else
	{
		DrawEndScreen(358,495,victoryState );
	}
  DrawGrid(baseX,baseY);
  for(int iy = 0;iy < 3;iy++)
     {
	   for(int ix = 0; ix < 3;ix++)
	  {
        if( GetSquareState( ix,iy) == X )
		{
	        DrawX(baseX + ix * squareSize,baseY + iy * squareSize );
        }
		else if(GetSquareState( ix,iy) == O )
	    {
            DrawO(baseX + ix * squareSize,baseY + iy * squareSize );
        }
	  }
    } 
}

Post Reply