PDA

View Full Version : Basic Array/Game help

Fewmitz
03-15-2007, 09:28 PM
Here's the thing, I have a Quarter Final to do (custom game, basically), and this class is REALLY basic, as in we haven't even gotten to arrays yet. So here's my question:

I chose Simon, as in Simon Says. I've looked at some sample code, and i've fiddled with arrays before, and I think I got the basics, but it's nothing concrete, which kinda puts me out of luck.

'Cause, what I was thinking of defining a variable as an array, and setting its length to a variable (the one that keeps track of score/round/turn #) and then setting everything to a random number 1-4 to have it choose which picture it "clicks".

Woo, wall of text, anyway, here are the things I'm not sure how to do:

~Set an array to a length predetermined to a variable, and have every element of the array equal the same thing
~Once that's done, record that the selected square takes up part of an element
~Set each of the user's clicks to an array's element
~When I calculate the random number, how to record that a selected square has been "clicked" so that it flashes and records it's value in the array

I feel dumb asking for help...but anything offered is appreciated.

03-15-2007, 09:35 PM
Are you looking for help in writing such a "Game" using JavaScript? Regardless, it would definitely help if you posted a portion of the code you need help with, instead of just a description of what you need help with. This gives us something to work with, and also, tells us you're not asking others to basically do your assignment for you.

Twey
03-15-2007, 09:55 PM
~Set an array to a length predetermined to a variable, and have every element of the array equal the same thingArrays in Javascript don't have predefined lengths, you simply create elements as necessary:
var numels = 5, arr = [];
for(var i = 0; i < numels; ++i)
arr.push("Some value");
~Once that's done, record that the selected square takes up part of an elementWhat do you mean, "takes up part of an element?"
~Set each of the user's clicks to an array's elementSet a user's click? You can't modify a user's actions without some form of mind control over the user...
~When I calculate the random number, how to record that a selected square has been "clicked" so that it flashes and records it's value in the arrayGive it a border, leave it there for a while, then remove it, using CSS and setTimeout(). I don't understand what this has to do with random numbers though.

Fewmitz
03-16-2007, 06:57 PM
In regards to the first part:

I'm not sure what that Code does...exactly....

Uh, as for the rest, it was late, and I just realized how bad I worded my question, sorry.

By "element" I mean like..

var x = new Array()
x[0]= This is what I meant by an element

And I didn't mean set a user's click as in...make them do something, I meant that when they click a square/button, it will be recorded as part of an array with which I can compare to the computer's generated sequence.

The third part: It's going to like...flash...not necessarily have a border. Like I said, this is basic javascript, so I don't know about setTimeout, but I'll look that up. And I meant generating a random number so that the PC "clicks" a random square.

For reference, this is the code I was looking at:

http://javascript.internet.com/games/simon-says.html

I'd like mine to sort of follow that, with differences, of course, but basically the same concept.