Results 1 to 7 of 7
Thread: array of methods?
- 05-17-2011, 01:27 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 55
- Rep Power
- 0
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 .
- 05-17-2011, 01:41 AM #2
Just make a ActionListener for the buttons man =P and just put what you want to happend there..
-
- 05-17-2011, 01:45 AM #4
- 05-17-2011, 03:11 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 55
- Rep Power
- 0
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.
- 05-17-2011, 05:37 AM #6... idt that alone would work bc ...
db
- 05-17-2011, 07:31 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 18
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
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-17-2012, 12:00 AM -
Methods for reading file with an array
By johnmergene in forum New To JavaReplies: 5Last Post: 01-26-2011, 05:20 AM -
Problems With Array/Methods
By blueduiker in forum New To JavaReplies: 4Last Post: 01-19-2010, 02:49 AM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 07:36 AM -
[SOLVED] Unable to access array defiened in constructor in other methods.
By Shyam Singh in forum New To JavaReplies: 1Last Post: 07-20-2008, 05:42 PM
Bookmarks