How do I do a while loop for a turn based game

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply
Author
3,386 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Topic: How do I do a while loop for a turn based game
    Posted: 01 Jan 2012 at 9:21am
Having a hard time wrapping my ageing brain around this concept in the event system.

So what I am trying to do is a simple memory game like Simon

http://en.wikipedia.org/wiki/Simon_(game)

Basically, the computer takes its turn, giving you a sequence to memorize, and then the player responds and attempts to duplicate. If the player is successful, the computer then repeats the sequence and adds one more step.

I get that you can build an array, adding a random additional turn each time.

What I am having a hard time figuring out is how do you confine things to turns within a loop.

So

Computer takes turn, blinks one of four boxes.

Then we wait for player response

If player is correct
-computer repeats the original pattern, and adds one more, and then waits for the player.

player takes his turn

and so on

Back to Top
8,519 Rep
Post Options Post Options   Quote Weishaupt Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 9:40am
How about creating a statusvariable that will be comepare to a countvariable. So for example, if you expect the user to hit 4 button, have the count set to 4 ans increase the status by one, whenever the user hits the button. So you should be able to "create an event" to react to....
_____________________
You want help? Post your CAPX!

virtus junxit mors non separabit
Back to Top
5,793 Rep
Post Options Post Options   Quote harrio Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 12:22pm
@gazoogle,
i'm sure others will better define the answer, but i don't think you need a classic loop to accomplish this. that's the beauty of the event system. you could simply cycle between the two; computer and player. with rules defining how they complete their turn.

example...
-setup array at beginning
-setup variable for 'sequence' at beginning

-computer add to 'sequence' random color
-computer play 'sequence'

-prompt player to copy 'sequence'
-check if player 'sequence' matched computer sequence or not

this is very vague pseudo code, but it should give you an idea of haw to proceed.

hope it helps...
Back to Top
11,750 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 1:15pm
wrapped that up. Sorry no sound

http://dl.dropbox.com/u/23551572/C2/Simon.capx

To answer your question, I believe that what you call a "while loop" in this case, is the game loop. Every tick, all the event are evaluated

Edited by Yann - 01 Jan 2012 at 3:34pm
Back to Top
8,519 Rep
Post Options Post Options   Quote Weishaupt Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 2:22pm
So Yann beat me to that

Anyhow, I compiled a tutorial for the "Simon" challenge...

Tutorial

Edited by Weishaupt - 01 Jan 2012 at 2:23pm
_____________________
You want help? Post your CAPX!

virtus junxit mors non separabit
Back to Top
11,750 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 3:18pm
Ok I added sound :D

haha I'm wasting my time on it now :D
http://dl.dropbox.com/u/23551572/C2-Games/Simon/index.html

Edited by Yann - 01 Jan 2012 at 3:37pm
Back to Top
8,519 Rep
Post Options Post Options   Quote Weishaupt Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 3:42pm
Originally posted by Yann Yann wrote:

Ok I added sound :D

haha I'm wasting my time on it now :D


pffff...

Very nice, especially the artwork. One can tell, that this is your profession



_____________________
You want help? Post your CAPX!

virtus junxit mors non separabit
Back to Top
11,750 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 4:04pm
Well... I'm a 3D modeler in a game company :D... Soooo not my profession but I indeed went to artschool :D

I'm sure you like the curves and the colors. Of course the design is all mine.
Back to Top

Moderator
28,452 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 4:25pm
Back to Top
3,386 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 01 Jan 2012 at 10:12pm
Thanks everyone for helping me grasp this.   
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down