• Posts: 196
• Loc: Portugal

3+ Months Ago

Hello guys.

I have to build this flash game for a client, I've never done anything similar to this, but I was asked to do it and I want to get it done, maybe learn something new in the process too.

Anyway, this game involves matching a currency with its country.

The player is shown a coin, and needs to select the right country, simple as that, I have already made this simple game, it has a score and a countdown too.

My biggest problem now is, I have to make the countries random, AND the coins aswell, for example, Spain has the euro currency, they have the 2€ coin, 1€ coin, 0.50€ coin and what not, so the game is supposed to show you ONE of these coins per country, it needs to select one at random.

So basically this is what I'm looking for:

1 Game starts,
2 Game randomly picks a country,
3 Game randomly picks a coin of chosen country (this bit I can manage I think),
4 Player clicks a country flag,
5 Game picks a new country, randomly, and respective random coin
6 Repeat from step 4

My problem lies in step 2... each country can only be shown once, therefore if Spain gets picked by the game at round 1, it will not be picked again in any of the rounds, but I don't know how to do this, when I randomize it, the countries repeat sometimes, any thoughts?
• Guru
• Posts: 1253
• Loc: Ro

3+ Months Ago

it's not that hard. create a random number smaller than the number of countries.
and check if it's in the AlreadyDisplayedArray. if it's not, place it in the AlreadyDisplayed array, otherwise create it again.
i.e:
Code: [ Select ]
nCount = 0; // current number of shown countries
do
{
rndNumber = (Math.round(Math.random()*100) ) % nrCountries;
{
nCount++;
break;
}

}
while (rndNumber in DisplayedArrays)
1. nCount = 0; // current number of shown countries
2. do
3. {
4.   rndNumber = (Math.round(Math.random()*100) ) % nrCountries;
6.   {
8.     nCount++;
9.     break;
10.   }
11.
12. }
13. while (rndNumber in DisplayedArrays)

and InAlreadyDisplayedArray function will return true if the parameter number is in the array, false otherwise[/code]

Post Information

• Total Posts in this topic: 2 posts
• Users browsing this forum: No registered users and 10 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum