How do I noughts and crosses

Get help using Construct 2

Post » Mon May 18, 2015 10:52 pm

Welcome all. Construct2 the best! :D
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
14
S
2
Posts: 66
Reputation: 776

Post » Mon May 18, 2015 11:19 pm

ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Tue May 19, 2015 12:08 am

Very hard. :(
B
14
S
2
Posts: 66
Reputation: 776

Post » 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
252
S
39
G
15
Posts: 1,965
Reputation: 40,765

Post » 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
92
S
32
G
110
Posts: 5,295
Reputation: 71,501


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, dand, tinhofiel and 32 guests