Results 1 to 4 of 4

Thread: Basic Array/Game help

  1. #1
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Basic Array/Game help

    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.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    ~Set an array to a length predetermined to a variable, and have every element of the array equal the same thing
    Arrays in Javascript don't have predefined lengths, you simply create elements as necessary:
    Code:
    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 element
    What do you mean, "takes up part of an element?"
    ~Set each of the user's clicks to an array's element
    Set 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 array
    Give 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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •