Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2012, 11:54 PM   PM User | #1
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
Tic-Tac-Toe detecting 3-in-a-row programming

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.
__________________
Element ID

Webs Support Helper

Your friendly neighborhood Taroman.

Last edited by Taro; 03-20-2012 at 12:55 AM.. Reason: forgot something
Taro is offline   Reply With Quote
Reply

Bookmarks

Tags
collision, game, maker, vip

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:15 AM.


Advertisement
Log in to turn off these ads.