how to make memory game puzzle (simmon say like)

Started by Tycahal1991, Mon 23/08/2010 21:32:33

Previous topic - Next topic

Tycahal1991

ok so I am new here, and am curently making an adventure game, I will use this type of puzzle alot in my game. I want to make a memory game a bit like simmon say.

I started coding it using a global variable (int) wich I caled Ordervalue.

so for exemple I make a cutscene :

function room_AfterFadeIn()
{
StartCutscene(eSkipESCOnly);{

// I change the views frame to light up the bottons (in 3 difrent colors: the inactive botton and two diferent active bottons)

// botton 1
  Oball1.SetView(2, 0, 2); // active 2
  Wait(15);
  Oball1.SetView(2, 0, 0);// inactive
  Wait(25);

// botton 3
  Oball3.SetView(2, 0, 1); //active 1
  Wait(15);
  Oball3.SetView(2, 0, 0); //inactive
  Wait(25);

//botton 2
  Oball2.SetView(2, 0, 2); //active 2
  Wait(15);
Oball2.SetView(2, 0, 0);//inactive
// I add the global variable some more
ordervalue++;
EndCutscene();


and the I do something like this:

// note: the Mode 9 is a mouse cursor I created
//on click
function Oball1_Mode9()
{
//botton
Oball1.SetView(2, 0, 2); //active 2
Wait(15);
Oball1.SetView(2, 0, 0);//inactive
if (ordervalue==1) {
ordervalue--;
}
else {
Display("you lose");
}
}

-------

this works for a bit but if its larger than 1 or lesser than -1 their isint really a numeric value to put the "if (ordervalue==2)" or "if (ordervalue==-2)"

----
if anyone knows a simpler and pragmatic way of coding this here I would be very thankful.
adicional note: I have searched the forum in search of this issue and fond nothing about it, I think its and important issue to the forum comunity.

I have already created a topic about the game I am developing in adventure related topics >>> http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41585.0 <<<
I would like feedback but if you are quiet its ok too... when its something worthy I will put on "games in developing" area of the forum and possibly make playable demos (alphas, betas etc.) 

Khris

First of all, "if (ordervalue==2)" is perfectly correct, working code.

Doing this like you're doing it now only makes sense if there's going to be exactly one, fixed sequence in the game. If you don't want to randomize it or have more than one, your approach will work (although I personally still wouldn't do it that way).

A quick way of storing simple sequences is using a String. (eg. "3121231").
Say the string was called "sequence". You can access its characters like this:
sequence.Chars[in]
where in is the index, 0 for first letter, sequence.Length-1 for the last.
Since a single character is a char which can be accessed like an int, you can do this:
if (sequence.Chars[in]-48 == 1)  // ASCII value of 1 is 49, asf. 


I'd do this:

Code: ags
String sequence;

// reset sequence, in AfterFadein, after clicking reset button or after getting it wrong
  sequence = "3121231";

function Oball_Mode9() {
// this function will handle clicks on all three balls, i.e. put "Oball_Mode9" in every object's Mode9 event field
  Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);
  if (o == null) return;  // precautionary line for fast mouse movement during click

  // make ball light up here, changing its .Graphic is enough; Views are only needed for animations
  int t = o.ID - 2;  // assuming the ball objects have ID's 3, 4, 5, this translates to 1, 2, 3

  int sl = o.Graphic;
  o.Graphic = t + X;   // replace X with correct value to change ball to their lit sprite
  Wait(15);
  o.Graphic = sl;  // change back to previous sprite graphic
  
  int s = sequence.Chars[0] - 48;  // get first letter

  if (t == s) {    // player clicked next character in sequence
    sequence = sequence.Substring(1, sequence.Length -1);  // remove first character
    if (String.IsNullOrEmpty(sequence))  player.ChangeRoom(?);  // win game
  }
  else {
    // loose / reset sequence
    sequence = "3121231";
  }
}


Note that my code assumes that the ball objects' ID's and their lit graphic slots are consecutively numbered in the same order. This is generally recommended as it makes life much easier.

Tycahal1991

thank you very much for your reply, about the first issue you broght up, yes there is a fixed sequence for each "level/puzzle" and sound will be a important element, as the grafics will be all the same for the bottons, only changing the position of them in the room.

the string may defenetly help to make a smaller code  :)

just one last question: Sound can be coded in the changing grafics part, right? but if every botton has a diferent sound, doesnt that mean I have to split code to each character in the sequence? if so, is it easy to code it that way  like:

if (sequence.Char(1)) {
play.sound(1);
}

sorry its dificult for me to picture the code, but if I make it the way I was making before it I would work, it would also take a lot of time coding.

Khris

You can write a function that plays back a sequence using a String, yes.
You'd use a while loop that iterates through the characters and changes the appropriate object graphic and plays the sound.

Tycahal1991

#4
if a string char is 10 or plus (more than one logoritim) does it work? how will he tell the difrence from two 1's and a 11?
can a comma do the job?

Khris

You can use two chars for each number, i.e. 3 6 12 would become "030612".
In the loop, add 2 two i each iteration and read the number using:

Code: ags
  n = sequence.Chars[i]*10 + sequence.Chars[i+1];


Since you're using a fixed number of characters there's no need for a separator.

GarageGothic

Actually, since a single char can store any number from 0-255, you would only need one String char for each value (even double-digit ones).

SMF spam blocked by CleanTalk