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.
Posts: 2
Reputation: 279

Post » Tue Oct 25, 2016 1:55 am


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: ... .capx?dl=0

There are many different ways to go about this, but to me, this was the simplest. I hope this helps.
Posts: 74
Reputation: 4,145

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.
<iframe frameborder="0" src="" width="552" height="167"></iframe>
Posts: 254
Reputation: 2,389

Return to How do I....?

Who is online

Users browsing this forum: stellko and 3 guests