Results 1 to 7 of 7
  1. #1
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default array of methods?

    So ive been studying java and android for the last 2 months and have decided its time to tackle my first app without a tutorial to guide me. I decided to start with a simple game. The game will have 3 buttons and when started the game will show users a graphic showing which button to press and it must be pressed within 2 seconds or game over.

    i tried to think out the game as best i could and this is what i came up with :

    Start game method{

    Generate random var
    Is game alive Boolean=true


    While isgamealive= true{

    Generate random number to pick witch button
    Button method array that uses the randomly generated number to select which array item to play



    Button 1 method
    Play button 1 sound
    Show button 1 prompt
    If button isn't pressed in 2 seconds isgamealive=false


    Button 2 method
    Play button 2 sound
    Show button 2 prompt
    If button isn't pressed in 2 seconds isgamealive=false

    Button 3
    Play button 3 sound
    Show button 3 prompt
    If button isn't pressed in 2 seconds isgamealive=false


    }


    Game over graphics





    if this is right i guess my q is how do i create the array of button methods?if this isnt possible can someone point out my logic flaws. Any real implementation snippets of any of this would be greatly appreciated/helpful. im in that stage of programming where i can read almost any code but, i have a big problem coming up with the right code from scratch in my head. i think this can be implemented completly in java without android knowledge and i can convert it if need be so any help is still help .

  2. #2
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    Just make a ActionListener for the buttons man =P and just put what you want to happend there..

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by santa View Post
    Just make a ActionListener for the buttons man =P and just put what you want to happend there..
    That's not going to work for the original poster as he's talking about Android coding, not Swing coding.

  4. #4
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    Quote Originally Posted by Fubarable View Post
    That's not going to work for the original poster as he's talking about Android coding, not Swing coding.
    Oh sry ... ;P my bad

  5. #5
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default

    thats like a button listener right? idt that alone would work bc theres no way i could pick which button the game asks the user to press at random like that.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,185
    Rep Power
    19

    Default

    ... idt that alone would work bc ...
    Click here

    db

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Once you have your randomly generated number, remember the associated button in an instance variable. Then all of the button listeners can do the same thing: compare the button that was pressed with the one that was supposed to be pressed.

    In fact a single button listener could do for all three buttons since the logic is the same: if correct button is pressed end the timer that would end the game or if an incorrect button was pressed do something else.

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Methods for reading file with an array
    By johnmergene in forum New To Java
    Replies: 5
    Last Post: 01-26-2011, 04:20 AM
  3. Problems With Array/Methods
    By blueduiker in forum New To Java
    Replies: 4
    Last Post: 01-19-2010, 01:49 AM
  4. Replies: 4
    Last Post: 04-03-2009, 06:36 AM
  5. Replies: 1
    Last Post: 07-20-2008, 04:42 PM

Posting Permissions

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