0 Reputation

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

Forum Home > Construct 2 General > How do I....?
Author
Topic Search   Topic Options
3,386 Rep
Post Options    Quote  Reply 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

8,519 Rep
Post Options    Quote  Reply 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
5,793 Rep
Post Options    Quote  Reply 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...
11,750 Rep
Post Options    Quote  Reply 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
8,519 Rep
Post Options    Quote  Reply 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
11,750 Rep
Post Options    Quote  Reply Posted: 01 Jan 2012 at 3:18pm

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
8,519 Rep
Post Options    Quote  Reply Posted: 01 Jan 2012 at 3:42pm
 Yann wrote:Ok I added sound :Dhaha 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
11,750 Rep
Post Options    Quote  Reply 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.

Moderator
28,452 Rep
Post Options    Quote  Reply Posted: 01 Jan 2012 at 4:25pm
3,386 Rep
Post Options    Quote  Reply Posted: 01 Jan 2012 at 10:12pm
Thanks everyone for helping me grasp this.

 Forum Jump -- Select Forum --  Arcade  Construct 2 general  How do I....?  Your Creations  Education  Bugs   - Closed bugs  Plugins for Construct 2  Javascript SDK development  Open Topic  General game design  Tools/resources  Website issues  Help Wanted  Construct Classic Discussion   - Help & Support using Construct Classic   - Your tutorials & example files   - Your Creations   - Completed addons   - Work-in-progress addons   - Construct engineering Forum Permissions You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot delete your posts in this forumYou cannot edit your posts in this forumYou cannot create polls in this forumYou cannot vote in polls in this forum