# How do I noughts and crosses

Get help using Construct 2

### » Mon May 18, 2015 10:52 pm

Welcome all. Construct2 the best!
My problem:
I cannot imagine how there could be a noughts and crosses to make a game the construct2 with a program.
Help to understand his logic for me.
B
16
S
2
Posts: 78
Reputation: 850

### » Mon May 18, 2015 11:19 pm

B
72
S
22
G
290
Posts: 3,885
Reputation: 159,511

Very hard.
B
16
S
2
Posts: 78
Reputation: 850

### » Tue May 19, 2015 7:43 am

LordViperion nothing in life is EASY as pie blackhornet gave you link learn from it. blackhornet cannot teach you or write a game for you. blackhornet only can guide you
B
269
S
52
G
16
Posts: 2,045
Reputation: 44,069

### » Tue May 19, 2015 8:10 pm

You could also do something tricky like this:
https://dl.dropboxusercontent.com/u/542 ... ctoe2.capx

But really tic tac toe is rathar simple although tedious. I like to opt for as few object types as possible but you could just as well just make a sprite per location.

Each sprite will have 3 animation frames "blank", "x" and "o". Be sure to set the animation speed to 0 so the frames don't change.

Placing an x or o is just a matter of using the event:
on sprite clicked
--- set animation frame to 1 or 2

I used a variable to keep track of whose turn it is, and switched it every time a player placed a piece.

global number turn=1
on sprite clicked
--- set animation frame to turn
--- set turn to 3-turn

Setting turn to 3-turn is just a simple way to toggle turn between the values 2 and 1.

Next comes the tedious part of checking for a win. It's very simple in concept, just look at each row,column and diagonal and see if there's three x's or o's in any of them. This is where you choose an approach you like.

One way is to use an array that you set from the visible x' and o's. This then makes it simpler to write like other programming languages, so you can check certain locations.
Here's an incomplete example of a very verbose way of checking for each win, for each player.
https://dl.dropboxusercontent.com/u/542 ... ctoe3.capx
Using loops help a lot to simplify things, and blackhornet's tutorial does just that.

Another way as I have done is to utilize picking to pick a row, column or diagonal in some way like I did.
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514