Hello,
I've been developing a Tic-Tac-Toe game using Gamemaker. I have a problem with detecting if any 3 'X' makes a diagonal, column, or row. Here is the simplified code for taking turns between 'X' and 'O'.
Code:
Information about object: obj_?
Sprite: spr_?
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
set the score to 0
set the information in the window caption:
show score with caption _turns:
don't show lives with caption _Lives:
don't show health with caption _health:
Mouse Event for Left Pressed:
set the sprite to spr_?_3 with subimage image_index and speed 1
Mouse Event for Right Pressed:
set the sprite to spr_?_3 with subimage image_index and speed 1
Mouse Event for Left Released:
if score is equal to 0
change the instance into object obj_x, not performing events
set the score to 1
else
if score is equal to 1
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 2
change the instance into object obj_x, not performing events
set the score relative to 1
else
if score is equal to 3
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 4
change the instance into object obj_x, not performing events
set the score relative to 1
else
if score is equal to 5
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 6
change the instance into object obj_x, not performing events
set the score relative to 1
else
if score is equal to 7
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 8
change the instance into object obj_x, not performing events
set the score relative to 1
else
if score is equal to 9
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
Mouse Event for Right Released:
if score is equal to 1
change the instance into object obj_o, not performing events
set the score relative to 1
else
if score is equal to 2
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 3
change the instance into object obj_o, not performing events
set the score relative to 1
else
if score is equal to 4
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 5
change the instance into object obj_o, not performing events
set the score relative to 1
else
if score is equal to 6
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 7
change the instance into object obj_o, not performing events
set the score relative to 1
else
if score is equal to 8
save the game in the file savegame
go to room rm_warning with transition effect <no effect>
if score is equal to 0
display message: Other user goes first in this mode.
Mouse Event for Mouse Enter:
set the sprite to spr_?_2 with subimage image_index and speed 1
Mouse Event for Mouse Leave:
set the sprite to spr_? with subimage image_index and speed 1
One suggestion I was thinking about was to create an object overlay in the specified room, then program a collision with an isolated, differential object.
I would additionally appreciate any C, C#, or C++ coding as well.
Code:
x= obj_1
y= obj_2
z= obj_3
...
then
game_end()
I was trying to say that object one collides with x at a certain point, then convert it to a number, each assigned to a different point in the room.