Passing a method as a parameter problem
Author |
Message |
Hoy2Coy
|
Posted: Mon Jan 17, 2011 2:40 pm Post subject: Passing a method as a parameter problem |
|
|
I was wondering how to put a method as a parameter in Java. I know there are other posts about this but I can't make sense of them (something to do with interface, right?). I'm relatively new to Java so I just know the basics. The reason I need to be able to do this is because I'm making an interactive story with each section being its own method. In pseudo-code I want it to be something like this:
public class Interactive_Story {
void Choose(Takes methods a and b as parameters){
if (user input=="a"){
Execute method a
}else{
if (user input=="b"){
Execute method b
}
}
}
void Start(){
Output beginning of story on the console.
Choose(Do_This,Do_That)
}
void main (String[] args){
Start()
}
}
I hope you see what I'm trying to get at. If you have any ideas or informative links please post them as soon as possible.
Thanks,
Hoy2Coy |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon Jan 17, 2011 3:06 pm Post subject: RE:Passing a method as a parameter problem |
|
|
You could have a class for a Chapter (or some other unit of a story section), and navigate through those. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|