/** Initial_scene.java * * @author Robert W. Harrison * * set the initial scence for the game * * use the abstract class scene */ import java.lang.Thread; import java.util.Vector; public class initial_scene extends scene { public initial_scene( Vector v, actor who) { super( v,who); small_object coin = new small_object( "gold colored coin", 0.0); add_to_contents(coin); } public void run() { set_the_scene(); while( !action()); // this runs until action is satisfied //next_scene.run(); // this is a great place for threads. (which we haven't covered) Thread next = new Thread(next_scene); next.start(); } public void set_the_scene() {// my is an instance variable that is defined in the abstract class scene zork.message("\n It is a hot and sunny day and you are climbing Stone Mountain, "+my.name()+".\n"); zork.message(" You have stopped for a rest. \n "); what_is_here(); zork.message(" You are thirsty and hungry. \n"); zork.message(" You can use the coin to pay for popcorn and\n a blue slurpy at the store on the top.\n"); } public boolean action() { String inputline; String [] basic = {"pick","coin"}; String [] variant = {"pickup","coin"}; String [] another_variant = {"pick" ,"up", "coin"}; String [] invalid = {"walk"}; String [] also_invalid = {"turn"}; int count = 0; do{// guess what? here is another valid do... while(); if( count++ > 0) zork.message("You can't do that. "); zork.message( "What are you going to do?\n"); inputline = zork.readLine(); if( inputline == null || inputline == "") { continue;} if( zork.simple_NLP(inputline,invalid) || zork.simple_NLP(inputline,also_invalid)) { count= 0; zork.message("It is rather hot and that slurpy sounds good, but how will you pay for it?\n");} if( count >= 10) { zork.message(" A mysterious stranger appears and says \"Pick up the coin dummy\"\n"); inputline = zork.readLine(); } if( count > 15) {zork.message(" You starve to death\n"); System.exit(0);} } while( !(zork.simple_NLP(inputline,basic) || zork.simple_NLP(inputline,variant) || zork.simple_NLP(inputline,another_variant)) ); // don't complain it could be worse!! zork.message(" A great wind blows you off of the mountain and you are inhaled by Jeff Davis's horse.\n"); next_scene = new great_hall(state_vector,me); // typically you would check that this exists before creating it. return true;} }// end of class initial_scene