View Full Version : How to create random and checking arrays
yan905
07-02-2008, 10:00 AM
Hi all, i am new, please help me out.
First of all I need to create a game that involves 4 players. Is this possible as i always see only two player game in flash.
Second, i need to create 52 movie clips appearing at random upon button click, its like a quiz once player A answers the question which is in mc (when they click on correct button will add to the score) and move on to player B then C then D and come back to A. Thing is i do not want the randomnised mc to appear twice, so once its correctly answered it should be marked as done, but if the player didnt get the correct answer it will go back to the pool of random mc. I hope you know what i mean.
I am kinda lost as to how to get started. Please enlightened me.. Thank you!!
GMaker0507
07-02-2008, 03:50 PM
your doing a quiz game? Are you using xml? That would make it easy to do the questions?
NOTE: flash already has 3 quiz templates.They should be viewable from the start screen. They dont use xml, but they should be of some help
But based on your post
First create a blank array. This will hold all the numbers of the available questions
var usableNumbers:Array=new Array()
Populate it with all the integers from 1 to 52
for(var i=0;i<52;i++)
{
useableNumbers.push(i+1)
}
Create another array that will hold the numbers of questions that cant be used
var nonUsableNumbers:Array=new Array()
When you want a random number within the array
var rNumIndex:Number=Math.floor(Math.random()*(useable Numbers.length-1))
var randomNumber = useAbleNumbers[rNumIndex]
then when you want to find a certain number in the usableNumbers array:
/*This function finds the index of the specified number in the useableNumbers array. If it doesnt exist in the array it returns -1.
NOTE: NO VALUE IN A ARRAY CAN HAVE AN INDEX OF OVER ZERO.
NOTE: IF YOUR USING AS3, YOU COULD USE ITS 'Array.indexOf()' METHOD INSTEAD OF THIS, BUT FOR AS2, I THINK YOU HAVE TO DO THIS*/
function FindNumber(numberToFind:Number)
{
for(var i=0;i<useableNumbers.length;i++)
{
if(useableNumbers[i]==numberToFind)
{
return i
}
}return -1
}
Then you should make sure all your question mc's have the same name but a different number, like Question1, Question2, Question3,etc...
finally attach movieclips like so
var qNumber=5
var mcName:String="Question"+qNumber
_root.attachMovie(mcName,mcName,_root.getNextHighe stDepth())
I cant really code the game for you, as its your game, so ill leave the rest to you, if you have any questions reply or send me a pm
yan905
07-04-2008, 03:52 AM
Hi, thank you so much, that kinda help clear some clouds, as i am not even sure how to begin. I am not even familiar with arrays..thats a lot of code to digest, i will write in soon after i explore the scripts.. Thank you!!
Oh for the quiz maker in flash its too quizies..what i wanted to do is a game like card game with 4 players and 4 score boards displayed..The pictures need to be in random but also need to be taken from external..so we can always change the picture, but the challenge is the picture shown needs to correspond with the answers, there will be 4 standard answer like a multiple choice when player sees the card they need to click to choose from the 4 answers if we randomnised how can the actionscript tells which picture to what answers do i need to create some kind of database? When you said using xml, what whould i store in xml? Thanks really appreciate the help.
GMaker0507
07-04-2008, 03:28 PM
So let me clearify that i fully understand you.
The sentences below with the 'A' or 'B' are what im a little confused about
You have one question, which will be displayed with four choices.
Those choices are (A) The same with every question and just have different images, or (B) different and can vary.
You want each choice to have (A) Its own specific image for it, or (B) a general set of images that correspond to it, which one will randomly be chosen for.
yan905
07-07-2008, 03:05 AM
Its most likely A. Sorry for the confusion. I will just set the whole scenario.
There will be 4 players (each own has a turn) playing this game. The 52 questions are using pictures... the players are given 4 choices for their answers (these 4 answers are the same for all 52) The question will be by looking at a picture that is given not in order (random) they choose from the four answer which category this picture belongs to. When the player has chosen the answer if its correct it will add to the player score board, if its wrong answer the picture will go back to the tray and later on can be used again, but those picture that has gotten the right answer shoul not appear anymore, that is why i need to have function to check if they already answers the card correctly the card will not be displayed again.
Player will answer one question each turn. They will take turns playing in the same swf so how do i make 4 players? Using arrays?
I hope this is clear explaination, thanks for helping.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.