Jump to content
  • Advertisement
Sign in to follow this  
jakobnator

Tictactoe check if spot taken?

This topic is 2776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry no code snippets bb code the editor isn't working.
My tic tac toe is having trouble checking if there is a spot taken or not, I think this is the problem

heres the position class
[color=#1C2837][size=2]
[color=#1C2837][size=2][color=#000088]class[color=#000000] [color=#660066]Target[color=#000000]
[color=#666600]{[color=#000000]
[color=#000088]private[color=#666600]:[color=#000000]
SDL_Rect box[color=#666600];[color=#000000]
[color=#000088]public[color=#666600]:[color=#000000]
[color=#000088]bool[color=#000000] taken[color=#666600];[color=#000000]
[color=#660066]Target[color=#666600]([color=#000088]int[color=#000000] x[color=#666600],[color=#000088]int[color=#000000] y[color=#666600],[color=#000088]int[color=#000000] h[color=#666600],[color=#000000] [color=#000088]int[color=#000000] w[color=#666600]);[color=#000000]
[color=#000088]void[color=#000000] handle_events[color=#666600]();[color=#000000]
[color=#666600]};
and heres the handle events function, I think I am not aloud to make something effect all classes is that why its not working?
[color=#1C2837][size=2][color=#000088]void[color=#000000] [color=#660066]Target[color=#666600]::[color=#000000]handle_events[color=#666600]()[color=#000000]
[color=#666600]{[color=#000000]
[color=#000088]int[color=#000000] x [color=#666600]=[color=#000000] [color=#006666]0[color=#666600],[color=#000000]y [color=#666600]=[color=#000000] [color=#006666]0[color=#666600];[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#000088]event[color=#666600].[color=#000000]type [color=#666600]==[color=#000000] SDL_MOUSEBUTTONDOWN[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
x [color=#666600]=[color=#000000] [color=#000088]event[color=#666600].[color=#000000]motion[color=#666600].[color=#000000]x[color=#666600];[color=#000000]
y [color=#666600]=[color=#000000] [color=#000088]event[color=#666600].[color=#000000]motion[color=#666600].[color=#000000]y[color=#666600];[color=#000000]

[color=#000088]if[color=#666600]([color=#000000] [color=#000088]event[color=#666600].[color=#000000]button[color=#666600].[color=#000000]button [color=#666600]==[color=#000000] SDL_BUTTON_LEFT [color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
x [color=#666600]=[color=#000000] [color=#000088]event[color=#666600].[color=#000000]button[color=#666600].[color=#000000]x[color=#666600];[color=#000000]
y [color=#666600]=[color=#000000] [color=#000088]event[color=#666600].[color=#000000]button[color=#666600].[color=#000000]y[color=#666600];[color=#000000]
[color=#000088]if[color=#666600]([color=#000000] [color=#666600]([color=#000000] x [color=#666600]>[color=#000000] box[color=#666600].[color=#000000]x [color=#666600])[color=#000000] [color=#666600]&&[color=#000000] [color=#666600]([color=#000000] x [color=#666600]<[color=#000000] box[color=#666600].[color=#000000]x [color=#666600]+[color=#000000] box[color=#666600].[color=#000000]w [color=#666600])[color=#000000] [color=#666600]&&[color=#000000] [color=#666600]([color=#000000] y [color=#666600]>[color=#000000] box[color=#666600].[color=#000000]y [color=#666600])[color=#000000] [color=#666600]&&[color=#000000] [color=#666600]([color=#000000] y [color=#666600]<[color=#000000] box[color=#666600].[color=#000000]y [color=#666600]+[color=#000000] box[color=#666600].[color=#000000]h [color=#666600])[color=#000000] [color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Turn[color=#000000] [color=#666600]==[color=#000000] [color=#000088]true[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Target[color=#666600]::[color=#000000]taken [color=#666600]==[color=#000000] [color=#000088]false[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
apply_surface[color=#666600]([color=#000000]box[color=#666600].[color=#000000]x[color=#666600],[color=#000000]box[color=#666600].[color=#000000]y[color=#666600],[color=#000000]target_X[color=#666600],[color=#000000]screen[color=#666600]);[color=#000000]
[color=#660066]Turn[color=#000000] [color=#666600]=[color=#000000] [color=#000088]false[color=#666600];[color=#000000]
[color=#660066]Target[color=#666600]::[color=#000000]taken [color=#666600]=[color=#000000] [color=#000088]true[color=#666600];[color=#000000]
[color=#666600]}[color=#000000]
[color=#666600]}[color=#000000]
[color=#000088]else[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Turn[color=#000000] [color=#666600]==[color=#000000] [color=#000088]false[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Target[color=#666600]::[color=#000000]taken [color=#666600]==[color=#000000] [color=#000088]false[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
apply_surface[color=#666600]([color=#000000]box[color=#666600].[color=#000000]x[color=#666600],[color=#000000]box[color=#666600].[color=#000000]y[color=#666600],[color=#000000]target_O[color=#666600],[color=#000000]screen[color=#666600]);[color=#000000]
[color=#660066]Turn[color=#000000] [color=#666600]=[color=#000000] [color=#000088]true[color=#666600];[color=#000000]
[color=#660066]Target[color=#666600]::[color=#000000]taken [color=#666600]=[color=#000000] [color=#000088]true[color=#666600];[color=#000000]
[color=#666600]}[color=#000000]
[color=#666600]}[color=#000000]
[color=#000088]else[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Target[color=#666600]::[color=#000000]taken [color=#666600]==[color=#000000] [color=#000088]true[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Turn[color=#000000] [color=#666600]==[color=#000000] [color=#000088]true[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
[color=#660066]Turn[color=#000000] [color=#666600]=[color=#000000] [color=#000088]false[color=#666600];[color=#000000]
[color=#666600]}[color=#000000]
[color=#000088]else[color=#000000]
[color=#000088]if[color=#000000] [color=#666600]([color=#660066]Turn[color=#000000] [color=#666600]==[color=#000000] [color=#000088]false[color=#666600])[color=#000000]
[color=#666600]{[color=#000000]
[color=#660066]Turn[color=#000000] [color=#666600]=[color=#000000] [color=#000088]true[color=#666600];[color=#000000]
[color=#666600]}[color=#000000]
[color=#666600]}[color=#000000]

[color=#666600]}[color=#000000]
[color=#666600]}[color=#000000]
[color=#666600]}[color=#000000]

Share this post


Link to post
Share on other sites
Advertisement
I'd think you'd need to first initialize tic tac toe board as a multidimensional array like and fill it up with 0's for blank, then you can apply 1's for Xs and 2's for Os


board[3][3];

for(int i = 0 ; i < 3 ; i++)
for(int j = 0 ; j < 3 ; j++)
board[j] = 0;



void setBoard(int x, int y, int pieceType)
{
board[x][y] = pieceType;
}

int getBoard(int x, int y)
{
return board[x][y];
}

Share this post


Link to post
Share on other sites

Any way possible without starting over?


While I think you should eventually do just that and this time try to strictly seperate game logic from gui and even that from rendering (ie. clicking a target tells the game "set cell #x for current player" and the grid is passed to a renderer for display)... did you ever initialize taken in your constructor? Where is it going wrong when you debug?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!