/** great_hall.java * * @author Robert W. Harrison * * example scene for zork * * use the abstract class scene */ import java.lang.Thread; import java.util.Vector; public class great_hall extends scene { public great_hall( Vector v, actor who) { super( v,who); small_object eats = new small_object( "food", 9.); add_to_contents(eats); eats.set_food(10000.); small_object knife = new small_object("knife", 1.); add_to_contents(knife); small_object bottle = new small_object("canteen",5.); add_to_contents(bottle); small_object wand = new small_object("wand", 0.1); add_to_contents(wand); wand.set_magic(); small_object ring = new small_object("ring", 0.1); add_to_contents(ring); ring.set_magic(); small_object dead_bird = new small_object( "dead_bird", 1.); add_to_contents(dead_bird); dead_bird.set_poison(1.); } /** The version of run in great_hall is inherited from scene. * */ public void set_the_scene() {// my is an instance variable that is defined in the abstract class scene zork.message("\n" +my.name()+", you are in a great hall.\n"); zork.message("There are a red, a green and a blue door at the other end.\n"); what_is_here(); if( my.kind().equalsIgnoreCase("troll")) zork.message("\n You are very hungry\n"); else if( me.am_hungry()) zork.message("\n You are still a little hungry\n"); } public boolean action() { String inputline; // these are the simple way to implment these. There are cleverer ways String [][] food = {{"pick","food"},{"pick","up","food"}}; String [][] knife = {{"pick","knife"},{"pick","up","knife"}}; String [][] wand = {{"pick","wand"},{"pick","up","wand"}}; String [][] ring = {{"pick","ring"},{"pick","up","ring"}}; String [][] canteen = {{"pick","canteen"},{"pick","up","canteen"}}; String [][] walk_red = {{"walk","red"},{"run","red"}}; String [][] walk_green = {{"walk","green"},{"run","green"}}; String [][] walk_blue = {{"walk","blue"},{"run","blue"}}; String [] open={"open"}; String [][] eat_food = {{"eat","food"},{"eat","knife"}}; String [][] eat_bird = {{"eat","bird"},{"eat","wand"}}; String [][] drink = {{"drink"},{"drink","canteen"},{"drink","some","water"}}; String [][] drop = {{"drop"},{"drop",""}}; String [] look = {"look"}; // initially you can pickup or eat stuff boolean red = false; boolean green = false; boolean blue = false; boolean not_moved = true; move_on: do{ inputline = zork.readLine(); if( inputline == null || inputline == "") continue; for(int i=0; i< 2; i++) { small_object o; if( zork.simple_NLP(inputline, food[i])) { o = pick_up("food"); if( !me.pickup(o)){add_to_contents(o);} break; } else if( zork.simple_NLP(inputline,knife[i])) { o = pick_up("knife"); if( !me.pickup(o)){add_to_contents(o);} break; } else if( zork.simple_NLP(inputline,wand[i])) { o = pick_up("wand"); if( !me.pickup(o)){add_to_contents(o);} break; } else if( zork.simple_NLP(inputline,ring[i])) { o = pick_up("ring"); if( !me.pickup(o)){add_to_contents(o);} break; } else if( zork.simple_NLP(inputline,canteen[i])) { o = pick_up("canteen"); if( !me.pickup(o)){add_to_contents(o);} break; } else if( zork.simple_NLP(inputline, eat_food[i])) { me.eat(eat_food[i][1]); break; } else if( zork.simple_NLP(inputline, eat_bird[i])) { o = pick_up("dead_bird"); if( !me.pickup(o)){add_to_contents(o); continue;} me.eat("dead_bird"); o.poison(1.); break; } else if( zork.simple_NLP(inputline, drink[i])) {} else if( zork.simple_NLP(inputline,walk_red[i])) {not_moved = false; red = true; break move_on;} else if( zork.simple_NLP(inputline,walk_green[i])) {not_moved = false; green = true; break move_on;} else if( zork.simple_NLP(inputline,walk_blue[i])) {not_moved = false; blue = true; break move_on;} } if( zork.simple_NLP(inputline,look)) {what_is_here(); my.inventory();} if( zork.simple_NLP(inputline,drop[0])) { my.inventory(); zork.message("Drop what ?\n"); inputline = zork.readLine(); inputline = inputline.trim(); me.drop(inputline, this); what_is_here(); } } while( not_moved); int count = 0; do{ if( count ++ > 0) zork.message("\n Open the door dummy!"); inputline = zork.readLine(); }while( !zork.simple_NLP(inputline, open)); not_moved = false; if( red || green || blue) for( count = 0; count < state_vector.size(); count ++) { Object what = state_vector.elementAt(count); if(!blue && what instanceof great_hall) { next_scene = (great_hall)what; not_moved = true; break;} if( blue && what instanceof twisty) { next_scene = (twisty)what; not_moved = true; break; } } if( !not_moved && !blue) next_scene = new great_hall(state_vector,me); // typically you would check that this exists before creating it. if( !not_moved && blue) next_scene = new twisty(state_vector,me); return true;} }// end of class