Sign in to follow this  
jakobnator

Tictactoe check if spot taken?

Recommended Posts

jakobnator    99
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][/size][/color]
[color=#1C2837][size=2][color=#000088]class[/color][color=#000000] [/color][color=#660066]Target[/color][color=#000000]
[/color][color=#666600]{[/color][color=#000000]
[/color][color=#000088]private[/color][color=#666600]:[/color][color=#000000]
SDL_Rect box[/color][color=#666600];[/color][color=#000000]
[/color][color=#000088]public[/color][color=#666600]:[/color][color=#000000]
[/color][color=#000088]bool[/color][color=#000000] taken[/color][color=#666600];[/color][color=#000000]
[/color][color=#660066]Target[/color][color=#666600]([/color][color=#000088]int[/color][color=#000000] x[/color][color=#666600],[/color][color=#000088]int[/color][color=#000000] y[/color][color=#666600],[/color][color=#000088]int[/color][color=#000000] h[/color][color=#666600],[/color][color=#000000] [/color][color=#000088]int[/color][color=#000000] w[/color][color=#666600]);[/color][color=#000000]
[/color][color=#000088]void[/color][color=#000000] handle_events[/color][color=#666600]();[/color][color=#000000]
[/color][color=#666600]};[/color][/size][/color]
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][color=#000000] [/color][color=#660066]Target[/color][color=#666600]::[/color][color=#000000]handle_events[/color][color=#666600]()[/color][color=#000000]
[/color][color=#666600]{[/color][color=#000000]
[/color][color=#000088]int[/color][color=#000000] x [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]0[/color][color=#666600],[/color][color=#000000]y [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]0[/color][color=#666600];[/color][color=#000000]
[/color][color=#000088]if[/color][color=#000000] [/color][color=#666600]([/color][color=#000088]event[/color][color=#666600].[/color][color=#000000]type [/color][color=#666600]==[/color][color=#000000] SDL_MOUSEBUTTONDOWN[/color][color=#666600])[/color][color=#000000]
[/color][color=#666600]{[/color][color=#000000]
x [/color][color=#666600]=[/color][color=#000000] [/color][color=#000088]event[/color][color=#666600].[/color][color=#000000]motion[/color][color=#666600].[/color][color=#000000]x[/color][color=#666600];[/color][color=#000000]
y [/color][color=#666600]=[/color][color=#000000] [/color][color=#000088]event[/color][color=#666600].[/color][color=#000000]motion[/color][color=#666600].[/color][color=#000000]y[/color][color=#666600];[/color][color=#000000]

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

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

Share this post


Link to post
Share on other sites
matt3d    137
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

[code]
board[3][3];

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

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

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

[/code]

Share this post


Link to post
Share on other sites
Trienco    2555
[quote name='jakobnator' timestamp='1302741834' post='4798213']
Any way possible without starting over?
[/quote]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this