How do I testfor 3 in a row

Get help using Construct 2

Post » Sun Oct 23, 2016 10:53 pm

So I'm making tic tac toe and cannot figure out how to know if there is 3 of the X's or O's in a row. That's it.
B
7
Posts: 2
Reputation: 279

Post » Tue Oct 25, 2016 1:55 am

@Fuzzywuzzy

Hi,
Since there are only 8 possible ways of winning a tic-tac-toe game (3 verticals, 3 horizontals and 2 diagonals), I would use a 3 by 3 array to check the value of each square. Here is an example of a simple tic-tac-toe game:

https://www.dropbox.com/s/5q2aulhuxnsbe ... .capx?dl=0

There are many different ways to go about this, but to me, this was the simplest. I hope this helps.
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Tue Oct 25, 2016 9:04 am

Although I love an array, you can do this without, using an animation that runs through those 8 configurations. Here's how:

Make sure your Xs and Os have collision boundaries less than half the size of one game square
Make a new sprite, WinStateChecker, and give it eight animation frames
Make each animation frame a line which corresponds to a win-state (as Simone says, 3 vertical, 3 horizontal and two diagonal)
Set the collision boundaries of the sprite to match the lines of the animation frames
After each turn, set the WinStateChecker's frame number to 0 then:

Sprite: Gamepiece - (your Xs and Os)
Instance Variable: Gamepiece.Player - (a number variable which indicates the owner of the piece)
Local Variable: CurrentPlayer - (a number variable telling which player played the last piece)

If Gamepiece overlapping WinStateChecker
CurrentPlayer = Gamepiece.Player
Gamepiece.PickedCount = 3

A positive check on those conditions should indicate a win-state.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306


Return to How do I....?

Who is online

Users browsing this forum: Unconnected and 23 guests