Lap32.zip

Lap3/Main.ctxt

#BlueJ class context comment0.target=Main comment0.text=\n\ The\ sole\ purpose\ of\ this\ class\ is\ to\ start\ the\ game\ up.\ It\ does\ this\ by\n\ creating\ an\ instance\ of\ the\ Game\ and\ calling\ it's\ play\ method.\n\ \n\ @author\ Maria\ Jump\n\ @version\ 2015.02.01\n comment1.params= comment1.target=Main() comment1.text=Default\ constructor. comment2.params=e comment2.target=void\ componentResized(java.awt.event.ComponentEvent) comment3.params=event comment3.target=void\ actionPerformed(java.awt.event.ActionEvent) comment3.text=\n\ Default\ action\ listener.\n\ \n\ @param\ event\n\ \ \ \ \ \ \ \ \ \ \ \ The\ action\ event.\n comment4.params=args comment4.target=void\ main(java.lang.String[]) comment4.text=\n\ The\ main\ method\ for\ the\ program.\n\ \n\ @param\ args\n\ \ \ \ \ \ \ \ \ \ \ \ The\ command\ line\ arguments.\n numComments=5

Lap3/Game.ctxt

#BlueJ class context comment0.target=Game comment0.text=\n\ This\ class\ is\ the\ main\ class\ of\ the\ "Campus\ of\ Kings"\ application.\n\ "Campus\ of\ Kings"\ is\ a\ very\ simple,\ text\ based\ adventure\ game.\ Users\ can\ walk\n\ around\ some\ scenery.\ That's\ all.\ It\ should\ really\ be\ extended\ to\ make\ it\ more\n\ interesting\!\n\ This\ game\ class\ creates\ and\ initializes\ all\ the\ others\:\ it\ creates\ all\ rooms,\n\ creates\ the\ parser\ and\ starts\ the\ game.\ It\ also\ evaluates\ and\ executes\ the\n\ commands\ that\ the\ parser\ returns.\n\ \n\ @author\ Mohammed\ Alharbi\n\ @version\ 2018/1/24\n comment1.params= comment1.target=Game() comment1.text=\n\ Create\ the\ game\ and\ initialize\ its\ internal\ map.\n comment10.params=command comment10.target=void\ dropItem(Command) comment10.text=\n\ Try\ to\ go\ to\ one\ direction.\ If\ there\ is\ an\ exit,\ enter\ the\ new\ room,\n\ otherwise\ print\ an\ error\ message.\n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment11.params= comment11.target=void\ inventory() comment11.text=\n\ Try\ to\ go\ to\ one\ direction.\ If\ there\ is\ an\ exit,\ enter\ the\ new\ room,\n\ otherwise\ print\ an\ error\ message.\n\n\ \ The\ command\ to\ be\ processed.\n comment12.params= comment12.target=void\ printGameStatus() comment12.text=\n\ Print\ out\ the\ status\ of\ the\ game.\n comment13.params= comment13.target=void\ goBack() comment13.text=\n\ Take\ the\ player\ back\ to\ the\ previous\ location.\n comment14.params= comment14.target=void\ printGoodbye() comment14.text=\n\ Print\ out\ the\ closing\ message\ for\ the\ player.\n comment15.params= comment15.target=void\ printLocationInformation() comment15.text=\n\ Prints\ out\ the\ current\ location\ and\ exits.\n comment16.params= comment16.target=void\ printHelp() comment16.text=\n\ Print\ out\ some\ help\ information.\ Here\ we\ print\ some\ stupid,\ cryptic\n\ message\ and\ a\ list\ of\ the\ command\ words.\n comment17.params= comment17.target=void\ printWelcome() comment17.text=\n\ Print\ out\ the\ opening\ message\ for\ the\ player.\n comment18.params=command comment18.target=boolean\ quit(Command) comment18.text=\n\ "Quit"\ was\ entered.\ Check\ the\ rest\ of\ the\ command\ to\ see\ whether\ we\n\ really\ quit\ the\ game.\n\n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n\ @return\ true,\ if\ this\ command\ quits\ the\ game,\ false\ otherwise.\n comment19.params= comment19.target=void\ look() comment19.text=\n\ prints\ out\ the\ location\ information.\n\ \n comment2.params= comment2.target=Player\ getCurrentPlayer() comment2.text=\n\ Get\ current\ player\ playing\ the\ game.\n\ @return\ current\ player\n comment20.params=command comment20.target=void\ pack(Command) comment20.text=\n\ Pack\ an\ item\ into.\ \ \n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment21.params=command comment21.target=void\ unpack(Command) comment21.text=\n\ Pack\ an\ item\ into.\ \ \n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment22.params=command comment22.target=void\ eat(Command) comment22.text=\n\ eat.\n\ @param\ command\ the\ command.\n\ \n comment23.params=command comment23.target=void\ drink(Command) comment23.text=\n\ drink.\n\ @param\ command\ the\ command.\n comment24.params=command comment24.target=void\ equip(Command) comment24.text=\n\ equip.\n\ @param\ command\ the\ command.\n comment25.params=command comment25.target=void\ unequip(Command) comment25.text=\n\ unequip\ .\n\ @param\ command\ the\ command.\n comment3.params= comment3.target=void\ play() comment3.text=\n\ Main\ play\ routine.\ Loops\ until\ end\ of\ play.\n comment4.params=command comment4.target=boolean\ processCommand(Command) comment4.text=\n\ Given\ a\ command,\ process\ (that\ is\:\ execute)\ the\ command.\n\ \n\ @param\ command\n\ \ \ \ \ \ \ \ \ \ \ \ The\ command\ to\ be\ processed.\n\ @return\ true\ If\ the\ command\ ends\ the\ game,\ false\ otherwise.\n comment5.params=command comment5.target=void\ goGame(Command) comment5.text=\n\ Try\ to\ go\ to\ one\ direction.\ If\ there\ is\ an\ exit,\ enter\ the\ new\ room,\n\ otherwise\ print\ an\ error\ message.\n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment6.params=command comment6.target=void\ unlock(Command) comment6.text=\n\ Unlock\ a\ locked\ door.\ \n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment7.params=command comment7.target=void\ lock(Command) comment7.text=\n\ lock\ a\ locked\ door.\ \n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment8.params=command comment8.target=void\ examineItem(Command) comment8.text=\n\ Try\ to\ examine\ a\ play\ item.\ If\ the\ item\ doesn't\ exist\ in\ the\n\ players\ inventory\ nor\ the\ current\ room,\n\ print\ an\ error\ message.\n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n comment9.params=command comment9.target=void\ takeItem(Command) comment9.text=\n\ Try\ to\ go\ to\ one\ direction.\ If\ there\ is\ an\ exit,\ enter\ the\ new\ room,\n\ otherwise\ print\ an\ error\ message.\n\ \n\ @param\ command\n\ \ The\ command\ to\ be\ processed.\n numComments=26

Lap3/Drink.java

Lap3/Drink.java


/**
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. 
 * 
 *  @author  mohammed alharbi
 *  @version  29/4/2018
 */
public   class   Drink   extends   Item   implements   Drinkable {
     /**
     * Drink.
     *  @param  name the name.
     *  @param  pointValue the pointValue.
     *  @param  description teh description.
     *  @param  weight teh weight.
     */
     public   Drink ( String  name ,   int  pointValue ,   String  description ,   int  weight )   {
         super ( name ,  pointValue ,  description ,  weight );
     }

    @ Override
     public   String  drink ( Player  p )   {

        p . updateHealth ( 2 );

        p . removeItem ( this . getName ());

         return   "you have taken a drink" ;
     }

}

Lap3/Player.ctxt

#BlueJ class context comment0.target=Player comment0.text=\n\ class\ Player.\n\ @author\ Mohammed\ Alharbi\n\ @version\ 2018.1.27\n comment1.params=playPlayer comment1.target=Player(Room) comment1.text=\ constructor\ in\ the\ Player\ class.\n\ @param\ playPlayer\ for\ the\ room\ .\n comment10.params=weapon comment10.target=void\ setCurrentWeapon(Item) comment10.text=\ a\ mutator\ for\ the\ current\ weapon\ of\ the\ character.\n\ @param\ weapon\ to\ be\ equipped\n comment11.params= comment11.target=Room\ getpreviousRoom() comment11.text=\ Accessors\ for\ the\ previous\ room\ the\ character.\n\ @return\ cerrentRoom\n comment12.params= comment12.target=java.lang.String\ getInventory() comment12.text=\ Accessors\ for\ the\ players\ inventory.\n\ @return\ players\ inventory\n comment13.params= comment13.target=Item\ getCurrentWeapon() comment13.text=\n\n\ @return\ the\ players\ current\ weapon\n comment2.params=health comment2.target=void\ updateHealth(int) comment3.params=item comment3.target=boolean\ inventoryAddItem(Item) comment3.text=\ Add\ item\ to\ inventory.\n\ @param\ item\n\ @return\ true\ if\ item\ added\ to\ inventory\n comment4.params= comment4.target=int\ getCurrentWeight() comment4.text=\n\n\ @return\ current\ weight\ that\ the\ player\ is\ carrying\n comment5.params= comment5.target=int\ getMaxWeight() comment5.text=\n\n\ @return\ the\ maximum\ weight\ that\ the\ player\ can\ carry\n comment6.params=itemName comment6.target=Item\ getItem(java.lang.String) comment6.text=\ Get\ an\ item\ from\ the\ players\ inventory.\n\ @param\ itemName\ -\ name\ of\ item\ to\ be\ picked\n\ @return\ an\ Item\ object\n comment7.params=itemName comment7.target=Item\ removeItem(java.lang.String) comment7.text=\ remove\ an\ item\ from\ the\ players\ inventory.\n\ @param\ itemName\ -\ name\ of\ item\ to\ be\ removed\n\ @return\ an\ Item\ object\n comment8.params= comment8.target=Room\ getcurrentRoom() comment8.text=\ accessors\ \ for\ the\ current\ room\ the\ character.\n\ @return\ currentRoom\n comment9.params=playing comment9.target=void\ setcurrentRoom(Room) comment9.text=\ a\ mutator\ for\ the\ current\ room\ of\ the\ character.\n\ @param\ playing\ for\ the\ Room\n numComments=14

Lap3/Room.java

Lap3/Room.java

import  java . util . HashMap ;
/**
 * Class Room - a room in an adventure game.
 * 
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * A "Room" represents one location in the scenery of the game. It is connected
 * to other rooms via doors. The doors are labeled north, east, south, west.
 * For each direction, the room stores a reference to an instance of door.
 * 
 *  @author  Mohammed ALharbi
 *  @version  2018.1.26
 */
public   class   Room   {
     /** Counter for the total number of rooms created in the world. */
     private   static   int  counter ;
     /** The name of this room.  Room names should be unique. */
     private   String  name ;
     /** The description of this room. */
     private   String  description ;
     /**earn points */
     private   int  points ;  
     /** directions hash map with directions keys and doors values */
     private   HashMap < String , Door >  directions  =   new   HashMap <   > ();  
    
     /** directions hash map with room item's keys and items values */
     private   HashMap < String , Item >  roomItems  =   new   HashMap <   > ();
     /**
     * Static initializer.
     */
     static   {
        counter  =   0 ;
     }
     /**
     * Create a room described "description". Initially, it has no exits.
     * "description" is something like "a kitchen" or "an open court yard".
     *  @param  name  The rooms name.
     *  @param  description
     *   The rooms description.
     */
     public   Room ( String  name ,   String  description )   {
         this . name  =  name ;
         this . description  =  description ;
        counter ++ ;
     }

     /**
     * Returns the name of this room.
     * 
     *  @return  The name of this room.
     */
     public   String  getName ()   {
         return  name ;
     }

     /**
     * Returns the description of this room.
     * 
     *  @return  The description of this room.
     */
     public   String  getDescription ()   {
         return  description ;
     }

     /**
     * Returns the door of this room.
     *  @return  The door of this room
     */
     public   Door  getDirection ( String  direction ){
         return  directions . get ( direction );
     }

     /**
     * Return the rooms that have been created int the world.
     *  @return  the rooms that have been created int the world.
     */
     public   static   int  getCounter (){
         return  counter ;
     }

     /**
     *  @return  getExit for getting the direction.
     */

     public   int  getPoints (){
         int  point  =  points ;
        points  =   0 ;
         return  point ;
     }

     /** Mutator for setting the points.
     *  @param  newPoints
     */

     public   void  setPoints ( int  newPoints ){
        points  =  newPoints ;
     }

     /**
     * Set exit.
     *  @param  direction
     *  @param  neighbor
     */
     public   void  setDirection ( String  direction , Door  neighbor )   {
        directions . put ( direction ,  neighbor );
     }
    
     /**
     * Add Item
     *  @param  item - The item object to be added
     */
     public   void  addItem ( Item  item )   {
        
        roomItems . put ( item . getName (),  item );
     }
    
      /**
     * get Item
     *  @param  name - The name of the item to be added to the room
     *  @return  Item - The item in the collection with the key name
     */
     public   Item  getItem ( String  name )   {
        
         return  roomItems . get ( name );
     }
      /**
     * Remove Item
     *  @param  name - The name of the item to be removed from the room
     *  @return  item - The item that has been removed from the room
     */
     public   Item  removeItem ( String  name )   {
        
         Item  item  =  roomItems . get ( name );
        
        roomItems . remove ( name );
        
         return  item ;
     }
    
     /**
     * Returns a string description including all the details of a Room.
     *Exits : north east south west
     *  @return  A string representing all the details of a Room.
     */
     public   String  toString (){
        
         String  roomInformation  =   "" ;
        
        roomInformation  +=  getName ()   +   " "   +  getDescription ()   +   "\n" ;
        
        roomInformation  +=   "Exits : "   ;
        
         for ( String  direction  :  directions . keySet ()){  
            
            roomInformation  +=    " "   +  direction ;

         }
        
        roomInformation  +=   "\nItems : " ;
        
        
        
         for ( String  item  :  roomItems . keySet ()){  
            
            roomInformation  +=    " "   +  item  +   ", " ;

         }

         return  roomInformation ;
     }

}

__MACOSX/Lap3/._Room.java

Lap3/Equippable.class

public abstract interface Equippable {
    public abstract String equip(Player);
    public abstract String unequip(Player);
}

Lap3/Door.java

Lap3/Door.java

/**
 * Class Door - a door or portal between two Rooms in an adventure game.
 * 
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * A "Door" represents a door or portal between two locations of the game.
 * It stores a reference to the neighboring room and whether that door
 * or portal is locked.  Doors are not locked by default.
 * 
 *  @author  Maria Jump
 *  @version  2015.02.01
 */
public   class   Door   {
    
     /** The room that this door leads to. */
     private   Room  destination ;
     /** Whether this door is locked. */
     private   boolean  locked ;
         /** the doorkey.*/
         private   Item  doorKey ;
    
     /**
     * Constructor for the Door class.
     *  @param  destination The room this door leads to
     */
     public   Door ( Room  destination )   {
         this . destination  =  destination ;
         this . locked  =   false ;
                 this . doorKey  =   null ;
     }
    
     /**
     * A getter for the room this door leads to.
     *  @return  The room this door leads to
     */
     public   Room  getDestination ()   {
         return  destination ;
     }
    
     /**
     * A getter for whether this door is locked.
     *  @return  Whether this door is locked
     */
     public   boolean  isLocked ()   {
         return  locked ;
     }
        
         /**
     * A setter for the key that opens a door.
         *  @param  key Specifies the key to unlock the door
     */
     public   void  setKey ( Item  key )   {
            
             this . doorKey  =  key ;
     }
        
         /**
     * A setter for the key that opens a door.
         *  @return  the key that unlocks that door 
     */
     public   Item  getKey ()   {
            
             return  doorKey ;
     }

     /**
     * A setter for whether this door is locked.
     *  @param  locked Whether this door is locked.
     */
     public   void  setLocked ( boolean  locked )   {
         this . locked  =  locked ;
     }
}

__MACOSX/Lap3/._Door.java

Lap3/Equippable.java

Lap3/Equippable.java

/**
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. 
 * 
 *  @author  mohammed alharbi
 *  @version  29/4/2018
 */
public   interface   Equippable   {
    
     /**
     * equip.
     *  @param  p The current player instance
     *  @return  message
     */
     public   String  equip ( Player  p );
    
     /**
     * unequip.
     *  @param  p - The current player instance
     *  @return  message
     */
     public   String  unequip ( Player  p );
}

Lap3/CommandWords.ctxt

#BlueJ class context comment0.target=CommandWords comment0.text=\n\ This\ class\ is\ part\ of\ the\ "Campus\ of\ Kings"\ application.\ "Campus\ of\ Kings"\ is\ a\n\ very\ simple,\ text\ based\ adventure\ game.\n\ \n\ This\ class\ holds\ an\ enumeration\ of\ all\ command\ words\ known\ to\ the\ game.\ It\ is\n\ used\ to\ recognize\ commands\ as\ they\ are\ typed\ in.\n\ \n\ @author\ Maria\ Jump\n\ @version\ 2015.02.01\n comment1.params=aString comment1.target=boolean\ isCommand(java.lang.String) comment1.text=\n\ Check\ whether\ a\ given\ String\ is\ a\ valid\ command\ word.\n\ \n\ @param\ aString\ The\ string\ to\ determine\ whether\ it\ is\ a\ valid\ command.\n\ @return\ true\ if\ a\ given\ string\ is\ a\ valid\ command,\ false\ if\ it\ isn't.\n comment2.params=theString comment2.target=CommandEnum\ getCommand(java.lang.String) comment2.text=\n\ Converts\ a\ String\ into\ a\ CommandEnum\ object.\n\ @param\ theString\ The\ String\ containing\ the\ command\ word.\n\ @return\ The\ CommandEnum\ object\ representing\ the\ command,\ or\ null\ if\ the\ command\ does\ not\ exist.\ \n numComments=3

Lap3/Reader.class

public synchronized class Reader {
    private static java.util.Scanner reader;
    public void Reader();
    public static Command getCommand();
    public static String getResponse();
    public static String getResponseKeepCase();
    static void <clinit>();
}

Lap3/Food.ctxt

#BlueJ class context comment0.target=Food comment0.text=\n\ To\ change\ this\ license\ header,\ choose\ License\ Headers\ in\ Project\ Properties.\n\ To\ change\ this\ template\ file,\ choose\ Tools\ |\ Templates\n\ and\ open\ the\ template\ in\ the\ editor.\ \n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 29/4/2018\n comment1.params=name\ pointValue\ description\ weight comment1.target=Food(java.lang.String,\ int,\ java.lang.String,\ int) comment1.text=\n\ food.\n\ @param\ name\ the\ name.\n\ @param\ pointValue\ the\ pointValue.\n\ @param\ description\ teh\ description.\n\ @param\ weight\ teh\ weight.\n comment2.params=p comment2.target=java.lang.String\ eat(Player) numComments=3

Lap3/.DS_Store

__MACOSX/Lap3/._.DS_Store

Lap3/Weapon.class

public synchronized class Weapon extends Item implements Equippable {
    public void Weapon(String, int, String, int);
    public String equip(Player);
    public String unequip(Player);
}

Lap3/World.java

Lap3/World.java

import  java . util . HashMap ;

/**
 * This class represents the entire world that makes up the "Campus of Kings"
 * application. "Campus of Kings" is a very simple, text based adventure game.
 * Users can walk around some scenery. That's all. It should really be extended
 * to make it more interesting!
 * 
 * This world class creates the world where the game takes place.
 * 
 *  @author  mohammed alharbi
 *  @version  20/2/2018
 */
public   class   World   {
     /** The rooms in the world. */
     private   HashMap < String ,   Room >  rooms ;

     /**
     * Constructor for the world.
     */
     public   World ()   {

        rooms  =   new   HashMap < String ,   Room > ();

        createRooms ();

        createItems ();
     }

     /**
     * item the item.
     */
     public   void  createItems (){

         Item  toothbrush  =   new   Item ( "tooth brush" ,   3 ,   "Brushing teeth" ,   10 );
         Item  toothpaste  =   new   Item ( "tooth paste" ,   3 ,   "Applied on a tooth brush" ,   20 );

         Weapon  knife  =   new   Weapon ( "knife" ,   5 ,   "Peel and cut fruits" ,   100 );
         Drink  coffee  =   new   Drink ( "coffee" ,   7 ,   "good for personal health" ,   150 );
         Food  grapes  =   new   Food ( "grapes" ,   10 ,   "Good for health and hunger" ,   100 );

         Container  purse  =   new   Container ( "purse" ,   2 , "Contains small small items" ,   100 );
         Item  houseKey  =   new   Item ( "house key" ,   5 ,   "Open locked doors" ,   20 );
        purse . addItem ( houseKey );

         //car
         Container  backBag  =   new   Container ( "back bag" ,   10 ,   "Carry things in" ,   200 );
         Item  carKey  =   new   Item ( "car key" ,   5 ,   "Open locked doors" ,   50 );
         Drink  water  =   new   Drink ( "bottle of water" ,   8 ,   "Quenches thirst" ,   250 );

         //out of the house
         Weapon  mopStick  =   new   Weapon ( "broom stick" ,   5 ,   "Pick items from the roof" ,   600 );

         //keep street
         Weapon  hammer  =   new   Weapon ( "hammer" ,   6 ,   "Can be used to fight wild animals" ,   1000 );
         Container  bucket  =   new   Container ( "water buckets" ,   15 ,   "carry more items if back is full" ,   50 );  
        bucket . addItem ( hammer );

         for ( String  room  :  rooms . keySet ()){

             switch ( room ){

                 case   "bathroom" :
                getcurrentRoom ( room ). addItem ( toothbrush );
                getcurrentRoom ( room ). addItem ( toothpaste );
                 break ;

                 case   "kitchen" :
                getcurrentRoom ( room ). addItem ( knife );
                getcurrentRoom ( room ). addItem ( coffee );
                getcurrentRoom ( room ). addItem ( grapes );
                getcurrentRoom ( room ). addItem ( purse );
                getcurrentRoom ( room ). getDirection ( "south" ). setLocked ( true );
                getcurrentRoom ( room ). getDirection ( "south" ). setKey ( houseKey );
                 break ;

                 case   "out of the house" :                    
                getcurrentRoom ( room ). addItem ( mopStick );
                getcurrentRoom ( room ). getDirection ( "north" ). setLocked ( true );
                getcurrentRoom ( room ). getDirection ( "north" ). setKey ( houseKey );
                 break ;

                 case   "car" :
                getcurrentRoom ( room ). addItem ( backBag );                     
                getcurrentRoom ( room ). addItem ( water );    
                getcurrentRoom ( room ). addItem ( carKey );
                 break ;

                 case   "keep street" :                     
                getcurrentRoom ( room ). addItem ( bucket );
                 break ;
                 default :
             }
         }

     }

     /**
     * This method takes care of creating all of the aspects of the world for
     * the "Campus of Kings" application.
     * 
     *  @param  name
     *            The provided name of the room.
     *  @return  The room associated with the provided name
     */
     public   Room  getcurrentRoom ( String  name )   {
         return  rooms . get ( name . toLowerCase ());
     }

     /////////////////////////////////////////////////////////////////////////////////////
     // Start of private helper methods

     /**
     * Helper method for recreating a Room. Ensure that the room is created and
     * installed in to the collection of Rooms.
     * 
     *  @param  theRoom
     *  The room to add to the world.
     */
     private   void  addRoom ( Room  theRoom )   {
        rooms . put ( theRoom . getName (). toLowerCase (),  theRoom );
     }

     /**
     * Helper method for creating doors between rooms.
     * 
     *  @param  from The room where the door originated.
     *  @param  direction The direction of the door in the from room.
     *  @param  to The room where the door goes.
     */
     private   void  createDoor ( Room  from ,   String  direction ,   Room  to ){
         Door  door  =    new   Door ( to );
        from . setDirection ( direction , door );
     }

     /**
     * This method creates all of the individual places in this world and all
     * the doors connecting them.
     */
     private   void  createRooms ()   {
         // Creating all the rooms.
         int  pointScore  =   0 ;

         Room  bathroom  =   new   Room ( "Bathroom" ,   "there is teeth brush, shower place." );
         Room  kitchen  =   new   Room ( "Kitchen" ,   "there are two doors, one the way to go out of the house. The second door the way to the living room.." );
         Room  outOfTheHouse  =   new   Room ( "out Of The House" ,   "the way outside the house to drive to university.." );
        outOfTheHouse . setPoints ( 10 );
        pointScore  =  pointScore  +   10 ;
         Room  car  =   new   Room ( "Car" ,   "inside the car, back bag, car key with house key.." );
        car . setPoints ( 7 );
        pointScore  =  pointScore  +   7 ;
         Room  keepStreet  =   new   Room ( "keep Street" ,   "the correct way." );
         Room  turnLeft  =   new   Room ( "Turn left" ,   "wrong way to go with it.." );
         Room  endOfTheRoad  =   new   Room ( "End of the road" ,   "closed way." );
         Room  gasStaion  =   new   Room ( "Gas Staion" ,   "the way to traffic signal." );
         Room  trafficSignal  =   new   Room ( "Traffic signal" ,   "there are three different ways." );
        trafficSignal . setPoints ( 10 );
        pointScore  =  pointScore  +   10 ;
         Room  turnLeft2  =   new   Room ( "Turn left2" ,   "maybe not the right way." );
         Room  wrongWay  =   new   Room ( "Wrong way" , "it will take long time to reach the goal." );
         Room  turnRight  =   new   Room ( "Turn right" , " more traffic." );
         Room  closedWay  =   new   Room ( "Closed Way" , "no place to go." );
         Room  keepGoing  =   new   Room ( "KeepGoing" , "almost arrive to university." );
        keepGoing . setPoints ( 10 );
        pointScore  =  pointScore  +   10 ;
         Room  parking  =   new   Room ( "Parking" , "there is a meter parking, 2$ in Hour." );
        parking . setPoints ( 17 );
        pointScore  =  pointScore  +   17 ;
         Room  library  =   new   Room ( "Library" , "some books, students, printer, computers." );
         Room  campusCenter  =   new   Room ( "Campus Center" , "office for the activity, mailboxes, four floors" );
         Room  hallCampus  =   new   Room ( "Hall Campus" , "the building for men." );
         Room  hBuilding  =   new   Room ( "H Building" , "Five floors, elevator, six classrooms" );
         Room  square  =   new   Room ( "Square" , "the place in the middle of the university, and from there the player can go any building." );
        square . setPoints ( 12 );
        pointScore  =  pointScore  +   12 ;
         Room  mCBuilding  =   new   Room ( "MCBuilding" , " Classes, six floors." );
         Room  aBuilding  =   new   Room ( "A Building" , ": the goal to reach the class, stairs, elevator, classroom." );
         Room  stairs  =   new   Room ( "Stairs" , "take the player until fourth floor." );
        stairs . setPoints ( 18 );
        pointScore  =  pointScore  +   18 ;
         Room  elevator  =   new   Room ( "Elevator" , "take the player until fourth floor." );
         Room  floor2  =   new   Room ( "2Floor" , "entry for classes" );
         Room  classroom  =   new   Room ( "Classroom" , "one door, blackboard, tables" );
         Room  classroom201  =   new   Room   ( "Classroom201" , "you reach the goal." );
        classroom201 . setPoints ( 30 );
        pointScore  =  pointScore  +   30 ;
         Room  classroom204  =   new   Room ( "Classroom204" , "one door, students." );
         Room  classroom202  =   new   Room ( "Classroom202" , "blackboard, table, students." );
         // Adding all the rooms to the world.
         this . addRoom ( bathroom );
         this . addRoom ( kitchen );
         this . addRoom ( outOfTheHouse );
         this . addRoom ( car );
         this . addRoom ( keepStreet );
         this . addRoom ( turnLeft );
         this . addRoom ( endOfTheRoad );
         this . addRoom ( gasStaion );
         this . addRoom ( trafficSignal );
         this . addRoom ( turnLeft2 );
         this . addRoom ( wrongWay );
         this . addRoom ( turnRight );
         this . addRoom ( closedWay );
         this . addRoom ( keepGoing );
         this . addRoom ( parking );
         this . addRoom ( library );
         this . addRoom ( campusCenter );
         this . addRoom ( hallCampus );
         this . addRoom ( hBuilding );
         this . addRoom ( square );
         this . addRoom ( mCBuilding );
         this . addRoom ( aBuilding );
         this . addRoom ( stairs );
         this . addRoom ( elevator );
         this . addRoom ( floor2 );
         this . addRoom ( classroom );
         this . addRoom ( classroom201 );
         this . addRoom ( classroom204 );
         this . addRoom ( classroom202 );
         // Creating all the doors between the rooms.
         this . createDoor ( bathroom , "east" , kitchen );
         this . createDoor ( kitchen ,   "west" , bathroom );

         this . createDoor ( kitchen , "south" ,  outOfTheHouse );
         this . createDoor ( outOfTheHouse , "north" ,  kitchen );

         this . createDoor ( outOfTheHouse , "west" , car );
         this . createDoor ( car , "east" , outOfTheHouse );

         this . createDoor ( car , "south" , keepStreet );
         this . createDoor ( keepStreet , "north" , car );

         this . createDoor ( keepStreet , "west" , turnLeft );
         this . createDoor ( turnLeft , "east" , keepStreet );

         this . createDoor ( turnLeft , "south" ,  endOfTheRoad );
         this . createDoor ( endOfTheRoad , "north" , turnLeft );

         this . createDoor ( keepStreet , "south" , gasStaion );
         this . createDoor ( gasStaion ,   "north" , keepStreet );

         this . createDoor ( gasStaion , "east" , trafficSignal );
         this . createDoor ( trafficSignal , "west" ,  gasStaion );

         this . createDoor ( trafficSignal , "north" , turnLeft2 );
         this . createDoor ( turnLeft2 , "south" , trafficSignal );

         this . createDoor ( turnLeft2 , "north" ,  wrongWay );
         this . createDoor ( wrongWay , "south" , turnLeft2 );

         this . createDoor ( trafficSignal , "south" ,  turnRight );
         this . createDoor ( turnRight , "north" ,  trafficSignal );

         this . createDoor ( turnRight , "south" , closedWay );
         this . createDoor ( closedWay , "north" ,  turnRight );

         this . createDoor ( trafficSignal , "east" ,  keepGoing );
         this . createDoor ( keepGoing ,   "west" , trafficSignal );

         this . createDoor ( keepGoing , "east" ,  parking );
         this . createDoor ( parking , "west" , keepGoing );

         this . createDoor ( parking , "southwest" , library );
         this . createDoor ( library ,   "northeast" , parking );

         this . createDoor ( library , "east" ,  campusCenter );
         this . createDoor ( campusCenter , "west" , library );

         this . createDoor ( parking , "south" , square );
         this . createDoor ( square , "north" , parking );

         this . createDoor ( square , "east" ,  hallCampus );
         this . createDoor ( hallCampus , "west" , square );

         this . createDoor ( square , "west" , hBuilding );
         this . createDoor ( hBuilding , "east" , square );

         this . createDoor ( square ,   "southeast" , mCBuilding );
         this . createDoor ( mCBuilding , "northwest" , square );

         this . createDoor ( square , "south" , aBuilding );
         this . createDoor ( aBuilding , "north" , square );

         this . createDoor ( aBuilding , "west" , stairs );
         this . createDoor ( stairs , "east" , aBuilding );

         this . createDoor ( aBuilding , "southwest" , classroom );
         this . createDoor ( classroom , "northeast" , aBuilding );

         this . createDoor ( aBuilding , "southwest" , elevator );
         this . createDoor ( elevator , "northeast" , aBuilding );

         this . createDoor ( elevator , "west" , floor2 );
         this . createDoor ( floor2 , "east" , elevator );

         this . createDoor ( stairs , "south" , floor2 );
         this . createDoor ( floor2 , "north" , stairs );

         this . createDoor ( floor2 , "south" , classroom204 );
         this . createDoor ( classroom204 , "north" , floor2 );

         this . createDoor ( floor2 , "east" , classroom202 );
         this . createDoor ( classroom202 , "west" , floor2 );

         this . createDoor ( floor2 , "southeast" , classroom201 );
         this . createDoor ( classroom201 , "northwest" , floor2 );

     }
}

Lap3/Drinkable.java

Lap3/Drinkable.java

/**
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. 
 * 
 *  @author  mohammed alharbi
 *  @version  29/4/2018
 */
public   interface   Drinkable   {
    
     /**
     * drink the drink.
     *  @param  p the current game character.
     *  @return  a message
     */
     public   String  drink ( Player  p );
    
}

Lap3/Game.class

public synchronized class Game {
    private World world;
    private int score;
    private int turns;
    private Player playerClass;
    public void Game();
    public Player getCurrentPlayer();
    public void play();
    private boolean processCommand(Command);
    private void goGame(Command);
    private void unlock(Command);
    private void lock(Command);
    private void examineItem(Command);
    private void takeItem(Command);
    private void dropItem(Command);
    private void inventory();
    private void printGameStatus();
    private void goBack();
    private void printGoodbye();
    private void printLocationInformation();
    private void printHelp();
    private void printWelcome();
    private boolean quit(Command);
    private void look();
    private void pack(Command);
    private void unpack(Command);
    private void eat(Command);
    private void drink(Command);
    private void equip(Command);
    private void unequip(Command);
}

Lap3/CommandEnum.java

Lap3/CommandEnum.java


/**
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * This class holds an enumeration of all command words known to the game. It is
 * used to recognize commands as they are typed in.
 * 
 *  @author  Maria Jump
 *  @version  2015.02.01
 */

public  enum  CommandEnum {
     /** A constant array that holds all valid commandwords.*/
    
    
    look ,  go ,  quit ,  help ,  status ,  back ,  examine ,  take ,  drop ,
    inventory ,  unlock ,  lock ,  unpack ,  pack ,  eat ,  drink ,  equip ,
    unequip ;
    
    
     /**
     * Check whether a given String is a valid command word.
     * 
     *  @param  aString The string to determine whether it is a valid command.
     *  @return  true if a given string is a valid command, false if it isn't.
     */
    
     public   static   boolean  isCommand ( CommandEnum  aString )   {

         return   CommandWords . commandMap . containsValue ( aString );
     }

     /**
     * Returns a list of the available commands, of the form:
     *  your command words are:
     *  look go quit help
     *  
     *  @return  A string containing the list of available commands.
     */
    
     public   static   String  getCommandString (){
        
         String  commandString  =   "" ;
        
         for ( CommandEnum  moh  :   CommandEnum . values ()){
                
                commandString  +=  moh . name ()   +   ", " ;
                
             }
         return  commandString ;
         //return getCommandString();
     }

     /**
     * Converts a String into a CommandEnum object.
     *  @param  theString The String containing the command word.
     *  @return  The CommandEnum object representing the command, or null if the command does not exist. 
     */
     public   static   CommandEnum  getCommand (   String  theString ){
        
         return   CommandEnum . valueOf ( theString );
     }
}

Lap3/Writer.java

Lap3/Writer.java

import  java . awt . Color ;
import  java . io . BufferedWriter ;
import  java . io . File ;
import  java . io . FileNotFoundException ;
import  java . io . FileWriter ;
import  java . io . IOException ;
import  java . util . Scanner ;

import  javax . swing . JFileChooser ;
import  javax . swing . JTextPane ;
import  javax . swing . text . BadLocationException ;
import  javax . swing . text . Document ;
import  javax . swing . text . SimpleAttributeSet ;
import  javax . swing . text . StyleConstants ;

/**
 * This class is a substitute for printing to standard out in our original text
 * adventure game. It uses a simple console to display the messages.
 * 
 *  @author  Maria Jump
 *  @version  2016-12-18
 */
public   class   Writer   {

     /** System new line character. */
     private   static   final   String  NEW_LINE ;
     /** Name of the default log. */
     private   static   final   String  DEFAULT_LOG ;

     /** The text area that we will be writing to. */
     private   static   JTextPane  textArea ;

     /** Static block. */
     static   {
        NEW_LINE  =   System . getProperty ( "line.separator" );
        DEFAULT_LOG  =   "defaultlog.txt" ;
        textArea  =   null ;
        restartLog ();
     }

     /**
     * Mutator for the text component.
     * 
     *  @param  text
     *            The text component.
     */
     public   static   void  setTextArea ( JTextPane  text )   {
        textArea  =  text ;
        textArea . setEditable ( false );
     }

     /**
     * Print the user input in blue.
     * 
     *  @param  input
     *            The text entered by the user.
     */
     public   static   void  printInput ( String  input )   {
         SimpleAttributeSet  attributes  =   new   SimpleAttributeSet ();
         StyleConstants . setForeground ( attributes ,   Color . BLUE );
        printWithAttributes ( attributes ,  input  +  NEW_LINE );
     }

     /**
     * Prints an empty line.
     */
     public   static   void  println ()   {
        standardPrint ( NEW_LINE );
     }

     /**
     * Prints out a single integer to a line.
     * 
     *  @param  toPrint
     *            The integer to print.
     */
     public   static   void  println ( int  toPrint )   {
         String  text  =   ""   +  toPrint  +  NEW_LINE ;
        standardPrint ( text );
     }

     /**
     * Prints out a single integer.
     * 
     *  @param  toPrint
     *            The integer to print.
     */
     public   static   void  print ( int  toPrint )   {
         String  text  =   ""   +  toPrint ;
        standardPrint ( text );
     }

     /**
     * Prints out a double to a line.
     * 
     *  @param  toPrint
     *            The double to print.
     */
     public   static   void  println ( double  toPrint )   {
         String  text  =   ""   +  toPrint  +  NEW_LINE ;
        standardPrint ( text );
     }

     /**
     * Prints out a double.
     * 
     *  @param  toPrint
     *            The double to print.
     */
     public   static   void  print ( double  toPrint )   {
         String  text  =   ""   +  toPrint ;
        standardPrint ( text );
     }

     /**
     * Prints out an object to a line.
     * 
     *  @param  toPrint
     *            The object to print.
     */
     public   static   void  println ( Object  toPrint )   {
         String  text  =   ""   +  toPrint  +  NEW_LINE ;
        standardPrint ( text );
     }

     /**
     * Prints out a object.
     * 
     *  @param  toPrint
     *            The object to print.
     */
     public   static   void  print ( Object  toPrint )   {
         String  text  =   ""   +  toPrint ;
        standardPrint ( text );
     }

     /**
     * Prints a string after word-wrapping it to 80 characters if possible. Note
     * that this fails to calculate correct widths if the string contains tabs.
     * Ends with a line return.
     *
     *  @param  toPrint
     *            The String to print.
     */
     public   static   void  println ( String  toPrint )   {
         String  text  =  toPrint  +  NEW_LINE ;
        standardPrint ( text );
     }

     /**
     * Prints a string after word-wrapping it to 80 characters if possible. Note
     * that this fails to calculate correct widths if the string contains tabs.
     * 
     *  @param  toPrint
     *            The String to print.
     */
     public   static   void  print ( String  toPrint )   {
        standardPrint ( toPrint );
     }
    
     /**
     * Helper method for standard printing.
     * 
     *  @param  toPrint
     *            The String to print.
     */
     private   static   void  standardPrint ( String  toPrint )   {
         SimpleAttributeSet  attributes  =   new   SimpleAttributeSet ();
        printWithAttributes ( attributes ,  toPrint );
     }

     /**
     * Helper method printing with attributes.
     *
     *  @param  attributes
     *            A set of attributes to use when printing.
     *  @param  toPrint
     *            The String to print.
     *  @throws  IllegalStateException
     *             If the text area has not been set and we are trying to print
     *             to it.
     */
     private   static   void  printWithAttributes ( SimpleAttributeSet  attributes ,   String  toPrint )   throws   IllegalStateException   {
         if   ( textArea  ==   null )   {
             throw   new   IllegalStateException ( "Need to set the text area before printing to it." );
         }
         try   {
             Document  document  =  textArea . getDocument ();
            document . insertString ( document . getLength (),  toPrint ,  attributes );
            textArea . setCaretPosition ( document . getLength ());
             BufferedWriter  log  =   new   BufferedWriter ( new   FileWriter ( DEFAULT_LOG ,   true ));
            log . write ( toPrint );
            log . close ();
         }   catch   ( BadLocationException  ex )   {
             System . err . println ( "ERROR: Should never get this ["   +  toPrint  +   "]" );
             System . exit ( 2 );
         }   catch   ( IOException  ex )   {
             System . err . println ( "ERROR printing to default log (see instructor for help)" );
             System . exit ( 1 );
         }
     }
    
     /**
     * Restart the default log.
     */
     public   static   void  restartLog ()   {
         try   {
             BufferedWriter  log  =   new   BufferedWriter ( new   FileWriter ( DEFAULT_LOG ,   false ));
            log . close ();
         }   catch   ( IOException  ex )   {
             System . err . println ( "ERROR resetting the default log (see instructor for help)" );
             System . exit ( 1 );
         }
     }

     /**
     * Copy the default log.
     */
     public   static   void  copyDefaultLog ()   {
         Scanner  input  =   null ;
         BufferedWriter  output  =   null ;
         try   {
             JFileChooser  chooser  =   new   JFileChooser ();
            chooser . setCurrentDirectory ( new   File ( "." ));
             int  result  =  chooser . showOpenDialog ( null );
             if   ( result  ==   JFileChooser . APPROVE_OPTION )   {
                input  =   new   Scanner ( new   File ( DEFAULT_LOG ));
                output  =   new   BufferedWriter ( new   FileWriter ( chooser . getSelectedFile (),   false ));
                 while   ( input . hasNextLine ())   {
                     String  line  =  input . nextLine ();
                    output . write ( line  +  NEW_LINE );
                 }
                output . close ();
                input . close ();
             }
         }   catch   ( FileNotFoundException  exception )   {
             System . err . println ( "ERROR: default log file cannot be found" );
             System . exit ( 3 );
         }   catch   ( IOException  exception )   {
             System . err . println ( "ERROR: file for copy cannot be written to" );
             System . exit ( 4 );
         }
     }    
}

Lap3/Main$1.class

synchronized class Main$1 extends java.awt.event.ComponentAdapter {
    void Main$1(Main);
    public void componentResized(java.awt.event.ComponentEvent);
}

Lap3/CommandWords.class

public synchronized class CommandWords {
    static java.util.Map commandMap;
    public void CommandWords();
    public static boolean isCommand(String);
    public static CommandEnum getCommand(String);
    static void <clinit>();
}

Lap3/Weapon.ctxt

#BlueJ class context comment0.target=Weapon comment0.text=\n\ To\ change\ this\ license\ header,\ choose\ License\ Headers\ in\ Project\ Properties.\n\ To\ change\ this\ template\ file,\ choose\ Tools\ |\ Templates\n\ and\ open\ the\ template\ in\ the\ editor.\ \n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 29/4/2018\n comment1.params=name\ pointValue\ description\ weight comment1.target=Weapon(java.lang.String,\ int,\ java.lang.String,\ int) comment1.text=\n\ weapon.\n\ @param\ name\ the\ name\n\ @param\ pointValue\ the\ pointValue.\n\ @param\ description\ teh\ description.\n\ @param\ weight\ teh\ weight.\n comment2.params=p comment2.target=java.lang.String\ equip(Player) comment3.params=p comment3.target=java.lang.String\ unequip(Player) numComments=4

Lap3/Item.class

public synchronized class Item {
    private String name;
    private String description;
    private int weight;
    private int pointVal;
    public void Item(String, int, String, int);
    public String getName();
    public String getDescription();
    public void setDescription(String);
    public void addItem(Item);
    public Item removeItem(String);
    public Item getItem(String);
    public int getPointValue();
    public int getWeight();
    public String toString();
}

Lap3/Item.ctxt

#BlueJ class context comment0.target=Item comment0.text=\n\ Class\ Item\ -\ An\ item\ in\ the\ game\ that\ the\ player\ can\n\ pick\ or\ drop.\n\ The\ class\ also\ describe\ items\ in\ the\ game\ by\ their\ name,\ weight\ etc\n\ \n\ @author\ Mohammed\ Alharbi\n\ @version\ 2018/4/24\n comment1.params=name\ pointValue\ description\ weight comment1.target=Item(java.lang.String,\ int,\ java.lang.String,\ int) comment1.text=\ item.\n\ @param\ name\ the\ name.\n\ @param\ pointValue\ the\ pointValue\n\ @param\ description\ the\ description\n\ @param\ weight\ the\ weight\n comment10.params= comment10.target=java.lang.String\ toString() comment2.params= comment2.target=java.lang.String\ getName() comment2.text=\n\ \n\ Returns\ the\ name\ of\ an\ item.\n\ @return\ The\ name\ of\ an\ item.\n\ \n comment3.params= comment3.target=java.lang.String\ getDescription() comment3.text=\n\ \n\ Returns\ the\ description\ of\ an\ item.\n\ @return\ The\ description\ of\ an\ item.\n\ \n comment4.params=desc comment4.target=void\ setDescription(java.lang.String) comment4.text=\n\ \n\ Sets\ the\ description\ of\ a\ room.\n@param\ desc\ the\ desc.\ \n comment5.params=item comment5.target=void\ addItem(Item) comment5.text=\ item.\ \n@param\ item\ the\ item.\n\n comment6.params=item comment6.target=Item\ removeItem(java.lang.String) comment6.text=\ item.\ \n@param\ item\ the\ item.\n@return\ item\ the\ item.\n comment7.params=item comment7.target=Item\ getItem(java.lang.String) comment7.text=\ item.\ \n@param\ item\ the\ item.\n@return\ item\ the\ item.\n comment8.params= comment8.target=int\ getPointValue() comment8.text=\n\ \n\ Returns\ the\ pointValue\ of\ an\ item.\n\ @return\ The\ pointValue\ of\ an\ item.\n\ \n comment9.params= comment9.target=int\ getWeight() comment9.text=\n\ \n\ Returns\ the\ weight\ of\ an\ item.\n\ @return\ The\ weight\ of\ an\ item.\n\ \n numComments=11

Lap3/Command.java

Lap3/Command.java

 

import  java . util . ArrayList ;
/**
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * This class holds information about a command that was issued by the user. A
 * command currently consists of two strings: a command word and a second word
 * (for example, if the command was "take map", then the two strings obviously
 * are "take" and "map").
 * 
 * The way this is used is: Commands are already checked for being valid command
 * words. If the user entered an invalid command (a word that is not known) then
 * the command word is <null>.
 * 
 * If the command had only one word, then the second word is <null>.
 * 
 *  @author  Maria Jump
 *  @version  2015.02.01
 */

public   class   Command   {
     /** The command word for this command. */
     private   CommandEnum  commandWord ;
     /** The rest of the line with all the spaces removed. */
     private   ArrayList < String >  restOfLine ;

     /**
     * Create a command object. First is supplied. The second word is assumed
     * to be null.
     * 
     *  @param  firstWord
     *            The first word of the command. Null if the command was not
     *            recognized.
     */
     public   Command ( String  firstWord )   {
        commandWord  =   CommandWords . getCommand ( firstWord );
        restOfLine  =   new   ArrayList < String > ();
                
     }
    
     /**
     * Create a command object. First and second word must be supplied, but
     * either one (or both) can be null.
     * 
     *  @param  firstWord
     *            The first word of the command. Null if the command was not
     *            recognized.
     *  @param  rest
     *            The rest of the command.
     */
     public   Command ( String  firstWord ,   ArrayList < String >  rest )   {
        commandWord  =   CommandWords . getCommand ( firstWord );
        restOfLine  =  rest ;
     }

     /**
     * Return the command word (the first word) of this command. If the command
     * was not understood, the result is null.
     * 
     *  @return  The command word.
     */
     public   CommandEnum  getCommandWord ()   {
            
         return  commandWord ;
     }

     /**
     * Returns if this command was not understood.
     * 
     *  @return  true if this command was not understood.
     */
     public   boolean  isUnknown ()   {
         return   ( commandWord  ==   null );
     }

     /**
     * Returns if this command has a second word.
     * 
     *  @return  true if the command has a second word.
     */
     public   boolean  hasSecondWord ()   {
         return  restOfLine  !=   null ;
     }
    
     /**
     * Returns if this command has more words.
     *
     *  @param  index The index of the word needed.
     *  @return  true if the command has a word at given index.
     */
     public   boolean  hasWord ( int  index )   {
         return  index  >=   0   &&  index  <  restOfLine . size ();
     }
    
     /**
     * Returns the word at the requested index in the command.
     * 
     *  @param  index
     *            The index of word in the command that is being requested.
     * 
     *  @return  A particular word in the command. Returns null if there is no
     *         word corresponding to that requested index.
     * 
     */
     public   String  getWord ( int  index )   {
         String  result  =   null ;
         if   ( index  >=   0   &&  index  <  restOfLine . size ())   {
            result  =  restOfLine . get ( index );
         }
         return  result ;
     }    
    

     /**
     * Returns the second word of this command, if it exists.
     * 
     *  @return  The second word of this command. Returns null if there was no
     *         second word.
     */
     public   String  getRestOfLine ()   {
         StringBuffer  buffer  =   null ;
         if   ( restOfLine . size ()   !=   0 )   {
             for ( String  word  :  restOfLine )   {
                 if   ( buffer  ==   null )   {
                    buffer  =   new   StringBuffer ();
                    buffer . append ( word );
                 }
                 else   {
                    buffer . append ( " " );
                    buffer . append ( word );
                 }
             }
         }
         String  result  =   "" ;
         if   ( buffer  !=   null )   {
            result  +=  buffer . toString ();
         }
         return  result ;
     }
}

__MACOSX/Lap3/._Command.java

Lap3/Drink.class

public synchronized class Drink extends Item implements Drinkable {
    public void Drink(String, int, String, int);
    public String drink(Player);
}

Lap3/Edible.java#backup

Lap3/Edible.java#backup

 

public   interface   Edible   {
     public   String  eat ();
}

Lap3/Command.class

public synchronized class Command {
    private CommandEnum commandWord;
    private java.util.ArrayList restOfLine;
    public void Command(String);
    public void Command(String, java.util.ArrayList);
    public CommandEnum getCommandWord();
    public boolean isUnknown();
    public boolean hasSecondWord();
    public boolean hasWord(int);
    public String getWord(int);
    public String getRestOfLine();
}

Lap3/Room.class

public synchronized class Room {
    private static int counter;
    private String name;
    private String description;
    private int points;
    private java.util.HashMap directions;
    private java.util.HashMap roomItems;
    public void Room(String, String);
    public String getName();
    public String getDescription();
    public Door getDirection(String);
    public static int getCounter();
    public int getPoints();
    public void setPoints(int);
    public void setDirection(String, Door);
    public void addItem(Item);
    public Item getItem(String);
    public Item removeItem(String);
    public String toString();
    static void <clinit>();
}

Lap3/Container.class

public synchronized class Container extends Item {
    private final java.util.HashMap containerItems;
    private int weight;
    public void Container(String, int, String, int);
    public void addItem(Item);
    public Item removeItem(String);
    public int getWeight();
    public Item getItem(String);
    private String getContainerItems();
    public String toString();
}

Lap3/defaultlog.txt

Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. You are in Bathroom there is teeth brush, shower place. Exits : east Items : tooth paste, tooth brush, > go east You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room.. Exits : south west Items : knife, coffee, purse, grapes, > go south door is locked! > unlock south With what? purse You don't have it! > pack purse pack where? south You don't see the container > go south door is locked! > unlock south With what? purse You don't have it! >

Lap3/Reader.java

Lap3/Reader.java

import  java . util . ArrayList ;
import  java . util . Scanner ;


/**
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * This parser reads user input and tries to interpret it as an "Adventure"
 * command. Every time it is called it reads a line from the terminal and tries
 * to interpret the line as a two word command. It returns the command as an
 * object of class Command.
 * 
 * The parser has a set of known command words. It checks user input against the
 * known commands, and if the input is not one of the known commands, it returns
 * a command object that is marked as an unknown command.
 * a
 *  @author  Maria Jump
 *  @version  2017.12.18
 */
public   class   Reader   {
     /** The source of command input. */
     private   static   Scanner  reader ;
    
     /**
     * Create a parser to read from the terminal window.
     */
     static   {
        reader  =   new   Scanner ( System . in );
     }    

     /**
     * Returns the next command from the user.
     *  @return  The next command from the user.
     */
     public   static   Command  getCommand ()   {
         String  inputLine ;   // will hold the full input line
         String  word1  =   null ;
         ArrayList < String >  restOfLine  =   null ;

         Writer . print ( "> " );   // print prompt

        inputLine  =  reader . nextLine (). toLowerCase ();
         Writer . printInput ( inputLine );

         // Find up to two words on the line.
         Scanner  tokenizer  =   new   Scanner ( inputLine );
         if   ( tokenizer . hasNext ())   {
            word1  =  tokenizer . next ();   // get first word
             if   ( tokenizer . hasNext ())   {
                restOfLine  =   new   ArrayList < String > ();
                 while ( tokenizer . hasNext ())   {
                    restOfLine . add ( tokenizer . next ());
                 }
             }
         }
        tokenizer . close ();

         // Now check whether this word is known. If so, create a command
         // with it. If not, create a "null" command (for unknown command).
         Command  result  =   null ;
                
         if   ( CommandWords . isCommand ( word1 ))   {
            
            result  =   new   Command ( word1 ,  restOfLine );
         }  
         else   {
            result  =   new   Command ( null ,  restOfLine );
         }
            
            //Command result = CommandWords.getCommand(word1);
           
         return  result ;
     }
    
     /**
     * Return the response to a question in all lower case.
     *
     *  @return  The response typed in by the user.
     */
     public   static   String  getResponse ()   {
         return  getResponseKeepCase (). toLowerCase ();
     }
    
     /**
     * Return the response to a question in the case used by the player.
     *
     *  @return  The response typed in by the user.
     */
     public   static   String  getResponseKeepCase ()   {
         String  response  =  reader . nextLine (). trim ();
         Writer . printInput ( response );
         return  response ;
     }
}

__MACOSX/Lap3/._Reader.java

Lap3/Edible.ctxt

#BlueJ class context comment0.target=Edible comment0.text=\n\ To\ change\ this\ license\ header,\ choose\ License\ Headers\ in\ Project\ Properties.\n\ To\ change\ this\ template\ file,\ choose\ Tools\ |\ Templates\n\ and\ open\ the\ template\ in\ the\ editor.\ \n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 29/4/2018\n comment1.params=p comment1.target=java.lang.String\ eat(Player) comment1.text=\n\ eat\ .\n\ @param\ p\ the\ current\ game\ character\n\ @return\ true\n numComments=2

Lap3/CommandEnum$validCommands.class

public final synchronized enum CommandEnum$validCommands {
    public static final CommandEnum$validCommands look;
    public static final CommandEnum$validCommands go;
    public static final CommandEnum$validCommands quit;
    public static final CommandEnum$validCommands help;
    public static final CommandEnum$validCommands status;
    public static final CommandEnum$validCommands back;
    public static CommandEnum$validCommands[] values();
    public static CommandEnum$validCommands valueOf(String);
    private void CommandEnum$validCommands(String, int);
    static void <clinit>();
}

Lap3/Container.java

Lap3/Container.java


import  java . util . HashMap ;

/*
 * Class Container - A container item in the game that the player can
 * pack or unpack
 * The class also describe containers in the game by their name, weight etc
 */

/**
 * 24 April 2018
 *  @author  [Your name]
 */

public   class   Container   extends   Item {
    
     private   final   HashMap < String ,   Item >  containerItems ;
    
     private   int  weight  =   0 ;
        
     public   Container ( String  name ,   int  pointValue ,   String  description ,   int  weight )   {
        
         super ( name ,  pointValue ,  description ,  weight );
                
        containerItems  =   new   HashMap <> ();
     }
        
     /**
     * Add item to a container.
     * 
     *  @param  item the item to be added to the container
    **/
    @ Override
     public   void  addItem ( Item  item ){
        
        containerItems . put ( item . getName (),  item );
     }        
    
     /**
     * remove item from a container.
     * 
     *  @param  itemName the item to be removed from the container
     *  @return  Item that has been removed from the container
    **/
    @ Override
     public   Item  removeItem ( String  itemName ){
        
         return  containerItems . remove ( itemName );
     }

    @ Override
     public   int  getWeight ()   {
        
        weight  =   super . getWeight ();
        
         for ( Item  item :  containerItems . values ()){
            
            weight  +=  item . getWeight ();
         }
        
         return  weight ;
     }     
    
     /**
     * get item from the container.
     * 
     *  @param  itemName the item to be removed from the container
     *  @return  Item that has been removed from the container
    **/
     //@Override
     public   Item  getItem ( String  itemName ){
        
         return  containerItems . get ( itemName );
     }
    
     private   String  getContainerItems (){
        
         String  containerItemsRes  =   "" ;
        
         for ( String  s :  containerItems . keySet ()){
        
            containerItemsRes  +=  s  +   ", " ;
            
         }
                
         return  containerItemsRes ;
     }
    
    
    @ Override
     public   String  toString (){
        
         String  itemInfo  =   super . toString ();
        
        itemInfo  +=   "\nItems : "   +  getContainerItems ()   ;
        
         return  itemInfo ;
     }
}

Lap3/CommandEnum.class

public final synchronized enum CommandEnum {
    public static final CommandEnum look;
    public static final CommandEnum go;
    public static final CommandEnum quit;
    public static final CommandEnum help;
    public static final CommandEnum status;
    public static final CommandEnum back;
    public static final CommandEnum examine;
    public static final CommandEnum take;
    public static final CommandEnum drop;
    public static final CommandEnum inventory;
    public static final CommandEnum unlock;
    public static final CommandEnum lock;
    public static final CommandEnum unpack;
    public static final CommandEnum pack;
    public static final CommandEnum eat;
    public static final CommandEnum drink;
    public static final CommandEnum equip;
    public static final CommandEnum unequip;
    public static CommandEnum[] values();
    public static CommandEnum valueOf(String);
    private void CommandEnum(String, int);
    public static boolean isCommand(CommandEnum);
    public static String getCommandString();
    public static CommandEnum getCommand(String);
    static void <clinit>();
}

Lap3/team.defs

#Mon Apr 30 14:39:34 EDT 2018 bluej.teamsettings.groupname= bluej.teamsettings.git.repositoryPrefix=/kings-cs/CS117-S18-AlharbiMohammed.git bluej.teamsettings.git.protocol=https bluej.teamsettings.user=alharbi333 bluej.teamsettings.git.server=github.com [email protected] bluej.teamsettings.vcs=git bluej.teamsettings.ignore8=\\.DS_Store bluej.teamsettings.ignore7=.*\\\#backup bluej.teamsettings.yourName=mohammedalharbi bluej.teamsettings.ignore6=.*\\\# bluej.teamsettings.ignore5=.*\\~ bluej.teamsettings.ignore4=.*\\.ctxt bluej.teamsettings.ignore3=team\\.defs bluej.teamsettings.ignore2=bluej\\.pkh bluej.teamsettings.ignore1=.*\\.class

Lap3/README.md

Project: CampusOfKings-bad Authors: Maria Jump This project is a simple framework for an text adventure game. In this version, it has a few rooms and the ability for a player to walk between these rooms. That's all. This version of the game contains some very bad class design. It should NOT be used as a basis for extending the project without fixing these design problems. It serves as an example to discuss good and bad design. We will fix the problems with this project through the next couple of labs which walk students through fixing bad design decisions and give them an opportunity to become familiar with the existing code.

Lap3/Food.java

Lap3/Food.java

/**
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. 
 * 
 *  @author  mohammed alharbi
 *  @version  29/4/2018
 */
public   class   Food   extends   Item   implements   Edible {
     /**
     * food.
     *  @param  name the name.
     *  @param  pointValue the pointValue.
     *  @param  description teh description.
     *  @param  weight teh weight.
     */
     public   Food ( String  name ,   int  pointValue ,   String  description ,   int  weight )   {
         super ( name ,  pointValue ,  description ,  weight );
     }

    @ Override
     public   String  eat ( Player  p )   {        

        p . updateHealth ( 5 );

        p . removeItem ( this . getName ());

         return   "you have eaten food" ;
     }

}

Lap3/CommandEnum.ctxt

#BlueJ class context comment0.target=CommandEnum comment0.text=\n\ This\ class\ is\ part\ of\ the\ "Campus\ of\ Kings"\ application.\ "Campus\ of\ Kings"\ is\ a\n\ very\ simple,\ text\ based\ adventure\ game.\n\ \n\ This\ class\ holds\ an\ enumeration\ of\ all\ command\ words\ known\ to\ the\ game.\ It\ is\n\ used\ to\ recognize\ commands\ as\ they\ are\ typed\ in.\n\ \n\ @author\ Maria\ Jump\n\ @version\ 2015.02.01\n comment1.params=aString comment1.target=boolean\ isCommand(CommandEnum) comment1.text=\n\ Check\ whether\ a\ given\ String\ is\ a\ valid\ command\ word.\n\ \n\ @param\ aString\ The\ string\ to\ determine\ whether\ it\ is\ a\ valid\ command.\n\ @return\ true\ if\ a\ given\ string\ is\ a\ valid\ command,\ false\ if\ it\ isn't.\n comment2.params= comment2.target=java.lang.String\ getCommandString() comment2.text=\n\ Returns\ a\ list\ of\ the\ available\ commands,\ of\ the\ form\:\n\ \ your\ command\ words\ are\:\n\ \ look\ go\ quit\ help\n\ \ \n\ @return\ A\ string\ containing\ the\ list\ of\ available\ commands.\n comment3.params=theString comment3.target=CommandEnum\ getCommand(java.lang.String) comment3.text=\n\ Converts\ a\ String\ into\ a\ CommandEnum\ object.\n\ @param\ theString\ The\ String\ containing\ the\ command\ word.\n\ @return\ The\ CommandEnum\ object\ representing\ the\ command,\ or\ null\ if\ the\ command\ does\ not\ exist.\ \n numComments=4

Lap3/World.ctxt

#BlueJ class context comment0.target=World comment0.text=\n\ This\ class\ represents\ the\ entire\ world\ that\ makes\ up\ the\ "Campus\ of\ Kings"\n\ application.\ "Campus\ of\ Kings"\ is\ a\ very\ simple,\ text\ based\ adventure\ game.\n\ Users\ can\ walk\ around\ some\ scenery.\ That's\ all.\ It\ should\ really\ be\ extended\n\ to\ make\ it\ more\ interesting\!\n\ \n\ This\ world\ class\ creates\ the\ world\ where\ the\ game\ takes\ place.\n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 20/2/2018\n comment1.params= comment1.target=World() comment1.text=\n\ Constructor\ for\ the\ world.\n comment2.params= comment2.target=void\ createItems() comment2.text=\n\ item\ the\ item.\n comment3.params=name comment3.target=Room\ getcurrentRoom(java.lang.String) comment3.text=\n\ This\ method\ takes\ care\ of\ creating\ all\ of\ the\ aspects\ of\ the\ world\ for\n\ the\ "Campus\ of\ Kings"\ application.\n\ \n\ @param\ name\n\ \ \ \ \ \ \ \ \ \ \ \ The\ provided\ name\ of\ the\ room.\n\ @return\ The\ room\ associated\ with\ the\ provided\ name\n comment4.params=theRoom comment4.target=void\ addRoom(Room) comment4.text=\n\ Helper\ method\ for\ recreating\ a\ Room.\ Ensure\ that\ the\ room\ is\ created\ and\n\ installed\ in\ to\ the\ collection\ of\ Rooms.\n\ \n\ @param\ theRoom\n\ \ The\ room\ to\ add\ to\ the\ world.\n comment5.params=from\ direction\ to comment5.target=void\ createDoor(Room,\ java.lang.String,\ Room) comment5.text=\n\ Helper\ method\ for\ creating\ doors\ between\ rooms.\n\ \n\ @param\ from\ The\ room\ where\ the\ door\ originated.\n\ @param\ direction\ The\ direction\ of\ the\ door\ in\ the\ from\ room.\n\ @param\ to\ The\ room\ where\ the\ door\ goes.\n comment6.params= comment6.target=void\ createRooms() comment6.text=\n\ This\ method\ creates\ all\ of\ the\ individual\ places\ in\ this\ world\ and\ all\n\ the\ doors\ connecting\ them.\n numComments=7

Lap3/Drinkable.ctxt

#BlueJ class context comment0.target=Drinkable comment0.text=\n\ To\ change\ this\ license\ header,\ choose\ License\ Headers\ in\ Project\ Properties.\n\ To\ change\ this\ template\ file,\ choose\ Tools\ |\ Templates\n\ and\ open\ the\ template\ in\ the\ editor.\ \n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 29/4/2018\n comment1.params=p comment1.target=java.lang.String\ drink(Player) comment1.text=\n\ drink\ the\ drink.\n\ @param\ p\ the\ current\ game\ character.\n\ @return\ a\ message\n numComments=2

Lap3/Game$1.class

synchronized class Game$1 {
    static void <clinit>();
}

Lap3/.gitignore

*.class *.ctxt *.*~ doc /.project default.log defaultlog.txt

Lap3/Player.java

Lap3/Player.java


import  java . util . HashMap ;

/**
 * class Player.
 *  @author  Mohammed Alharbi
 *  @version  2018.1.27
 */
  public   class   Player {  

    /** field in the Player class to store the currentRoom.*/
     private   Room  currentRoom ;
     private   Room  previousRoom ;
     private   Item  currentWeapon ;
     private   int  health ;     
     private   int  currentWeight ;
    
     public   static   final   int  MAX_WEIGHT  =   5000 ;
    
     private   HashMap < String ,   Item >  inventory ;
    
    /** constructor in the Player class.
    *  @param  playPlayer for the room .
    */
     public   Player ( Room  playPlayer ){
        
       currentRoom  =  playPlayer ;
       
       previousRoom  =   null ;
       
       health  =   100 ;
       
       currentWeapon  =   null ;
       
       inventory  =   new   HashMap <> ();
       
       currentWeight  =   0 ;
     }  
    
     public   void  updateHealth ( int  health ){
        
         this . health  +=  health ;
     }
        
     /** Add item to inventory.
     *  @param  item
     *  @return  true if item added to inventory
     */
     public   boolean  inventoryAddItem ( Item  item ){
       
        inventory . put ( item . getName (),  item );
        
         return   true ;
    }
    
     /**
     *
     *  @return  current weight that the player is carrying
     */
     public   int  getCurrentWeight (){
        
         return  currentWeight ;
     }
    
     /**
     *
     *  @return  the maximum weight that the player can carry
     */
     public   int  getMaxWeight (){
        
         return  MAX_WEIGHT ;
     }
    
     /** Get an item from the players inventory.
     *  @param  itemName - name of item to be picked
     *  @return  an Item object
     */
     public   Item  getItem ( String  itemName ){
        
         return  inventory . get ( itemName );
     
    }
    
     /** remove an item from the players inventory.
     *  @param  itemName - name of item to be removed
     *  @return  an Item object
     */
     public   Item  removeItem ( String  itemName ){
            
        currentWeight  -=  getItem ( itemName ). getWeight ();
        
         return  inventory . remove ( itemName );
     
    }
    
    /** accessors  for the current room the character.
    *  @return  currentRoom
    */
     public   Room  getcurrentRoom (){
         return  currentRoom ;
     }
    
     /** a mutator for the current room of the character.
     *  @param  playing for the Room
     */
     public   void  setcurrentRoom ( Room  playing ){
        
     previousRoom  =  currentRoom ;
   
     currentRoom  =  playing ;
    }
    
     /** a mutator for the current weapon of the character.
     *  @param  weapon to be equipped
     */
     public   void  setCurrentWeapon ( Item  weapon ){
           
     currentWeapon  =  weapon ;
     
    }
    
     
    /** Accessors for the previous room the character.
    *  @return  cerrentRoom
    */
     public   Room  getpreviousRoom (){
         return  previousRoom ;
     }
    
     /** Accessors for the players inventory.
    *  @return  players inventory
    */
     public   String  getInventory (){
        
         String  inventoryInfo  =   "" ;
        
         for ( String  s :  inventory . keySet ()){
            
            inventoryInfo  +=   " "   +  s  + ", " ;
         }
        
         return  inventoryInfo ;
     }

     /**
     *
     *  @return  the players current weapon
     */
     public   Item  getCurrentWeapon ()   {
        
         return  currentWeapon ;
     }
}

Lap3/Room.ctxt

#BlueJ class context comment0.target=Room comment0.text=\n\ Class\ Room\ -\ a\ room\ in\ an\ adventure\ game.\n\ \n\ This\ class\ is\ part\ of\ the\ "Campus\ of\ Kings"\ application.\ "Campus\ of\ Kings"\ is\ a\n\ very\ simple,\ text\ based\ adventure\ game.\n\ \n\ A\ "Room"\ represents\ one\ location\ in\ the\ scenery\ of\ the\ game.\ It\ is\ connected\n\ to\ other\ rooms\ via\ doors.\ The\ doors\ are\ labeled\ north,\ east,\ south,\ west.\n\ For\ each\ direction,\ the\ room\ stores\ a\ reference\ to\ an\ instance\ of\ door.\n\ \n\ @author\ Mohammed\ ALharbi\n\ @version\ 2018.1.26\n comment1.params=name\ description comment1.target=Room(java.lang.String,\ java.lang.String) comment1.text=\n\ Create\ a\ room\ described\ "description".\ Initially,\ it\ has\ no\ exits.\n\ "description"\ is\ something\ like\ "a\ kitchen"\ or\ "an\ open\ court\ yard".\n\ @param\ name\ \ The\ rooms\ name.\n\ @param\ description\n\ \ \ The\ rooms\ description.\n comment10.params=name comment10.target=Item\ getItem(java.lang.String) comment10.text=\n\ get\ Item\n\ @param\ name\ -\ The\ name\ of\ the\ item\ to\ be\ added\ to\ the\ room\n\ @return\ Item\ -\ The\ item\ in\ the\ collection\ with\ the\ key\ name\n comment11.params=name comment11.target=Item\ removeItem(java.lang.String) comment11.text=\n\ Remove\ Item\n\ @param\ name\ -\ The\ name\ of\ the\ item\ to\ be\ removed\ from\ the\ room\n\ @return\ item\ -\ The\ item\ that\ has\ been\ removed\ from\ the\ room\n comment12.params= comment12.target=java.lang.String\ toString() comment12.text=\n\ Returns\ a\ string\ description\ including\ all\ the\ details\ of\ a\ Room.\nExits\ \:\ north\ east\ south\ west\n\ @return\ A\ string\ representing\ all\ the\ details\ of\ a\ Room.\n comment2.params= comment2.target=java.lang.String\ getName() comment2.text=\n\ Returns\ the\ name\ of\ this\ room.\n\ \n\ @return\ The\ name\ of\ this\ room.\n comment3.params= comment3.target=java.lang.String\ getDescription() comment3.text=\n\ Returns\ the\ description\ of\ this\ room.\n\ \n\ @return\ The\ description\ of\ this\ room.\n comment4.params=direction comment4.target=Door\ getDirection(java.lang.String) comment4.text=\n\ Returns\ the\ door\ of\ this\ room.\n\ @return\ The\ door\ of\ this\ room\n comment5.params= comment5.target=int\ getCounter() comment5.text=\n\ Return\ the\ rooms\ that\ have\ been\ created\ int\ the\ world.\n\ @return\ the\ rooms\ that\ have\ been\ created\ int\ the\ world.\n comment6.params= comment6.target=int\ getPoints() comment6.text=\n\ @return\ getExit\ for\ getting\ the\ direction.\n comment7.params=newPoints comment7.target=void\ setPoints(int) comment7.text=\ Mutator\ for\ setting\ the\ points.\n\ @param\ newPoints\n comment8.params=direction\ neighbor comment8.target=void\ setDirection(java.lang.String,\ Door) comment8.text=\n\ Set\ exit.\n\ @param\ direction\n\ @param\ neighbor\n comment9.params=item comment9.target=void\ addItem(Item) comment9.text=\n\ Add\ Item\n\ @param\ item\ -\ The\ item\ object\ to\ be\ added\n numComments=13

Lap3/Drink.ctxt

#BlueJ class context comment0.target=Drink comment0.text=\n\ To\ change\ this\ license\ header,\ choose\ License\ Headers\ in\ Project\ Properties.\n\ To\ change\ this\ template\ file,\ choose\ Tools\ |\ Templates\n\ and\ open\ the\ template\ in\ the\ editor.\ \n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 29/4/2018\n comment1.params=name\ pointValue\ description\ weight comment1.target=Drink(java.lang.String,\ int,\ java.lang.String,\ int) comment1.text=\n\ Drink.\n\ @param\ name\ the\ name.\n\ @param\ pointValue\ the\ pointValue.\n\ @param\ description\ teh\ description.\n\ @param\ weight\ teh\ weight.\n comment2.params=p comment2.target=java.lang.String\ drink(Player) numComments=3

Lap3/Game.java

Lap3/Game.java

/**
 * This class is the main class of the "Campus of Kings" application.
 * "Campus of Kings" is a very simple, text based adventure game. Users can walk
 * around some scenery. That's all. It should really be extended to make it more
 * interesting!
 * This game class creates and initializes all the others: it creates all rooms,
 * creates the parser and starts the game. It also evaluates and executes the
 * commands that the parser returns.
 * 
 *  @author  Mohammed Alharbi
 *  @version  2018/1/24
 */

public   class   Game   {
     /** The world where the game takes place. */
     private   World  world ;
     //** stores the character controlled by the Player. */
     //private Player Playing;
     /** the total score. */
     private   int  score  ;
     /** the total number of turns. */
     private   int  turns ;
     /** This is an object for getting the room from the Player class. */
     private    Player  playerClass ;
     /**
     * Create the game and initialize its internal map.
     */
     public   Game ()   {
        world  =   new   World ();
        playerClass  =   new   Player ( world . getcurrentRoom ( "Bathroom" ));
        score  =   0 ;
        turns  =   0 ;

     }
    
     /**
     * Get current player playing the game.
     *  @return  current player
     */
     public    Player  getCurrentPlayer (){
        
         return  playerClass ;
     }

     /**
     * Main play routine. Loops until end of play.
     */
     public   void  play ()   {
        printWelcome ();

         // Enter the main game loop. Here we repeatedly read commands and
         // execute them until the game is over.
         boolean  wantToQuit  =   false ;
         while   ( ! wantToQuit )   {
             Command  command  =   Reader . getCommand ();
            wantToQuit  =  processCommand ( command );
            turns  =  turns  +   1 ;
         }
        printGoodbye ();
     }

     ///////////////////////////////////////////////////////////////////////////
     // Helper methods for processing the commands

     /**
     * Given a command, process (that is: execute) the command.
     * 
     *  @param  command
     *            The command to be processed.
     *  @return  true If the command ends the game, false otherwise.
     */
     private   boolean  processCommand ( Command  command )   {
         //private static CommandEnum g(){

         boolean  wantToQuit  =   false ;

         if   ( ! CommandEnum . isCommand ( command . getCommandWord ()))   {
            
             Writer . println ( "I don't know what you mean..." );
            
         } else   {

             CommandEnum  commandWord  =  command . getCommandWord ();
            
             switch ( commandWord ){
                
                 case  help :
                    printHelp ();
                     break ;
                    
                 case  go :
                    goGame ( command );
                     break ;
                    
                 case  look :
                    look ();
                     break ;
                    
                 case  quit :
                    wantToQuit  =  quit ( command );
                     break ;
                    
                 case  status :
                    printGameStatus ();
                     break ;
                    
                 case  back :
                    goBack ();
                     break ;
                    
                 case  examine :
                    examineItem ( command );
                     break ;
                    
                 case  take :
                    takeItem ( command );
                     break ;
                    
                 case  drop :
                    dropItem ( command );
                     break ;
                    
                 case  inventory :
                    inventory ();
                     break ;
                    
                 case  lock :
                    lock ( command );
                     break ;
                    
                 case  unlock :
                    unlock ( command );
                     break ;
                    
                 case  pack :
                    pack ( command );
                     break ;
                    
                 case  unpack :
                    unpack ( command );
                     break ;
                    
                 case  eat :
                    eat ( command );
                     break ;
                    
                 case  drink :
                    drink ( command );
                     break ;
                    
                 case  equip :
                    equip ( command );
                     break ;
                    
                 case  unequip :
                    unequip ( command );
                     break ;
                    
                 default :
                     Writer . println ( commandWord  +   " is not implemented yet!" );
                     break ;
             }
         }
         return  wantToQuit ;

     }

     ///////////////////////////////////////////////////////////////////////////
     // Helper methods for implementing all of the commands.
     // It helps if you organize these in alphabetical order.

     /**
     * Try to go to one direction. If there is an exit, enter the new room,
     * otherwise print an error message.
     * 
     *  @param  command
     *  The command to be processed.
     */
     private   void  goGame ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "Go where?" );
            
         }   else   {
             String  direction  =  command . getRestOfLine ();
            
             Door  doorway  =  playerClass . getcurrentRoom (). getDirection ( direction );

             if   ( doorway  ==   null )   {
                
                 Writer . println ( "There is no door!" );
                
             }   else   {                 
                
                 if ( doorway . isLocked ()){
                    
                     Writer . println ( "door is locked!" );
                    
                 } else {
                    
                     Room  newRoom  =  doorway . getDestination ();  
                    playerClass . setcurrentRoom ( newRoom );
                    score  =  score  +  newRoom . getPoints ();  
                    printLocationInformation  ();
                
                 }
             }
         }
     }
     /**
     * Unlock a locked door. 
     * 
     *  @param  command
     *  The command to be processed.
     */
     private   void  unlock ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "Unlock what?" );
            
         }   else   {
            
             String  direction  =  command . getRestOfLine ();
            
             Door  doorway  =  playerClass . getcurrentRoom (). getDirection ( direction );

             if   ( doorway  ==   null )   {
                
                 Writer . println ( "There is no door!" );
                
             }   else   {  
                
                 if   ( doorway . isLocked ()   ==   false )   {
                    
                     Writer . println ( "Door is not locked!" );
                    
                 } else {
                    
                     Writer . println ( "With what?" );
                    
                     String  key  =   Reader . getResponse ();
                    
                     if ( playerClass . getItem ( key )   !=   null ){
                        
                         if ( doorway . getKey ()   ==  playerClass . getItem ( key )){
                            
                            doorway . setLocked ( false );
                            
                             Writer . println ( "You unlocked it!" );
                            
                         } else {
                            
                             Writer . println ( "That doesn't fit!" );
                         }
                        
                     } else {
                        
                         Writer . println ( "You don't have it!" );
                     }
                 }
             }
         }
     }
    
      /**
     * lock a locked door. 
     * 
     *  @param  command
     *  The command to be processed.
     */
     private   void  lock ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "Lock what?" );
            
         }   else   {
            
             String  direction  =  command . getRestOfLine ();
            
             Door  doorway   =  playerClass . getcurrentRoom (). getDirection ( direction );

             if   ( doorway  ==   null )   {
                
                 Writer . println ( "no door!" );
                
             }   else   {  
                
                 if   ( doorway . isLocked ()   ==   true )   {
                    
                     Writer . println ( "Door is already locked!" );
                    
                 } else {
                    
                     if ( doorway . getKey ()   ==   null ){
                        
                         Writer . println ( "Door cannot be locked!" );
                        
                     } else {
                    
                         Writer . println ( "With what?" );

                         String  key  =   Reader . getResponse ();

                         if ( playerClass . getItem ( key )   !=   null ){

                             if ( doorway . getKey ()   ==  playerClass . getItem ( key )){

                                doorway . setLocked ( true );

                                 Writer . println ( "You locked it!" );

                             } else {

                                 Writer . println ( "wrong key!!" );
                             }

                         } else {

                             Writer . println ( "You don't have it!" );
                         }
                     }
                 }
             }
         }
        
     }
     /**
     * Try to examine a play item. If the item doesn't exist in the
     * players inventory nor the current room,
     * print an error message.
     * 
     *  @param  command
     *  The command to be processed.
     */
     private   void  examineItem ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "Which item?" );
            
         }   else   {
             String  itemName  =  command . getRestOfLine ();
            
             Item  item   =  playerClass . getItem ( itemName );
            
             //Check the item value has had something added, if no, check for the item in the current room
            
             if   ( item  ==   null )   {
                
                item  =  playerClass . getcurrentRoom (). getItem ( itemName );
                
             }
            
             //Check if item exists in the current room
            
             if   ( item  ==   null )   {
                
                 Writer . println ( "No such item!" );
                
             }   else   {                 
                
                 Writer . println ( item . toString ());
             }
         }
     }
            
     /**
     * Try to go to one direction. If there is an exit, enter the new room,
     * otherwise print an error message.
     * 
     *  @param  command
     *  The command to be processed.
     */
     private   void  takeItem ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "take what?" );
            
         }   else   {
             String  itemName  =  command . getRestOfLine ();
            
             Item  item   =  playerClass . getcurrentRoom (). getItem ( itemName );
            
             //Check if item exists in the current room
            
             if   ( item  ==   null )   {
                
                 Writer . println ( "No such item!" );
                
             }   else   {  
                
                 if ( item . getWeight ()   >  playerClass . MAX_WEIGHT ){
                    
                     Writer . println ( "too heavy to lift" );
                    
                 } else {
                    
                     if ( playerClass . getCurrentWeight ()   +  item . getWeight ()   >  playerClass . MAX_WEIGHT ){
                        
                         Writer . println ( "Carrying too much" );
                        
                     } else {
                        
                        playerClass . inventoryAddItem ( item );
                        
                        playerClass . getcurrentRoom (). removeItem ( itemName );
                        
                         Writer . println ( "you took the item" );
                     }
                 }
             }
         }
     }
    
         /**
     * Try to go to one direction. If there is an exit, enter the new room,
     * otherwise print an error message.
     * 
     *  @param  command
     *  The command to be processed.
     */
     private   void  dropItem ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "which item?" );
            
         }   else   {
             String  itemName  =  command . getRestOfLine ();
            
             Item  item  =  playerClass . getItem ( itemName );
            
             //Check if item exists in the current room
            
             if   ( item  ==   null )   {
                
                 Writer . println ( "you don't have it!" );
                
             }   else   {  

                playerClass . getcurrentRoom (). addItem ( item );

                playerClass . removeItem ( itemName );

                 Writer . println ( "you dropped the item" );
             }
         }
     }
    
         /**
     * Try to go to one direction. If there is an exit, enter the new room,
     * otherwise print an error message.
     *
     *  The command to be processed.
     */
     private   void  inventory ()   {

        Writer . println ( "Inventory :"   +  playerClass . getInventory ());
            
     }
    
     /**
     * Print out the status of the game.
     */
     private   void  printGameStatus (){
         Writer . println ( "You have earned"   +   " "   +  score  +   "points in"   +   " "   +  turns  +   " "   +   "turns." );
        printLocationInformation ();
     }
    
     /**
     * Take the player back to the previous location.
     */
     private   void  goBack (){
        
         if ( playerClass . getpreviousRoom ()   !=   null ){
                        
            playerClass . setcurrentRoom ( playerClass . getpreviousRoom ());
            
            printLocationInformation ();
            
         } else {
             Writer . println ( "There is no Previous room. Please make a move" );
         }
     }

     /**
     * Print out the closing message for the player.
     */
     private   void  printGoodbye ()   {
         Writer . println ( "I hope you weren't too bored here on the Campus of Kings!" );
         Writer . println ( "Thank you for playing.  Good bye." );
         Writer . println ( "You have earned"   +   " "   +  score  +   "points in"   +   " "   +  turns  +   " "   +   "turns." );
     }

     /**
     * Prints out the current location and exits.
     */
     private   void  printLocationInformation (){
         //Writer.println(playerClass.getcurrentRoom() + " : ");
         Writer . println ( "You are in "   +  playerClass . getcurrentRoom ());
         //Writer.println("Exits: ");

     }

     /**
     * Print out some help information. Here we print some stupid, cryptic
     * message and a list of the command words.
     */
    
     private   void  printHelp ()   {
         Writer . println ( "You are lost. You are alone. You wander" );
         Writer . println ( "around at the university.\n" );
         Writer . println ( "Your command words are:" );
         Writer . println ( CommandEnum . getCommandString ());

     }

     /**
     * Print out the opening message for the player.
     */
    
     private   void  printWelcome ()   {
         Writer . println ( "\nWelcome to the Campus of Kings!" );
         Writer . println ( "Campus of Kings is a new, incredibly boring adventure game." );
         Writer . println ( "Type 'help' if you need help.\n" );
        printLocationInformation ();
     }

     /**
     * "Quit" was entered. Check the rest of the command to see whether we
     * really quit the game.
     *
     *  @param  command
     *  The command to be processed.
     *  @return  true, if this command quits the game, false otherwise.
     */
    
     private   boolean  quit ( Command  command )   {
         boolean  wantToQuit  =   true ;
         if   ( command . hasSecondWord ())   {
             Writer . println ( "Quit what?" );
            wantToQuit  =   false ;
         }
         return  wantToQuit ;
     }

     /**
     * prints out the location information.
     * 
     */
    
     private   void  look (){
        printLocationInformation ();
     }
    
     /**
     * Pack an item into.  
     * 
     *  @param  command
     *  The command to be processed.
     */
    
     private   void  pack ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "pack what?" );
            
         }   else   {
                        
             String  itemName  =  command . getRestOfLine ();
            
             //Get item from players inventory
            
             Item  item  =  playerClass . getItem ( itemName );
            
             //Check the item value has had something added, if no, check for the item in the current room
            
             if   ( item  ==   null )   {
                
                item  =  playerClass . getcurrentRoom (). getItem ( itemName );
                
             }
            
             //Check if item exists in the current room
            
             if   ( item  ==   null )   {
                
                 Writer . println ( "you don't have!" );
                
             }   else   {                 
                
                 if ( item . getWeight ()   >  playerClass . MAX_WEIGHT ){
                    
                     Writer . println ( "too heavy" );
                    
                 } else {
                    
                     Writer . println ( "pack where?" );
                    
                     String  containerString  =   Reader . getResponse ();
                        
                     Item  container  =  playerClass . getItem ( containerString );
                    
                     if ( container  ==   null ){
                         
                        container  =  playerClass . getcurrentRoom (). getItem ( containerString );
                        
                     }
                        
                     if ( container  !=   null ){
                        
                         if ( container  instanceof   Container ){
                            
                            container . addItem ( item );
                            
                             if ( playerClass . getcurrentRoom (). removeItem ( itemName )   !=   null   ||  playerClass . removeItem ( itemName )   !=   null ){
                                                            
                                 Writer . println ( "you packed it" );
                                
                             }
                            
                         } else {
                            
                             Writer . println ( "that's not a container" );
                         }
                        
                     } else {

                         Writer . println ( "You don't see the container" );
                     }
                 }
             }

         }
     }
    
    
     /**
     * Pack an item into.  
     * 
     *  @param  command
     *  The command to be processed.
     */
    
     private   void  unpack ( Command  command )   {

         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "unpack what?" );
            
         }   else   {
            
             String  containerName  =  command . getRestOfLine ();
            
             //Get item from players inventory
            
             Item  container  =  playerClass . getItem ( containerName );
            
             //Check the item value has had something added, if no, check for the item in the current room
            
             if   ( container  ==   null )   {
                
                container  =  playerClass . getcurrentRoom (). getItem ( containerName );
                
             }
            
             //Check if item exists in the current room
            
             if   ( container  ==   null )   {
                
                 Writer . println ( "you don't see it!" );
                
             }   else   {                 
                
                 if ( container  instanceof   Container ){
                    
                     Writer . println ( "which item?" );
                    
                     String  itemName  =   Reader . getResponse ();
                    
                     Item  item  =  container . getItem ( itemName );
                    
                     if ( item  !=   null ){
                        
                         if ( playerClass . getCurrentWeight ()   +  item . getWeight ()   >  playerClass . getMaxWeight ()){
                            
                             Writer . println ( "you are carrying too much" );
                            
                         } else {
                                                        
                            playerClass . inventoryAddItem ( item );
                            
                            container . removeItem ( item . getName ());
                            
                             Writer . println ( "you unpacked it" );
                         }
                            
                     } else {
                        
                         Writer . println ( "you don't find it" );
                     }
                                        
                 } else {
                    
                     Writer . println ( "that's not a container" );
                 }
             }

         }
         }
     /**
     * eat.
     *  @param  command the command.
     * 
     */
     private   void  eat ( Command  command ){         
        
         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "Eat what?" );
            
         }   else   {
            
             String  foodName  =  command . getRestOfLine ();
            
             //Get item from players inventory
            
             Item  food  =  playerClass . getItem ( foodName );
            
             //Check if item exists
            
             if   ( food  ==   null )   {
                
                 Writer . println ( "you don't have it!" );
                
             } else {
                
                 if ( food  instanceof   Food   ==   false ){
                    
                     Writer . println ( "item is not food!" );
                    
                 } else {
                    
                     Edible  ed  =   ( Edible )  food ;
                    
                     Writer . println ( ed . eat ( playerClass ));
                 }
             }
        
         }

     }
     /**
     * drink.
     *  @param  command the command.
     */
     private   void  drink ( Command  command ){         
        
         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "drink what?" );
            
         }   else   {
            
             String  drinkName  =  command . getRestOfLine ();
            
             //Get item from players inventory
            
             Item  drink  =  playerClass . getItem ( drinkName );
            
             if   ( drink  ==   null )   {
                
                 Writer . println ( "you don't have it!" );
                
             } else {
                
                 if ( drink  instanceof   Drinkable   ==   false ){
                    
                     Writer . println ( "item is not drink!" );
                    
                 } else {
                    
                     Drinkable  dr  =   ( Drinkable )  drink ;
                    
                     Writer . println ( dr . drink ( playerClass ));
                 }
             }
        
         }

     }
      /**
     * equip.
     *  @param  command the command.
     */
     private   void  equip ( Command  command )   {
        
         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "equip what?" );
            
         }   else   {
            
             String  weaponName  =  command . getRestOfLine ();             
                
             Item  weapon  =  playerClass . getcurrentRoom (). getItem ( weaponName );
                
             //Check if item exists in the current room
            
             if   ( weapon  ==   null )   {
                
                 Writer . println ( "you don't see it!" );
                
             } else {
                
                 if ( weapon  instanceof   Weapon   ==   false ){
                    
                     Writer . println ( "item is not a weapon!" );
                    
                 } else {                     
                    
                     Equippable  eq  =   ( Equippable )  weapon ;
                    
                     Writer . println ( eq . equip ( playerClass ));
                 }
             }
        
         }
     }
     /**
     * unequip .
     *  @param  command the command.
     */

     private   void  unequip ( Command  command )   {
        
         if   ( ! command . hasSecondWord ())   {

             Writer . println ( "unequip what?" );
            
         }   else   {
            
             String  weaponName  =  command . getRestOfLine ();             
                
             Item  weapon  =  playerClass . getCurrentWeapon ();
                
             //Check if item exists in the current room
            
             if   ( ! weapon . getName (). equals ( weaponName ))   {
                
                 Writer . println ( "weapon is not equipped!" );
                
             } else {
                    
                 Equippable  eq  =   ( Equippable )  weapon ;

                 Writer . println ( eq . unequip ( playerClass ));
             }
        
         }
     }
}

Lap3/Main.java

Lap3/Main.java

import  java . awt . BorderLayout ;
import  java . awt . Dimension ;
import  java . awt . event . ActionEvent ;
import  java . awt . event . ActionListener ;
import  java . awt . event . ComponentAdapter ;
import  java . awt . event . ComponentEvent ;
import  java . io . InputStream ;
import  java . io . IOException ;

import  javax . swing . JButton ;
import  javax . swing . JFrame ;
import  javax . swing . JMenu ;
import  javax . swing . JMenuBar ;
import  javax . swing . JMenuItem ;
import  javax . swing . JPanel ;
import  javax . swing . JScrollPane ;
import  javax . swing . JTextField ;
import  javax . swing . JTextPane ;

/**
 * The sole purpose of this class is to start the game up. It does this by
 * creating an instance of the Game and calling it's play method.
 * 
 *  @author  Maria Jump
 *  @version  2015.02.01
 */
public   class   Main   extends   JFrame   implements   ActionListener   {

     /** Generated unique serial unique id. */
     private   static   final   long  serialVersionUID  =   - 4610552759287004513L ;

     /** Starting dimension of the window. */
     private   static   final   Dimension  WINDOW_DIMENSION ;

     /** The scroll pane so we can resize it when the window is resized. */
     private   JScrollPane  outputScrollPane ;

     /** The save log menu item. */
     private   JMenuItem  saveItem ;
     /** The exit menu item. */
     private   JMenuItem  exitItem ;

     /** The game instance. */
     private   Game  game ;

     /** Static block for initializing static fields. */
     static   {
        WINDOW_DIMENSION  =   new   Dimension ( 500 ,   500 );
     }

     /** Default constructor. */
     public   Main ()   {
        setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );
        setLayout ( new   BorderLayout ());

         // Setting up the menu bar
         JMenuBar  menuBar  =   new   JMenuBar ();
        setJMenuBar ( menuBar );
         JMenu  fileMenu  =   new   JMenu ( "File" );
        menuBar . add ( fileMenu );
        saveItem  =   new   JMenuItem ( "Save Log ..." );
        saveItem . addActionListener ( this );
        fileMenu . add ( saveItem );
        exitItem  =   new   JMenuItem ( "Exit" );
        exitItem . addActionListener ( this );
        fileMenu . add ( exitItem );

         // Setting out the output area
         JTextPane  output  =   new   JTextPane ();
        outputScrollPane  =   new   JScrollPane ( output );
         Dimension  outputSize  =   new   Dimension ();
        outputSize . setSize ( WINDOW_DIMENSION . getWidth (),  WINDOW_DIMENSION . getHeight ()   -   100 );
        outputScrollPane . setPreferredSize ( outputSize );
         // So that the scroll pane will resize when the window is resized
        addComponentListener ( new   ComponentAdapter ()   {
             public   void  componentResized ( ComponentEvent  e )   {
                 Dimension  outputSize  =   new   Dimension ();
                outputSize . setSize ( getContentPane (). getWidth (),  getContentPane (). getHeight ()   -   100 );
                outputScrollPane . setPreferredSize ( outputSize );
             }
         });
        add ( BorderLayout . NORTH ,  outputScrollPane );
         // Set up the Writer so that it can be used throughout the game.
         Writer . setTextArea ( output );

         // Setting up the bottom panel for input
         JPanel  bottomPane  =   new   JPanel ();
        bottomPane . setLayout ( new   BorderLayout ());

         JButton  enterButton  =   new   JButton ( "Enter" );
         JTextField  commandField  =   new   JTextField ();

         TextFieldStreamer  streamer  =   new   TextFieldStreamer ( commandField );
         // maybe this next line should be done in the TextFieldStreamer ctor
         // but that would cause a "leak a this from the ctor" warning
        commandField . addActionListener ( streamer );
        enterButton . addActionListener ( streamer );

         System . setIn ( streamer );

        bottomPane . add ( BorderLayout . CENTER ,  commandField );
        bottomPane . add ( BorderLayout . EAST ,  enterButton );

        add ( BorderLayout . SOUTH ,  bottomPane );
        setSize ( WINDOW_DIMENSION );
        setVisible ( true );
        commandField . requestFocus ();

        game  =   new   Game ();
        game . play ();
     }

     /**
     * Default action listener.
     * 
     *  @param  event
     *            The action event.
     */
    @ Override
     public   void  actionPerformed ( ActionEvent  event )   {
         if   ( event . getSource ()   ==  saveItem )   {
             Writer . copyDefaultLog ();
         }   else   if   ( event . getSource ()   ==  exitItem )   {
             System . exit ( 0 );
         }
     }

     /**
     * The main method for the program.
     * 
     *  @param  args
     *            The command line arguments.
     */
     public   static   void  main ( String []  args )   {
         new   Main ();
     }

     /**
     * Implementation of InputStream that uses the text from a JTextField as the
     * input buffer.
     * 
     *  @author  Maria Jump
     */
     private   class   TextFieldStreamer   extends   InputStream   implements   ActionListener   {

         /** The JTextField to use for input. */
         private   JTextField  textField ;

         /** The string of text that being passed as input. */
         private   String  text ;

         /** Used for checking if the available input has reached its end. */
         private   int  position ;

         /**
         * Default constructor for TextFieldStreamer.
         * 
         *  @param  field
         *            JTextField component being used as input buffer.
         */
         public   TextFieldStreamer ( JTextField  field )   {
            position  =   0 ;
            text  =   null ;
            textField  =  field ;
         }

         // gets
         /**
         * Invoked when an action occurs. In this case, prints the text of the
         * JTextField to StdOut as an error message to differentiate between
         * user input and game output. Triggered every time that "Enter" is
         * pressed on the JTextField.
         * 
         * Triggered every time that "Enter" is pressed on the textfield
         * 
         *  @param  event
         *            ActionEvent passed by the component.
         */
        @ Override
         public   void  actionPerformed ( ActionEvent  event )   {
            text  =  textField . getText ()   +   System . getProperty ( "line.separator" );
            position  =   0 ;
            textField . setText ( "" );
             synchronized   ( this )   {
                 // maybe this should only notify() as multiple threads may
                 // be waiting for input and they would now race for input
                 this . notifyAll ();
             }
         }

         /**
         * Reads the next byte of data from the input stream. The value byte is
         * returned as an <code>int</code> in the range <code>0</code> to
         * <code>255</code>. If no byte is available because the end of the
         * stream has been reached, the value <code>-1</code> is returned. This
         * method blocks until input data is available, the end of the stream is
         * detected, or an exception is thrown.
         * 
         * <p>
         * A subclass must provide an implementation of this method.
         * 
         *  @return  the next byte of data, or <code>-1</code> if the end of the
         *         stream is reached.
         *  @exception  IOException
         *                if an I/O error occurs.
         */
        @ Override
         public   int  read ()   throws   IOException   {
             int  result  =   0xDEADBEEF ;
             // test if the available input has reached its end
             // and the EOS should be returned
             if   ( text  !=   null   &&  position  ==  text . length ())   {
                text  =   null ;
                 // this is supposed to return -1 on "end of stream"
                 // but I'm having a hard time locating the constant
                result  =  java . io . StreamTokenizer . TT_EOF ;
             }
             if   ( result  ==   0xDEADBEEF )   {
                 // no input available, block until more is available because
                 // that's
                 // the behavior specified in the Javadocs.
                 while   ( text  ==   null   ||  position  >=  text . length ())   {
                     try   {
                         // read() should block until new input is available.
                         synchronized   ( this )   {
                             this . wait ();
                         }
                     }   catch   ( InterruptedException  ex )   {
                        ex . printStackTrace ();
                     }
                 }
                 // read an additional character, return it and increment the
                 // index.
                result  =  text . charAt ( position ++ );
             }
             return  result ;
         }
     }
}

__MACOSX/Lap3/._Main.java

Lap3/CommandWords.java

Lap3/CommandWords.java


import  java . util . HashMap ;
import  java . util . Map ;

/**
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * This class holds an enumeration of all command words known to the game. It is
 * used to recognize commands as they are typed in.
 * 
 *  @author  Maria Jump
 *  @version  2015.02.01
 */

public   class   CommandWords   {
     static   Map < String ,   CommandEnum >  commandMap ;
     /** A constant array that holds all valid command words. */
     //private static String[] validCommands;
     /**
     * Static block to initialize the fields of CommandWords.
     **/     

     static   {

        commandMap  =   new   HashMap <> ();

         CommandEnum []  tempCommands  =   CommandEnum . values ();

         for ( CommandEnum  moh :  tempCommands ){

            commandMap . put ( moh . name (),   CommandEnum . getCommand ( moh . name ()));

         }
     }

     /**
     * Check whether a given String is a valid command word.
     * 
     *  @param  aString The string to determine whether it is a valid command.
     *  @return  true if a given string is a valid command, false if it isn't.
     */
     public   static   boolean  isCommand ( String  aString )   {

         // if we get here, the string was not found in the commands
         return  commandMap . containsKey ( aString );
     }

     /**
     * Converts a String into a CommandEnum object.
     *  @param  theString The String containing the command word.
     *  @return  The CommandEnum object representing the command, or null if the command does not exist. 
     */
     public   static   CommandEnum  getCommand ( String  theString ){

         return  commandMap . get ( theString );
     }

}

__MACOSX/Lap3/._CommandWords.java

Lap3/Main$TextFieldStreamer.class

synchronized class Main$TextFieldStreamer extends java.io.InputStream implements java.awt.event.ActionListener {
    private javax.swing.JTextField textField;
    private String text;
    private int position;
    public void Main$TextFieldStreamer(Main, javax.swing.JTextField);
    public void actionPerformed(java.awt.event.ActionEvent);
    public int read() throws java.io.IOException;
}

Lap3/Equippable.ctxt

#BlueJ class context comment0.target=Equippable comment0.text=\n\ To\ change\ this\ license\ header,\ choose\ License\ Headers\ in\ Project\ Properties.\n\ To\ change\ this\ template\ file,\ choose\ Tools\ |\ Templates\n\ and\ open\ the\ template\ in\ the\ editor.\ \n\ \n\ @author\ mohammed\ alharbi\n\ @version\ 29/4/2018\n comment1.params=p comment1.target=java.lang.String\ equip(Player) comment1.text=\n\ equip.\n\ @param\ p\ The\ current\ player\ instance\n\ @return\ message\n comment2.params=p comment2.target=java.lang.String\ unequip(Player) comment2.text=\n\ unequip.\n\ @param\ p\ -\ The\ current\ player\ instance\n\ @return\ message\n numComments=3

Lap3/Door.ctxt

#BlueJ class context comment0.target=Door comment0.text=\n\ Class\ Door\ -\ a\ door\ or\ portal\ between\ two\ Rooms\ in\ an\ adventure\ game.\n\ \n\ This\ class\ is\ part\ of\ the\ "Campus\ of\ Kings"\ application.\ "Campus\ of\ Kings"\ is\ a\n\ very\ simple,\ text\ based\ adventure\ game.\n\ \n\ A\ "Door"\ represents\ a\ door\ or\ portal\ between\ two\ locations\ of\ the\ game.\n\ It\ stores\ a\ reference\ to\ the\ neighboring\ room\ and\ whether\ that\ door\n\ or\ portal\ is\ locked.\ \ Doors\ are\ not\ locked\ by\ default.\n\ \n\ @author\ Maria\ Jump\n\ @version\ 2015.02.01\n comment1.params=destination comment1.target=Door(Room) comment1.text=\n\ Constructor\ for\ the\ Door\ class.\n\ @param\ destination\ The\ room\ this\ door\ leads\ to\n comment2.params= comment2.target=Room\ getDestination() comment2.text=\n\ A\ getter\ for\ the\ room\ this\ door\ leads\ to.\n\ @return\ The\ room\ this\ door\ leads\ to\n comment3.params= comment3.target=boolean\ isLocked() comment3.text=\n\ A\ getter\ for\ whether\ this\ door\ is\ locked.\n\ @return\ Whether\ this\ door\ is\ locked\n comment4.params=key comment4.target=void\ setKey(Item) comment4.text=\n\ A\ setter\ for\ the\ key\ that\ opens\ a\ door.\n\ @param\ key\ Specifies\ the\ key\ to\ unlock\ the\ door\n comment5.params= comment5.target=Item\ getKey() comment5.text=\n\ A\ setter\ for\ the\ key\ that\ opens\ a\ door.\n\ @return\ the\ key\ that\ unlocks\ that\ door\ \n comment6.params=locked comment6.target=void\ setLocked(boolean) comment6.text=\n\ A\ setter\ for\ whether\ this\ door\ is\ locked.\n\ @param\ locked\ Whether\ this\ door\ is\ locked.\n numComments=7

Lap3/Player.class

public synchronized class Player {
    private Room currentRoom;
    private Room previousRoom;
    private Item currentWeapon;
    private int health;
    private int currentWeight;
    public static final int MAX_WEIGHT = 5000;
    private java.util.HashMap inventory;
    public void Player(Room);
    public void updateHealth(int);
    public boolean inventoryAddItem(Item);
    public int getCurrentWeight();
    public int getMaxWeight();
    public Item getItem(String);
    public Item removeItem(String);
    public Room getcurrentRoom();
    public void setcurrentRoom(Room);
    public void setCurrentWeapon(Item);
    public Room getpreviousRoom();
    public String getInventory();
    public Item getCurrentWeapon();
}

Lap3/World.class

public synchronized class World {
    private java.util.HashMap rooms;
    public void World();
    public void createItems();
    public Room getcurrentRoom(String);
    private void addRoom(Room);
    private void createDoor(Room, String, Room);
    private void createRooms();
}

Lap3/documents/GWT.txt

// Original commands from the game (alphabetical) GO Scenario #1: No direction specified GIVEN : WHEN : "go" is entered THEN: appropriate message is displayed (which direction?) GO Scenario #2: No exit exists GIVEN : there is no exit in the given direction WHEN : "go direction" is entered THEN : appropriate message is displayed (no door) GO Scenario #3: Exit exists GIVEN : there is an exit in the given direction WHEN : "go direction" is entered THEN : player's current room is changed to the room in the given direction and : the current room's points are added to the player's score and : player's current location is displayed HELP Scenario #1: GIVEN : WHEN : "help" is entered THEN : available commands are displayed SCORE Scenario #1: GIVEN : WHEN : "score" is entered THEN : player's current score is displayed TURNS Scenario #1: GIVEN : WHEN : "turns" is entered THEN : current number of turns is displayed to the screen QUIT Scenario #1: GIVEN : WHEN : "quit" is entered THEN : appropriate message is displayed (thanks for playing) and : program quits /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 2 (alphabetical) BACK Scenario #1: no previous room GIVEN : there is no previous room WHEN : "back" is entered THEN : appropriate message is displayed (cannot go back) BACK Scenario #2: there is a previous room GIVEN : there is a previous room WHEN : "back" is entered THEN : player's current location is changed to the previous location and : player's current location is displayed LOOK Scenario #1: GIVEN : WHEN : "look" is entered THEN : player's current location is displayed STATUS Scenario #1: GIVEN : WHEN : "status" is entered THEN : current number of turns is displayed and : player's current score is displayed and : player's current location is displayed /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 3 (alphabetical) DROP Scenario #1: No item specified GIVEN : WHEN : "drop" is entered THEN : appropriate message is displayed (which item?) DROP Scenario #2: Player does not have the specified item GIVEN : player does not have the specified item WHEN : "drop item" is entered THEN : appropriate message is displayed (you don't have it) DROP Scenario #3: Player has the specified item GIVEN : player has the specified item WHEN : "drop item" is entered THEN : "item" is removed from the player's inventory and : "item" is added to the current room and : appropriate message is displayed (you dropped the item) EXAMINE Scenario #1: No item specified GIVEN : WHEN : "examine" is entered THEN : appropriate message is displayed (which item?) EXAMINE Scenario #2: Specified item does not exist GIVEN : specified item is not in the room and : specified item is not in player's inventory WHEN : "examine item" is entered THEN : appropriate message is displayed (no such item) EXAMINE Scenario #3: Specified item does exist GIVEN : specified item is in the room or in the player's inventory WHEN : "examine item" is entered THEN : complete description of the item is displayed including the item's name, description and (optionally) the weight. INVENTORY Scenario #1: GIVEN : WHEN : "inventory" is entered THEN : a list of the items in the players inventory is displayed TAKE Scenario #1: no item specified GIVEN : WHEN : "take" is entered THEN : appropriate message is displayed (take what?) TAKE Scenario #2: specified item does not exist GIVEN : specified item is not in the current room WHEN : "take item" is entered THEN : appropriate message is displayed (no such item) TAKE Scenario #3: specified item is too heavy to lift GIVEN : specified item is in the current room and : specified item by itself exceeds maximum carrying weight WHEN : "take item" is entered THEN : appropriate message is displayed (too heavy to lift) TAKE Scenario #4: specified item makes inventory too heavy GIVEN : specified item is in the current room and : adding specified item to inventory weight exceeds maximum carrying weight WHEN : "take item" is entered THEN : appropriate message is displayed (carrying too much) TAKE Scenario #5: specified item is taken GIVEN : specified item is in the current room and : adding specified item to inventory weight does not exceed maximum carrying weight WHEN : "take item" is entered THEN : item is removed from the current room and : item is added to the player's inventory and : appropriate message is displayed (you took the item) /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 4 (alphabetical) GO Scenario #4: Door is locked GIVEN : there is an exit in the given direction and : that exit is locked WHEN : "go direction" is entered THEN : appropriate message is displayed (door is locked) LOCK Scenario #1: No direction specified GIVEN : WHEN : "lock" is entered THEN : appropriate message is displayed (lock what?) LOCK Scenario #2: No Door GIVEN : there is no door in that direction WHEN : "lock direction" is entered THEN : appropriate message is displayed (no door) LOCK Scenario #3: Door is locked GIVEN : door in "direction" is locked WHEN : "lock direction" is entered THEN : appropriate message is displayed (door is already locked) LOCK Scenario #4: Door cannot be locked GIVEN : door in "direction" has no associated key WHEN : "lock direction" is entered THEN : appropriate message is displayed (door cannot be locked) LOCK Scenario #5: Door can be locked GIVEN : door in "direction" is unlocked and : door in "direction" can be locked WHEN : "lock direction" is entered THEN : user is prompted for key LOCK Scenario #6: Player does not have the key GIVEN : player does not have specific key in inventory WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (you do not have it) LOCK Scenario #7: Incorrect key specified GIVEN : player's inventory has the specific key and : specified key is not the correct key WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (wrong key) LOCK Scenario #8: Correct key specified GIVEN : player's inventory has the specific key and : specified key is the correct key WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : door in "direction" is locked and : appropriate message is displayed (you locked it) PACK Scenario #1: No item specified GIVEN : WHEN : "pack" is entered THEN : appropriate message is displayed (pack what?) PACK Scenario #2: Item is not available GIVEN : item is NOT in the current room and : item is NOT in the players inventory WHEN : "pack item" is entered THEN : appropriate message is displayed (you don't have it) PACK Scenario #3: Item is too heavy GIVEN : item is in the current room and : item is heavier than player's carrying capacity WHEN : "pack item" is entered THEN : appropriate message is displayed (too heavy) PACK Scenario #4: Item is available GIVEN : item is in the current room or : item is in the player's inventory and : there are no weight problems WHEN : "pack item" is entered THEN : user is prompted for the container to put it in PACK Scenario #5: Container is not available GIVEN : container is NOT in the current room and : container is NOT in the player's inventory WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (you don't see the container) PACK Scenario #6: Container is NOT a container GIVEN : container is in the current room or : container is in the player's inventory and : container is not really a container WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (that's not a container) PACK Scenario #7: Container is a container, but item too heavy GIVEN : item is in the current room and : container is in the player's inventory and : item would put player over their inventory weight limit WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (carrying too much) PACK Scenario #8: Packing is possible GIVEN : container is in the current room or : container is in the player's inventory and : container is really a container and : there are no weight problems WHEN : "pack item" had been entered and : user has been prompted for the container THEN : item is removed from the current room or : item is removed from the player's inventory and : item is added to the container and : appropriate message is displayed (you packed it) UNLOCK Scenario #1: No direction specified GIVEN : WHEN : "unlock" is entered THEN : appropriate message is displayed (unlock what?) UNLOCK Scenario #2: No door in that direction GIVEN : there is no door in the "direction" WHEN : "unlock direction" is entered THEN : appropriate message is displayed (there is no door) UNLOCK Scenario #3: Direction is specified and is not locked GIVEN : there is a door in the "direction" and : door in "direction" is NOT locked WHEN : "unlock direction" is entered THEN : appropriate message is displayed (door is not locked) UNLOCK Scenario #4: Direction is specified and is locked GIVEN : there is a door in the "direction" and : door in "direction" is locked WHEN : "unlock direction" is entered THEN : user is prompted for key UNLOCK Scenario #5: Player missing specified key GIVEN : player's inventory does NOT have the specific key WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (you don't have it) UNLOCK Scenario #6: Incorrect key GIVEN : player's inventory has the specific key and : specified key is incorrect item WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (that doesn't fit) UNLOCK Scenario #7: Correct key GIVEN : player's inventory has the specific key and : specified key is the correct object WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : door in "direction" is unlocked and : appropriate message is displayed (you unlocked it) UNPACK Scenario #1: No container specified GIVEN : WHEN : "unpack" is entered THEN : appropriate message is displayed (unpack what?) UNPACK Scenario #2: Specified container is not in the current room GIVEN : specified container is NOT in the current room and : specified container is NOT in the players inventory WHEN : "unpack container" is entered THEN : appropriate message is displayed (you don't see it) UNPACK Scenario #3: Specified item is not a container GIVEN : specified container is in the current room or : specified container is in the player's inventory and : specified container is NOT a container WHEN : "unpack container" is entered THEN : appropriate message is displayed (that's not a container) UNPACK Scenario #4: Container is OK GIVEN : specified container is in the current room or : specified container is in the player's inventory and : specified container is a container WHEN : "unpack container" is entered THEN : user is prompted for an item to unpack UNPACK Scenario #5: Item is NOT in container GIVEN : item to unpack is NOT in the container WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : appropriate message is displayed (you don't find it) UNPACK Scenario #6: Item is in container but too heavy GIVEN : item to unpack is in the container and : container was in the current room and : item would make the player exceed his weight limit WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : appropriate message is displayed (you are already carrying too much) UNPACK Scenario #7: Item can be unpacked GIVEN : item to unpack is in the container and : there is no weight problem WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : item to unpack is removed from the container and : item to unpack is added to the player's inventory and : appropriate message is displayed (you unpack it) EAT Scenario #1: No item is specified GIVEN : WHEN : "eat" is entered THEN : appropriate message is displayed (eat what?) EAT Scenario #2: Specified item is not in the players inventory GIVEN : Food is specified WHEN : "eat food" is entered THEN : appropriate message is displayed (you don't have it) EAT Scenario #3: Specified item is in the players inventory GIVEN : food is specified and : specified item is not food WHEN : "eat food" is entered THEN : appropriate message is displayed (item is not food) EAT Scenario #4: Specified item is in the players inventory GIVEN : food is specified and : specified item is food WHEN : "eat food" is entered THEN : food is removed from players invetory and : players health is increased and : appropriate message is displayed (you have eaten food) DRINK Scenario #1: No item is specified GIVEN : WHEN : "drink" is entered THEN : appropriate message is displayed (drink what?) DRINK Scenario #2: Specified item is not in the players inventory GIVEN : Drink is specified WHEN : "drink Drink" is entered THEN : appropriate message is displayed (you don't have it) DRINK Scenario #3: Specified item is in the players inventory GIVEN : Drink is specified and : specified item is not drink WHEN : "drink Drink" is entered THEN : appropriate message is displayed (item is not a drink) DRINK Scenario #4: Specified item is in the players inventory GIVEN : Drink is specified and : specified item is Drink WHEN : "drink Drink" is entered THEN : drink is removed from players invetory and : players health is increased and : appropriate message is displayed (you have taken a drink) EQUIP Scenario #1: No weapon is specified GIVEN : WHEN : "equip" is entered THEN : appropriate message is displayed (equip what?) EQUIP Scenario #2: Specified weapon is not in the players inventory GIVEN : weapon is specified WHEN : "equip weapon" is entered THEN : appropriate message is displayed (you don't have it) EQUIP Scenario #3: Specified item is in the players inventory GIVEN : weapon is specified and : specified item is not weapon WHEN : "equip weapon" is entered THEN : appropriate message is displayed (item is not a weapon) EQUIP Scenario #4: Specified item is in the players inventory GIVEN : weapon is specified and : specified item is a weapon WHEN : "equip weapon" is entered THEN : weapon is removed from players invetory and : player is equipped with the weapon and : appropriate message is displayed (weapon equipped) UNEQUIP Scenario #1: No weapon is specified GIVEN : WHEN : "unequip" is entered THEN : appropriate message is displayed (unequip what?) UNEQUIP Scenario #2: Specified weapon is not the players current weapon GIVEN : weapon is specified WHEN : "unequip weapon" is entered THEN : appropriate message is displayed (weapon is not equipped) UNEQUIP Scenario #3: Specified item is the players current weapon GIVEN : weapon is specified and : specified item is a weapon WHEN : "unequip weapon" is entered THEN : weapon is added to the players invetory and : players is unequipped and : appropriate message is displayed (weapon unequipped)

__MACOSX/Lap3/documents/._GWT.txt

Lap3/documents/.DS_Store

__MACOSX/Lap3/documents/._.DS_Store

Lap3/documents/Game.xml

5VxLc6M4EP41OW6KlwAfZ7KzM4edqqnKYWeOxJZtNtjyAs5jf/2KgDDqlhNFFqDK5pAybczj6+6vu6WWrsKb3dPXMjtsv7MVLa4Cb/V0Ff5+FQRJEvH/jeC5FYRR2go2Zb5qRf5JcJv/Szuh10mP+YpW0ok1Y0WdH2Thku33dFlLsqws2aN82poV8l0P2YYiwe0yK7D0r3xVb1tpSryT/BvNN1txZ9/rvrnLlvebkh333f2ugnD98td+vcvEtbrzq222Yo8DUfjlKrwpGavbT7unG1o00ArY2t/9cebb/rlLuq91fhC2P3jIimP36nf8Efn9d93z1c8Ck5e3os3vvKvw8+M2r+ntIVs23z5yI+Cybb0r+JHPP+Ln6B7tgZY1fRqIuuf6StmO1uUzP0V8K9DubEhA9jhQSCfaDnQRdbKsM4FNf+ETDPxDh4QalQihMjsaQfwmGr0R2obDTxAe93m93NI9goW/TS2/e1WX7J7esIKVXLJne37m53VeFECUFflmzw+XHCPK5Z8bbHLukp+6L3b5atXcRgm2rA4beKcAb4LwjhRwhzbgXrxtfnS/+tTw3Am/AeT8rcvnnx0WLwe/moNr0hw+5fVPcR7/fPrmLGgVO5ZLKvFFnZUbKiysFdGVRKkY2AFyRIGckJW0yOr8QSZiFZzdHX6wnD/viTWA2gKgkPZluh8NiRFcB7ibn4DrtAig67zotn9pLXUrOBip+w1+yapDGwXX+VPjBGM4wEKPflMLDqDg32VWugCKPyMoxEkzgYgE3oSQxNaI8jr2h1zZH/ygZc6fqwlILZt29Hki019vxZwhfbrPn4j4FoYEGgIm9mEmYpFBcX7igmvEZD7PSBEi3BG4gK0b69vSxlBYtnIBpkS2kzCeECaNTGsWTvVng0QksOacelmCKehwyJCCNV2lSJgbGlMkTFbtUWQojNBCqCQoUl4YFIlC5W5FxT4KCi6HdZ6uyvuiUagc+qxFlQeTqDzyQ8nTvTDtjmHupGcMqcIYEreMQVZhFBvaAqCRyB/PFDRKzFFJ3TEFAidEgVNXg6j4GS/HDXGtw461nNFt2bGiSLEfZkgOh0u9MTkYVY3SIlxi1MdyzyUFXdcfF/MU1DCKYefRIMc1zD2lhxegS0o/MOiBJ+f/fbYxAeriuv83Q4eYh4qhvdEwdzk570pkKR8jboVzOSwQz1I+RkYL5hFOzesyW6/zZYM+N/+sQAYwwzhE6MmITDkOEeGU9XX2nwGfKJoRH405asOU/rXpQ2POECbvCGdAZw9NSwCYlIZwZMAia2jMAM2lcqFeSeVuDdtFkM1MVR6R6VSOq77XsjEHYkQ/nD8FB54tysqXGzkITzRliMAF1Dv5Yry0UskXsVN8EQbAzeHgjnaIADNcAZxStcgX9lqH7Ks8UajcrawABvPIdJg/fCu9sKdy8erDZpmCVZzAOGrZM1Z/UeSH6lxdbblpEUybEAX7KbsWYellQn8EV9WPJdtvHMTFT/FIphIXONNohMvFlcOIHBFjjhB6dIQjAEUkplkkYIhkvCSSXFw3vKJwLbUK6CXqd2tOCEb72Fa0J+NFe4KrA66I+7zhOKDfqdvVCQyAirIgUWgTzqUaERwuC4r8rsxKTPpzDBoB7o8mLJiIRnpYbbND87HI9/cyGn/Tun7u1upkx5pxESvrLduwfVb8ydhBgy7ES/qvhgSJ/t2qCshCnhFbGI82g8HDaLy5Y+FUUj/17nCsuKybfnHAMeJwPseINWZgbDoGHmU7PzYnXj/QzqKIotISNuCKG8EoCTN+bTcCcRvN/lh0owAZSfXPkasCmYp2LTGGHxFALLHCj3xfoVofNiAZeZJGdXG5J/U+EZytObST01jRfihU7Yi3wOGERLRHvtdboG0kmt7Ca4OmZO5POzQnVO944O6+JyNqr2jsirik+cYP7455sVKlv3OM/MKCQnP9qpVwhguDbVY4Maccg8kTMuESqlhjnYhFbnqVgRxhFqiOxHi95CJVRx3LzALvIx7YGrPgSZNPgllcoRZCztQgU/gQLiG/3zhGvQmIPumEHCPMfhqO8SO53vYCqeLmgjQVAu12fCkRWrhFV6K1RHi/6dIbaCKojLdFV6BDXGwhYouuEly4LousqpQ7eMxCVWCmwyMT+iIu2G7rLC8rF5CBzWNTkniCm+toQR+ympUuQjOt0eACNlgXzA1k0MShP2FVkeCiq+eawMNhbg7LCQjAJ50QH1x1DfCJXMAH2U84Jevg8muAj+8CPhFcYjQpPpf2a50FwJHsjYhhKxHyTAd94ewiupC9Qd/EYkeV3y6V7efDrr1+7ay6Z+J9eftwUDNRbDQiSltHrCFKz0X5d5tDCK803iSAeOiLm7C96wQOV/emIu1F844ubJXWRT7jiNYJZFi0At6UBLh3jaf1i1doqbXuDbX+m6J+j+PwMh5QbKchyiJHLAIt6/WMtxyCFuGNN6ee4trSOC7Y7qITgwIOkz8eFzAdyYk9eKXxdlFJrbVOAoZPhi0A3lDn14E++ysmMh1jf+ShxhupoEx9xJ1U0jEbKE++7uPQYLqLSqLoo3XMFCKYtBmvr0CJ5IgLLFKLWw4mZs20iaK7xzHdhpDdUeO6tm4hu6MF9xZ1qzE9PNv6SkVm71pnJGh4MF48A3vD7C2e4YenrdXb00/b14df/gM=

__MACOSX/Lap3/documents/._Game.xml

Lap3/documents/Game name copy.docx

Game name: Go to class

-The goal to reach the classroom201 in building A.

-there are 28 rooms until to reach the class.

- the player will lose if he goes to wrong direction and have to bake one room to start again.

-some of the rooms have three ways, two ways, and one way.

-Player will see different ways in each room after leaving the house.

-Items: car key, back bag, coffee.

Bathroom: there is teeth brush, shower place.

Kitchen: there are two doors, one the way to go out of the house. The second door the way to the living room.

Out of the house: the way outside the house to drive to university.

Car: inside the car, back bag, car key with house key.

Keep street: the correct way.

Turn left: wrong way to go with it.

End of the road: closed way.

Gas Station: the way to traffic signal.

Traffic signal: there are three different ways.

Park: maybe not the right way.

Wrong way: it will take long time to reach the goal.

Turn right: more traffic.

Closed way: no place to go.

Walk path: almost arrive to university.

Parking: there is a meter parking, 2$ in Hour.

Library: some books, students, printer, computers.

Campus center: office for the activity, mailboxes, four floors.

Hall campus: the building for men.

H building: Five floors, elevator, six classrooms.

Square: the place in the middle of the university, and from there the player can go any building.

A building: the goal to reach the class, stairs, elevator, classroom.

Stairs: take the player until fourth floor.

Elevator: take the player until fourth floor

Floor2:the pathway to the classes

Classroom: one door, blackboard, tables.

Classroom201: you reach the goal.

Classroom204:one door, students.

Classroom202: blackboard, table, students.

-Optional to earn points.

1- get a coffee.

2-snack.

3-cheek the email if the class might be canceled.

- Player need to pick up his laptop to the class.

-it will be two player, and they can carry their back bag, cellphone, embrella.

__MACOSX/Lap3/documents/._Game name copy.docx

Lap3/documents/GameSummary-AlharbiMohammed.pdf

Mohammed Alharbi’s Game Summary Tuesday 13th February, 2018 at 13:34– Page 1

NAME: Go To Class

Overview: The player is trying to get to classroom 201 in building A.

Winning: Getting to the correct classroom.

Losing: Not possible?

Other objectives: None?

Player: Unspecified.

Weight limit: Unspecified.

The World : Enough rooms with some detail.

Scoring: Not specified.

Additional Stuff: Unusual features of your game.

1. Not specified.

2.

3.

TODO: As you elaborate on things, you will probably need to find a few more things like this.

Lap3/package.bluej

#BlueJ package file dependency1.from=Room dependency1.to=Door dependency1.type=UsesDependency dependency10.from=Command dependency10.to=CommandWords dependency10.type=UsesDependency dependency11.from=Edible dependency11.to=Player dependency11.type=UsesDependency dependency12.from=Equippable dependency12.to=Player dependency12.type=UsesDependency dependency13.from=Food dependency13.to=Player dependency13.type=UsesDependency dependency14.from=Weapon dependency14.to=Player dependency14.type=UsesDependency dependency15.from=CommandEnum dependency15.to=CommandWords dependency15.type=UsesDependency dependency16.from=Player dependency16.to=Room dependency16.type=UsesDependency dependency17.from=Player dependency17.to=Item dependency17.type=UsesDependency dependency18.from=Main dependency18.to=Game dependency18.type=UsesDependency dependency19.from=Main dependency19.to=Writer dependency19.type=UsesDependency dependency2.from=Room dependency2.to=Item dependency2.type=UsesDependency dependency20.from=World dependency20.to=Room dependency20.type=UsesDependency dependency21.from=World dependency21.to=Item dependency21.type=UsesDependency dependency22.from=World dependency22.to=Weapon dependency22.type=UsesDependency dependency23.from=World dependency23.to=Food dependency23.type=UsesDependency dependency24.from=World dependency24.to=Container dependency24.type=UsesDependency dependency25.from=World dependency25.to=Door dependency25.type=UsesDependency dependency26.from=Game dependency26.to=World dependency26.type=UsesDependency dependency27.from=Game dependency27.to=Player dependency27.type=UsesDependency dependency28.from=Game dependency28.to=Command dependency28.type=UsesDependency dependency29.from=Game dependency29.to=CommandEnum dependency29.type=UsesDependency dependency3.from=Door dependency3.to=Room dependency3.type=UsesDependency dependency30.from=Game dependency30.to=Door dependency30.type=UsesDependency dependency31.from=Game dependency31.to=Room dependency31.type=UsesDependency dependency32.from=Game dependency32.to=Item dependency32.type=UsesDependency dependency33.from=Game dependency33.to=Container dependency33.type=UsesDependency dependency34.from=Game dependency34.to=Food dependency34.type=UsesDependency dependency35.from=Game dependency35.to=Edible dependency35.type=UsesDependency dependency36.from=Game dependency36.to=Drinkable dependency36.type=UsesDependency dependency37.from=Game dependency37.to=Weapon dependency37.type=UsesDependency dependency38.from=Game dependency38.to=Equippable dependency38.type=UsesDependency dependency39.from=Game dependency39.to=Reader dependency39.type=UsesDependency dependency4.from=Door dependency4.to=Item dependency4.type=UsesDependency dependency40.from=Game dependency40.to=Writer dependency40.type=UsesDependency dependency41.from=Drinkable dependency41.to=Player dependency41.type=UsesDependency dependency42.from=Drink dependency42.to=Player dependency42.type=UsesDependency dependency5.from=Reader dependency5.to=Command dependency5.type=UsesDependency dependency6.from=Reader dependency6.to=Writer dependency6.type=UsesDependency dependency7.from=Reader dependency7.to=CommandWords dependency7.type=UsesDependency dependency8.from=CommandWords dependency8.to=CommandEnum dependency8.type=UsesDependency dependency9.from=Command dependency9.to=CommandEnum dependency9.type=UsesDependency editor.fx.0.height=586 editor.fx.0.width=694 editor.fx.0.x=150 editor.fx.0.y=118 objectbench.height=101 objectbench.width=844 package.divider.horizontal=0.6 package.divider.vertical=0.8057553956834532 package.editor.height=425 package.editor.width=703 package.editor.x=498 package.editor.y=23 package.frame.height=614 package.frame.width=868 package.numDependencies=42 package.numTargets=19 package.showExtends=true package.showUses=true project.charset=UTF-8 readme.height=58 readme.name=@README readme.width=47 readme.x=10 readme.y=10 target1.height=50 target1.name=Edible target1.showInterface=false target1.type=InterfaceTarget target1.width=80 target1.x=310 target1.y=250 target10.height=50 target10.name=Item target10.showInterface=false target10.type=ClassTarget target10.width=80 target10.x=10 target10.y=80 target11.height=50 target11.name=Container target11.showInterface=false target11.type=ClassTarget target11.width=90 target11.x=290 target11.y=110 target12.height=50 target12.name=Game target12.naviview.expanded=true target12.showInterface=false target12.type=ClassTarget target12.width=80 target12.x=240 target12.y=20 target13.height=50 target13.name=Equippable target13.showInterface=false target13.type=InterfaceTarget target13.width=90 target13.x=360 target13.y=320 target14.height=50 target14.name=Command target14.showInterface=false target14.type=ClassTarget target14.width=90 target14.x=150 target14.y=290 target15.height=50 target15.name=Drinkable target15.showInterface=false target15.type=InterfaceTarget target15.width=80 target15.x=250 target15.y=360 target16.height=50 target16.name=Room target16.showInterface=false target16.type=ClassTarget target16.width=80 target16.x=670 target16.y=270 target17.height=50 target17.name=Main target17.showInterface=false target17.type=ClassTarget target17.width=80 target17.x=70 target17.y=20 target18.height=50 target18.name=Writer target18.showInterface=false target18.type=ClassTarget target18.width=80 target18.x=0 target18.y=180 target19.height=50 target19.name=Food target19.showInterface=false target19.type=ClassTarget target19.width=80 target19.x=130 target19.y=210 target2.height=50 target2.name=Player target2.showInterface=false target2.type=ClassTarget target2.width=80 target2.x=610 target2.y=380 target3.height=50 target3.name=CommandEnum target3.showInterface=false target3.type=EnumTarget target3.width=120 target3.x=230 target3.y=180 target4.height=50 target4.name=Reader target4.showInterface=false target4.type=ClassTarget target4.width=80 target4.x=120 target4.y=110 target5.height=50 target5.name=Drink target5.showInterface=false target5.type=ClassTarget target5.width=80 target5.x=20 target5.y=360 target6.height=50 target6.name=World target6.showInterface=false target6.type=ClassTarget target6.width=80 target6.x=370 target6.y=20 target7.height=50 target7.name=CommandWords target7.showInterface=false target7.type=ClassTarget target7.width=130 target7.x=460 target7.y=200 target8.height=50 target8.name=Door target8.showInterface=false target8.type=ClassTarget target8.width=80 target8.x=510 target8.y=80 target9.height=50 target9.name=Weapon target9.showInterface=false target9.type=ClassTarget target9.width=80 target9.x=0 target9.y=270

__MACOSX/Lap3/._package.bluej

Lap3/Door.class

public synchronized class Door {
    private Room destination;
    private boolean locked;
    private Item doorKey;
    public void Door(Room);
    public Room getDestination();
    public boolean isLocked();
    public void setKey(Item);
    public Item getKey();
    public void setLocked(boolean);
}

Lap3/Command.ctxt

#BlueJ class context comment0.target=Command comment0.text=\n\ This\ class\ is\ part\ of\ the\ "Campus\ of\ Kings"\ application.\ "Campus\ of\ Kings"\ is\ a\n\ very\ simple,\ text\ based\ adventure\ game.\n\ \n\ This\ class\ holds\ information\ about\ a\ command\ that\ was\ issued\ by\ the\ user.\ A\n\ command\ currently\ consists\ of\ two\ strings\:\ a\ command\ word\ and\ a\ second\ word\n\ (for\ example,\ if\ the\ command\ was\ "take\ map",\ then\ the\ two\ strings\ obviously\n\ are\ "take"\ and\ "map").\n\ \n\ The\ way\ this\ is\ used\ is\:\ Commands\ are\ already\ checked\ for\ being\ valid\ command\n\ words.\ If\ the\ user\ entered\ an\ invalid\ command\ (a\ word\ that\ is\ not\ known)\ then\n\ the\ command\ word\ is\ <null>.\n\ \n\ If\ the\ command\ had\ only\ one\ word,\ then\ the\ second\ word\ is\ <null>.\n\ \n\ @author\ Maria\ Jump\n\ @version\ 2015.02.01\n comment1.params=firstWord comment1.target=Command(java.lang.String) comment1.text=\n\ Create\ a\ command\ object.\ First\ is\ supplied.\ The\ second\ word\ is\ assumed\n\ to\ be\ null.\n\ \n\ @param\ firstWord\n\ \ \ \ \ \ \ \ \ \ \ \ The\ first\ word\ of\ the\ command.\ Null\ if\ the\ command\ was\ not\n\ \ \ \ \ \ \ \ \ \ \ \ recognized.\n comment2.params=firstWord\ rest comment2.target=Command(java.lang.String,\ java.util.ArrayList) comment2.text=\n\ Create\ a\ command\ object.\ First\ and\ second\ word\ must\ be\ supplied,\ but\n\ either\ one\ (or\ both)\ can\ be\ null.\n\ \n\ @param\ firstWord\n\ \ \ \ \ \ \ \ \ \ \ \ The\ first\ word\ of\ the\ command.\ Null\ if\ the\ command\ was\ not\n\ \ \ \ \ \ \ \ \ \ \ \ recognized.\n\ @param\ rest\n\ \ \ \ \ \ \ \ \ \ \ \ The\ rest\ of\ the\ command.\n comment3.params= comment3.target=CommandEnum\ getCommandWord() comment3.text=\n\ Return\ the\ command\ word\ (the\ first\ word)\ of\ this\ command.\ If\ the\ command\n\ was\ not\ understood,\ the\ result\ is\ null.\n\ \n\ @return\ The\ command\ word.\n comment4.params= comment4.target=boolean\ isUnknown() comment4.text=\n\ Returns\ if\ this\ command\ was\ not\ understood.\n\ \n\ @return\ true\ if\ this\ command\ was\ not\ understood.\n comment5.params= comment5.target=boolean\ hasSecondWord() comment5.text=\n\ Returns\ if\ this\ command\ has\ a\ second\ word.\n\ \n\ @return\ true\ if\ the\ command\ has\ a\ second\ word.\n comment6.params=index comment6.target=boolean\ hasWord(int) comment6.text=\n\ Returns\ if\ this\ command\ has\ more\ words.\n\n\ @param\ index\ The\ index\ of\ the\ word\ needed.\n\ @return\ true\ if\ the\ command\ has\ a\ word\ at\ given\ index.\n comment7.params=index comment7.target=java.lang.String\ getWord(int) comment7.text=\n\ Returns\ the\ word\ at\ the\ requested\ index\ in\ the\ command.\n\ \n\ @param\ index\n\ \ \ \ \ \ \ \ \ \ \ \ The\ index\ of\ word\ in\ the\ command\ that\ is\ being\ requested.\n\ \n\ @return\ A\ particular\ word\ in\ the\ command.\ Returns\ null\ if\ there\ is\ no\n\ \ \ \ \ \ \ \ \ word\ corresponding\ to\ that\ requested\ index.\n\ \n comment8.params= comment8.target=java.lang.String\ getRestOfLine() comment8.text=\n\ Returns\ the\ second\ word\ of\ this\ command,\ if\ it\ exists.\n\ \n\ @return\ The\ second\ word\ of\ this\ command.\ Returns\ null\ if\ there\ was\ no\n\ \ \ \ \ \ \ \ \ second\ word.\n numComments=9

Lap3/Main.class

public synchronized class Main extends javax.swing.JFrame implements java.awt.event.ActionListener {
    private static final long serialVersionUID = -4610552759287004513;
    private static final java.awt.Dimension WINDOW_DIMENSION;
    private javax.swing.JScrollPane outputScrollPane;
    private javax.swing.JMenuItem saveItem;
    private javax.swing.JMenuItem exitItem;
    private Game game;
    public void Main();
    public void actionPerformed(java.awt.event.ActionEvent);
    public static void main(String[]);
    static void <clinit>();
}

Lap3/Container.ctxt

#BlueJ class context comment0.target=Container comment0.text=\n\ 24\ April\ 2018\n\ @author\ [Your\ name]\n comment1.params=name\ pointValue\ description\ weight comment1.target=Container(java.lang.String,\ int,\ java.lang.String,\ int) comment2.params=item comment2.target=void\ addItem(Item) comment2.text=\n\ Add\ item\ to\ a\ container.\n\ \n\ @param\ item\ the\ item\ to\ be\ added\ to\ the\ container\n comment3.params=itemName comment3.target=Item\ removeItem(java.lang.String) comment3.text=\n\ remove\ item\ from\ a\ container.\n\ \n\ @param\ itemName\ the\ item\ to\ be\ removed\ from\ the\ container\n\ @return\ Item\ that\ has\ been\ removed\ from\ the\ container\n comment4.params= comment4.target=int\ getWeight() comment5.params=itemName comment5.target=Item\ getItem(java.lang.String) comment5.text=\n\ get\ item\ from\ the\ container.\n\ \n\ @param\ itemName\ the\ item\ to\ be\ removed\ from\ the\ container\n\ @return\ Item\ that\ has\ been\ removed\ from\ the\ container\n comment6.params= comment6.target=java.lang.String\ getContainerItems() comment7.params= comment7.target=java.lang.String\ toString() numComments=8

Lap3/Edible.class

public abstract interface Edible {
    public abstract String eat(Player);
}

Lap3/Food.class

public synchronized class Food extends Item implements Edible {
    public void Food(String, int, String, int);
    public String eat(Player);
}

Lap3/.git/config

[core] repositoryformatversion = 0 filemode = true logallrefupdates = true precomposeunicode = true [remote "origin"] url = https://github.com/kings-cs/CS117-S18-AlharbiMohammed.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] name = mohammedalharbi email = [email protected]

Lap3/.git/objects/61/c33f2630143a842db4215e48d226c92b153c74

Lap3/.git/objects/61/c33f2630143a842db4215e48d226c92b153c74

blob 2791� import java.util.HashMap; /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; private Room previousRoom; public static final int MAX_WEIGHT = 5000; private int currentWeight; private HashMap<String, Item> inventory; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; previousRoom = null; inventory = new HashMap<>(); currentWeight = 0; } /** Add item to inventory. * @param itemName to be added */ public boolean inventoryAddItem(String itemName){ Item item = currentRoom.getItem(itemName); inventory.put(itemName, item); currentRoom.removeItem(itemName); return true; } /** * * @return current weight that the player is carrying */ public int getCurrentWeight(){ return currentWeight; } /** * * @return the maximum weight that the player can carry */ public int getMaxWeight(){ return MAX_WEIGHT; } /** Get an item from the players inventory. * @param itemName - name of item to be picked * @return an Item object */ public Item getItem(String itemName){ return inventory.get(itemName); } /** remove an item from the players inventory. * @param itemName - name of item to be removed * @return an Item object */ public Item removeItem(String itemName){ currentWeight -= getItem(itemName).getWeight(); return inventory.remove(itemName); } /** accessors for the current room the character. * @return currentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ previousRoom = currentRoom; currentRoom = playing; } /** Accessors for the previous room the character. * @return cerrentRoom */ public Room getpreviousRoom(){ return previousRoom; } /** Accessors for the players inventory. * @return players inventory */ public String getInventory(){ String inventoryInfo = ""; for(String moh: inventory.keySet()){ inventoryInfo += " " + moh +", "; } return inventoryInfo; } }

Lap3/.git/objects/61/f5574deee2e72ca9fddd05117424963fcb0311

Lap3/.git/objects/61/f5574deee2e72ca9fddd05117424963fcb0311

blob 2217� import java.util.HashMap; /* * Class Container - A container item in the game that the player can * pack or unpack * The class also describe containers in the game by their name, weight etc */ /** * 24 April 2018 * @author [Your name] */ public class Container extends Item{ private final HashMap<String, Item> containerItems; private int weight = 0; public Container(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); containerItems = new HashMap<>(); } /** * Add item to a container. * * @param item the item to be added to the container **/ @Override public void addItem(Item item){ containerItems.put(item.getName(), item); } /** * remove item from a container. * * @param itemName the item to be removed from the container * @return Item that has been removed from the container **/ @Override public Item removeItem(String itemName){ return containerItems.remove(itemName); } @Override public int getWeight() { weight = super.getWeight(); for(Item item: containerItems.values()){ weight += item.getWeight(); } return weight; } /** * get item from the container. * * @param itemName the item to be removed from the container * @return Item that has been removed from the container **/ //@Override public Item getItem(String itemName){ return containerItems.get(itemName); } private String getContainerItems(){ String containerItemsRes = ""; for(String s: containerItems.keySet()){ containerItemsRes += s + ", "; } return containerItemsRes; } @Override public String toString(){ String itemInfo = super.toString(); itemInfo += "\nItems : " + getContainerItems() ; return itemInfo; } }

Lap3/.git/objects/0d/fa0b4836bcaba1ebcbe991c5f1250ff527a5d0

Lap3/.git/objects/0d/fa0b4836bcaba1ebcbe991c5f1250ff527a5d0

blob 1880� /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public enum CommandEnum{ /** A constant array that holds all valid command words. */ //private static String[] validCommands; look, go, quit, help, status, back, examine, take, drop, inventory, unlock, lock, unpack, pack, eat, drink, equip, unequip; /** * Static block to initialize the fields of CommandWords. */ /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(CommandEnum aString) { return CommandWords.commandMap.containsValue(aString); } /** * Returns a list of the available commands, of the form: * your command words are: * look go quit help * * @return A string containing the list of available commands. */ public static String getCommandString(){ String commandString = " "; for(CommandEnum moh : CommandEnum.values()){ commandString += moh.name() + " "; } return commandString; //return getCommandString(); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return CommandEnum.valueOf(theString); } }

Lap3/.git/objects/0d/dd05f92f2d9f0d16c6fbea1c09b2ece7b1422f

Lap3/.git/objects/0d/dd05f92f2d9f0d16c6fbea1c09b2ece7b1422f

blob 124� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help.

Lap3/.git/objects/0d/92bd7810b78525d6937e9395ab078b69ff31ef

Lap3/.git/objects/0d/92bd7810b78525d6937e9395ab078b69ff31ef

blob 7086�import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.io.InputStream; import java.io.IOException; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; /** * The sole purpose of this class is to start the game up. It does this by * creating an instance of the Game and calling it's play method. * * @author Maria Jump * @version 2015.02.01 */ public class Main extends JFrame implements ActionListener { /** Generated unique serial unique id. */ private static final long serialVersionUID = -4610552759287004513L; /** Starting dimension of the window. */ private static final Dimension WINDOW_DIMENSION; /** The scroll pane so we can resize it when the window is resized. */ private JScrollPane outputScrollPane; /** The save log menu item. */ private JMenuItem saveItem; /** The exit menu item. */ private JMenuItem exitItem; /** The game instance. */ private Game game; /** Static block for initializing static fields. */ static { WINDOW_DIMENSION = new Dimension(500, 500); } /** Default constructor. */ public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); // Setting up the menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); saveItem = new JMenuItem("Save Log ..."); saveItem.addActionListener(this); fileMenu.add(saveItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); fileMenu.add(exitItem); // Setting out the output area JTextPane output = new JTextPane(); outputScrollPane = new JScrollPane(output); Dimension outputSize = new Dimension(); outputSize.setSize(WINDOW_DIMENSION.getWidth(), WINDOW_DIMENSION.getHeight() - 100); outputScrollPane.setPreferredSize(outputSize); // So that the scroll pane will resize when the window is resized addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { Dimension outputSize = new Dimension(); outputSize.setSize(getContentPane().getWidth(), getContentPane().getHeight() - 100); outputScrollPane.setPreferredSize(outputSize); } }); add(BorderLayout.NORTH, outputScrollPane); // Set up the Writer so that it can be used throughout the game. Writer.setTextArea(output); // Setting up the bottom panel for input JPanel bottomPane = new JPanel(); bottomPane.setLayout(new BorderLayout()); JButton enterButton = new JButton("Enter"); JTextField commandField = new JTextField(); TextFieldStreamer streamer = new TextFieldStreamer(commandField); // maybe this next line should be done in the TextFieldStreamer ctor // but that would cause a "leak a this from the ctor" warning commandField.addActionListener(streamer); enterButton.addActionListener(streamer); System.setIn(streamer); bottomPane.add(BorderLayout.CENTER, commandField); bottomPane.add(BorderLayout.EAST, enterButton); add(BorderLayout.SOUTH, bottomPane); setSize(WINDOW_DIMENSION); setVisible(true); commandField.requestFocus(); game = new Game(); game.play(); } /** * Default action listener. * * @param event * The action event. */ @Override public void actionPerformed(ActionEvent event) { if (event.getSource() == saveItem) { Writer.copyDefaultLog(); } else if (event.getSource() == exitItem) { System.exit(0); } } /** * The main method for the program. * * @param args * The command line arguments. */ public static void main(String[] args) { new Main(); } /** * Implementation of InputStream that uses the text from a JTextField as the * input buffer. * * @author Maria Jump */ private class TextFieldStreamer extends InputStream implements ActionListener { /** The JTextField to use for input. */ private JTextField textField; /** The string of text that being passed as input. */ private String text; /** Used for checking if the available input has reached its end. */ private int position; /** * Default constructor for TextFieldStreamer. * * @param field * JTextField component being used as input buffer. */ public TextFieldStreamer(JTextField field) { position = 0; text = null; textField = field; } // gets /** * Invoked when an action occurs. In this case, prints the text of the * JTextField to StdOut as an error message to differentiate between * user input and game output. Triggered every time that "Enter" is * pressed on the JTextField. * * Triggered every time that "Enter" is pressed on the textfield * * @param event * ActionEvent passed by the component. */ @Override public void actionPerformed(ActionEvent event) { text = textField.getText() + System.getProperty("line.separator"); position = 0; textField.setText(""); synchronized (this) { // maybe this should only notify() as multiple threads may // be waiting for input and they would now race for input this.notifyAll(); } } /** * Reads the next byte of data from the input stream. The value byte is * returned as an <code>int</code> in the range <code>0</code> to * <code>255</code>. If no byte is available because the end of the * stream has been reached, the value <code>-1</code> is returned. This * method blocks until input data is available, the end of the stream is * detected, or an exception is thrown. * * <p> * A subclass must provide an implementation of this method. * * @return the next byte of data, or <code>-1</code> if the end of the * stream is reached. * @exception IOException * if an I/O error occurs. */ @Override public int read() throws IOException { int result = 0xDEADBEEF; // test if the available input has reached its end // and the EOS should be returned if (text != null && position == text.length()) { text = null; // this is supposed to return -1 on "end of stream" // but I'm having a hard time locating the constant result = java.io.StreamTokenizer.TT_EOF; } if (result == 0xDEADBEEF) { // no input available, block until more is available because // that's // the behavior specified in the Javadocs. while (text == null || position >= text.length()) { try { // read() should block until new input is available. synchronized (this) { this.wait(); } } catch (InterruptedException ex) { ex.printStackTrace(); } } // read an additional character, return it and increment the // index. result = text.charAt(position++); } return result; } } }

Lap3/.git/objects/95/60b43b6af9b34f6c1516353022f8c44e3e2d04

Lap3/.git/objects/95/60b43b6af9b34f6c1516353022f8c44e3e2d04

blob 790� /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * @author mohammed alharbi * @version 29/4/2018 */ public class Food extends Item implements Edible{ /** * super food. * @param name the name. * @param pointValue the pointValue. * @param description the description. * @param weight the weight. */ public Food(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); } /** * itemName. * @param itemName the itemName. * @return eat. */ public boolean eat(String itemName) { return true; } }

Lap3/.git/objects/59/1ef3299cd55be79bafdaf5739253d377125a4f

Lap3/.git/objects/59/1ef3299cd55be79bafdaf5739253d377125a4f

blob 12096�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author mohammed alharbi * @version 20/2/2018 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); createItems(); } /** * item the item. */ public void createItems(){ Item toothbrush = new Item("tooth brush", 3, "Brushing teeth", 10); Item toothpaste = new Item("tooth paste", 3, "Applied on a tooth brush", 20); Weapon knife = new Weapon("knife", 5, "Peel and cut fruits", 100); Drink coffee = new Drink("coffee", 7, "good for personal health", 150); Food grapes = new Food("grapes", 10, "Good for health and hunger", 100); Container purse = new Container("purse", 2,"Contains small small items", 100); Item houseKey = new Item("house key", 5, "Open locked doors", 20); purse.addItem(houseKey); //car Container backBag = new Container("back bag", 10, "Carry things in", 200); Item carKey = new Item("car key", 5, "Open locked doors", 50); Drink water = new Drink("bottle of water", 8, "Quenches thirst", 250); //out of the house Weapon mopStick = new Weapon("broom stick", 5, "Pick items from the roof", 600); //keep street Weapon hammer = new Weapon("hammer", 6, "Can be used to fight wild animals", 1000); Container bucket = new Container("water buckets", 15, "carry more items if back is full", 50); bucket.addItem(hammer); for(String room : rooms.keySet()){ switch(room){ case "bathroom": getcurrentRoom(room).addItem(toothbrush); getcurrentRoom(room).addItem(toothpaste); break; case "kitchen": getcurrentRoom(room).addItem(knife); getcurrentRoom(room).addItem(coffee); getcurrentRoom(room).addItem(grapes); getcurrentRoom(room).addItem(purse); getcurrentRoom(room).getDirection("south").setLocked(true); getcurrentRoom(room).getDirection("south").setKey(houseKey); break; case "out of the house": getcurrentRoom(room).addItem(mopStick); getcurrentRoom(room).getDirection("north").setLocked(true); getcurrentRoom(room).getDirection("north").setKey(houseKey); break; case "car": getcurrentRoom(room).addItem(backBag); getcurrentRoom(room).addItem(water); getcurrentRoom(room).addItem(carKey); break; case "keep street": getcurrentRoom(room).addItem(bucket); break; default: } } } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms. * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from The room where the door originated. * @param direction The direction of the door in the from room. * @param to The room where the door goes. */ private void createDoor(Room from, String direction, Room to){ Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room outOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); outOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room car = new Room("Car", "inside the car, back bag, car key with house key.."); car.setPoints(7); pointScore = pointScore + 7; Room keepStreet = new Room("keep Street", "the correct way."); Room turnLeft = new Room("Turn left", "wrong way to go with it.."); Room endOfTheRoad = new Room("End of the road", "closed way."); Room gasStaion = new Room("Gas Staion", "the way to traffic signal."); Room trafficSignal = new Room("Traffic signal", "there are three different ways."); trafficSignal.setPoints(10); pointScore = pointScore + 10; Room turnLeft2 = new Room("Turn left2", "maybe not the right way."); Room wrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room turnRight = new Room("Turn right"," more traffic."); Room closedWay = new Room("Closed Way","no place to go."); Room keepGoing = new Room("KeepGoing","almost arrive to university."); keepGoing.setPoints(10); pointScore = pointScore + 10; Room parking = new Room("Parking","there is a meter parking, 2$ in Hour."); parking.setPoints(17); pointScore = pointScore + 17; Room library = new Room("Library","some books, students, printer, computers."); Room campusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room hallCampus = new Room("Hall Campus","the building for men."); Room hBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); square.setPoints(12); pointScore = pointScore + 12; Room mCBuilding = new Room("MCBuilding"," Classes, six floors."); Room aBuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room stairs = new Room("Stairs","take the player until fourth floor."); stairs.setPoints(18); pointScore = pointScore + 18; Room elevator = new Room("Elevator","take the player until fourth floor."); Room floor2 = new Room("2Floor","entry for classes"); Room classroom = new Room("Classroom","one door, blackboard, tables"); Room classroom201 = new Room ("Classroom201","you reach the goal."); classroom201.setPoints(30); pointScore = pointScore + 30; Room classroom204 = new Room("Classroom204","one door, students."); Room classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(bathroom); this.addRoom(kitchen); this.addRoom(outOfTheHouse); this.addRoom(car); this.addRoom(keepStreet); this.addRoom(turnLeft); this.addRoom(endOfTheRoad); this.addRoom(gasStaion); this.addRoom(trafficSignal); this.addRoom(turnLeft2); this.addRoom(wrongWay); this.addRoom(turnRight); this.addRoom(closedWay); this.addRoom(keepGoing); this.addRoom(parking); this.addRoom(library); this.addRoom(campusCenter); this.addRoom(hallCampus); this.addRoom(hBuilding); this.addRoom(square); this.addRoom(mCBuilding); this.addRoom(aBuilding); this.addRoom(stairs); this.addRoom(elevator); this.addRoom(floor2); this.addRoom(classroom); this.addRoom(classroom201); this.addRoom(classroom204); this.addRoom(classroom202); // Creating all the doors between the rooms. this.createDoor(bathroom,"east",kitchen); this.createDoor(kitchen, "west",bathroom); this.createDoor(kitchen,"south", outOfTheHouse); this.createDoor(outOfTheHouse,"north", kitchen); this.createDoor(outOfTheHouse,"west",car); this.createDoor(car,"east",outOfTheHouse); this.createDoor(car,"south",keepStreet); this.createDoor(keepStreet,"north",car); this.createDoor(keepStreet,"west",turnLeft); this.createDoor(turnLeft,"east",keepStreet); this.createDoor(turnLeft,"south", endOfTheRoad); this.createDoor(endOfTheRoad,"north",turnLeft); this.createDoor(keepStreet,"south",gasStaion); this.createDoor(gasStaion, "north",keepStreet); this.createDoor(gasStaion,"east",trafficSignal); this.createDoor(trafficSignal,"west", gasStaion); this.createDoor(trafficSignal,"north",turnLeft2); this.createDoor(turnLeft2,"south",trafficSignal); this.createDoor(turnLeft2,"north", wrongWay); this.createDoor(wrongWay,"south",turnLeft2); this.createDoor(trafficSignal,"south", turnRight); this.createDoor(turnRight,"north", trafficSignal); this.createDoor(turnRight,"south",closedWay); this.createDoor(closedWay,"north", turnRight); this.createDoor(trafficSignal,"east", keepGoing); this.createDoor(keepGoing, "west",trafficSignal); this.createDoor(keepGoing,"east", parking); this.createDoor(parking,"west",keepGoing); this.createDoor(parking,"southwest",library); this.createDoor(library, "northeast",parking); this.createDoor(library,"east", campusCenter); this.createDoor(campusCenter,"west",library); this.createDoor(parking,"south",square); this.createDoor(square,"north",parking); this.createDoor(square,"east", hallCampus); this.createDoor(hallCampus,"west",square); this.createDoor(square,"west",hBuilding); this.createDoor(hBuilding,"east",square); this.createDoor(square, "southeast",mCBuilding); this.createDoor(mCBuilding,"northwest",square); this.createDoor(square,"south",aBuilding); this.createDoor(aBuilding,"north",square); this.createDoor(aBuilding,"west",stairs); this.createDoor(stairs,"east",aBuilding); this.createDoor(aBuilding,"southwest",classroom); this.createDoor(classroom,"northeast",aBuilding); this.createDoor(aBuilding,"southwest",elevator); this.createDoor(elevator,"northeast",aBuilding); this.createDoor(elevator,"west",floor2); this.createDoor(floor2,"east",elevator); this.createDoor(stairs,"south",floor2); this.createDoor(floor2,"north",stairs); this.createDoor(floor2,"south",classroom204); this.createDoor(classroom204,"north",floor2); this.createDoor(floor2,"east",classroom202); this.createDoor(classroom202,"west",floor2); this.createDoor(floor2,"southeast",classroom201); this.createDoor(classroom201,"northwest",floor2); } }

Lap3/.git/objects/59/76adbcd54608f71b0efd54bbd279049acb20aa

Lap3/.git/objects/59/76adbcd54608f71b0efd54bbd279049acb20aa

blob 20708�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord.name()){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; case "examine": examineItem(command); break; case "take": takeItem(command); break; case "drop": dropItem(command); break; case "inventory": inventory(); break; case "lock": lock(command); break; case "unlock": unlock(command); break; case "pack": pack(command); break; case "unpack": unpack(command); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if(doorway.isLocked()){ Writer.println("door is locked!"); }else{ Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } } /** * Unlock a locked door. * * @param command * The command to be processed. */ private void unlock(Command command) { if (!command.hasSecondWord()) { Writer.println("Unlock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if (doorway.isLocked() == false) { Writer.println("Door is not locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(false); Writer.println("You unlocked it!"); }else{ Writer.println("That doesn't fit!"); } }else{ Writer.println("You don't have it!"); } } } } } /** * lock a locked door. * * @param command * The command to be processed. */ private void lock(Command command) { if (!command.hasSecondWord()) { Writer.println("Lock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("no door!"); } else { if (doorway.isLocked() == true) { Writer.println("Door is already locked!"); }else{ if(doorway.getKey() == null){ Writer.println("Door cannot be locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(true); Writer.println("You locked it!"); }else{ Writer.println("wrong key!!"); } }else{ Writer.println("You don't have it!"); } } } } } } /** * Try to examine a play item. If the item doesn't exist in the * players inventory nor the current room, * print an error message. * * @param command * The command to be processed. */ private void examineItem(Command command) { if (!command.hasSecondWord()) { Writer.println("Which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { Writer.println(item.toString()); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void takeItem(Command command) { if (!command.hasSecondWord()) { Writer.println("take what?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getcurrentRoom().getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy to lift"); }else{ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("Carrying too much"); }else{ playerClass.inventoryAddItem(item); playerClass.getcurrentRoom().removeItem(itemName); Writer.println("you took the item"); } } } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Writer.println("which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("you don't have it!"); } else { playerClass.getcurrentRoom().addItem(item); playerClass.removeItem(itemName); Writer.println("you dropped the item"); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param * The command to be processed. */ private void inventory() { Writer.println("Inventory :" + playerClass.getInventory()); } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } /** * Pack an item into. * * @param command * The command to be processed. */ private void pack(Command command) { if (!command.hasSecondWord()) { Writer.println("pack what?"); } else { String itemName = command.getRestOfLine(); //Get item from players inventory Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("you don't have!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy"); }else{ Writer.println("pack where?"); String containerString = Reader.getResponse(); Item container = playerClass.getItem(containerString); if(container == null){ container = playerClass.getcurrentRoom().getItem(containerString); } if(container != null){ if(container instanceof Container){ container.addItem(item); if(playerClass.getcurrentRoom().removeItem(itemName) != null || playerClass.removeItem(itemName) != null){ Writer.println("you packed it"); } }else{ Writer.println("that's not a container"); } }else{ Writer.println("You don't see the container"); } } } } } /** * Pack an item into. * * @param command * The command to be processed. */ private void unpack(Command command) { if (!command.hasSecondWord()) { Writer.println("unpack what?"); } else { String containerName = command.getRestOfLine(); //Get item from players inventory Item container = playerClass.getItem(containerName); //Check the item value has had something added, if no, check for the item in the current room if (container == null) { container = playerClass.getcurrentRoom().getItem(containerName); } //Check if item exists in the current room if (container == null) { Writer.println("you don't see it!"); } else { if(container instanceof Container){ Writer.println("which item?"); String itemName = Reader.getResponse(); Item item = container.getItem(itemName); if(item != null){ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.getMaxWeight()){ Writer.println("you are carrying too much"); }else{ playerClass.inventoryAddItem(item); container.removeItem(item.getName()); Writer.println("you unpacked it"); } }else{ Writer.println("you don't find it"); } }else{ Writer.println("that's not a container"); } } } } }

Lap3/.git/objects/0c/efac37058dc468b1bb5e637b68ea8a8abe5e02

Lap3/.git/objects/0c/efac37058dc468b1bb5e637b68ea8a8abe5e02

blob 4750�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /** This room's north exit, null if none exits. */ public Door northExit; /** This room's south exit, null if none exits. */ public Door southExit; /** This room's east exit, null if none exits. */ public Door eastExit; /** This room's west exit, null if none exits. */ public Door westExit; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap<>(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Returns the number of rooms that have been created in the world. * @return The number of rooms that have been created in the world. */ public static int getCounter() { return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public Door getExit(String direction) { return directions.get(direction); } /** * Set exit. * @param direction * @param neighbor */ public void setExit(String direction,Door neighbor) { directions.put(direction, neighbor); } /** /** Accessor for geting the northExit. * @return getNorthExit for getting that direction. */ public Door getNorthExit(){ return northExit; } /** Accessor for geting the southExit. * @return getSouthExit for getting that direction. */ public Door getSouthExit(){ return southExit; } /** Accessor for geting the eastExit. * @return getEastExit for getting that direction. */ public Door getEastExit(){ return eastExit; } /** Accessor for geting the westExit. * @return getWestExit for getting that direction. */ public Door getWestExit(){ return westExit; } /** Mutator for setting the northExit. * @param newNorthExit for setting that direction. */ public void setNorthExit(Door newNorthExit){ northExit = newNorthExit; } /** Mutator for setting the southExit. * @param newSouthExit for setting that direction. */ public void setSouthExit(Door newSouthExit){ southExit = newSouthExit; } /** Mutator for setting the eastExit. * @param newEastExit for setting that direction. */ public void setEastExit(Door newEastExit){ eastExit = newEastExit; } /** Mutator for setting the westExit. * @param newWestExit for setting that direction. */ public void setWestExit(Door newWestExit){ westExit = newWestExit; } /** * Returns a string description including all the details of a Room . * For example , *Outside : *You are outside in the center of the King's College campus . *Exits : north east south west * * @return A string representing all the details of a Room . */ public String toString (){ String roomInformation = "Exist:"; roomInformation = getName() + "" + getDescription(); for (String direction : directions.keySet()) { roomInformation += direction + " "; } return roomInformation; } }

Lap3/.git/objects/3e/d1ad10557200c7dda9781c0163f9dfdf1440d8

Lap3/.git/objects/3e/d1ad10557200c7dda9781c0163f9dfdf1440d8

blob 9375�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author Maria Jump * @version 2015.02.01 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param west * The room to the west of the originating room. */ private void createDoor(Room from, String direction, Room to) { Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room Bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room Kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room OutOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); OutOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room Car = new Room("Car", "inside the car, back bag, car key with house key.."); Car.setPoints(7); pointScore = pointScore + 7; Room KeepStreet = new Room(" keep Street", "the correct way."); Room TurnLeft = new Room("Turn left", "wrong way to go with it.."); Room EndOfTheRoad = new Room("End of the road", "closed way."); Room TurnLeft1 = new Room(" Turn left1", "the way to traffic signal."); Room TrafficSignal = new Room("Traffic signal", "there are three different ways."); TrafficSignal.setPoints(10); pointScore = pointScore + 10; Room TurnLeft2 = new Room("Turn left2", "maybe not the right way."); Room WrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room TurnRight = new Room("Turn right"," more traffic."); Room ClosedWay = new Room("Closed Way","no place to go."); Room KeepStreet1 = new Room("KeepStreet1","almost arrive to university."); KeepStreet1.setPoints(10); pointScore = pointScore + 10; Room Parking = new Room("Parking","there is a meter parking, 2$ in Hour."); Parking.setPoints(17); pointScore = pointScore + 17; Room Library = new Room("Library","some books, students, printer, computers."); Room CampusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room HallCampus = new Room("Hall Campus","the building for men."); Room HBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room Square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); Square.setPoints(12); pointScore = pointScore + 12; Room MCBuilding = new Room("MCBuilding"," Classes, six floors."); Room ABuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room Stairs = new Room("Stairs","take the player until fourth floor."); Stairs.setPoints(18); pointScore = pointScore + 18; Room Elevator = new Room("Elevator","take the player until fourth floor."); Room Floor2 = new Room("2Floor","entry for classes"); Room Classroom = new Room("Classroom","one door, blackboard, tables"); Room Classroom201 = new Room ("Classroom201","you reach the goal."); Classroom201.setPoints(30); pointScore = pointScore + 30; Room Classroom204 = new Room("Classroom204","one door, students."); Room Classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(Bathroom); this.addRoom(Kitchen); this.addRoom(OutOfTheHouse); this.addRoom(Car); this.addRoom(KeepStreet); this.addRoom(TurnLeft); this.addRoom(EndOfTheRoad); this.addRoom(TurnLeft1); this.addRoom(TrafficSignal); this.addRoom(TurnLeft2); this.addRoom(WrongWay); this.addRoom(TurnRight); this.addRoom(ClosedWay); this.addRoom(KeepStreet1); this.addRoom(Parking); this.addRoom(Library); this.addRoom(CampusCenter); this.addRoom(HallCampus); this.addRoom(HBuilding); this.addRoom(Square); this.addRoom(MCBuilding); this.addRoom(ABuilding); this.addRoom(Stairs); this.addRoom(Elevator); this.addRoom(Floor2); this.addRoom(Classroom); this.addRoom(Classroom201); this.addRoom(Classroom204); this.addRoom(Classroom202); // Creating all the doors between the rooms. this.createDoor(Bathroom,"east",Kitchen); this.createDoor(Kitchen, "west",Bathroom); this.createDoor(Kitchen,"south", OutOfTheHouse); this.createDoor(OutOfTheHouse,"north", Kitchen); this.createDoor(OutOfTheHouse,"west",Car); this.createDoor(Car,"east",OutOfTheHouse); this.createDoor(Car,"south",KeepStreet); this.createDoor(KeepStreet,"north",Car); this.createDoor(KeepStreet,"west",TurnLeft); this.createDoor(TurnLeft,"east",KeepStreet); this.createDoor(TurnLeft,"south", EndOfTheRoad); this.createDoor(EndOfTheRoad,"north",TurnLeft); this.createDoor(KeepStreet,"south",TurnLeft1); this.createDoor(TurnLeft1, "north",KeepStreet); this.createDoor(TurnLeft1,"east",TrafficSignal); this.createDoor(TrafficSignal,"west", TurnLeft1); this.createDoor(TrafficSignal,"north",TurnLeft2); this.createDoor(TurnLeft2,"south",TrafficSignal); this.createDoor(TurnLeft2,"north", WrongWay); this.createDoor(WrongWay,"south",TurnLeft2); this.createDoor(TrafficSignal,"south", TurnRight); this.createDoor(TurnRight,"north", TrafficSignal); this.createDoor(TurnRight,"south",ClosedWay); this.createDoor(ClosedWay,"north", TurnRight); this.createDoor(TrafficSignal,"east", KeepStreet1); this.createDoor(KeepStreet1, "west",TrafficSignal); this.createDoor(KeepStreet1,"east", Parking); this.createDoor(Parking,"west",KeepStreet1); this.createDoor(Parking,"south",Library); this.createDoor(Library, "north",Parking); this.createDoor(Library,"west", CampusCenter); this.createDoor(CampusCenter,"east",Library); this.createDoor(Parking,"south",Square); this.createDoor(Square,"north",Parking); this.createDoor(Square,"east", HallCampus); this.createDoor(HallCampus,"west",Square); this.createDoor(Square,"west",HBuilding); this.createDoor(HBuilding,"east",Square); this.createDoor(Square, "south",MCBuilding); this.createDoor(MCBuilding,"north",Square); this.createDoor(Square,"south",ABuilding); this.createDoor(ABuilding,"north",ABuilding); this.createDoor(ABuilding,"west",Stairs); this.createDoor(Stairs,"east",ABuilding); this.createDoor(ABuilding,"south",Classroom); this.createDoor(Classroom,"north",ABuilding); this.createDoor(ABuilding,"south",Elevator); this.createDoor(Elevator,"north",ABuilding); this.createDoor(Elevator,"south",Floor2); this.createDoor(Floor2,"north",Elevator); this.createDoor(Stairs,"south",Floor2); this.createDoor(Floor2,"north",Stairs); this.createDoor(Floor2,"south",Classroom204); this.createDoor(Classroom204,"north",Floor2); this.createDoor(Floor2,"east",Classroom202); this.createDoor(Classroom202,"west",Floor2); this.createDoor(Floor2,"south",Classroom201); this.createDoor(Classroom201,"north",Floor2); } }

Lap3/.git/objects/3e/9f281b6908df0647aeac16e1ae175393263ec4

Lap3/.git/objects/3e/9f281b6908df0647aeac16e1ae175393263ec4

Lap3/.git/objects/68/892ff3d3ee00fb7177f3629010dc7544352b49

Lap3/.git/objects/68/892ff3d3ee00fb7177f3629010dc7544352b49

commit 234�tree 3e9f281b6908df0647aeac16e1ae175393263ec4 parent c2e9a520d044f09221a71a769adbe400f1dafcb9 author mohammedalharbi <[email protected]> 1524253317 -0400 committer mohammedalharbi <[email protected]> 1524253317 -0400 stage3

Lap3/.git/objects/57/01328dc5767393adb8bb115fe717b731fb8636

Lap3/.git/objects/57/01328dc5767393adb8bb115fe717b731fb8636

blob 3610�import java.util.ArrayList; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds information about a command that was issued by the user. A * command currently consists of two strings: a command word and a second word * (for example, if the command was "take map", then the two strings obviously * are "take" and "map"). * * The way this is used is: Commands are already checked for being valid command * words. If the user entered an invalid command (a word that is not known) then * the command word is <null>. * * If the command had only one word, then the second word is <null>. * * @author Maria Jump * @version 2015.02.01 */ public class Command { /** The command word for this command. */ private String commandWord; /** The rest of the line with all the spaces removed. */ private ArrayList<String> restOfLine; /** * Create a command object. First is supplied. The second word is assumed * to be null. * * @param firstWord * The first word of the command. Null if the command was not * recognized. */ public Command(String firstWord) { commandWord = firstWord; restOfLine = new ArrayList<String>(); } /** * Create a command object. First and second word must be supplied, but * either one (or both) can be null. * * @param firstWord * The first word of the command. Null if the command was not * recognized. * @param rest * The rest of the command. */ public Command(String firstWord, ArrayList<String> rest) { commandWord = firstWord; restOfLine = rest; } /** * Return the command word (the first word) of this command. If the command * was not understood, the result is null. * * @return The command word. */ public String getCommandWord() { return commandWord; } /** * Returns if this command was not understood. * * @return true if this command was not understood. */ public boolean isUnknown() { return (commandWord == null); } /** * Returns if this command has a second word. * * @return true if the command has a second word. */ public boolean hasSecondWord() { return restOfLine != null; } /** * Returns if this command has more words. * * @param index The index of the word needed. * @return true if the command has a word at given index. */ public boolean hasWord(int index) { return index >= 0 && index < restOfLine.size(); } /** * Returns the word at the requested index in the command. * * @param index * The index of word in the command that is being requested. * * @return A particular word in the command. Returns null if there is no * word corresponding to that requested index. * */ public String getWord(int index) { String result = null; if (index >= 0 && index < restOfLine.size()) { result = restOfLine.get(index); } return result; } /** * Returns the second word of this command, if it exists. * * @return The second word of this command. Returns null if there was no * second word. */ public String getRestOfLine() { StringBuffer buffer = null; if (restOfLine.size() != 0) { for(String word : restOfLine) { if (buffer == null) { buffer = new StringBuffer(); buffer.append(word); } else { buffer.append(" "); buffer.append(word); } } } String result = ""; if (buffer != null) { result += buffer.toString(); } return result; } }

Lap3/.git/objects/9b/b43e9d0ae1710a64486e87ab9fa94205447ee0

Lap3/.git/objects/9b/b43e9d0ae1710a64486e87ab9fa94205447ee0

blob 2850�import java.util.ArrayList; import java.util.Scanner; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This parser reads user input and tries to interpret it as an "Adventure" * command. Every time it is called it reads a line from the terminal and tries * to interpret the line as a two word command. It returns the command as an * object of class Command. * * The parser has a set of known command words. It checks user input against the * known commands, and if the input is not one of the known commands, it returns * a command object that is marked as an unknown command. * * @author Maria Jump * @version 2017.12.18 */ public class Reader { /** The source of command input. */ private static Scanner reader; /** * Create a parser to read from the terminal window. */ static { reader = new Scanner(System.in); } /** * Returns the next command from the user. * @return The next command from the user. */ public static Command getCommand() { String inputLine; // will hold the full input line String word1 = null; ArrayList<String> restOfLine = null; Writer.print("> "); // print prompt inputLine = reader.nextLine().toLowerCase(); Writer.printInput(inputLine); // Find up to two words on the line. Scanner tokenizer = new Scanner(inputLine); if (tokenizer.hasNext()) { word1 = tokenizer.next(); // get first word if (tokenizer.hasNext()) { restOfLine = new ArrayList<String>(); while(tokenizer.hasNext()) { restOfLine.add(tokenizer.next()); } } } tokenizer.close(); // Now check whether this word is known. If so, create a command // with it. If not, create a "null" command (for unknown command). Command result = null; if (CommandWords.isCommand(word1)) { result = new Command(word1, restOfLine); } else { result = new Command(null, restOfLine); } //Command result = CommandWords.getCommand(word1); return result; } /** * Return the response to a question in all lower case. * * @return The response typed in by the user. */ public static String getResponse() { return getResponseKeepCase().toLowerCase(); } /** * Return the response to a question in the case used by the player. * * @return The response typed in by the user. */ public static String getResponseKeepCase() { String response = reader.nextLine().trim(); Writer.printInput(response); return response; } }

Lap3/.git/objects/9e/4feafe23a7caf2e08f90103ed127b9d59f21c1

Lap3/.git/objects/9e/4feafe23a7caf2e08f90103ed127b9d59f21c1

blob 809� /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public class Drink extends Item implements Drinkable{ /** * Drink. * @param name the name. * @param pointValue the pointValue. * @param description teh description. * @param weight teh weight. */ public Drink(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); } @Override public String drink(Player p) { p.updateHealth(2); p.removeItem(this.getName()); return "you have taken a drink"; } }

Lap3/.git/objects/51/7feb6375a09bfa2f9de8968ffb458cc34a2904

Lap3/.git/objects/51/7feb6375a09bfa2f9de8968ffb458cc34a2904

Lap3/.git/objects/3d/abd97788e63a02c7b5ba0b10fa342821943462

Lap3/.git/objects/3d/abd97788e63a02c7b5ba0b10fa342821943462

blob 1999� /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public enum CommandEnum{ /** A constant array that holds all valid command words. */ //private static String[] validCommands; look, go, quit, help, status, back; /** * Static block to initialize the fields of CommandWords. */ // static { // String[] tempCommands = {"look","go", "quit", "help" }; // validCommands = tempCommands; // // } /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(CommandEnum aString) { return CommandWords.commandMap.containsValue(aString); } /** * Returns a list of the available commands, of the form: * your command words are: * look go quit help * * @return A string containing the list of available commands. */ public static String getCommandString(){ String commandString = ""; for(CommandEnum s: CommandEnum.values()){ commandString += s.name() + " "; } return commandString; //return getCommandString(); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return CommandEnum.valueOf(theString); } }

Lap3/.git/objects/67/10927b5418b35dac1bd71c3904707522be1330

Lap3/.git/objects/67/10927b5418b35dac1bd71c3904707522be1330

blob 3819�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**.*/ private HashMap<String, Door> exit; /**earn poins */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getExit(String direction){ return exit.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setExit(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room . * For example , *Outside : *You are outside in the center of the King's College campus . *Exits : north east south west * * @return A string representing all the details of a Room . */ public String toString(){ String roomInformation = " "; roomInformation = getName() + " " + getDescription(); for(String exit : exit.keySet()){ roomInformation =roomInformation + "Exit" + exit; } for(Door door : exit.values()){ roomInformation = roomInformation + "Door" + door; String RoomInformation = getName() + " " + getDescription(); roomInformation = "Exit:"; roomInformation = "Name:"; roomInformation = "Description:"; for (String Direction : directions.keySet()) { roomInformation += Direction + " "; } } return roomInformation; } }

Lap3/.git/objects/0b/54102bee4956f451cecec5e699795e9af23e7a

Lap3/.git/objects/0b/54102bee4956f451cecec5e699795e9af23e7a

blob 3303�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; ///**.*/ //private HashMap<String, Door> exit; /**earn poins */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = "Exits "; roomInformation = getName() + " " + getDescription(); for(String direction : directions.keySet()){ roomInformation = roomInformation + "Exit" + direction; } return roomInformation; } }

Lap3/.git/objects/94/5ebe2b1f73e262c642844596d9a5691a6d343a

Lap3/.git/objects/94/5ebe2b1f73e262c642844596d9a5691a6d343a

Lap3/.git/objects/94/3fd33a423d2a416d32d74377ffb19f46100cff

Lap3/.git/objects/94/3fd33a423d2a416d32d74377ffb19f46100cff

blob 407� /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * @author mohammed alharbi * @version 29/4/2018 */ public interface Edible { /** * interface Edible. * @param itemName the itemName. * @return true */ public boolean eat(String itemName); }

Lap3/.git/objects/0e/98e700ea30820baaedc369b97a8cdb32c8205d

Lap3/.git/objects/0e/98e700ea30820baaedc369b97a8cdb32c8205d

blob 3216� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. Bathroom there is teeth brush, shower place.Exiteast : You are in Bathroom there is teeth brush, shower place.Exiteast Exits: > go east Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest : You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest Exits: > go south out Of The House the way outside the house to drive to university..ExitnorthExitwest : You are in out Of The House the way outside the house to drive to university..ExitnorthExitwest Exits: > go west Car inside the car, back bag, car key with house key..ExiteastExitsouth : You are in Car inside the car, back bag, car key with house key..ExiteastExitsouth Exits: > go south keep Street the correct way.ExitsouthExitnorthExitwest : You are in keep Street the correct way.ExitsouthExitnorthExitwest Exits: > go east There is no door! > go west Turn left wrong way to go with it..ExiteastExitsouth : You are in Turn left wrong way to go with it..ExiteastExitsouth Exits: > go east keep Street the correct way.ExitsouthExitnorthExitwest : You are in keep Street the correct way.ExitsouthExitnorthExitwest Exits: > go south Gas Staion the way to traffic signal.ExiteastExitnorth : You are in Gas Staion the way to traffic signal.ExiteastExitnorth Exits: > go east Traffic signal there are three different ways.ExiteastExitsouthExitnorthExitwest : You are in Traffic signal there are three different ways.ExiteastExitsouthExitnorthExitwest Exits: > go east KeepGoing almost arrive to university.ExiteastExitwest : You are in KeepGoing almost arrive to university.ExiteastExitwest Exits: > go east Parking there is a meter parking, 2$ in Hour.ExitsouthwestExitsouthExitwest : You are in Parking there is a meter parking, 2$ in Hour.ExitsouthwestExitsouthExitwest Exits: > go south Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast : You are in Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast Exits: > go south A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest : You are in A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest Exits: > go south There is no door! > go west Stairs take the player until fourth floor.ExiteastExitsouth : You are in Stairs take the player until fourth floor.ExiteastExitsouth Exits: > go south 2Floor entry for classesExiteastExitsouthExitnorthExitsoutheast : You are in 2Floor entry for classesExiteastExitsouthExitnorthExitsoutheast Exits: > go southeast Classroom201 you reach the goal.Exitnorthwest : You are in Classroom201 you reach the goal.Exitnorthwest Exits: > go southwest There is no door! > quit I hope you weren't too bored here on the Campus of Kings! Thank you for playing. Good bye. You have earned 114points in 19 turns.

Lap3/.git/objects/33/c652c2507d0cc360c76895d7f9d431365d070e

Lap3/.git/objects/33/c652c2507d0cc360c76895d7f9d431365d070e

Lap3/.git/objects/02/e12452b81ff410ad72251225b8cccccb02f02d

Lap3/.git/objects/02/e12452b81ff410ad72251225b8cccccb02f02d

blob 1657� import java.util.HashMap; import java.util.Map; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public class CommandWords { static Map<String, CommandEnum> commandMap; /** A constant array that holds all valid command words. */ //private static String[] validCommands; /** * Static block to initialize the fields of CommandWords. **/ static { commandMap = new HashMap<>(); CommandEnum[] tempCommands = CommandEnum.values(); for(CommandEnum moh: tempCommands){ commandMap.put(moh.name(), CommandEnum.getCommand(moh.name())); } } /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(String aString) { // if we get here, the string was not found in the commands return commandMap.containsKey(aString); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand(String theString){ return commandMap.get(theString); } }

Lap3/.git/objects/d9/6adf78bc53d4e2b3c81826987cb62150b25863

Lap3/.git/objects/d9/6adf78bc53d4e2b3c81826987cb62150b25863

blob 6940�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; /** stores the character controlled by the Player. */ private Player team; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { score = 0; turns = 0; world = new World(); // set the starting room Room out = world.getRoom("outside"); team = new Player(out); } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; if (direction.equals("north")) { doorway = team.getcurrentRoom().northExit; } if (direction.equals("east")) { doorway = team.getcurrentRoom().eastExit; } if (direction.equals("south")) { doorway = team.getcurrentRoom().southExit; } if (direction.equals("west")) { doorway = team.getcurrentRoom().westExit; } if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); team.setcurrentRoom(newRoom); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(team.getcurrentRoom() + " : "); Writer.println("You are " + team.getcurrentRoom()); Writer.print("Exits: "); if (team.getcurrentRoom().northExit != null) { Writer.print("north "); } if (team.getcurrentRoom().eastExit != null) { Writer.print("east "); } if (team.getcurrentRoom().southExit != null) { Writer.print("south "); } if (team.getcurrentRoom().westExit != null) { Writer.print("west "); } Writer.println(); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(" go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); Writer.println(); printLocationInformation(); if (team.getcurrentRoom().northExit != null) { Writer.print("north "); } if (team.getcurrentRoom().eastExit != null) { Writer.print("east "); } if (team.getcurrentRoom().southExit != null) { Writer.print("south "); } if (team.getcurrentRoom().westExit != null) { Writer.print("west "); } Writer.println(); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/ac/9a3fc965cae9ddc32aaae75a37c8a71bc452a8

Lap3/.git/objects/ac/9a3fc965cae9ddc32aaae75a37c8a71bc452a8

blob 4393�/** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /** This room's north exit, null if none exits. */ public Door northExit; /** This room's south exit, null if none exits. */ public Door southExit; /** This room's east exit, null if none exits. */ public Door eastExit; /** This room's west exit, null if none exits. */ public Door westExit; /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Returns the number of rooms that have been created in the world. * @return The number of rooms that have been created in the world. */ public static int getCounter() { return counter; } /** Accessor for geting the northExit. * @return getNorthExit for getting that direction. */ public Door getNorthExit(){ return northExit; } /** Accessor for geting the southExit. * @return getSouthExit for getting that direction. */ public Door getSouthExit(){ return southExit; } /** Accessor for geting the eastExit. * @return getEastExit for getting that direction. */ public Door getEastExit(){ return eastExit; } /** Accessor for geting the westExit. * @return getWestExit for getting that direction. */ public Door getWestExit(){ return westExit; } /** Mutator for setting the northExit. * @param newNorthExit for setting that direction. */ public void setNorthExit(Door newNorthExit){ northExit = newNorthExit; } /** Mutator for setting the southExit. * @param newSouthExit for setting that direction. */ public void setSouthExit(Door newSouthExit){ southExit = newSouthExit; } /** Mutator for setting the eastExit. * @param newEastExit for setting that direction. */ public void setEastExit(Door newEastExit){ eastExit = newEastExit; } /** Mutator for setting the westExit. * @param newWestExit for setting that direction. */ public void setWestExit(Door newWestExit){ westExit = newWestExit; } /** * Returns a string description including all the details of a Room . * For example , *Outside : *You are outside in the center of the King's College campus . *Exits : north east south west * * @return A string representing all the details of a Room . */ public String toString (){ String roomInformation = ""; roomInformation = getName() + "" + getDescription(); boolean moh = true; if((getNorthExit() != null) && (getSouthExit() != null) && (getEastExit() != null) && (getWestExit() != null)){ moh = false; roomInformation = getName() + " " + getDescription() + getNorthExit() + getSouthExit() + getEastExit() + getWestExit() ; } return roomInformation; } }

Lap3/.git/objects/ad/5d870ff31474c58eed44ac4f2e8987c743415c

Lap3/.git/objects/ad/5d870ff31474c58eed44ac4f2e8987c743415c

commit 232�tree 3fdab05801a9f2211b9b2cc052c4ccad75e77b45 parent 304fb2fe31611842f6d5bf4858fa6bf934833ac4 author mohammedalharbi <[email protected]> 1522116992 -0400 committer mohammedalharbi <[email protected]> 1522116992 -0400 lap3

Lap3/.git/objects/d7/04c037166dcf9fafc4f9d123474c7cbdcb3717

Lap3/.git/objects/d7/04c037166dcf9fafc4f9d123474c7cbdcb3717

blob 1082� /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; private Room previousRoom = null; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; } /** accessor for the current room the character. * @return cerrentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ currentRoom = playing; } /** Accessor for the previous room the character. * @return cerrentRoom */ public Room getpreviousRoom(){ return previousRoom; } /** a mutator for the previous room the character. * @param previous for the Room */ public void setpreviousRoom(Room previous){ previousRoom = previous; } }

Lap3/.git/objects/d7/d6b795300692b2f41957ce72ccdee29cf95ce2

Lap3/.git/objects/d7/d6b795300692b2f41957ce72ccdee29cf95ce2

commit 232�tree 6cef56a888dd99dcbb0a165075f06b6f04af7b4c parent 3f705e964028fab9fe251a0e491df78a19dc12eb author mohammedalharbi <[email protected]> 1519181878 -0500 committer mohammedalharbi <[email protected]> 1519181878 -0500 lap3

Lap3/.git/objects/df/80e5d47e15386febd1a724fdb3c7e087f1d6b4

Lap3/.git/objects/df/80e5d47e15386febd1a724fdb3c7e087f1d6b4

Lap3/.git/objects/a2/617388ab7ab0565e40091ae75dc874c3d738c2

Lap3/.git/objects/a2/617388ab7ab0565e40091ae75dc874c3d738c2

blob 3703�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; ///**.*/ //private HashMap<String, Door> exit; /**earn poins */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = "Exits "; roomInformation = getName() + " " + getDescription(); for(String direction : directions.keySet()){ roomInformation = roomInformation + "Exit" + direction; } //for(Door door : directions.values()){ // roomInformation = roomInformation + "Door" + door; //String RoomInformation = getName() + " " + getDescription(); //roomInformation = "Exit:"; //roomInformation = "Name:"; //roomInformation = "Description:"; //for (String Direction : directions.keySet()) { //roomInformation += Direction + " "; return roomInformation; } }

Lap3/.git/objects/a5/0058e243ec0e4732cbdbf794b1dc700fc6a5dd

Lap3/.git/objects/a5/0058e243ec0e4732cbdbf794b1dc700fc6a5dd

Lap3/.git/objects/d6/8020e28958745ee47bc6d264c57309e7791c06

Lap3/.git/objects/d6/8020e28958745ee47bc6d264c57309e7791c06

Lap3/.git/objects/d6/5e566f4424108f36c75595e355d28fef5d76b8

Lap3/.git/objects/d6/5e566f4424108f36c75595e355d28fef5d76b8

Lap3/.git/objects/bc/c60a87d35cb11a5f13bb6e067c3ba5b75c3975

Lap3/.git/objects/bc/c60a87d35cb11a5f13bb6e067c3ba5b75c3975

blob 765� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. Outsideoutside in the center of the King's College campus. : You are Outsideoutside in the center of the King's College campus. Exits: north east south west north east south west Outsideoutside in the center of the King's College campus. : You are Outsideoutside in the center of the King's College campus. Exits: north east south west > go Go where? > king's college I don't know what you mean... > go Go where? > north I don't know what you mean... > go west Campus Centerin the center of student activities on campus. : You are Campus Centerin the center of student activities on campus. Exits: east > go north There is no door! >

Lap3/.git/objects/ab/cd336e810ee7bcac6e3d41bb4e7ea44c3c6460

Lap3/.git/objects/ab/cd336e810ee7bcac6e3d41bb4e7ea44c3c6460

blob 565� /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * @author mohammed alharbi * @version 29/4/2018 */ public interface Equippable { /** * interface Equippable. * @param weaponName the weaponName. * @return true */ public String equip(String weaponName); /** * the unequip. * @param weaponName the weaponName. * @return true */ public String unequip(String weaponName); }

Lap3/.git/objects/e5/85f93e4837caee5535b04d0b22a15cdd594ec0

Lap3/.git/objects/e5/85f93e4837caee5535b04d0b22a15cdd594ec0

Lap3/.git/objects/f4/85a8fc763b702243a4d0b785bdbc79851b03ba

Lap3/.git/objects/f4/85a8fc763b702243a4d0b785bdbc79851b03ba

blob 1941� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. You are in Bathroom there is teeth brush, shower place. Exits : east > go east You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room.. Exits : south west > go south You are in out Of The House the way outside the house to drive to university.. Exits : north west > go west You are in Car inside the car, back bag, car key with house key.. Exits : east south > go south You are in keep Street the correct way. Exits : south north west > go west You are in Turn left wrong way to go with it.. Exits : east south > go east You are in keep Street the correct way. Exits : south north west > go west You are in Turn left wrong way to go with it.. Exits : east south > go east You are in keep Street the correct way. Exits : south north west > go south You are in Gas Staion the way to traffic signal. Exits : east north > go east You are in Traffic signal there are three different ways. Exits : east south north west > go east You are in KeepGoing almost arrive to university. Exits : east west > go east You are in Parking there is a meter parking, 2$ in Hour. Exits : southwest south west > go south You are in Square the place in the middle of the university, and from there the player can go any building. Exits : east south north west southeast > go south You are in A Building : the goal to reach the class, stairs, elevator, classroom. Exits : southwest north west > go west You are in Stairs take the player until fourth floor. Exits : east south > go south You are in 2Floor entry for classes Exits : east south north southeast > go southeast You are in Classroom201 you reach the goal. Exits : northwest > quit I hope you weren't too bored here on the Campus of Kings! Thank you for playing. Good bye. You have earned 114points in 18 turns.

Lap3/.git/objects/c9/4ee45d128dad631e2dbe9ca14081a93d5820d4

Lap3/.git/objects/c9/4ee45d128dad631e2dbe9ca14081a93d5820d4

Lap3/.git/objects/c9/c2c1714b00122efc17689d12d9a845a80199e3

Lap3/.git/objects/c9/c2c1714b00122efc17689d12d9a845a80199e3

blob 2961�<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36" version="8.4.7" editor="www.draw.io" type="device"><diagram id="09f86a44-1c33-1832-6ab6-e38326b24b1a" name="Page-1">5VxLc6M4EP41OW6KlwAfZ7KzM4edqqnKYWeOxJZtNtjyAs5jf/2KgDDqlhNFFqDK5pAybczj6+6vu6WWrsKb3dPXMjtsv7MVLa4Cb/V0Ff5+FQRJEvH/jeC5FYRR2go2Zb5qRf5JcJv/Szuh10mP+YpW0ok1Y0WdH2Thku33dFlLsqws2aN82poV8l0P2YYiwe0yK7D0r3xVb1tpSryT/BvNN1txZ9/rvrnLlvebkh333f2ugnD98td+vcvEtbrzq222Yo8DUfjlKrwpGavbT7unG1o00ArY2t/9cebb/rlLuq91fhC2P3jIimP36nf8Efn9d93z1c8Ck5e3os3vvKvw8+M2r+ntIVs23z5yI+Cybb0r+JHPP+Ln6B7tgZY1fRqIuuf6StmO1uUzP0V8K9DubEhA9jhQSCfaDnQRdbKsM4FNf+ETDPxDh4QalQihMjsaQfwmGr0R2obDTxAe93m93NI9goW/TS2/e1WX7J7esIKVXLJne37m53VeFECUFflmzw+XHCPK5Z8bbHLukp+6L3b5atXcRgm2rA4beKcAb4LwjhRwhzbgXrxtfnS/+tTw3Am/AeT8rcvnnx0WLwe/moNr0hw+5fVPcR7/fPrmLGgVO5ZLKvFFnZUbKiysFdGVRKkY2AFyRIGckJW0yOr8QSZiFZzdHX6wnD/viTWA2gKgkPZluh8NiRFcB7ibn4DrtAig67zotn9pLXUrOBip+w1+yapDGwXX+VPjBGM4wEKPflMLDqDg32VWugCKPyMoxEkzgYgE3oSQxNaI8jr2h1zZH/ygZc6fqwlILZt29Hki019vxZwhfbrPn4j4FoYEGgIm9mEmYpFBcX7igmvEZD7PSBEi3BG4gK0b69vSxlBYtnIBpkS2kzCeECaNTGsWTvVng0QksOacelmCKehwyJCCNV2lSJgbGlMkTFbtUWQojNBCqCQoUl4YFIlC5W5FxT4KCi6HdZ6uyvuiUagc+qxFlQeTqDzyQ8nTvTDtjmHupGcMqcIYEreMQVZhFBvaAqCRyB/PFDRKzFFJ3TEFAidEgVNXg6j4GS/HDXGtw461nNFt2bGiSLEfZkgOh0u9MTkYVY3SIlxi1MdyzyUFXdcfF/MU1DCKYefRIMc1zD2lhxegS0o/MOiBJ+f/fbYxAeriuv83Q4eYh4qhvdEwdzk570pkKR8jboVzOSwQz1I+RkYL5hFOzesyW6/zZYM+N/+sQAYwwzhE6MmITDkOEeGU9XX2nwGfKJoRH405asOU/rXpQ2POECbvCGdAZw9NSwCYlIZwZMAia2jMAM2lcqFeSeVuDdtFkM1MVR6R6VSOq77XsjEHYkQ/nD8FB54tysqXGzkITzRliMAF1Dv5Yry0UskXsVN8EQbAzeHgjnaIADNcAZxStcgX9lqH7Ks8UajcrawABvPIdJg/fCu9sKdy8erDZpmCVZzAOGrZM1Z/UeSH6lxdbblpEUybEAX7KbsWYellQn8EV9WPJdtvHMTFT/FIphIXONNohMvFlcOIHBFjjhB6dIQjAEUkplkkYIhkvCSSXFw3vKJwLbUK6CXqd2tOCEb72Fa0J+NFe4KrA66I+7zhOKDfqdvVCQyAirIgUWgTzqUaERwuC4r8rsxKTPpzDBoB7o8mLJiIRnpYbbND87HI9/cyGn/Tun7u1upkx5pxESvrLduwfVb8ydhBgy7ES/qvhgSJ/t2qCshCnhFbGI82g8HDaLy5Y+FUUj/17nCsuKybfnHAMeJwPseINWZgbDoGHmU7PzYnXj/QzqKIotISNuCKG8EoCTN+bTcCcRvN/lh0owAZSfXPkasCmYp2LTGGHxFALLHCj3xfoVofNiAZeZJGdXG5J/U+EZytObST01jRfihU7Yi3wOGERLRHvtdboG0kmt7Ca4OmZO5POzQnVO944O6+JyNqr2jsirik+cYP7455sVKlv3OM/MKCQnP9qpVwhguDbVY4Maccg8kTMuESqlhjnYhFbnqVgRxhFqiOxHi95CJVRx3LzALvIx7YGrPgSZNPgllcoRZCztQgU/gQLiG/3zhGvQmIPumEHCPMfhqO8SO53vYCqeLmgjQVAu12fCkRWrhFV6K1RHi/6dIbaCKojLdFV6BDXGwhYouuEly4LousqpQ7eMxCVWCmwyMT+iIu2G7rLC8rF5CBzWNTkniCm+toQR+ympUuQjOt0eACNlgXzA1k0MShP2FVkeCiq+eawMNhbg7LCQjAJ50QH1x1DfCJXMAH2U84Jevg8muAj+8CPhFcYjQpPpf2a50FwJHsjYhhKxHyTAd94ewiupC9Qd/EYkeV3y6V7efDrr1+7ay6Z+J9eftwUDNRbDQiSltHrCFKz0X5d5tDCK803iSAeOiLm7C96wQOV/emIu1F844ubJXWRT7jiNYJZFi0At6UBLh3jaf1i1doqbXuDbX+m6J+j+PwMh5QbKchyiJHLAIt6/WMtxyCFuGNN6ee4trSOC7Y7qITgwIOkz8eFzAdyYk9eKXxdlFJrbVOAoZPhi0A3lDn14E++ysmMh1jf+ShxhupoEx9xJ1U0jEbKE++7uPQYLqLSqLoo3XMFCKYtBmvr0CJ5IgLLFKLWw4mZs20iaK7xzHdhpDdUeO6tm4hu6MF9xZ1qzE9PNv6SkVm71pnJGh4MF48A3vD7C2e4YenrdXb00/b14df/gM=</diagram></mxfile>

Lap3/.git/objects/fc/03dcc4fbedb5d91e8d5fda1f98b288823e4c66

Lap3/.git/objects/fc/03dcc4fbedb5d91e8d5fda1f98b288823e4c66

Lap3/.git/objects/fc/145870670dd3ba168ba2f260eb2407a6be4309

Lap3/.git/objects/fc/145870670dd3ba168ba2f260eb2407a6be4309

blob 11236�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author mohammed alharbi * @version 20/2/2018 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); createItems(); } /** * Items can earn point. */ public void createItems(){ Item toothbrush = new Item("tooth brush", 3, "Brushing teeth", 10); Item toothpaste = new Item("tooth paste", 3, "Applied on a tooth brush", 20); Item knife = new Item("knife", 5, "Peel and cut fruits", 100); Item coffee = new Item("coffee", 7, "good for personal health", 150); Item water = new Item("bottle of water", 8, "Quenches thirst", 250); Item broomStick = new Item("broom btick", 5, "pick items from the roof", 600); Item backBag = new Item("back bag", 10, "Carry things in", 200); Item houseKey = new Item("House key", 5, "Open locked doors", 50); Item bucket = new Item("water buckets", 15, "carry more items if back is full", 50); for(String room : rooms.keySet()){ System.out.println(room); switch(room){ case "bathroom": getcurrentRoom(room).addItem(toothbrush); getcurrentRoom(room).addItem(toothpaste); break; case "kitchen": getcurrentRoom(room).addItem(knife); getcurrentRoom(room).addItem(coffee); getcurrentRoom(room).addItem(water); break; case "out of the house": getcurrentRoom(room).addItem(broomStick); break; case "car": getcurrentRoom(room).addItem(backBag); getcurrentRoom(room).addItem(houseKey); break; case "keep street": getcurrentRoom(room).addItem(bucket); break; default: } } } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms. * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from The room where the door originated. * @param direction The direction of the door in the from room. * @param to The room where the door goes. */ private void createDoor(Room from, String direction, Room to){ Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room outOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); outOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room car = new Room("Car", "inside the car, back bag, car key with house key.."); car.setPoints(7); pointScore = pointScore + 7; Room keepStreet = new Room("keep Street", "the correct way."); Room turnLeft = new Room("Turn left", "wrong way to go with it.."); Room endOfTheRoad = new Room("End of the road", "closed way."); Room gasStaion = new Room("Gas Staion", "the way to traffic signal."); Room trafficSignal = new Room("Traffic signal", "there are three different ways."); trafficSignal.setPoints(10); pointScore = pointScore + 10; Room turnLeft2 = new Room("Turn left2", "maybe not the right way."); Room wrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room turnRight = new Room("Turn right"," more traffic."); Room closedWay = new Room("Closed Way","no place to go."); Room keepGoing = new Room("KeepGoing","almost arrive to university."); keepGoing.setPoints(10); pointScore = pointScore + 10; Room parking = new Room("Parking","there is a meter parking, 2$ in Hour."); parking.setPoints(17); pointScore = pointScore + 17; Room library = new Room("Library","some books, students, printer, computers."); Room campusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room hallCampus = new Room("Hall Campus","the building for men."); Room hBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); square.setPoints(12); pointScore = pointScore + 12; Room mCBuilding = new Room("MCBuilding"," Classes, six floors."); Room aBuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room stairs = new Room("Stairs","take the player until fourth floor."); stairs.setPoints(18); pointScore = pointScore + 18; Room elevator = new Room("Elevator","take the player until fourth floor."); Room floor2 = new Room("2Floor","entry for classes"); Room classroom = new Room("Classroom","one door, blackboard, tables"); Room classroom201 = new Room ("Classroom201","you reach the goal."); classroom201.setPoints(30); pointScore = pointScore + 30; Room classroom204 = new Room("Classroom204","one door, students."); Room classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(bathroom); this.addRoom(kitchen); this.addRoom(outOfTheHouse); this.addRoom(car); this.addRoom(keepStreet); this.addRoom(turnLeft); this.addRoom(endOfTheRoad); this.addRoom(gasStaion); this.addRoom(trafficSignal); this.addRoom(turnLeft2); this.addRoom(wrongWay); this.addRoom(turnRight); this.addRoom(closedWay); this.addRoom(keepGoing); this.addRoom(parking); this.addRoom(library); this.addRoom(campusCenter); this.addRoom(hallCampus); this.addRoom(hBuilding); this.addRoom(square); this.addRoom(mCBuilding); this.addRoom(aBuilding); this.addRoom(stairs); this.addRoom(elevator); this.addRoom(floor2); this.addRoom(classroom); this.addRoom(classroom201); this.addRoom(classroom204); this.addRoom(classroom202); // Creating all the doors between the rooms. this.createDoor(bathroom,"east",kitchen); this.createDoor(kitchen, "west",bathroom); this.createDoor(kitchen,"south", outOfTheHouse); this.createDoor(outOfTheHouse,"north", kitchen); this.createDoor(outOfTheHouse,"west",car); this.createDoor(car,"east",outOfTheHouse); this.createDoor(car,"south",keepStreet); this.createDoor(keepStreet,"north",car); this.createDoor(keepStreet,"west",turnLeft); this.createDoor(turnLeft,"east",keepStreet); this.createDoor(turnLeft,"south", endOfTheRoad); this.createDoor(endOfTheRoad,"north",turnLeft); this.createDoor(keepStreet,"south",gasStaion); this.createDoor(gasStaion, "north",keepStreet); this.createDoor(gasStaion,"east",trafficSignal); this.createDoor(trafficSignal,"west", gasStaion); this.createDoor(trafficSignal,"north",turnLeft2); this.createDoor(turnLeft2,"south",trafficSignal); this.createDoor(turnLeft2,"north", wrongWay); this.createDoor(wrongWay,"south",turnLeft2); this.createDoor(trafficSignal,"south", turnRight); this.createDoor(turnRight,"north", trafficSignal); this.createDoor(turnRight,"south",closedWay); this.createDoor(closedWay,"north", turnRight); this.createDoor(trafficSignal,"east", keepGoing); this.createDoor(keepGoing, "west",trafficSignal); this.createDoor(keepGoing,"east", parking); this.createDoor(parking,"west",keepGoing); this.createDoor(parking,"southwest",library); this.createDoor(library, "northeast",parking); this.createDoor(library,"east", campusCenter); this.createDoor(campusCenter,"west",library); this.createDoor(parking,"south",square); this.createDoor(square,"north",parking); this.createDoor(square,"east", hallCampus); this.createDoor(hallCampus,"west",square); this.createDoor(square,"west",hBuilding); this.createDoor(hBuilding,"east",square); this.createDoor(square, "southeast",mCBuilding); this.createDoor(mCBuilding,"northwest",square); this.createDoor(square,"south",aBuilding); this.createDoor(aBuilding,"north",square); this.createDoor(aBuilding,"west",stairs); this.createDoor(stairs,"east",aBuilding); this.createDoor(aBuilding,"southwest",classroom); this.createDoor(classroom,"northeast",aBuilding); this.createDoor(aBuilding,"southwest",elevator); this.createDoor(elevator,"northeast",aBuilding); this.createDoor(elevator,"west",floor2); this.createDoor(floor2,"east",elevator); this.createDoor(stairs,"south",floor2); this.createDoor(floor2,"north",stairs); this.createDoor(floor2,"south",classroom204); this.createDoor(classroom204,"north",floor2); this.createDoor(floor2,"east",classroom202); this.createDoor(classroom202,"west",floor2); this.createDoor(floor2,"southeast",classroom201); this.createDoor(classroom201,"northwest",floor2); } }

Lap3/.git/objects/f5/7b88c9d1b8ac6a81beaf0ea7f5cd3f157d699c

Lap3/.git/objects/f5/7b88c9d1b8ac6a81beaf0ea7f5cd3f157d699c

blob 6993�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; /** stores the character controlled by the Player. */ private Player team; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { score = 0; turns = 0; world = new World(); // set the starting room Room out = world.getRoom("outside"); team = new Player(out); } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; if (direction.equals("north")) { doorway = team.getcurrentRoom().getExit("north"); } if (direction.equals("east")) { doorway = team.getcurrentRoom().getExit("east"); } if (direction.equals("south")) { doorway = team.getcurrentRoom().getExit("south"); } if (direction.equals("setwest")) { doorway = team.getcurrentRoom().getExit("west"); } if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); team.setcurrentRoom(newRoom); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(team.getcurrentRoom() + " : "); Writer.println("You are " + team.getcurrentRoom()); Writer.print("Exits: "); if (team.getcurrentRoom().getExit("north")!=(null)) { Writer.print("north "); } if (team.getcurrentRoom().getExit("east") != null) { Writer.print("east "); } if (team.getcurrentRoom().getExit("south") != null) { Writer.print("south "); } if (team.getcurrentRoom().getExit("west") != null) { Writer.print("west "); } Writer.println(); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(" go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); Writer.println(); if (team.getcurrentRoom().getExit("north") != null) { Writer.print("north "); } if (team.getcurrentRoom().getExit("east") != null) { Writer.print("east "); } if (team.getcurrentRoom().getExit("south") != null) { Writer.print("south "); } if (team.getcurrentRoom().getExit("west") != null) { Writer.print("west "); } Writer.println(); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/e4/0dbe35e828964c52583dce18833cb5b3ce155c

Lap3/.git/objects/e4/0dbe35e828964c52583dce18833cb5b3ce155c

Lap3/.git/objects/fe/db09a812677b03a51e908b79979094054831c7

Lap3/.git/objects/fe/db09a812677b03a51e908b79979094054831c7

blob 2851�import java.util.ArrayList; import java.util.Scanner; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This parser reads user input and tries to interpret it as an "Adventure" * command. Every time it is called it reads a line from the terminal and tries * to interpret the line as a two word command. It returns the command as an * object of class Command. * * The parser has a set of known command words. It checks user input against the * known commands, and if the input is not one of the known commands, it returns * a command object that is marked as an unknown command. * a * @author Maria Jump * @version 2017.12.18 */ public class Reader { /** The source of command input. */ private static Scanner reader; /** * Create a parser to read from the terminal window. */ static { reader = new Scanner(System.in); } /** * Returns the next command from the user. * @return The next command from the user. */ public static Command getCommand() { String inputLine; // will hold the full input line String word1 = null; ArrayList<String> restOfLine = null; Writer.print("> "); // print prompt inputLine = reader.nextLine().toLowerCase(); Writer.printInput(inputLine); // Find up to two words on the line. Scanner tokenizer = new Scanner(inputLine); if (tokenizer.hasNext()) { word1 = tokenizer.next(); // get first word if (tokenizer.hasNext()) { restOfLine = new ArrayList<String>(); while(tokenizer.hasNext()) { restOfLine.add(tokenizer.next()); } } } tokenizer.close(); // Now check whether this word is known. If so, create a command // with it. If not, create a "null" command (for unknown command). Command result = null; if (CommandWords.isCommand(word1)) { result = new Command(word1, restOfLine); } else { result = new Command(null, restOfLine); } //Command result = CommandWords.getCommand(word1); return result; } /** * Return the response to a question in all lower case. * * @return The response typed in by the user. */ public static String getResponse() { return getResponseKeepCase().toLowerCase(); } /** * Return the response to a question in the case used by the player. * * @return The response typed in by the user. */ public static String getResponseKeepCase() { String response = reader.nextLine().trim(); Writer.printInput(response); return response; } }

Lap3/.git/objects/c6/5bbfae82fc134e1841bff9b8b44d42c2f38913

Lap3/.git/objects/c6/5bbfae82fc134e1841bff9b8b44d42c2f38913

blob 3283�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**earn points */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = "Exit"; roomInformation = getName() + " " + getDescription(); for(String direction : directions.keySet()){ roomInformation = roomInformation + "Exit" + direction; //roomInformation = "Name"; } return roomInformation; } }

Lap3/.git/objects/c6/2063f7af6c984d998530e2af1ed4d51ee9aefa

Lap3/.git/objects/c6/2063f7af6c984d998530e2af1ed4d51ee9aefa

Lap3/.git/objects/4e/eb29795bd70f62bb6e7ebf829c65b29deb70b6

Lap3/.git/objects/4e/eb29795bd70f62bb6e7ebf829c65b29deb70b6

Lap3/.git/objects/4b/1b0231b293edc68c4dd7e9add87dfce0468c5f

Lap3/.git/objects/4b/1b0231b293edc68c4dd7e9add87dfce0468c5f

blob 2709� import java.util.HashMap; /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; private Room previousRoom; public static final int MAX_WEIGHT = 5000; private int currentWeight; private HashMap<String, Item> inventory; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; previousRoom = null; inventory = new HashMap<>(); currentWeight = 0; } /** Add item to inventory. * @param item * @return true if item added to inventory */ public boolean inventoryAddItem(Item item){ inventory.put(item.getName(), item); return true; } /** * * @return current weight that the player is carrying */ public int getCurrentWeight(){ return currentWeight; } /** * * @return the maximum weight that the player can carry */ public int getMaxWeight(){ return MAX_WEIGHT; } /** Get an item from the players inventory. * @param itemName - name of item to be picked * @return an Item object */ public Item getItem(String itemName){ return inventory.get(itemName); } /** remove an item from the players inventory. * @param itemName - name of item to be removed * @return an Item object */ public Item removeItem(String itemName){ currentWeight -= getItem(itemName).getWeight(); return inventory.remove(itemName); } /** accessors for the current room the character. * @return currentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ previousRoom = currentRoom; currentRoom = playing; } /** Accessors for the previous room the character. * @return cerrentRoom */ public Room getpreviousRoom(){ return previousRoom; } /** Accessors for the players inventory. * @return players inventory */ public String getInventory(){ String inventoryInfo = ""; for(String s: inventory.keySet()){ inventoryInfo += " " + s +", "; } return inventoryInfo; } }

Lap3/.git/objects/pack/pack-392afbcc87b5190d2606e3171c0c2d7641a74985.pack

Lap3/.git/objects/pack/pack-a7c7707b0757bde831a46640d805439ad5138689.pack

Lap3/.git/objects/pack/pack-b29326e846551bdd235e86ee4c6e6b24e01c76c7.idx

Lap3/.git/objects/pack/pack-b29326e846551bdd235e86ee4c6e6b24e01c76c7.pack

Lap3/.git/objects/pack/pack-a7c7707b0757bde831a46640d805439ad5138689.idx

Lap3/.git/objects/pack/pack-8eb9fa29cb40d3109018533e63943a1c9fe207e0.pack

Lap3/.git/objects/pack/pack-6e41e8333efec83ce98693b7e5e8b648f28ccadf.idx

Lap3/.git/objects/pack/pack-392afbcc87b5190d2606e3171c0c2d7641a74985.idx

Lap3/.git/objects/pack/pack-48d6f0093f364e5ecb7efb7fec999f6493eb0e19.idx

Lap3/.git/objects/pack/pack-6e41e8333efec83ce98693b7e5e8b648f28ccadf.pack

Lap3/.git/objects/pack/pack-8eb9fa29cb40d3109018533e63943a1c9fe207e0.idx

Lap3/.git/objects/pack/pack-48d6f0093f364e5ecb7efb7fec999f6493eb0e19.pack

Lap3/.git/objects/11/ec7cf45e7833e16eb25f6bb0f76e7bbce1a4bd

Lap3/.git/objects/11/ec7cf45e7833e16eb25f6bb0f76e7bbce1a4bd

blob 1781�/** * Class Door - a door or portal between two Rooms in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Door" represents a door or portal between two locations of the game. * It stores a reference to the neighboring room and whether that door * or portal is locked. Doors are not locked by default. * * @author Maria Jump * @version 2015.02.01 */ public class Door { /** The room that this door leads to. */ private Room destination; /** Whether this door is locked. */ private boolean locked; /** the doorkey.*/ private Item doorKey; /** * Constructor for the Door class. * @param destination The room this door leads to */ public Door(Room destination) { this.destination = destination; this.locked = false; this.doorKey = null; } /** * A getter for the room this door leads to. * @return The room this door leads to */ public Room getDestination() { return destination; } /** * A getter for whether this door is locked. * @return Whether this door is locked */ public boolean isLocked() { return locked; } /** * A setter for the key that opens a door. * @param key Specifies the key to unlock the door */ public void setKey(Item key) { this.doorKey = key; } /** * A setter for the key that opens a door. * @return the key that unlocks that door */ public Item getKey() { return doorKey; } /** * A setter for whether this door is locked. * @param locked Whether this door is locked. */ public void setLocked(boolean locked) { this.locked = locked; } }

Lap3/.git/objects/42/d828d2971fdab5da809ed89cc39435907c9f89

Lap3/.git/objects/42/d828d2971fdab5da809ed89cc39435907c9f89

blob 9370�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author Maria Jump * @version 2015.02.01 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param west * The room to the west of the originating room. */ private void createDoor(Room from, String direction, Room to) { Door door = new Door(to); from.setExit(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room Bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room Kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room OutOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); OutOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room Car = new Room("Car", "inside the car, back bag, car key with house key.."); Car.setPoints(7); pointScore = pointScore + 7; Room KeepStreet = new Room(" keep Street", "the correct way."); Room TurnLeft = new Room("Turn left", "wrong way to go with it.."); Room EndOfTheRoad = new Room("End of the road", "closed way."); Room TurnLeft1 = new Room(" Turn left1", "the way to traffic signal."); Room TrafficSignal = new Room("Traffic signal", "there are three different ways."); TrafficSignal.setPoints(10); pointScore = pointScore + 10; Room TurnLeft2 = new Room("Turn left2", "maybe not the right way."); Room WrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room TurnRight = new Room("Turn right"," more traffic."); Room ClosedWay = new Room("Closed Way","no place to go."); Room KeepStreet1 = new Room("KeepStreet1","almost arrive to university."); KeepStreet1.setPoints(10); pointScore = pointScore + 10; Room Parking = new Room("Parking","there is a meter parking, 2$ in Hour."); Parking.setPoints(17); pointScore = pointScore + 17; Room Library = new Room("Library","some books, students, printer, computers."); Room CampusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room HallCampus = new Room("Hall Campus","the building for men."); Room HBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room Square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); Square.setPoints(12); pointScore = pointScore + 12; Room MCBuilding = new Room("MCBuilding"," Classes, six floors."); Room ABuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room Stairs = new Room("Stairs","take the player until fourth floor."); Stairs.setPoints(18); pointScore = pointScore + 18; Room Elevator = new Room("Elevator","take the player until fourth floor."); Room Floor2 = new Room("2Floor","entry for classes"); Room Classroom = new Room("Classroom","one door, blackboard, tables"); Room Classroom201 = new Room ("Classroom201","you reach the goal."); Classroom201.setPoints(30); pointScore = pointScore + 30; Room Classroom204 = new Room("Classroom204","one door, students."); Room Classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(Bathroom); this.addRoom(Kitchen); this.addRoom(OutOfTheHouse); this.addRoom(Car); this.addRoom(KeepStreet); this.addRoom(TurnLeft); this.addRoom(EndOfTheRoad); this.addRoom(TurnLeft1); this.addRoom(TrafficSignal); this.addRoom(TurnLeft2); this.addRoom(WrongWay); this.addRoom(TurnRight); this.addRoom(ClosedWay); this.addRoom(KeepStreet1); this.addRoom(Parking); this.addRoom(Library); this.addRoom(CampusCenter); this.addRoom(HallCampus); this.addRoom(HBuilding); this.addRoom(Square); this.addRoom(MCBuilding); this.addRoom(ABuilding); this.addRoom(Stairs); this.addRoom(Elevator); this.addRoom(Floor2); this.addRoom(Classroom); this.addRoom(Classroom201); this.addRoom(Classroom204); this.addRoom(Classroom202); // Creating all the doors between the rooms. this.createDoor(Bathroom,"east",Kitchen); this.createDoor(Kitchen, "west",Bathroom); this.createDoor(Kitchen,"south", OutOfTheHouse); this.createDoor(OutOfTheHouse,"north", Kitchen); this.createDoor(OutOfTheHouse,"west",Car); this.createDoor(Car,"east",OutOfTheHouse); this.createDoor(Car,"south",KeepStreet); this.createDoor(KeepStreet,"north",Car); this.createDoor(KeepStreet,"west",TurnLeft); this.createDoor(TurnLeft,"east",KeepStreet); this.createDoor(TurnLeft,"south", EndOfTheRoad); this.createDoor(EndOfTheRoad,"north",TurnLeft); this.createDoor(KeepStreet,"south",TurnLeft1); this.createDoor(TurnLeft1, "north",KeepStreet); this.createDoor(TurnLeft1,"east",TrafficSignal); this.createDoor(TrafficSignal,"west", TurnLeft1); this.createDoor(TrafficSignal,"north",TurnLeft2); this.createDoor(TurnLeft2,"south",TrafficSignal); this.createDoor(TurnLeft2,"north", WrongWay); this.createDoor(WrongWay,"south",TurnLeft2); this.createDoor(TrafficSignal,"south", TurnRight); this.createDoor(TurnRight,"north", TrafficSignal); this.createDoor(TurnRight,"south",ClosedWay); this.createDoor(ClosedWay,"north", TurnRight); this.createDoor(TrafficSignal,"east", KeepStreet1); this.createDoor(KeepStreet1, "west",TrafficSignal); this.createDoor(KeepStreet1,"east", Parking); this.createDoor(Parking,"west",KeepStreet1); this.createDoor(Parking,"south",Library); this.createDoor(Library, "north",Parking); this.createDoor(Library,"west", CampusCenter); this.createDoor(CampusCenter,"east",Library); this.createDoor(Parking,"south",Square); this.createDoor(Square,"north",Parking); this.createDoor(Square,"east", HallCampus); this.createDoor(HallCampus,"west",Square); this.createDoor(Square,"west",HBuilding); this.createDoor(HBuilding,"east",Square); this.createDoor(Square, "south",MCBuilding); this.createDoor(MCBuilding,"north",Square); this.createDoor(Square,"south",ABuilding); this.createDoor(ABuilding,"north",ABuilding); this.createDoor(ABuilding,"west",Stairs); this.createDoor(Stairs,"east",ABuilding); this.createDoor(ABuilding,"south",Classroom); this.createDoor(Classroom,"north",ABuilding); this.createDoor(ABuilding,"south",Elevator); this.createDoor(Elevator,"north",ABuilding); this.createDoor(Elevator,"south",Floor2); this.createDoor(Floor2,"north",Elevator); this.createDoor(Stairs,"south",Floor2); this.createDoor(Floor2,"north",Stairs); this.createDoor(Floor2,"south",Classroom204); this.createDoor(Classroom204,"north",Floor2); this.createDoor(Floor2,"east",Classroom202); this.createDoor(Classroom202,"west",Floor2); this.createDoor(Floor2,"south",Classroom201); this.createDoor(Classroom201,"north",Floor2); } }

Lap3/.git/objects/45/b4bcc42b3969b307a4b1babef5f2030a73c610

Lap3/.git/objects/45/b4bcc42b3969b307a4b1babef5f2030a73c610

blob 9382�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author mohammed alharbi * @version 20/2/2018 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param west * The room to the west of the originating room. */ private void createDoor(Room from, String direction, Room to) { Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room Bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room Kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room OutOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); OutOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room Car = new Room("Car", "inside the car, back bag, car key with house key.."); Car.setPoints(7); pointScore = pointScore + 7; Room KeepStreet = new Room(" keep Street", "the correct way."); Room TurnLeft = new Room("Turn left", "wrong way to go with it.."); Room EndOfTheRoad = new Room("End of the road", "closed way."); Room GasStaion = new Room("Gas Staion", "the way to traffic signal."); Room TrafficSignal = new Room("Traffic signal", "there are three different ways."); TrafficSignal.setPoints(10); pointScore = pointScore + 10; Room TurnLeft2 = new Room("Turn left2", "maybe not the right way."); Room WrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room TurnRight = new Room("Turn right"," more traffic."); Room ClosedWay = new Room("Closed Way","no place to go."); Room KeepStreet1 = new Room("KeepStreet1","almost arrive to university."); KeepStreet1.setPoints(10); pointScore = pointScore + 10; Room Parking = new Room("Parking","there is a meter parking, 2$ in Hour."); Parking.setPoints(17); pointScore = pointScore + 17; Room Library = new Room("Library","some books, students, printer, computers."); Room CampusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room HallCampus = new Room("Hall Campus","the building for men."); Room HBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room Square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); Square.setPoints(12); pointScore = pointScore + 12; Room MCBuilding = new Room("MCBuilding"," Classes, six floors."); Room ABuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room Stairs = new Room("Stairs","take the player until fourth floor."); Stairs.setPoints(18); pointScore = pointScore + 18; Room Elevator = new Room("Elevator","take the player until fourth floor."); Room Floor2 = new Room("2Floor","entry for classes"); Room Classroom = new Room("Classroom","one door, blackboard, tables"); Room Classroom201 = new Room ("Classroom201","you reach the goal."); Classroom201.setPoints(30); pointScore = pointScore + 30; Room Classroom204 = new Room("Classroom204","one door, students."); Room Classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(Bathroom); this.addRoom(Kitchen); this.addRoom(OutOfTheHouse); this.addRoom(Car); this.addRoom(KeepStreet); this.addRoom(TurnLeft); this.addRoom(EndOfTheRoad); this.addRoom(GasStaion); this.addRoom(TrafficSignal); this.addRoom(TurnLeft2); this.addRoom(WrongWay); this.addRoom(TurnRight); this.addRoom(ClosedWay); this.addRoom(KeepStreet1); this.addRoom(Parking); this.addRoom(Library); this.addRoom(CampusCenter); this.addRoom(HallCampus); this.addRoom(HBuilding); this.addRoom(Square); this.addRoom(MCBuilding); this.addRoom(ABuilding); this.addRoom(Stairs); this.addRoom(Elevator); this.addRoom(Floor2); this.addRoom(Classroom); this.addRoom(Classroom201); this.addRoom(Classroom204); this.addRoom(Classroom202); // Creating all the doors between the rooms. this.createDoor(Bathroom,"east",Kitchen); this.createDoor(Kitchen, "west",Bathroom); this.createDoor(Kitchen,"south", OutOfTheHouse); this.createDoor(OutOfTheHouse,"north", Kitchen); this.createDoor(OutOfTheHouse,"west",Car); this.createDoor(Car,"east",OutOfTheHouse); this.createDoor(Car,"south",KeepStreet); this.createDoor(KeepStreet,"north",Car); this.createDoor(KeepStreet,"west",TurnLeft); this.createDoor(TurnLeft,"east",KeepStreet); this.createDoor(TurnLeft,"south", EndOfTheRoad); this.createDoor(EndOfTheRoad,"north",TurnLeft); this.createDoor(KeepStreet,"south",GasStaion); this.createDoor(GasStaion, "north",KeepStreet); this.createDoor(GasStaion,"east",TrafficSignal); this.createDoor(TrafficSignal,"west", GasStaion); this.createDoor(TrafficSignal,"north",TurnLeft2); this.createDoor(TurnLeft2,"south",TrafficSignal); this.createDoor(TurnLeft2,"north", WrongWay); this.createDoor(WrongWay,"south",TurnLeft2); this.createDoor(TrafficSignal,"south", TurnRight); this.createDoor(TurnRight,"north", TrafficSignal); this.createDoor(TurnRight,"south",ClosedWay); this.createDoor(ClosedWay,"north", TurnRight); this.createDoor(TrafficSignal,"east", KeepStreet1); this.createDoor(KeepStreet1, "west",TrafficSignal); this.createDoor(KeepStreet1,"east", Parking); this.createDoor(Parking,"west",KeepStreet1); this.createDoor(Parking,"southwest",Library); this.createDoor(Library, "northeast",Parking); this.createDoor(Library,"east", CampusCenter); this.createDoor(CampusCenter,"west",Library); this.createDoor(Parking,"south",Square); this.createDoor(Square,"north",Parking); this.createDoor(Square,"east", HallCampus); this.createDoor(HallCampus,"west",Square); this.createDoor(Square,"west",HBuilding); this.createDoor(HBuilding,"east",Square); this.createDoor(Square, "southeast",MCBuilding); this.createDoor(MCBuilding,"northwest",Square); this.createDoor(Square,"south",ABuilding); this.createDoor(ABuilding,"north",Square); this.createDoor(ABuilding,"west",Stairs); this.createDoor(Stairs,"east",ABuilding); this.createDoor(ABuilding,"southwest",Classroom); this.createDoor(Classroom,"northeast",ABuilding); this.createDoor(ABuilding,"southwest",Elevator); this.createDoor(Elevator,"northeast",ABuilding); this.createDoor(Elevator,"west",Floor2); this.createDoor(Floor2,"east",Elevator); this.createDoor(Stairs,"south",Floor2); this.createDoor(Floor2,"north",Stairs); this.createDoor(Floor2,"south",Classroom204); this.createDoor(Classroom204,"north",Floor2); this.createDoor(Floor2,"east",Classroom202); this.createDoor(Classroom202,"west",Floor2); this.createDoor(Floor2,"southeast",Classroom201); this.createDoor(Classroom201,"northwest",Floor2); } }

Lap3/.git/objects/45/8fe2ac43891480397c2f9423a05d06ff7c94dd

Lap3/.git/objects/45/8fe2ac43891480397c2f9423a05d06ff7c94dd

blob 1842� /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public enum CommandEnum{ /** A constant array that holds all valid commandwords.*/ look, go, quit, help, status, back, examine, take, drop, inventory, unlock, lock, unpack, pack, eat, drink, equip, unequip; /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(CommandEnum aString) { return CommandWords.commandMap.containsValue(aString); } /** * Returns a list of the available commands, of the form: * your command words are: * look go quit help * * @return A string containing the list of available commands. */ public static String getCommandString(){ String commandString = ""; for(CommandEnum moh : CommandEnum.values()){ commandString += moh.name() + ", "; } return commandString; //return getCommandString(); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return CommandEnum.valueOf(theString); } }

Lap3/.git/objects/87/29f68f372f137ae0e40ccb51e3345d9f05b78d

Lap3/.git/objects/87/29f68f372f137ae0e40ccb51e3345d9f05b78d

blob 3286�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**earn poins */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = "Exit"; roomInformation = getName() + " " + getDescription(); for(String direction : directions.keySet()){ roomInformation = roomInformation + "Exit" + direction; //roomInformation = "Name"; } return roomInformation; } }

Lap3/.git/objects/74/f5bd1b9585fd8676cf3d1c4382f6ec562680cb

Lap3/.git/objects/74/f5bd1b9585fd8676cf3d1c4382f6ec562680cb

commit 331�tree d68020e28958745ee47bc6d264c57309e7791c06 parent d7d6b795300692b2f41957ce72ccdee29cf95ce2 parent 6b3850b5b96aedbd8c8595c8532ad8f7b18af418 author mohammedalharbi <[email protected]> 1519181900 -0500 committer mohammedalharbi <[email protected]> 1519181900 -0500 Merge commit '6b3850b5b96aedbd8c8595c8532ad8f7b18af418'

Lap3/.git/objects/28/147207ee260a1d776781bd86459829f5c1f84e

Lap3/.git/objects/28/147207ee260a1d776781bd86459829f5c1f84e

blob 10801�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord.name()){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; case "examine": examineItem(command); break; case "take": takeItem(command); break; case "drop": dropItem(command); break; case "inventory": inventory(); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } /** * Try to examine a play item. If the item doesn't exist in the * players inventory nor the current room, * print an error message. * * @param command * The command to be processed. */ private void examineItem(Command command) { if (!command.hasSecondWord()) { Writer.println("Which item?"); } else { String itemName = command.getRestOfLine(); Item item = null; //Get item from players inventory item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { Writer.println(item.toString()); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void takeItem(Command command) { if (!command.hasSecondWord()) { Writer.println("take what?"); } else { String itemName = command.getRestOfLine(); Item item = null; //Look for the item in the current room item = playerClass.getcurrentRoom().getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy to lift"); }else{ if(playerClass.inventoryAddItem(itemName) == false){ Writer.println("Carrying too much"); }else{ playerClass.inventoryAddItem(itemName); playerClass.getcurrentRoom().removeItem(itemName); Writer.println("you took the item"); } } } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Writer.println("which item?"); } else { String itemName = command.getRestOfLine(); Item item = null; //Look for the item in the current room item = playerClass.getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("you don't have it!"); } else { playerClass.getcurrentRoom().addItem(item); playerClass.removeItem(itemName); Writer.println("you dropped the item"); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command . * The command to be processed. */ private void inventory() { Writer.println("Inventory :" + playerClass.getInventory()); } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } }

Lap3/.git/objects/28/097f950a7d27ad1519536c2b305fc237bfb29c

Lap3/.git/objects/28/097f950a7d27ad1519536c2b305fc237bfb29c

commit 232�tree 945ebe2b1f73e262c642844596d9a5691a6d343a parent 72095e7c283a7b1e57d54464d87b9bc0168482f2 author mohammedalharbi <[email protected]> 1521153706 -0400 committer mohammedalharbi <[email protected]> 1521153706 -0400 lap3

Lap3/.git/objects/28/187d65cf7aa02f9b656c4700ca3a05b7d3b4b2

Lap3/.git/objects/28/187d65cf7aa02f9b656c4700ca3a05b7d3b4b2

blob 3397�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**earn points */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String directionString = ""; String roomInformation = ""; roomInformation = getName() + " " + getDescription(); for(String direction : directions.keySet()){ directionString += " " + direction; //roomInformation = "Name"; } roomInformation = roomInformation + "\nExits :" + directionString; return roomInformation; } }

Lap3/.git/objects/8f/eb151ed737f06f8ab9d937d5c8c905c18e7b78

Lap3/.git/objects/8f/eb151ed737f06f8ab9d937d5c8c905c18e7b78

blob 404�/** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public interface Edible { /** * eat . * @param p the current game character * @return true */ public String eat(Player p); }

Lap3/.git/objects/8f/6c0ac67d90add1d72c1a79623d9de85ced0915

Lap3/.git/objects/8f/6c0ac67d90add1d72c1a79623d9de85ced0915

blob 3849�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**.*/ private HashMap<String, Door> exit; /**earn poins */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap<>(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getExit(String direction){ return exit.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint /** * Set exit. * @param direction * @param neighbor */ public void setPoints(int newPoints){ points = newPoints; } public void setExit(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room . * For example , *Outside : *You are outside in the center of the King's College campus . *Exits : north east south west * * @return A string representing all the details of a Room . */ public String toString(){ String roomInformation = ""; roomInformation = getName() + "" + getDescription(); for(String exit : exit.keySet()){ roomInformation =roomInformation + "Exit" + exit; } for(Door door : exit.values()){ roomInformation =roomInformation + "Door" + door; String RoomInformation = getName() + " " + getDescription(); roomInformation = "Exist:"; roomInformation = "Name:"; roomInformation = "Description:"; for (String Direction : directions.keySet()) { roomInformation += Direction + " "; } } return roomInformation; } }

Lap3/.git/objects/8a/155c761a0a183dd8c7a75b2573b9dcfd9e1854

Lap3/.git/objects/8a/155c761a0a183dd8c7a75b2573b9dcfd9e1854

commit 234�tree c94ee45d128dad631e2dbe9ca14081a93d5820d4 parent 2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 author mohammedalharbi <[email protected]> 1525113583 -0400 committer mohammedalharbi <[email protected]> 1525113583 -0400 stage5

Lap3/.git/objects/10/08fd8898044c2d1160ef1b9160fc9238d47cad

Lap3/.git/objects/10/08fd8898044c2d1160ef1b9160fc9238d47cad

blob 2138�/** * Class Item - An item in the game that the player can * pick or drop. * The class also describe items in the game by their name, weight etc * @author mohammed alharbi * @version 20/4/2018 */ public class Item { /** the name of item. */ private String name,description; //** the description. */ //private String ; //** the pointval.*/ //private int ; /** the weight.*/ private int weight,pointVal; /** Constructor for Items. * @param name the name. * @param pointValue the pointValue * @param description the description * @param weight the weight * */ public Item(String name, int pointValue, String description, int weight) { this.name = name; this.description = description; this.pointVal = pointValue; this.weight = weight; } /** * * Returns the name of an item. * @return The name of an item. * **/ public String getName(){ return name; } /** * * Returns the description of an item. * @return The description of an item. * **/ public String getDescription(){ return description; } /** * * Sets the desc of a room. * @param desc the description . * **/ public void setDescription(String desc){ description = desc; } /** * * Returns the pointValue of an item. * @return The pointValue of an item. * **/ public int getPointValue(){ return pointVal; } /** * * Returns the weight of an item. * @return The weight of an item. * **/ public int getWeight(){ return weight; } @Override public String toString(){ String itemInfo = ""; itemInfo += "Name : " + name + "\n"; itemInfo += "Description : " + description + "\n"; itemInfo += "Weight : " + weight + "grams"; return itemInfo; } }

Lap3/.git/objects/4c/5468bff8d06c631e0b7cfd6954806c365e6b9c

Lap3/.git/objects/4c/5468bff8d06c631e0b7cfd6954806c365e6b9c

blob 1014� /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * @author mohammed alharbi * @version 29/4/2018 */ public class Weapon extends Item implements Equippable{ /** * weapon. * @param name the name. * @param pointValue the pointValue. * @param description the description . * @param weight the we * */ public Weapon(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); } /** * equip. * @return equip. * @param weaponName the weaponName. */ @Override public String equip(String weaponName) { return "weapon equiped"; } /** * unequip. * @param weaponName the weaponName. * @return unequip. */ @Override public String unequip(String weaponName) { return "weapon unequipped"; } }

Lap3/.git/objects/4c/92ee36c15271f6e9c5ad6388735280db9361d8

Lap3/.git/objects/4c/92ee36c15271f6e9c5ad6388735280db9361d8

blob 7311�import java.util.HashMap; /** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; /** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; //Playing = Playing; // set the starting room //Room out = world.getcurrentRoom("Bathroom"); //Playing = new Player(out); } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; if (direction.equals("north")) { doorway = playerClass.getcurrentRoom().getDirection("north"); } if (direction.equals("east")) { doorway = playerClass.getcurrentRoom().getDirection("east"); } if (direction.equals("south")) { doorway = playerClass.getcurrentRoom().getDirection("south"); } if (direction.equals("west")) { doorway = playerClass.getcurrentRoom().getDirection("west"); } if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are " + playerClass.getcurrentRoom()); Writer.print("Exits: "); if (playerClass.getcurrentRoom().getDirection("north") != (null)) { Writer.print("north "); } if (playerClass.getcurrentRoom().getDirection("east") != null) { Writer.print("east "); } if (playerClass.getcurrentRoom().getDirection("south") != null) { Writer.print("south "); } if (playerClass.getcurrentRoom().getDirection("west") != null) { Writer.print("west "); } Writer.println(); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println("go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); if (playerClass.getcurrentRoom().getDirection("east") != null) { Writer.print("east"); } if (playerClass.getcurrentRoom().getDirection("west") != null) { Writer.print("west"); } if (playerClass.getcurrentRoom().getDirection("south") != null) { Writer.print("south"); } if (playerClass.getcurrentRoom().getDirection("north") != null) { Writer.print("north"); } //Writer.println(); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/81/f115945636e4599b089905d39fdd48728792fd

Lap3/.git/objects/81/f115945636e4599b089905d39fdd48728792fd

commit 280�tree d65e566f4424108f36c75595e355d28fef5d76b8 parent ad5d870ff31474c58eed44ac4f2e8987c743415c parent 06713f96120d3be7e7f95285736775fc251948c3 author mohammedalharbi <[email protected]> 1522119231 -0400 committer mohammedalharbi <[email protected]> 1522119231 -0400 lap3

Lap3/.git/objects/81/7f82161c5c0d59090c476bddc0c1bd810cbc5c

Lap3/.git/objects/81/7f82161c5c0d59090c476bddc0c1bd810cbc5c

commit 235�tree e585f93e4837caee5535b04d0b22a15cdd594ec0 parent 628ca4a5d61987fbc62787fdc61e957944585f37 author mohammedalharbi <[email protected]> 1524774655 -0400 committer mohammedalharbi <[email protected]> 1524774655 -0400 stage 4

Lap3/.git/objects/72/095e7c283a7b1e57d54464d87b9bc0168482f2

Lap3/.git/objects/72/095e7c283a7b1e57d54464d87b9bc0168482f2

commit 331�tree 8299c43d952b4275bebb5b276fbfab12eb687d71 parent 64506a6dd3dac60899bcd529ce6381a5cddbc03c parent 7b4374acc0bd543c76bea7ab86de61e2d39d2ac7 author mohammedalharbi <[email protected]> 1520970198 -0400 committer mohammedalharbi <[email protected]> 1520970198 -0400 Merge commit '7b4374acc0bd543c76bea7ab86de61e2d39d2ac7'

Lap3/.git/objects/72/a0ee4ad96f13d635406f8764669bc3c450a39e

Lap3/.git/objects/72/a0ee4ad96f13d635406f8764669bc3c450a39e

blob 12044�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author mohammed alharbi * @version 20/2/2018 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); createItems(); } /** * items the item. */ public void createItems(){ Item toothbrush = new Item("tooth brush", 3, "Brushing teeth", 10); Item toothpaste = new Item("tooth paste", 3, "Applied on a tooth brush", 20); Item knife = new Item("knife", 5, "Peel and cut fruits", 100); Item coffee = new Item("coffee", 7, "good for personal health", 150); Item water = new Item("bottle of water", 8, "Quenches thirst", 250); Container purse = new Container("purse", 2,"Contains small small items", 100); Item houseKey = new Item("house key", 5, "Open locked doors", 20); purse.addItem(houseKey); Item backBag = new Item("back bag", 10, "Carry things in", 200); Item carKey = new Item("car key", 5, "Open locked doors", 50); Item bucket = new Item("water buckets", 15, "carry more items if back is full", 50); Item broomStick = new Item("broom stick", 5, "Pick items from the roof", 600); for(String room : rooms.keySet()){ switch(room){ case "bathroom": getcurrentRoom(room).addItem(toothbrush); getcurrentRoom(room).addItem(toothpaste); break; case "kitchen": getcurrentRoom(room).addItem(knife); getcurrentRoom(room).addItem(coffee); getcurrentRoom(room).addItem(water); getcurrentRoom(room).addItem(purse); getcurrentRoom(room).getDirection("south").setLocked(true); getcurrentRoom(room).getDirection("south").setKey(houseKey); break; case "out of the house": getcurrentRoom(room).addItem(broomStick); getcurrentRoom(room).getDirection("north").setLocked(true); getcurrentRoom(room).getDirection("north").setKey(houseKey); break; case "car": getcurrentRoom(room).addItem(backBag); getcurrentRoom(room).addItem(carKey); break; case "keep street": getcurrentRoom(room).addItem(bucket); break; default: } } } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms. * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from The room where the door originated. * @param direction The direction of the door in the from room. * @param to The room where the door goes. */ private void createDoor(Room from, String direction, Room to){ Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room outOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); outOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room car = new Room("Car", "inside the car, back bag, car key with house key.."); car.setPoints(7); pointScore = pointScore + 7; Room keepStreet = new Room("keep Street", "the correct way."); Room turnLeft = new Room("Turn left", "wrong way to go with it.."); Room endOfTheRoad = new Room("End of the road", "closed way."); Room gasStaion = new Room("Gas Staion", "the way to traffic signal."); Room trafficSignal = new Room("Traffic signal", "there are three different ways."); trafficSignal.setPoints(10); pointScore = pointScore + 10; Room turnLeft2 = new Room("Turn left2", "maybe not the right way."); Room wrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room turnRight = new Room("Turn right"," more traffic."); Room closedWay = new Room("Closed Way","no place to go."); Room keepGoing = new Room("KeepGoing","almost arrive to university."); keepGoing.setPoints(10); pointScore = pointScore + 10; Room parking = new Room("Parking","there is a meter parking, 2$ in Hour."); parking.setPoints(17); pointScore = pointScore + 17; Room library = new Room("Library","some books, students, printer, computers."); Room campusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room hallCampus = new Room("Hall Campus","the building for men."); Room hBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); square.setPoints(12); pointScore = pointScore + 12; Room mCBuilding = new Room("MCBuilding"," Classes, six floors."); Room aBuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room stairs = new Room("Stairs","take the player until fourth floor."); stairs.setPoints(18); pointScore = pointScore + 18; Room elevator = new Room("Elevator","take the player until fourth floor."); Room floor2 = new Room("2Floor","entry for classes"); Room classroom = new Room("Classroom","one door, blackboard, tables"); Room classroom201 = new Room ("Classroom201","you reach the goal."); classroom201.setPoints(30); pointScore = pointScore + 30; Room classroom204 = new Room("Classroom204","one door, students."); Room classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(bathroom); this.addRoom(kitchen); this.addRoom(outOfTheHouse); this.addRoom(car); this.addRoom(keepStreet); this.addRoom(turnLeft); this.addRoom(endOfTheRoad); this.addRoom(gasStaion); this.addRoom(trafficSignal); this.addRoom(turnLeft2); this.addRoom(wrongWay); this.addRoom(turnRight); this.addRoom(closedWay); this.addRoom(keepGoing); this.addRoom(parking); this.addRoom(library); this.addRoom(campusCenter); this.addRoom(hallCampus); this.addRoom(hBuilding); this.addRoom(square); this.addRoom(mCBuilding); this.addRoom(aBuilding); this.addRoom(stairs); this.addRoom(elevator); this.addRoom(floor2); this.addRoom(classroom); this.addRoom(classroom201); this.addRoom(classroom204); this.addRoom(classroom202); // Creating all the doors between the rooms. this.createDoor(bathroom,"east",kitchen); this.createDoor(kitchen, "west",bathroom); this.createDoor(kitchen,"south", outOfTheHouse); this.createDoor(outOfTheHouse,"north", kitchen); this.createDoor(outOfTheHouse,"west",car); this.createDoor(car,"east",outOfTheHouse); this.createDoor(car,"south",keepStreet); this.createDoor(keepStreet,"north",car); this.createDoor(keepStreet,"west",turnLeft); this.createDoor(turnLeft,"east",keepStreet); this.createDoor(turnLeft,"south", endOfTheRoad); this.createDoor(endOfTheRoad,"north",turnLeft); this.createDoor(keepStreet,"south",gasStaion); this.createDoor(gasStaion, "north",keepStreet); this.createDoor(gasStaion,"east",trafficSignal); this.createDoor(trafficSignal,"west", gasStaion); this.createDoor(trafficSignal,"north",turnLeft2); this.createDoor(turnLeft2,"south",trafficSignal); this.createDoor(turnLeft2,"north", wrongWay); this.createDoor(wrongWay,"south",turnLeft2); this.createDoor(trafficSignal,"south", turnRight); this.createDoor(turnRight,"north", trafficSignal); this.createDoor(turnRight,"south",closedWay); this.createDoor(closedWay,"north", turnRight); this.createDoor(trafficSignal,"east", keepGoing); this.createDoor(keepGoing, "west",trafficSignal); this.createDoor(keepGoing,"east", parking); this.createDoor(parking,"west",keepGoing); this.createDoor(parking,"southwest",library); this.createDoor(library, "northeast",parking); this.createDoor(library,"east", campusCenter); this.createDoor(campusCenter,"west",library); this.createDoor(parking,"south",square); this.createDoor(square,"north",parking); this.createDoor(square,"east", hallCampus); this.createDoor(hallCampus,"west",square); this.createDoor(square,"west",hBuilding); this.createDoor(hBuilding,"east",square); this.createDoor(square, "southeast",mCBuilding); this.createDoor(mCBuilding,"northwest",square); this.createDoor(square,"south",aBuilding); this.createDoor(aBuilding,"north",square); this.createDoor(aBuilding,"west",stairs); this.createDoor(stairs,"east",aBuilding); this.createDoor(aBuilding,"southwest",classroom); this.createDoor(classroom,"northeast",aBuilding); this.createDoor(aBuilding,"southwest",elevator); this.createDoor(elevator,"northeast",aBuilding); this.createDoor(elevator,"west",floor2); this.createDoor(floor2,"east",elevator); this.createDoor(stairs,"south",floor2); this.createDoor(floor2,"north",stairs); this.createDoor(floor2,"south",classroom204); this.createDoor(classroom204,"north",floor2); this.createDoor(floor2,"east",classroom202); this.createDoor(classroom202,"west",floor2); this.createDoor(floor2,"southeast",classroom201); this.createDoor(classroom201,"northwest",floor2); } }

Lap3/.git/objects/72/b4bae1638e99dfe920fb5606cbb891f2a529c2

Lap3/.git/objects/72/b4bae1638e99dfe920fb5606cbb891f2a529c2

blob 9515�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author Maria Jump * @version 2015.02.01 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param west * The room to the west of the originating room. */ private void createDoor(Room from, String direction, Room to) { Door door = new Door(to); from.setExit(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room Bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room Kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room OutOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); OutOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room Car = new Room("Car", "inside the car, back bag, car key with house key.."); Car.setPoints(7); pointScore = pointScore + 7; Room KeepStreet = new Room(" keep Street", "the correct way."); Room TurnLeft = new Room("Turn left", "wrong way to go with it.."); Room EndOfTheRoad = new Room("End of the road", "closed way."); Room TurnLeft1 = new Room(" Turn left1", "the way to traffic signal."); Room TrafficSignal = new Room("Traffic signal", "there are three different ways."); TrafficSignal.setPoints(10); pointScore = pointScore + 10; Room TurnLeft2 = new Room("Turn left2", "maybe not the right way."); Room WrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room TurnRight = new Room("Turn right"," more traffic."); Room ClosedWay = new Room("Closed Way","no place to go."); Room KeepStreet1 = new Room("KeepStreet1","almost arrive to university."); KeepStreet1.setPoints(10); pointScore = pointScore + 10; Room Parking = new Room("Parking","there is a meter parking, 2$ in Hour."); Parking.setPoints(17); pointScore = pointScore + 17; Room Library = new Room("Library","some books, students, printer, computers."); Room CampusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room HallCampus = new Room("Hall Campus","the building for men."); Room HBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room Square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); Square.setPoints(12); pointScore = pointScore + 12; Room MCBuilding = new Room("MCBuilding"," Classes, six floors."); Room ABuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room Stairs = new Room("Stairs","take the player until fourth floor."); Stairs.setPoints(18); pointScore = pointScore + 18; Room Elevator = new Room("Elevator","take the player until fourth floor."); Room Floor2 = new Room("2Floor","entry for classes"); Room Classroom = new Room("Classroom","one door, blackboard, tables"); Room Classroom201 = new Room ("Classroom201","you reach the goal."); Classroom201.setPoints(30); pointScore = pointScore + 30; Room Classroom204 = new Room("Classroom204","one door, students."); Room Classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(Bathroom); this.addRoom(Kitchen); this.addRoom(OutOfTheHouse); this.addRoom(Car); this.addRoom(KeepStreet); this.addRoom(TurnLeft); this.addRoom(EndOfTheRoad); this.addRoom(TurnLeft1); this.addRoom(TrafficSignal); this.addRoom(TurnLeft2); this.addRoom(WrongWay); this.addRoom(TurnRight); this.addRoom(ClosedWay); this.addRoom(KeepStreet1); this.addRoom(Parking); this.addRoom(Library); this.addRoom(CampusCenter); this.addRoom(HallCampus); this.addRoom(HBuilding); this.addRoom(Square); this.addRoom(MCBuilding); this.addRoom(ABuilding); this.addRoom(Stairs); this.addRoom(Elevator); this.addRoom(Floor2); this.addRoom(Classroom); this.addRoom(Classroom201); this.addRoom(Classroom204); this.addRoom(Classroom202); // Creating all the doors between the rooms. this.createDoor(Bathroom,"east",Kitchen); this.createDoor(Kitchen, "west",Bathroom); this.createDoor(Kitchen,"south", OutOfTheHouse); this.createDoor(OutOfTheHouse,"north", Kitchen); this.createDoor(OutOfTheHouse,"west",Car); this.createDoor(Car,"east",OutOfTheHouse); this.createDoor(Car,"south",KeepStreet); this.createDoor(KeepStreet,"north",Car); this.createDoor(KeepStreet,"west",TurnLeft); this.createDoor(TurnLeft,"east",KeepStreet); this.createDoor(TurnLeft,"south", EndOfTheRoad); this.createDoor(EndOfTheRoad,"north",TurnLeft); this.createDoor(KeepStreet,"south",TurnLeft1); this.createDoor(TurnLeft1, "north",KeepStreet); this.createDoor(TurnLeft1,"east",TrafficSignal); this.createDoor(TrafficSignal,"west", TurnLeft1); this.createDoor(TrafficSignal,"north",TurnLeft2); this.createDoor(TurnLeft2,"south",TrafficSignal); this.createDoor(TurnLeft2,"north", WrongWay); this.createDoor(WrongWay,"south",TurnLeft2); this.createDoor(TrafficSignal,"south", TurnRight); this.createDoor(TurnRight,"north", TrafficSignal); this.createDoor(TurnRight,"south",ClosedWay); this.createDoor(ClosedWay,"north", TurnRight); this.createDoor(TrafficSignal,"east", KeepStreet1); this.createDoor(KeepStreet1, "west",TrafficSignal); this.createDoor(KeepStreet1,"east", Parking); this.createDoor(Parking,"west",KeepStreet1); this.createDoor(Parking,"south",Library); this.createDoor(Library, "north",Parking); this.createDoor(Library,"west", CampusCenter); this.createDoor(CampusCenter,"east",Library); this.createDoor(Parking,"south",Square); this.createDoor(Square,"north",Parking); this.createDoor(Square,"east", HallCampus); this.createDoor(HallCampus,"west",Square); this.createDoor(Square,"west",HBuilding); this.createDoor(HBuilding,"east",Square); this.createDoor(Square, "south",MCBuilding); this.createDoor(MCBuilding,"north",Square); this.createDoor(Square,"south",ABuilding); this.createDoor(ABuilding,"north",ABuilding); this.createDoor(ABuilding,"west",Stairs); this.createDoor(Stairs,"east",ABuilding); this.createDoor(ABuilding,"south",Classroom); this.createDoor(Classroom,"north",ABuilding); this.createDoor(ABuilding,"south",Elevator); this.createDoor(Elevator,"north",ABuilding); this.createDoor(Elevator,"south",Floor2); this.createDoor(Floor2,"north",Elevator); this.createDoor(Stairs,"south",Floor2); this.createDoor(Floor2,"north",Stairs); this.createDoor(Floor2,"south",Classroom204); this.createDoor(Classroom204,"north",Floor2); this.createDoor(Floor2,"east",Classroom202); this.createDoor(Classroom202,"west",Floor2); this.createDoor(Floor2,"south",Classroom201); this.createDoor(Classroom201,"north",Floor2); } }

Lap3/.git/objects/2a/3c003981589f7bb03a89211bb839c694e7659f

Lap3/.git/objects/2a/3c003981589f7bb03a89211bb839c694e7659f

blob 1958� import java.util.Map.Entry; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public class CommandEnum{ /** A constant array that holds all valid command words. */ public enum validCommands{look, go, quit, help, status, back}; /** * Static block to initialize the fields of CommandWords. */ /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(CommandEnum aString) { boolean valid = false; for(Entry<String,CommandEnum> pair : CommandWords.commandMap.entrySet()){ if(pair.getValue() == aString){ valid = true; } } return valid; } /** * Returns a list of the available commands, of the form: * your command words are: * look go quit help * * @return A string containing the list of available commands. */ public static String getCommandString(){ String commandString = " "; for(CommandEnum.validCommands s : validCommands.values()){ commandString += s.name() + " "; } return commandString; } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return CommandWords.commandMap.get(theString); } }

Lap3/.git/objects/2f/0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568

Lap3/.git/objects/2f/0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568

commit 234�tree 23ecd84efcaeaa901fd60738fb969aff9bc68860 parent 817f82161c5c0d59090c476bddc0c1bd810cbc5c author mohammedalharbi <[email protected]> 1525021777 -0400 committer mohammedalharbi <[email protected]> 1525021777 -0400 stage5

Lap3/.git/objects/6b/1e6515c63f643ad52418df4385facb8dc92a20

Lap3/.git/objects/6b/1e6515c63f643ad52418df4385facb8dc92a20

blob 5870�//import java.util.HashMap; /** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); Writer.print("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println("go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/6b/36ca17784d3d6b46d8d2259854c4694df0dea2

Lap3/.git/objects/6b/36ca17784d3d6b46d8d2259854c4694df0dea2

Lap3/.git/objects/36/bb334fe1bbb346cf2129d9fe5802dbdc7ac3da

Lap3/.git/objects/36/bb334fe1bbb346cf2129d9fe5802dbdc7ac3da

blob 2119�/** * Class Item - An item in the game that the player can * pick or drop. * The class also describe items in the game by their name, weight etc * @author mohammed alharbi * @version 20/4/2018 */ public class Item { /** the name of item. */ public String name; /** the description. */ private String description; /** the pointval.*/ private int pointVal; /** the weight.*/ private int weight; /** Constructor for Items. * @param name the name. * @param pointValue the pointValue * @param description the description * @param weight the weight * */ public Item(String name, int pointValue, String description, int weight) { this.name = name; this.description = description; this.pointVal = pointValue; this.weight = weight; } /** * * Returns the name of an item. * @return The name of an item. * **/ public String getName(){ return name; } /** * * Returns the description of an item. * @return The description of an item. * **/ public String getDescription(){ return description; } /** * * Sets the description of a room. * @param desc. * **/ public void setDescription(String desc){ description = desc; } /** * * Returns the pointValue of an item. * @return The pointValue of an item. * **/ public int getPointValue(){ return pointVal; } /** * * Returns the weight of an item. * @return The weight of an item. * **/ public int getWeight(){ return weight; } @Override public String toString(){ String itemInfo = ""; itemInfo += "Name : " + name + "\n"; itemInfo += "Description : " + description + "\n"; itemInfo += "Weight : " + weight + "grams"; return itemInfo; } }

Lap3/.git/objects/36/3c92e452f22f83cc1f7a056d1ec91d83aac6ce

Lap3/.git/objects/36/3c92e452f22f83cc1f7a056d1ec91d83aac6ce

blob 714� /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public class Drink extends Item implements Drinkable{ /** * the drink class. * @param name the name. * @param pointValue the pointValue. * @param description the description . * @param weight the weight. */ public Drink(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); } @Override public boolean drink(String drinkName) { return true; } }

Lap3/.git/objects/5d/4f4621e92de21ec99f679cf8a08f8b1b044ac5

Lap3/.git/objects/5d/4f4621e92de21ec99f679cf8a08f8b1b044ac5

blob 3684�import java.util.ArrayList; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds information about a command that was issued by the user. A * command currently consists of two strings: a command word and a second word * (for example, if the command was "take map", then the two strings obviously * are "take" and "map"). * * The way this is used is: Commands are already checked for being valid command * words. If the user entered an invalid command (a word that is not known) then * the command word is <null>. * * If the command had only one word, then the second word is <null>. * * @author Maria Jump * @version 2015.02.01 */ public class Command { /** The command word for this command. */ private CommandEnum commandWord; /** The rest of the line with all the spaces removed. */ private ArrayList<String> restOfLine; /** * Create a command object. First is supplied. The second word is assumed * to be null. * * @param firstWord * The first word of the command. Null if the command was not * recognized. */ public Command(String firstWord) { commandWord = CommandWords.getCommand(firstWord); restOfLine = new ArrayList<String>(); } /** * Create a command object. First and second word must be supplied, but * either one (or both) can be null. * * @param firstWord * The first word of the command. Null if the command was not * recognized. * @param rest * The rest of the command. */ public Command(String firstWord, ArrayList<String> rest) { commandWord = CommandWords.getCommand(firstWord); restOfLine = rest; } /** * Return the command word (the first word) of this command. If the command * was not understood, the result is null. * * @return The command word. */ public CommandEnum getCommandWord() { return commandWord; } /** * Returns if this command was not understood. * * @return true if this command was not understood. */ public boolean isUnknown() { return (commandWord == null); } /** * Returns if this command has a second word. * * @return true if the command has a second word. */ public boolean hasSecondWord() { return restOfLine != null; } /** * Returns if this command has more words. * * @param index The index of the word needed. * @return true if the command has a word at given index. */ public boolean hasWord(int index) { return index >= 0 && index < restOfLine.size(); } /** * Returns the word at the requested index in the command. * * @param index * The index of word in the command that is being requested. * * @return A particular word in the command. Returns null if there is no * word corresponding to that requested index. * */ public String getWord(int index) { String result = null; if (index >= 0 && index < restOfLine.size()) { result = restOfLine.get(index); } return result; } /** * Returns the second word of this command, if it exists. * * @return The second word of this command. Returns null if there was no * second word. */ public String getRestOfLine() { StringBuffer buffer = null; if (restOfLine.size() != 0) { for(String word : restOfLine) { if (buffer == null) { buffer = new StringBuffer(); buffer.append(word); } else { buffer.append(" "); buffer.append(word); } } } String result = ""; if (buffer != null) { result += buffer.toString(); } return result; } }

Lap3/.git/objects/62/8ca4a5d61987fbc62787fdc61e957944585f37

Lap3/.git/objects/62/8ca4a5d61987fbc62787fdc61e957944585f37

commit 234�tree fc03dcc4fbedb5d91e8d5fda1f98b288823e4c66 parent 68892ff3d3ee00fb7177f3629010dc7544352b49 author mohammedalharbi <[email protected]> 1524622546 -0400 committer mohammedalharbi <[email protected]> 1524622546 -0400 stage4

Lap3/.git/objects/62/aa1fe8f836c8e2f7db3d62521e70180bba71fc

Lap3/.git/objects/62/aa1fe8f836c8e2f7db3d62521e70180bba71fc

commit 233�tree 6b36ca17784d3d6b46d8d2259854c4694df0dea2 parent 28097f950a7d27ad1519536c2b305fc237bfb29c author mohammedalharbi <[email protected]> 1521414134 -0400 committer mohammedalharbi <[email protected]> 1521414134 -0400 lap3

Lap3/.git/objects/62/08fab7077ff5d0d4b2a70f1a7399be32fa436a

Lap3/.git/objects/62/08fab7077ff5d0d4b2a70f1a7399be32fa436a

blob 5756�//import java.util.HashMap; /** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); Writer.print("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println("go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/53/97a1c08eb82f45423d4c4dd7baefe7deca6789

Lap3/.git/objects/53/97a1c08eb82f45423d4c4dd7baefe7deca6789

blob 5246�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author Maria Jump * @version 2015.02.01 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } //** /* Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param north * The room to the north of the originating room. */ //private void createNorthDoor(Room from, Room north) { //Door northDoor = new Door(north); //from.northExit = northDoor; //** /* Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param east * The room to the east of the originating room. */ //private void createEastDoor(Room from, Room east) { //Door eastDoor = new Door(east); //from.eastExit = eastDoor; //} //** // * Helper method for creating doors between rooms. /* * @param from * The room where the door originates. * @param south * The room to the south of the originating room. */ //private void createSouthDoor(Room from, Room south) { // Door southDoor = new Door(south); //from.southExit = southDoor; //} //** /* Helper method for creating doors between rooms. /* * @param from * The room where the door originates. * @param west * The room to the west of the originating room. */ //private void createWestDoor(Room from, Room west) { // Door westDoor = new Door(west); // from.getExit(westDoor); // } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { //Creating all the rooms. Room outside = new Room("Outside", "outside in the center of the King's College campus."); Room holyCross = new Room("Holy Cross", "at one of two main dormitories on campus."); Room essef = new Room("Essef", "at the other main dormitory on campus."); Room campusCenter = new Room("Campus Center", "in the center of student activities on campus."); Room admin = new Room("Admin", "in the oldest building on campus and home to the computer science department."); Room jumpOffice = new Room("Jump's Office", "in Dr Jump's office."); Room hoggOffice = new Room("Hogg's Office", "in Dr Hogg's office."); Room lab = new Room("Computer Lab", "in the Computer Science and Math computing lab."); Room classroom = new Room("Classroom", "in the classroom where the computer science classes are taught."); //Adding all the rooms to the world. this.addRoom(outside); this.addRoom(holyCross); this.addRoom(essef); this.addRoom(campusCenter); this.addRoom(admin); this.addRoom(jumpOffice); this.addRoom(hoggOffice); this.addRoom(lab); this.addRoom(classroom); //Creating all the doors between the rooms. //this.createSouthDoor(essef, outside); //this.createNorthDoor(outside, essef); //this.createEastDoor(campusCenter, outside); //this.createWestDoor(outside, campusCenter); //this.createEastDoor(outside, holyCross); //this.createWestDoor(holyCross, outside); //this.createSouthDoor(outside, admin); //this.createNorthDoor(admin, outside); //this.createEastDoor(admin, lab); //this.createWestDoor(lab, admin); //this.createSouthDoor(admin, hoggOffice); //this.createNorthDoor(hoggOffice, admin); //this.createWestDoor(admin, jumpOffice); //this.createEastDoor(jumpOffice, admin); //this.createSouthDoor(lab, classroom); //this.createNorthDoor(classroom, lab); } }

Lap3/.git/objects/53/2cb2d21afc4041257b38e958244a5c7553fc64

Lap3/.git/objects/53/2cb2d21afc4041257b38e958244a5c7553fc64

blob 1289�/** * Class Door - a door or portal between two Rooms in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Door" represents a door or portal between two locations of the game. * It stores a reference to the neighboring room and whether that door * or portal is locked. Doors are not locked by default. * * @author Maria Jump * @version 2015.02.01 */ public class Door { /** The room that this door leads to. */ private Room destination; /** Whether this door is locked. */ private boolean locked; /** * Constructor for the Door class. * @param destination The room this door leads to */ public Door(Room destination) { this.destination = destination; this.locked = false; } /** * A getter for the room this door leads to. * @return The room this door leads to */ public Room getDestination() { return destination; } /** * A getter for whether this door is locked. * @return Whether this door is locked */ public boolean isLocked() { return locked; } /** * A setter for whether this door is locked. * @param locked Whether this door is locked. */ public void setLocked(boolean locked) { this.locked = locked; } }

Lap3/.git/objects/3f/fe95afc35a0cf09e5c5724829eb613b1021cfe

Lap3/.git/objects/3f/fe95afc35a0cf09e5c5724829eb613b1021cfe

blob 1756� import java.util.HashMap; import java.util.Map; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public class CommandWords { static Map<String, CommandEnum> commandMap; /** A constant array that holds all valid command words. */ //private static String[] validCommands; /** * Static block to initialize the fields of CommandWords. **/ static { commandMap = new HashMap<>(); CommandEnum[] tempCommands = CommandEnum.values(); for(CommandEnum s: tempCommands){ commandMap.put(s.name(), CommandEnum.getCommand(s.name())); } } /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(String aString) { // if we get here, the string was not found in the commands return commandMap.containsKey(aString); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand(String theString){ return commandMap.get(theString); } }

Lap3/.git/objects/3f/705e964028fab9fe251a0e491df78a19dc12eb

Lap3/.git/objects/3f/705e964028fab9fe251a0e491df78a19dc12eb

commit 331�tree 517feb6375a09bfa2f9de8968ffb458cc34a2904 parent 1301775cc1c2b4fd94c7905c963f5f6cfb914a2d parent a4e2272a137d2dde8a838d9c73be6e8f12967a27 author mohammedalharbi <[email protected]> 1518056756 -0500 committer mohammedalharbi <[email protected]> 1518056756 -0500 Merge commit 'a4e2272a137d2dde8a838d9c73be6e8f12967a27'

Lap3/.git/objects/3f/dab05801a9f2211b9b2cc052c4ccad75e77b45

Lap3/.git/objects/3f/dab05801a9f2211b9b2cc052c4ccad75e77b45

Lap3/.git/objects/30/4fb2fe31611842f6d5bf4858fa6bf934833ac4

Lap3/.git/objects/30/4fb2fe31611842f6d5bf4858fa6bf934833ac4

commit 232�tree c62063f7af6c984d998530e2af1ed4d51ee9aefa parent a62ed382a705487d7667dbe1cd664e4069257396 author mohammedalharbi <[email protected]> 1522015723 -0400 committer mohammedalharbi <[email protected]> 1522015723 -0400 lap3

Lap3/.git/objects/30/78411bc8f26e0e0772dede5795a3ff6e3f9f9a

Lap3/.git/objects/30/78411bc8f26e0e0772dede5795a3ff6e3f9f9a

blob 2064� /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public enum CommandEnum{ /** A constant array that holds all valid command words. */ //private static String[] validCommands; look, go, quit, help, status, back, examine, take, drop, inventory, unlock, lock, unpack, pack; /** * Static block to initialize the fields of CommandWords. */ // static { // String[] tempCommands = {"look","go", "quit", "help" }; // validCommands = tempCommands; // // } /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(CommandEnum aString) { return CommandWords.commandMap.containsValue(aString); } /** * Returns a list of the available commands, of the form: * your command words are: * look go quit help * * @return A string containing the list of available commands. */ public static String getCommandString(){ String commandString = ""; for(CommandEnum moh : CommandEnum.values()){ commandString += moh.name() + " "; } return commandString; //return getCommandString(); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return CommandEnum.valueOf(theString); } }

Lap3/.git/objects/08/3be6693292f620dc03b9ff4515007226bf4fb6

Lap3/.git/objects/08/3be6693292f620dc03b9ff4515007226bf4fb6

blob 2018� import java.util.HashMap; /** * Class Container - A container item in the game that the player can * pack or unpack * The class also describe containers in the game by their name, weight etc * @author mohammed alharbi * @version 24/4/2018 */ public class Container extends Item{ private final HashMap<String, Item> containerItems; public Container(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); containerItems = new HashMap<>(); } /** * Add item to a container. * * @param item the item to be added to the container **/ @Override public void addItem(Item item){ containerItems.put(item.getName(), item); } @Override public boolean isContainer() { return true; } /** * remove item from a container. * * @param itemName the item to be removed from the container * @return Item that has been removed from the container **/ @Override public Item removeItem(String itemName){ return containerItems.remove(itemName); } /** * get item from the container. * * @param itemName the item to be removed from the container * @return Item that has been removed from the container **/ @Override public Item getItem(String itemName){ return containerItems.get(itemName); } private String getContainerItems(){ String containerItemsRes = ""; for(String s: containerItems.keySet()){ containerItemsRes += s + ", "; } return containerItemsRes; } @Override public String toString(){ String itemInfo = ""; itemInfo += "Name : " + super.getName() + "\n"; itemInfo += "Description : " + super.getDescription() + "\n"; itemInfo += "Weight : " + super.getWeight() + "grams \n"; itemInfo += "Items : " + getContainerItems() ; return itemInfo; } }

Lap3/.git/objects/6d/2f136d37dc8e3582246d1bbf96c0e6f3722fe1

Lap3/.git/objects/6d/2f136d37dc8e3582246d1bbf96c0e6f3722fe1

blob 940� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. eastBathroom there is teeth brush, shower place.Exiteast : You are Bathroom there is teeth brush, shower place.Exiteast Exits: east > go Go where? > go west There is no door! > go east Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest : You are Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest Exits: south west > go south out Of The House the way outside the house to drive to university..ExitnorthExitwest : You are out Of The House the way outside the house to drive to university..ExitnorthExitwest Exits: north west > quit I hope you weren't too bored here on the Campus of Kings! Thank you for playing. Good bye. You have earned 0points in 5 turns.

Lap3/.git/objects/6d/db4e6702aa5885b9e95b70613e3309977e31f6

Lap3/.git/objects/6d/db4e6702aa5885b9e95b70613e3309977e31f6

blob 597� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. You are in Bathroom there is teeth brush, shower place. Exits : east Items : tooth paste, tooth brush, > go east You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room.. Exits : south west Items : knife, bottle of water, coffee, purse, > go south door is locked! > go unlock south There is no door! > go south door is locked! > go south door is locked! > unlock south I don't know what you mean... >

Lap3/.git/objects/06/3ece284f581d84a9258bc78ff6f0de6d125002

Lap3/.git/objects/06/3ece284f581d84a9258bc78ff6f0de6d125002

Lap3/.git/objects/6c/ef56a888dd99dcbb0a165075f06b6f04af7b4c

Lap3/.git/objects/6c/ef56a888dd99dcbb0a165075f06b6f04af7b4c

Lap3/.git/objects/39/739db2aa206ad3fbd7f6641d1d46e83877e910

Lap3/.git/objects/39/739db2aa206ad3fbd7f6641d1d46e83877e910

blob 3061�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap<>(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Returns the number of rooms that have been created in the world. * @return The number of rooms that have been created in the world. */ public static int getCounter() { return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public Door getExit(String direction) { return directions.get(direction); } /** * Set exit. * @param direction * @param neighbor */ public void setExit(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room . * For example , *Outside : *You are outside in the center of the King's College campus . *Exits : north east south west * * @return A string representing all the details of a Room . */ public String toString (){ String roomInformation = getName() + " " + getDescription(); roomInformation = "Exist:"; roomInformation = "Name:"; roomInformation = "Description:"; for (String direction : directions.keySet()) { roomInformation += direction + " "; } return roomInformation; } }

Lap3/.git/objects/39/00a2fb4bd498e1901946022fa3b62cf94d0659

Lap3/.git/objects/39/00a2fb4bd498e1901946022fa3b62cf94d0659

blob 641� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. You are in Bathroom there is teeth brush, shower place. Exits : east Items : tooth paste, tooth brush, > go east You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room.. Exits : south west Items : knife, coffee, purse, grapes, > go south door is locked! > unlock south With what? purse You don't have it! > pack purse pack where? south You don't see the container > go south door is locked! > unlock south With what? purse You don't have it! >

Lap3/.git/objects/97/c1e2ca8d9925127f563d5403883b8069b42e30

Lap3/.git/objects/97/c1e2ca8d9925127f563d5403883b8069b42e30

blob 7309�//import java.util.HashMap; /** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; /** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; //Playing = Playing; // set the starting room //Room out = world.getcurrentRoom("Bathroom"); //Playing = new Player(out); } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; if (direction.equals("north")) { doorway = playerClass.getcurrentRoom().getDirection("north"); } if (direction.equals("east")) { doorway = playerClass.getcurrentRoom().getDirection("east"); } if (direction.equals("south")) { doorway = playerClass.getcurrentRoom().getDirection("south"); } if (direction.equals("west")) { doorway = playerClass.getcurrentRoom().getDirection("west"); } if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are " + playerClass.getcurrentRoom()); Writer.print("Exits: "); if (playerClass.getcurrentRoom().getDirection("north") != (null)) { Writer.print("north "); } if (playerClass.getcurrentRoom().getDirection("east") != null) { Writer.print("east "); } if (playerClass.getcurrentRoom().getDirection("south") != null) { Writer.print("south "); } if (playerClass.getcurrentRoom().getDirection("west") != null) { Writer.print("west "); } Writer.println(); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println("go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); if (playerClass.getcurrentRoom().getDirection("east") != null) { Writer.print("east"); } if (playerClass.getcurrentRoom().getDirection("west") != null) { Writer.print("west"); } if (playerClass.getcurrentRoom().getDirection("south") != null) { Writer.print("south"); } if (playerClass.getcurrentRoom().getDirection("north") != null) { Writer.print("north"); } //Writer.println(); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/0a/c2d59359ef610bdef52c4a797a365accb1525e

Lap3/.git/objects/0a/c2d59359ef610bdef52c4a797a365accb1525e

blob 553� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. Outside outside in the center of the King's College campus.: You are Outside outside in the center of the King's College campus. Exits: north east south west north east south west Outside outside in the center of the King's College campus.: You are Outside outside in the center of the King's College campus. Exits: north east south west > moh I don't know what you mean... > go Go where? > to I don't know what you mean... >

Lap3/.git/objects/64/506a6dd3dac60899bcd529ce6381a5cddbc03c

Lap3/.git/objects/64/506a6dd3dac60899bcd529ce6381a5cddbc03c

commit 232�tree 4eeb29795bd70f62bb6e7ebf829c65b29deb70b6 parent 74f5bd1b9585fd8676cf3d1c4382f6ec562680cb author mohammedalharbi <[email protected]> 1520970106 -0400 committer mohammedalharbi <[email protected]> 1520970106 -0400 lap3

Lap3/.git/objects/64/fe557accb0714fe0f46ac5e1b126585b3ae005

Lap3/.git/objects/64/fe557accb0714fe0f46ac5e1b126585b3ae005

blob 6816�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; /** stores the character controlled by the Player. */ private Player team; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** * Create the game and initialize its internal map. */ public Game() { score = 0; turns = 0; world = new World(); // set the starting room Room out = world.getRoom("outside"); team = new Player(out); } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; if (direction.equals("north")) { doorway = team.getcurrentRoom().northExit; } if (direction.equals("east")) { doorway = team.getcurrentRoom().eastExit; } if (direction.equals("south")) { doorway = team.getcurrentRoom().southExit; } if (direction.equals("west")) { doorway = team.getcurrentRoom().westExit; } if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); team.setcurrentRoom(newRoom); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + score + "points in" + turns + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(team.getcurrentRoom() + ":"); Writer.println("You are " + team.getcurrentRoom()); Writer.print("Exits: "); if (team.getcurrentRoom().northExit != null) { Writer.print("north "); } if (team.getcurrentRoom().eastExit != null) { Writer.print("east "); } if (team.getcurrentRoom().southExit != null) { Writer.print("south "); } if (team.getcurrentRoom().westExit != null) { Writer.print("west "); } Writer.println(); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(" go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); Writer.println(); printLocationInformation(); if (team.getcurrentRoom().northExit != null) { Writer.print("north "); } if (team.getcurrentRoom().eastExit != null) { Writer.print("east "); } if (team.getcurrentRoom().southExit != null) { Writer.print("south "); } if (team.getcurrentRoom().westExit != null) { Writer.print("west "); } Writer.println(); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/bf/877250b9df1bd097892de3507e3bfc6f3de917

Lap3/.git/objects/bf/877250b9df1bd097892de3507e3bfc6f3de917

blob 426�/** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public interface Drinkable { /** * drink the drink. * @param p the current game character. * @return a message */ public String drink(Player p); }

Lap3/.git/objects/d3/2450f7f906dc3b39627349493d66959269e6ed

Lap3/.git/objects/d3/2450f7f906dc3b39627349493d66959269e6ed

blob 695� /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; /** constructor in the Player class. * @param player for the room . */ public Player(Room PlayPlayer){ currentRoom = PlayPlayer; } /** accessor for the current room the character. * @return cerrentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param Playing for the Room */ public void setcurrentRoom(Room Playing){ currentRoom = Playing; } }

Lap3/.git/objects/a7/14e8145c5ce725636e8fbafc453b5e3c68d68b

Lap3/.git/objects/a7/14e8145c5ce725636e8fbafc453b5e3c68d68b

Lap3/.git/objects/b8/f61a8c9ede4c2ded9a1e95bf12ab0fa4914187

Lap3/.git/objects/b8/f61a8c9ede4c2ded9a1e95bf12ab0fa4914187

Lap3/.git/objects/dd/b82e9a33c29135e54038311a52e67c2e687879

Lap3/.git/objects/dd/b82e9a33c29135e54038311a52e67c2e687879

blob 560� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. You are in Bathroom there is teeth brush, shower place. Exits : east Items : tooth paste, tooth brush, > go east You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room.. Exits : south west Items : knife, bottle of water, coffee, > go south You are in out Of The House the way outside the house to drive to university.. Exits : north west Items : broom btick, >

Lap3/.git/objects/dd/bfc73deca642fd92018899d2d2bbaad191ce83

Lap3/.git/objects/dd/bfc73deca642fd92018899d2d2bbaad191ce83

blob 9383�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author Maria Jump * @version 2015.02.01 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from * The room where the door originates. * @param west * The room to the west of the originating room. */ private void createDoor(Room from, String direction, Room to) { Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room Bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room Kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room OutOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); OutOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room Car = new Room("Car", "inside the car, back bag, car key with house key.."); Car.setPoints(7); pointScore = pointScore + 7; Room KeepStreet = new Room(" keep Street", "the correct way."); Room TurnLeft = new Room("Turn left", "wrong way to go with it.."); Room EndOfTheRoad = new Room("End of the road", "closed way."); Room TurnLeft1 = new Room(" Turn left1", "the way to traffic signal."); Room TrafficSignal = new Room("Traffic signal", "there are three different ways."); TrafficSignal.setPoints(10); pointScore = pointScore + 10; Room TurnLeft2 = new Room("Turn left2", "maybe not the right way."); Room WrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room TurnRight = new Room("Turn right"," more traffic."); Room ClosedWay = new Room("Closed Way","no place to go."); Room KeepStreet1 = new Room("KeepStreet1","almost arrive to university."); KeepStreet1.setPoints(10); pointScore = pointScore + 10; Room Parking = new Room("Parking","there is a meter parking, 2$ in Hour."); Parking.setPoints(17); pointScore = pointScore + 17; Room Library = new Room("Library","some books, students, printer, computers."); Room CampusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room HallCampus = new Room("Hall Campus","the building for men."); Room HBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room Square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); Square.setPoints(12); pointScore = pointScore + 12; Room MCBuilding = new Room("MCBuilding"," Classes, six floors."); Room ABuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room Stairs = new Room("Stairs","take the player until fourth floor."); Stairs.setPoints(18); pointScore = pointScore + 18; Room Elevator = new Room("Elevator","take the player until fourth floor."); Room Floor2 = new Room("2Floor","entry for classes"); Room Classroom = new Room("Classroom","one door, blackboard, tables"); Room Classroom201 = new Room ("Classroom201","you reach the goal."); Classroom201.setPoints(30); pointScore = pointScore + 30; Room Classroom204 = new Room("Classroom204","one door, students."); Room Classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(Bathroom); this.addRoom(Kitchen); this.addRoom(OutOfTheHouse); this.addRoom(Car); this.addRoom(KeepStreet); this.addRoom(TurnLeft); this.addRoom(EndOfTheRoad); this.addRoom(TurnLeft1); this.addRoom(TrafficSignal); this.addRoom(TurnLeft2); this.addRoom(WrongWay); this.addRoom(TurnRight); this.addRoom(ClosedWay); this.addRoom(KeepStreet1); this.addRoom(Parking); this.addRoom(Library); this.addRoom(CampusCenter); this.addRoom(HallCampus); this.addRoom(HBuilding); this.addRoom(Square); this.addRoom(MCBuilding); this.addRoom(ABuilding); this.addRoom(Stairs); this.addRoom(Elevator); this.addRoom(Floor2); this.addRoom(Classroom); this.addRoom(Classroom201); this.addRoom(Classroom204); this.addRoom(Classroom202); // Creating all the doors between the rooms. this.createDoor(Bathroom,"east",Kitchen); this.createDoor(Kitchen, "west",Bathroom); this.createDoor(Kitchen,"south", OutOfTheHouse); this.createDoor(OutOfTheHouse,"north", Kitchen); this.createDoor(OutOfTheHouse,"west",Car); this.createDoor(Car,"east",OutOfTheHouse); this.createDoor(Car,"south",KeepStreet); this.createDoor(KeepStreet,"north",Car); this.createDoor(KeepStreet,"west",TurnLeft); this.createDoor(TurnLeft,"east",KeepStreet); this.createDoor(TurnLeft,"south", EndOfTheRoad); this.createDoor(EndOfTheRoad,"north",TurnLeft); this.createDoor(KeepStreet,"south",TurnLeft1); this.createDoor(TurnLeft1, "north",KeepStreet); this.createDoor(TurnLeft1,"east",TrafficSignal); this.createDoor(TrafficSignal,"west", TurnLeft1); this.createDoor(TrafficSignal,"north",TurnLeft2); this.createDoor(TurnLeft2,"south",TrafficSignal); this.createDoor(TurnLeft2,"north", WrongWay); this.createDoor(WrongWay,"south",TurnLeft2); this.createDoor(TrafficSignal,"south", TurnRight); this.createDoor(TurnRight,"north", TrafficSignal); this.createDoor(TurnRight,"south",ClosedWay); this.createDoor(ClosedWay,"north", TurnRight); this.createDoor(TrafficSignal,"east", KeepStreet1); this.createDoor(KeepStreet1, "west",TrafficSignal); this.createDoor(KeepStreet1,"east", Parking); this.createDoor(Parking,"west",KeepStreet1); this.createDoor(Parking,"southwest",Library); this.createDoor(Library, "northeast",Parking); this.createDoor(Library,"west", CampusCenter); this.createDoor(CampusCenter,"east",Library); this.createDoor(Parking,"south",Square); this.createDoor(Square,"north",Parking); this.createDoor(Square,"east", HallCampus); this.createDoor(HallCampus,"west",Square); this.createDoor(Square,"west",HBuilding); this.createDoor(HBuilding,"east",Square); this.createDoor(Square, "south",MCBuilding); this.createDoor(MCBuilding,"north",Square); this.createDoor(Square,"south",ABuilding); this.createDoor(ABuilding,"north",ABuilding); this.createDoor(ABuilding,"west",Stairs); this.createDoor(Stairs,"east",ABuilding); this.createDoor(ABuilding,"south",Classroom); this.createDoor(Classroom,"north",ABuilding); this.createDoor(ABuilding,"south",Elevator); this.createDoor(Elevator,"north",ABuilding); this.createDoor(Elevator,"south",Floor2); this.createDoor(Floor2,"north",Elevator); this.createDoor(Stairs,"south",Floor2); this.createDoor(Floor2,"north",Stairs); this.createDoor(Floor2,"south",Classroom204); this.createDoor(Classroom204,"north",Floor2); this.createDoor(Floor2,"east",Classroom202); this.createDoor(Classroom202,"west",Floor2); this.createDoor(Floor2,"south",Classroom201); this.createDoor(Classroom201,"north",Floor2); } }

Lap3/.git/objects/dc/7a53a9ea491a5ab5d6fbd70da66c0cd026f695

Lap3/.git/objects/dc/7a53a9ea491a5ab5d6fbd70da66c0cd026f695

blob 7387�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum (){ boolean wantToQuit = false; if (!CommandWords.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { String commandWord = command.getCommandWord(); switch(commandWord){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { playerClass.setpreviousRoom(playerClass.getcurrentRoom()); Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ Room currentRoom = playerClass.getcurrentRoom(); playerClass.setcurrentRoom(playerClass.getpreviousRoom()); playerClass.setpreviousRoom(currentRoom); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); Writer.print("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } }

Lap3/.git/objects/d2/8ae4ded823571d6380194161d105ebb753efe0

Lap3/.git/objects/d2/8ae4ded823571d6380194161d105ebb753efe0

blob 1968� /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public enum CommandEnum{ /** A constant array that holds all valid command words. */ //private static String[] validCommands; look, go, quit, help, status, back, examine, take, drop, inventory; /** * Static block to initialize the fields of CommandWords. */ // static { // String[] tempCommands = {"look","go", "quit", "help" }; // validCommands = tempCommands; // // } /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(CommandEnum aString) { return CommandWords.commandMap.containsValue(aString); } /** * Returns a list of the available commands, of the form: * your command words are: * look go quit help * * @return A string containing the list of available commands. */ public static String getCommandString(){ String commandString = ""; for(CommandEnum moh : CommandEnum.values()){ commandString += moh.name() + " "; } return commandString; //return getCommandString(); } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return CommandEnum.valueOf(theString); } }

Lap3/.git/objects/d2/7ebe18449050c9e6fb19044d12cad1dc252bd7

Lap3/.git/objects/d2/7ebe18449050c9e6fb19044d12cad1dc252bd7

blob 537� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. Bathroom there is teeth brush, shower place.Exiteast : You are in Bathroom there is teeth brush, shower place.Exiteast Exits: > go east Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest : You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest Exits: >

Lap3/.git/objects/aa/886682c92cb8fc389c1d3c496c9fa158146c64

Lap3/.git/objects/aa/886682c92cb8fc389c1d3c496c9fa158146c64

blob 974� /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; private Room previousRoom; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; previousRoom = null; } /** Accessor for the current room the character. * @return cerrentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ previousRoom = currentRoom; currentRoom = playing; } /** Accessor for the previous room the character. * @return cerrentRoom */ public Room getpreviousRoom(){ return previousRoom; } }

Lap3/.git/objects/aa/5347b62bfc16ef5875b980934596795f9ad4be

Lap3/.git/objects/aa/5347b62bfc16ef5875b980934596795f9ad4be

commit 234�tree a714e8145c5ce725636e8fbafc453b5e3c68d68b parent 4662788eea9e09d04bc0241270c52e050b506f37 author mohammedalharbi <[email protected]> 1523828244 -0400 committer mohammedalharbi <[email protected]> 1523828244 -0400 stage2

Lap3/.git/objects/de/1facec6d231cea9e52e1a0ec47d9736c198ff1

Lap3/.git/objects/de/1facec6d231cea9e52e1a0ec47d9736c198ff1

blob 4406�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**earn points */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** directions hash map with room item's keys and items values */ private HashMap<String,Item> roomItems = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The rooms name. * @param description * The rooms description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Returns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Return the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting the direction. */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoints */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Add Item * @param item - The item object to be added */ public void addItem(Item item) { roomItems.put(item.getName(), item); } /** * get Item * @param name - The name of the item to be added to the room * @return Item - The item in the collection with the key name */ public Item getItem(String name) { return roomItems.get(name); } /** * Remove Item * @param name - The name of the item to be removed from the room * @return item - The item that has been removed from the room */ public Item removeItem(String name) { Item item = roomItems.get(name); roomItems.remove(name); return item; } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = ""; roomInformation += getName() + " " + getDescription() + "\n"; roomInformation += "Exits : " ; for(String direction : directions.keySet()){ roomInformation += " " + direction; } roomInformation += "\nItems : "; for(String item : roomItems.keySet()){ roomInformation += " " + item + ", "; } return roomInformation; } }

Lap3/.git/objects/de/ce66fcccd1ef2e26b5c4c01b878650b3cb4aab

Lap3/.git/objects/de/ce66fcccd1ef2e26b5c4c01b878650b3cb4aab

blob 20731�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord.name()){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; case "examine": examineItem(command); break; case "take": takeItem(command); break; case "drop": dropItem(command); break; case "inventory": inventory(); break; case "lock": lock(command); break; case "unlock": unlock(command); break; case "pack": pack(command); break; case "unpack": unpack(command); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if(doorway.isLocked()){ Writer.println("door is locked!"); }else{ Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } } /** * Unlock a locked door. * * @param command * The command to be processed. */ private void unlock(Command command) { if (!command.hasSecondWord()) { Writer.println("Unlock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if (doorway.isLocked() == false) { Writer.println("Door is not locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(false); Writer.println("You unlocked it!"); }else{ Writer.println("That doesn't fit!"); } }else{ Writer.println("You don't have it!"); } } } } } /** * lock a locked door. * * @param command * The command to be processed. */ private void lock(Command command) { if (!command.hasSecondWord()) { Writer.println("Lock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("no door!"); } else { if (doorway.isLocked() == true) { Writer.println("Door is already locked!"); }else{ if(doorway.getKey() == null){ Writer.println("Door cannot be locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(true); Writer.println("You locked it!"); }else{ Writer.println("wrong key!!"); } }else{ Writer.println("You don't have it!"); } } } } } } /** * Try to examine a play item. If the item doesn't exist in the * players inventory nor the current room, * print an error message. * * @param command * The command to be processed. */ private void examineItem(Command command) { if (!command.hasSecondWord()) { Writer.println("Which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { Writer.println(item.toString()); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void takeItem(Command command) { if (!command.hasSecondWord()) { Writer.println("take what?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getcurrentRoom().getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy to lift"); }else{ if(playerClass.inventoryAddItem(itemName) == false){ Writer.println("Carrying too much"); }else{ playerClass.inventoryAddItem(itemName); playerClass.getcurrentRoom().removeItem(itemName); Writer.println("you took the item"); } } } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Writer.println("which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("you don't have it!"); } else { playerClass.getcurrentRoom().addItem(item); playerClass.removeItem(itemName); Writer.println("you dropped the item"); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param * The command to be processed. */ private void inventory() { Writer.println("Inventory :" + playerClass.getInventory()); } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } /** * Pack an item into. * * @param command * The command to be processed. */ private void pack(Command command) { if (!command.hasSecondWord()) { Writer.println("pack what?"); } else { String itemName = command.getRestOfLine(); //Get item from players inventory Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("you don't have!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy"); }else{ Writer.println("pack where?"); String containerString = Reader.getResponse(); Item container = playerClass.getItem(containerString); if(container == null){ container = playerClass.getcurrentRoom().getItem(containerString); } if(container != null){ if(container.isContainer()){ container.addItem(item); if(playerClass.getcurrentRoom().removeItem(itemName) != null || playerClass.removeItem(itemName) != null){ Writer.println("you packed it"); } }else{ Writer.println("that's not a container"); } }else{ Writer.println("You don't see the container"); } } } } } /** * Pack an item into. * * @param command * The command to be processed. */ private void unpack(Command command) { if (!command.hasSecondWord()) { Writer.println("unpack what?"); } else { String containerName = command.getRestOfLine(); //Get item from players inventory Item container = playerClass.getItem(containerName); //Check the item value has had something added, if no, check for the item in the current room if (container == null) { container = playerClass.getcurrentRoom().getItem(containerName); } //Check if item exists in the current room if (container == null) { Writer.println("you don't see it!"); } else { if(container.isContainer()){ Writer.println("which item?"); String itemName = Reader.getResponse(); Item item = container.getItem(itemName); if(item != null){ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.getMaxWeight()){ Writer.println("you are carrying too much"); }else{ playerClass.getcurrentRoom().addItem(item); playerClass.inventoryAddItem(itemName); container.removeItem(item.getName()); Writer.println("you unpacked it"); } }else{ Writer.println("you don't find it"); } }else{ Writer.println("that's not a container"); } } } } }

Lap3/.git/objects/b0/76b401c15f991a5b33018c7df67a0849344c10

Lap3/.git/objects/b0/76b401c15f991a5b33018c7df67a0849344c10

blob 3280� import java.util.HashMap; /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; private Room previousRoom; private Item currentWeapon; private int health; private int currentWeight; public static final int MAX_WEIGHT = 5000; private HashMap<String, Item> inventory; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; previousRoom = null; health = 100; currentWeapon = null; inventory = new HashMap<>(); currentWeight = 0; } public void updateHealth(int health){ this.health += health; } /** Add item to inventory. * @param item * @return true if item added to inventory */ public boolean inventoryAddItem(Item item){ inventory.put(item.getName(), item); return true; } /** * * @return current weight that the player is carrying */ public int getCurrentWeight(){ return currentWeight; } /** * * @return the maximum weight that the player can carry */ public int getMaxWeight(){ return MAX_WEIGHT; } /** Get an item from the players inventory. * @param itemName - name of item to be picked * @return an Item object */ public Item getItem(String itemName){ return inventory.get(itemName); } /** remove an item from the players inventory. * @param itemName - name of item to be removed * @return an Item object */ public Item removeItem(String itemName){ currentWeight -= getItem(itemName).getWeight(); return inventory.remove(itemName); } /** accessors for the current room the character. * @return currentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room of the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ previousRoom = currentRoom; currentRoom = playing; } /** a mutator for the current weapon of the character. * @param weapon to be equipped */ public void setCurrentWeapon(Item weapon){ currentWeapon = weapon; } /** Accessors for the previous room the character. * @return cerrentRoom */ public Room getpreviousRoom(){ return previousRoom; } /** Accessors for the players inventory. * @return players inventory */ public String getInventory(){ String inventoryInfo = ""; for(String s: inventory.keySet()){ inventoryInfo += " " + s +", "; } return inventoryInfo; } /** * * @return the players current weapon */ public Item getCurrentWeapon() { return currentWeapon; } }

Lap3/.git/objects/a6/e4dad9e5ae0283de0f00e2706eafe9e82929e5

Lap3/.git/objects/a6/e4dad9e5ae0283de0f00e2706eafe9e82929e5

Lap3/.git/objects/a6/2ed382a705487d7667dbe1cd664e4069257396

Lap3/.git/objects/a6/2ed382a705487d7667dbe1cd664e4069257396

commit 252�tree 33c652c2507d0cc360c76895d7f9d431365d070e parent 62aa1fe8f836c8e2f7db3d62521e70180bba71fc author mohammedalharbi <[email protected]> 1521574637 -0400 committer mohammedalharbi <[email protected]> 1521574637 -0400 deleted extar deucmnets

Lap3/.git/objects/b9/ba2854b88b29683955269e19276aa53866e618

Lap3/.git/objects/b9/ba2854b88b29683955269e19276aa53866e618

blob 553�/** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public interface Equippable { /** * equip. * @param p The current player instance * @return message */ public String equip(Player p); /** * unequip. * @param p - The current player instance * @return message */ public String unequip(Player p); }

Lap3/.git/objects/a1/601613046aebd97f4e4e91ebf23c9b8a2ef9ef

Lap3/.git/objects/a1/601613046aebd97f4e4e91ebf23c9b8a2ef9ef

blob 2663� import java.util.HashMap; /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; private Room previousRoom; public static final int MAX_WEIGHT = 5000; private int currentWeight; private HashMap<String, Item> inventory; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; previousRoom = null; inventory = new HashMap<>(); currentWeight = 0; } /** Add item to inventory. * @param itemName to be added */ public boolean inventoryAddItem(String itemName){ boolean added = false; if(currentWeight + currentRoom.getItem(itemName).getWeight() <= MAX_WEIGHT ){ inventory.put(itemName, currentRoom.getItem(itemName)); currentWeight += currentRoom.getItem(itemName).getWeight(); added = true; } return added; } /** Get an item from the players inventory. * @param itemName - name of item to be picked * @return an Item object */ public Item getItem(String itemName){ return inventory.get(itemName); } /** remove an item from the players inventory. * @param itemName - name of item to be removed * @return an Item object */ public Item removeItem(String itemName){ currentWeight -= getItem(itemName).getWeight(); return inventory.remove(itemName); } /** accessors for the current room the character. * @return currentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ previousRoom = currentRoom; currentRoom = playing; } /** Accessors for the previous room the character. * @return cerrentRoom */ public Room getpreviousRoom(){ return previousRoom; } /** Accessors for the players inventory. * @return players inventory */ public String getInventory(){ String inventoryInfo = ""; for(String s: inventory.keySet()){ inventoryInfo += " " + s +", "; } return inventoryInfo; } }

Lap3/.git/objects/ef/4a862ad21a9d312eb07a0da38c59e018a11839

Lap3/.git/objects/ef/4a862ad21a9d312eb07a0da38c59e018a11839

blob 7251�import java.util.HashMap; /** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; /** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; //Playing = Playing; // set the starting room //Room out = world.getcurrentRoom("Bathroom"); //Playing = new Player(out); } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { boolean wantToQuit = false; if (command.isUnknown()) { Writer.println("I don't know what you mean..."); } else { String commandWord = command.getCommandWord(); if (commandWord.equals("help")) { printHelp(); } else if (commandWord.equals("go")) { goGame(command); } else if (commandWord.equals("quit")) { wantToQuit = quit(command); } else { Writer.println(commandWord + " is not implemented yet!"); } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; if (direction.equals("north")) { doorway = playerClass.getcurrentRoom().getExit("north"); } if (direction.equals("east")) { doorway = playerClass.getcurrentRoom().getExit("east"); } if (direction.equals("south")) { doorway = playerClass.getcurrentRoom().getExit("south"); } if (direction.equals("west")) { doorway = playerClass.getcurrentRoom().getExit("west"); } if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); printLocationInformation (); } } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are " + playerClass.getcurrentRoom()); Writer.print("Exits: "); if (playerClass.getcurrentRoom().getExit("north") != (null)) { Writer.print("north "); } if (playerClass.getcurrentRoom().getExit("east") != null) { Writer.print("east "); } if (playerClass.getcurrentRoom().getExit("south") != null) { Writer.print("south "); } if (playerClass.getcurrentRoom().getExit("west") != null) { Writer.print("west "); } Writer.println(); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println("go quit help"); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); if (playerClass.getcurrentRoom().getExit("east") != null) { Writer.print("east"); } if (playerClass.getcurrentRoom().getExit("west") != null) { Writer.print("west"); } if (playerClass.getcurrentRoom().getExit("south") != null) { Writer.print("south"); } if (playerClass.getcurrentRoom().getExit("north") != null) { Writer.print("north"); } //Writer.println(); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } }

Lap3/.git/objects/c3/dcd1a4366826424a9e8dd2bff1b9c48e0498a4

Lap3/.git/objects/c3/dcd1a4366826424a9e8dd2bff1b9c48e0498a4

blob 424� /** * * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor * @author mohammed alharbi * @version 29/4/2018 * */ public interface Drinkable { /** * interfacr drinkable. * @param drinkName the drinkName. * @return true */ public boolean drink(String drinkName); }

Lap3/.git/objects/ea/f341e2bcca863da1f698356ed5cea5dd8468e4

Lap3/.git/objects/ea/f341e2bcca863da1f698356ed5cea5dd8468e4

blob 2535�/* * Class Item - An item in the game that the player can * pick or drop * The class also describe items in the game by their name, weight etc */ /** * Class Item - An item in the game that the player can * pick or drop. * The class also describe items in the game by their name, weight etc * * @author Mohammed Alharbi * @version 2018/4/24 */ public class Item { /** the name. */ private String name; /** the description. */ private String description; /** the pointValue . */ private int weight; /** the weight. */ private int pointVal; /** item. * @param name the name. * @param pointValue the pointValue * @param description the description * @param weight the weight */ public Item(String name, int pointValue, String description, int weight) { this.name = name; this.description = description; this.pointVal = pointValue; this.weight = weight; } /** * * Returns the name of an item. * @return The name of an item. * **/ public String getName(){ return name; } /** * * Returns the description of an item. * @return The description of an item. * **/ public String getDescription(){ return description; } /** * * Sets the description of a room. *@param desc the desc. **/ public void setDescription(String desc){ description = desc; } /** item. *@param item the item. */ public void addItem(Item item){ } /** item. *@param item the item. *@return item the item. */ public Item removeItem(String item){ return null; } /** item. *@param item the item. *@return item the item. */ public Item getItem(String item){ return null; } /** * * Returns the pointValue of an item. * @return The pointValue of an item. * **/ public int getPointValue(){ return pointVal; } /** * * Returns the weight of an item. * @return The weight of an item. * **/ public int getWeight(){ return weight; } @Override public String toString(){ String itemInfo = ""; itemInfo += "Name : " + getName() + "\n"; itemInfo += "Description : " + getDescription() + "\n"; itemInfo += "Weight : " + getWeight() + "grams"; return itemInfo; } }

Lap3/.git/objects/f9/710ab3d4044c8a956b1e27eb91806ce2157289

Lap3/.git/objects/f9/710ab3d4044c8a956b1e27eb91806ce2157289

blob 25088�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Get current player playing the game. * @return current player */ public Player getCurrentPlayer(){ return playerClass; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord){ case help: printHelp(); break; case go: goGame(command); break; case look: look(); break; case quit: wantToQuit = quit(command); break; case status: printGameStatus(); break; case back: goBack(); break; case examine: examineItem(command); break; case take: takeItem(command); break; case drop: dropItem(command); break; case inventory: inventory(); break; case lock: lock(command); break; case unlock: unlock(command); break; case pack: pack(command); break; case unpack: unpack(command); break; case eat: eat(command); break; case drink: drink(command); break; case equip: equip(command); break; case unequip: unequip(command); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if(doorway.isLocked()){ Writer.println("door is locked!"); }else{ Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } } /** * Unlock a locked door. * * @param command * The command to be processed. */ private void unlock(Command command) { if (!command.hasSecondWord()) { Writer.println("Unlock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if (doorway.isLocked() == false) { Writer.println("Door is not locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(false); Writer.println("You unlocked it!"); }else{ Writer.println("That doesn't fit!"); } }else{ Writer.println("You don't have it!"); } } } } } /** * lock a locked door. * * @param command * The command to be processed. */ private void lock(Command command) { if (!command.hasSecondWord()) { Writer.println("Lock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("no door!"); } else { if (doorway.isLocked() == true) { Writer.println("Door is already locked!"); }else{ if(doorway.getKey() == null){ Writer.println("Door cannot be locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(true); Writer.println("You locked it!"); }else{ Writer.println("wrong key!!"); } }else{ Writer.println("You don't have it!"); } } } } } } /** * Try to examine a play item. If the item doesn't exist in the * players inventory nor the current room, * print an error message. * * @param command * The command to be processed. */ private void examineItem(Command command) { if (!command.hasSecondWord()) { Writer.println("Which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { Writer.println(item.toString()); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void takeItem(Command command) { if (!command.hasSecondWord()) { Writer.println("take what?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getcurrentRoom().getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy to lift"); }else{ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("Carrying too much"); }else{ playerClass.inventoryAddItem(item); playerClass.getcurrentRoom().removeItem(itemName); Writer.println("you took the item"); } } } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Writer.println("which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("you don't have it!"); } else { playerClass.getcurrentRoom().addItem(item); playerClass.removeItem(itemName); Writer.println("you dropped the item"); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * The command to be processed. */ private void inventory() { Writer.println("Inventory :" + playerClass.getInventory()); } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university.\n"); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Writer.println("\nWelcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help.\n"); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } /** * Pack an item into. * * @param command * The command to be processed. */ private void pack(Command command) { if (!command.hasSecondWord()) { Writer.println("pack what?"); } else { String itemName = command.getRestOfLine(); //Get item from players inventory Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("you don't have!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy"); }else{ Writer.println("pack where?"); String containerString = Reader.getResponse(); Item container = playerClass.getItem(containerString); if(container == null){ container = playerClass.getcurrentRoom().getItem(containerString); } if(container != null){ if(container instanceof Container){ container.addItem(item); if(playerClass.getcurrentRoom().removeItem(itemName) != null || playerClass.removeItem(itemName) != null){ Writer.println("you packed it"); } }else{ Writer.println("that's not a container"); } }else{ Writer.println("You don't see the container"); } } } } } /** * Pack an item into. * * @param command * The command to be processed. */ private void unpack(Command command) { if (!command.hasSecondWord()) { Writer.println("unpack what?"); } else { String containerName = command.getRestOfLine(); //Get item from players inventory Item container = playerClass.getItem(containerName); //Check the item value has had something added, if no, check for the item in the current room if (container == null) { container = playerClass.getcurrentRoom().getItem(containerName); } //Check if item exists in the current room if (container == null) { Writer.println("you don't see it!"); } else { if(container instanceof Container){ Writer.println("which item?"); String itemName = Reader.getResponse(); Item item = container.getItem(itemName); if(item != null){ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.getMaxWeight()){ Writer.println("you are carrying too much"); }else{ playerClass.inventoryAddItem(item); container.removeItem(item.getName()); Writer.println("you unpacked it"); } }else{ Writer.println("you don't find it"); } }else{ Writer.println("that's not a container"); } } } } /** * eat. * @param command the command. * */ private void eat(Command command){ if (!command.hasSecondWord()) { Writer.println("Eat what?"); } else { String foodName = command.getRestOfLine(); //Get item from players inventory Item food = playerClass.getItem(foodName); //Check if item exists if (food == null) { Writer.println("you don't have it!"); }else{ if(food instanceof Food == false){ Writer.println("item is not food!"); }else{ Edible ed = (Edible) food; Writer.println(ed.eat(playerClass)); } } } } /** * drink. * @param command the command. */ private void drink(Command command){ if (!command.hasSecondWord()) { Writer.println("drink what?"); } else { String drinkName = command.getRestOfLine(); //Get item from players inventory Item drink = playerClass.getItem(drinkName); if (drink == null) { Writer.println("you don't have it!"); }else{ if(drink instanceof Drink == false){ Writer.println("item is not drink!"); }else{ Drinkable dr = (Drinkable) drink; Writer.println(dr.drink(playerClass)); } } } } /** * equip. * @param command the command. */ private void equip(Command command) { if (!command.hasSecondWord()) { Writer.println("equip what?"); } else { String weaponName = command.getRestOfLine(); Item weapon = playerClass.getcurrentRoom().getItem(weaponName); //Check if item exists in the current room if (weapon == null) { Writer.println("you don't see it!"); }else{ if(weapon instanceof Weapon == false){ Writer.println("item is not a weapon!"); }else{ Equippable eq = (Equippable) weapon; Writer.println(eq.equip(playerClass)); } } } } /** * unequip . * @param command the command. */ private void unequip(Command command) { if (!command.hasSecondWord()) { Writer.println("unequip what?"); } else { String weaponName = command.getRestOfLine(); Item weapon = playerClass.getCurrentWeapon(); //Check if item exists in the current room if (!weapon.getName().equals(weaponName)) { Writer.println("weapon is not equipped!"); }else{ Equippable eq = (Equippable) weapon; Writer.println(eq.unequip(playerClass)); } } } }

Lap3/.git/objects/f9/ac9dd8c65564815fd28d65be0d078afb141b56

Lap3/.git/objects/f9/ac9dd8c65564815fd28d65be0d078afb141b56

blob 2899�import java.util.ArrayList; import java.util.Scanner; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This parser reads user input and tries to interpret it as an "Adventure" * command. Every time it is called it reads a line from the terminal and tries * to interpret the line as a two word command. It returns the command as an * object of class Command. * * The parser has a set of known command words. It checks user input against the * known commands, and if the input is not one of the known commands, it returns * a command object that is marked as an unknown command. * * @author Maria Jump * @version 2017.12.18 */ public class Reader { /** The source of command input. */ private static Scanner reader; /** * Create a parser to read from the terminal window. */ static { reader = new Scanner(System.in); } /** * Returns the next command from the user. * @return The next command from the user. */ public static Command getCommand() { String inputLine; // will hold the full input line String word1 = null; ArrayList<String> restOfLine = null; Writer.print("> "); // print prompt inputLine = reader.nextLine().toLowerCase(); Writer.printInput(inputLine); // Find up to two words on the line. Scanner tokenizer = new Scanner(inputLine); if (tokenizer.hasNext()) { word1 = tokenizer.next(); // get first word if (tokenizer.hasNext()) { restOfLine = new ArrayList<String>(); while(tokenizer.hasNext()) { restOfLine.add(tokenizer.next()); } } } tokenizer.close(); // Now check whether this word is known. If so, create a command // with it. If not, create a "null" command (for unknown command). Command result = null; CommandEnum command = CommandWords.getCommand(word1); if (CommandEnum.isCommand(command)) { result = new Command(word1, restOfLine); } else { result = new Command(null, restOfLine); } //Command result = CommandWords.getCommand(word1); return result; } /** * Return the response to a question in all lower case. * * @return The response typed in by the user. */ public static String getResponse() { return getResponseKeepCase().toLowerCase(); } /** * Return the response to a question in the case used by the player. * * @return The response typed in by the user. */ public static String getResponseKeepCase() { String response = reader.nextLine().trim(); Writer.printInput(response); return response; } }

Lap3/.git/objects/fa/c2bdbea69b09b30bfbaedc75bbb4186e2908ba

Lap3/.git/objects/fa/c2bdbea69b09b30bfbaedc75bbb4186e2908ba

blob 776�/** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public class Food extends Item implements Edible{ /** * food. * @param name the name. * @param pointValue the pointValue. * @param description teh description. * @param weight teh weight. */ public Food(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); } @Override public String eat(Player p) { p.updateHealth(5); p.removeItem(this.getName()); return "you have eaten food"; } }

Lap3/.git/objects/c2/e9a520d044f09221a71a769adbe400f1dafcb9

Lap3/.git/objects/c2/e9a520d044f09221a71a769adbe400f1dafcb9

commit 234�tree a6e4dad9e5ae0283de0f00e2706eafe9e82929e5 parent aa5347b62bfc16ef5875b980934596795f9ad4be author mohammedalharbi <[email protected]> 1524233532 -0400 committer mohammedalharbi <[email protected]> 1524233532 -0400 stage3

Lap3/.git/objects/f6/4716c70f4f457505fa1a29287fbf5d268b6c4e

Lap3/.git/objects/f6/4716c70f4f457505fa1a29287fbf5d268b6c4e

blob 22568�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * player. * @return Player. */ public Player getCurrentPlayer(){ return playerClass; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord.name()){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; case "examine": examineItem(command); break; case "take": takeItem(command); break; case "drop": dropItem(command); break; case "inventory": inventory(); break; case "lock": lock(command); break; case "unlock": unlock(command); break; case "pack": pack(command); break; case "unpack": unpack(command); break; case "eat": eat(command); break; case "drink": drink(command); break; case "equip": equip(command); break; case "unequip": unequip(command); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if(doorway.isLocked()){ Writer.println("door is locked!"); }else{ Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } } /** * Unlock a locked door. * * @param command * The command to be processed. */ private void unlock(Command command) { if (!command.hasSecondWord()) { Writer.println("Unlock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { if (doorway.isLocked() == false) { Writer.println("Door is not locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(false); Writer.println("You unlocked it!"); }else{ Writer.println("That doesn't fit!"); } }else{ Writer.println("You don't have it!"); } } } } } /** * lock a locked door. * * @param command * The command to be processed. */ private void lock(Command command) { if (!command.hasSecondWord()) { Writer.println("Lock what?"); } else { String direction = command.getRestOfLine(); Door doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("no door!"); } else { if (doorway.isLocked() == true) { Writer.println("Door is already locked!"); }else{ if(doorway.getKey() == null){ Writer.println("Door cannot be locked!"); }else{ Writer.println("With what?"); String key = Reader.getResponse(); if(playerClass.getItem(key) != null){ if(doorway.getKey() == playerClass.getItem(key)){ doorway.setLocked(true); Writer.println("You locked it!"); }else{ Writer.println("wrong key!!"); } }else{ Writer.println("You don't have it!"); } } } } } } /** * Try to examine a play item. If the item doesn't exist in the * players inventory nor the current room, * print an error message. * * @param command * The command to be processed. */ private void examineItem(Command command) { if (!command.hasSecondWord()) { Writer.println("Which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { Writer.println(item.toString()); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void takeItem(Command command) { if (!command.hasSecondWord()) { Writer.println("take what?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getcurrentRoom().getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy to lift"); }else{ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("Carrying too much"); }else{ playerClass.inventoryAddItem(item); playerClass.getcurrentRoom().removeItem(itemName); Writer.println("you took the item"); } } } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Writer.println("which item?"); } else { String itemName = command.getRestOfLine(); Item item = playerClass.getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("you don't have it!"); } else { playerClass.getcurrentRoom().addItem(item); playerClass.removeItem(itemName); Writer.println("you dropped the item"); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * The command to be processed. */ private void inventory() { Writer.println("Inventory :" + playerClass.getInventory()); } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } /** * Pack an item into. * * @param command * The command to be processed. */ private void pack(Command command) { if (!command.hasSecondWord()) { Writer.println("pack what?"); } else { String itemName = command.getRestOfLine(); //Get item from players inventory Item item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("you don't have!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy"); }else{ Writer.println("pack where?"); String containerString = Reader.getResponse(); Item container = playerClass.getItem(containerString); if(container == null){ container = playerClass.getcurrentRoom().getItem(containerString); } if(container != null){ if(container instanceof Container){ container.addItem(item); if(playerClass.getcurrentRoom().removeItem(itemName) != null || playerClass.removeItem(itemName) != null){ Writer.println("you packed it"); } }else{ Writer.println("that's not a container"); } }else{ Writer.println("You don't see the container"); } } } } } /** * Pack an item into. * * @param command * The command to be processed. */ private void unpack(Command command) { if (!command.hasSecondWord()) { Writer.println("unpack what?"); } else { String containerName = command.getRestOfLine(); //Get item from players inventory Item container = playerClass.getItem(containerName); //Check the item value has had something added, if no, check for the item in the current room if (container == null) { container = playerClass.getcurrentRoom().getItem(containerName); } //Check if item exists in the current room if (container == null) { Writer.println("you don't see it!"); } else { if(container instanceof Container){ Writer.println("which item?"); String itemName = Reader.getResponse(); Item item = container.getItem(itemName); if(item != null){ if(playerClass.getCurrentWeight() + item.getWeight() > playerClass.getMaxWeight()){ Writer.println("you are carrying too much"); }else{ playerClass.inventoryAddItem(item); container.removeItem(item.getName()); Writer.println("you unpacked it"); } }else{ Writer.println("you don't find it"); } }else{ Writer.println("that's not a container"); } } } } /** * eat. * @param command the command. * */ private void eat(Command command){ if (!command.hasSecondWord()) { Writer.println("Eat what?"); } else { String foodName = command.getRestOfLine(); //Get item from players inventory Item food = playerClass.getItem(foodName); //Check the item value has had something added, if no, check for the item in the current room if (food == null) { food = playerClass.getcurrentRoom().getItem(foodName); } //Check if item exists in the current room if (food == null) { Writer.println("you don't see it!"); }else{ if(food instanceof Food == false){ Writer.println("item is not food!"); }else{ if(playerClass.getcurrentRoom().removeItem(foodName) == null){ playerClass.removeItem(foodName); } Writer.println("You have eaten food"); } } } } /** * drink. * @param command the command. */ private void drink(Command command){ if (!command.hasSecondWord()) { Writer.println("drink what?"); } else { String drinkName = command.getRestOfLine(); //Get item from players inventory Item drink = playerClass.getItem(drinkName); //Check the item value has had something added, if no, check for the item in the current room if (drink == null) { drink = playerClass.getcurrentRoom().getItem(drinkName); } //Check if item exists in the current room if (drink == null) { Writer.println("you don't see it!"); }else{ if(drink instanceof Drink == false){ Writer.println("item is not drink!"); }else{ if(playerClass.getcurrentRoom().removeItem(drinkName) == null){ playerClass.removeItem(drinkName); } Writer.println("You have taken a drink"); } } } } /** * equip. * @param command the command. */ private void equip(Command command) { if (!command.hasSecondWord()) { Writer.println("equip what?"); } else { String weaponName = command.getRestOfLine(); Item weapon = playerClass.getcurrentRoom().getItem(weaponName); //Check if item exists in the current room if (weapon == null) { Writer.println("you don't see it!"); }else{ if(weapon instanceof Weapon == false){ Writer.println("item is not a weapon!"); }else{ Weapon dire = new Weapon(weapon.getName(), weapon.getPointValue(), weapon.getDescription(), weapon.getWeight()); playerClass.getcurrentRoom().removeItem(weaponName); playerClass.inventoryAddItem(weapon); Writer.println(dire.equip(weaponName)); } } } } /** * unequip . * @param command the command. */ private void unequip(Command command) { if (!command.hasSecondWord()) { Writer.println("unequip what?"); } else { String weaponName = command.getRestOfLine(); Item weapon = playerClass.getItem(weaponName); //Check if item exists in the current room if (weapon == null) { Writer.println("you don't have it!"); }else{ if(weapon instanceof Weapon == false){ Writer.println("item is not a weapon!"); }else{ Weapon dire = new Weapon(weapon.getName(), weapon.getPointValue(), weapon.getDescription(), weapon.getWeight()); playerClass.getcurrentRoom().addItem(weapon); playerClass.removeItem(weaponName); Writer.println(dire.unequip(weaponName)); } } } } }

Lap3/.git/objects/cb/94cd5a184fc6660b2fa1c0d0dbabf7d2705f27

Lap3/.git/objects/cb/94cd5a184fc6660b2fa1c0d0dbabf7d2705f27

blob 699� /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; /** constructor in the Player class. * @param playPlayer for the room . */ public Player(Room playPlayer){ currentRoom = playPlayer; } /** accessor for the current room the character. * @return cerrentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param playing for the Room */ public void setcurrentRoom(Room playing){ currentRoom = playing; } }

Lap3/.git/objects/ce/d34a3ac2268fb3e968bf103c63941d9f28e45b

Lap3/.git/objects/ce/d34a3ac2268fb3e968bf103c63941d9f28e45b

blob 1008�/** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * * @author mohammed alharbi * @version 29/4/2018 */ public class Weapon extends Item implements Equippable{ /** * weapon. * @param name the name * @param pointValue the pointValue. * @param description teh description. * @param weight teh weight. */ public Weapon(String name, int pointValue, String description, int weight) { super(name, pointValue, description, weight); } @Override public String equip(Player p) { p.setCurrentWeapon(this); p.removeItem(this.getName()); return "weapon equiped"; } @Override public String unequip(Player p) { p.inventoryAddItem(this); p.setCurrentWeapon(null); return "weapon unequipped"; } }

Lap3/.git/objects/46/62788eea9e09d04bc0241270c52e050b506f37

Lap3/.git/objects/46/62788eea9e09d04bc0241270c52e050b506f37

commit 232�tree 764157d1f431efb74da95a21e2beaeb1ad1257ca parent c49849e8c3f66c6936ab6ccff8659cbd2299d069 author mohammedalharbi <[email protected]> 1523496155 -0400 committer mohammedalharbi <[email protected]> 1523496155 -0400 lap3

Lap3/.git/objects/79/432f8e5c7112086a4c464cd6305c29175cfa05

Lap3/.git/objects/79/432f8e5c7112086a4c464cd6305c29175cfa05

blob 5362� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. Bathroom there is teeth brush, shower place.Exiteast : You are in Bathroom there is teeth brush, shower place.Exiteast Exits: > go east Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest : You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room..ExitsouthExitwest Exits: > go south out Of The House the way outside the house to drive to university..ExitnorthExitwest : You are in out Of The House the way outside the house to drive to university..ExitnorthExitwest Exits: > go west Car inside the car, back bag, car key with house key..ExiteastExitsouth : You are in Car inside the car, back bag, car key with house key..ExiteastExitsouth Exits: > go south keep Street the correct way.ExitsouthExitnorthExitwest : You are in keep Street the correct way.ExitsouthExitnorthExitwest Exits: > go east There is no door! > go west Turn left wrong way to go with it..ExiteastExitsouth : You are in Turn left wrong way to go with it..ExiteastExitsouth Exits: > go east keep Street the correct way.ExitsouthExitnorthExitwest : You are in keep Street the correct way.ExitsouthExitnorthExitwest Exits: > go east There is no door! > go west Turn left wrong way to go with it..ExiteastExitsouth : You are in Turn left wrong way to go with it..ExiteastExitsouth Exits: > go south End of the road closed way.Exitnorth : You are in End of the road closed way.Exitnorth Exits: > go north Turn left wrong way to go with it..ExiteastExitsouth : You are in Turn left wrong way to go with it..ExiteastExitsouth Exits: > go west There is no door! > go east keep Street the correct way.ExitsouthExitnorthExitwest : You are in keep Street the correct way.ExitsouthExitnorthExitwest Exits: > go east There is no door! > go east There is no door! > go south Gas Staion the way to traffic signal.ExiteastExitnorth : You are in Gas Staion the way to traffic signal.ExiteastExitnorth Exits: > go east Traffic signal there are three different ways.ExiteastExitsouthExitnorthExitwest : You are in Traffic signal there are three different ways.ExiteastExitsouthExitnorthExitwest Exits: > go east KeepGoing almost arrive to university.ExiteastExitwest : You are in KeepGoing almost arrive to university.ExiteastExitwest Exits: > go east Parking there is a meter parking, 2$ in Hour.ExitsouthwestExitsouthExitwest : You are in Parking there is a meter parking, 2$ in Hour.ExitsouthwestExitsouthExitwest Exits: > go south Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast : You are in Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast Exits: > go south A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest : You are in A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest Exits: > go south There is no door! > go north Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast : You are in Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast Exits: > go east Hall Campus the building for men.Exitwest : You are in Hall Campus the building for men.Exitwest Exits: > go weat There is no door! > go north There is no door! > go south There is no door! > go west Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast : You are in Square the place in the middle of the university, and from there the player can go any building.ExiteastExitsouthExitnorthExitwestExitsoutheast Exits: > go south A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest : You are in A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest Exits: > go south There is no door! > go east There is no door! > go west Stairs take the player until fourth floor.ExiteastExitsouth : You are in Stairs take the player until fourth floor.ExiteastExitsouth Exits: > go west There is no door! > go east A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest : You are in A Building : the goal to reach the class, stairs, elevator, classroom.ExitsouthwestExitnorthExitwest Exits: > go west Stairs take the player until fourth floor.ExiteastExitsouth : You are in Stairs take the player until fourth floor.ExiteastExitsouth Exits: > go south 2Floor entry for classesExiteastExitsouthExitnorthExitsoutheast : You are in 2Floor entry for classesExiteastExitsouthExitnorthExitsoutheast Exits: > go southeast Classroom201 you reach the goal.Exitnorthwest : You are in Classroom201 you reach the goal.Exitnorthwest Exits: > quit I hope you weren't too bored here on the Campus of Kings! Thank you for playing. Good bye. You have earned 114points in 38 turns.

Lap3/.git/objects/1b/cd36d194be9075d3772e4259f78b86d865260f

Lap3/.git/objects/1b/cd36d194be9075d3772e4259f78b86d865260f

blob 9402�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author mohammed alharbi * @version 20/2/2018 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms. * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from The room where the door originated. * @param direction The direction of the door in the from room. * @param to The room where the door goes. */ private void createDoor(Room from, String direction, Room to){ Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room outOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); outOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room car = new Room("Car", "inside the car, back bag, car key with house key.."); car.setPoints(7); pointScore = pointScore + 7; Room keepStreet = new Room(" keep Street", "the correct way."); Room turnLeft = new Room("Turn left", "wrong way to go with it.."); Room endOfTheRoad = new Room("End of the road", "closed way."); Room gasStaion = new Room("Gas Staion", "the way to traffic signal."); Room trafficSignal = new Room("Traffic signal", "there are three different ways."); trafficSignal.setPoints(10); pointScore = pointScore + 10; Room turnLeft2 = new Room("Turn left2", "maybe not the right way."); Room wrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room turnRight = new Room("Turn right"," more traffic."); Room closedWay = new Room("Closed Way","no place to go."); Room keepGoing = new Room("KeepGoing","almost arrive to university."); keepGoing.setPoints(10); pointScore = pointScore + 10; Room parking = new Room("Parking","there is a meter parking, 2$ in Hour."); parking.setPoints(17); pointScore = pointScore + 17; Room library = new Room("Library","some books, students, printer, computers."); Room campusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room hallCampus = new Room("Hall Campus","the building for men."); Room hBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); square.setPoints(12); pointScore = pointScore + 12; Room mCBuilding = new Room("MCBuilding"," Classes, six floors."); Room aBuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room stairs = new Room("Stairs","take the player until fourth floor."); stairs.setPoints(18); pointScore = pointScore + 18; Room elevator = new Room("Elevator","take the player until fourth floor."); Room floor2 = new Room("2Floor","entry for classes"); Room classroom = new Room("Classroom","one door, blackboard, tables"); Room classroom201 = new Room ("Classroom201","you reach the goal."); classroom201.setPoints(30); pointScore = pointScore + 30; Room classroom204 = new Room("Classroom204","one door, students."); Room classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(bathroom); this.addRoom(kitchen); this.addRoom(outOfTheHouse); this.addRoom(car); this.addRoom(keepStreet); this.addRoom(turnLeft); this.addRoom(endOfTheRoad); this.addRoom(gasStaion); this.addRoom(trafficSignal); this.addRoom(turnLeft2); this.addRoom(wrongWay); this.addRoom(turnRight); this.addRoom(closedWay); this.addRoom(keepGoing); this.addRoom(parking); this.addRoom(library); this.addRoom(campusCenter); this.addRoom(hallCampus); this.addRoom(hBuilding); this.addRoom(square); this.addRoom(mCBuilding); this.addRoom(aBuilding); this.addRoom(stairs); this.addRoom(elevator); this.addRoom(floor2); this.addRoom(classroom); this.addRoom(classroom201); this.addRoom(classroom204); this.addRoom(classroom202); // Creating all the doors between the rooms. this.createDoor(bathroom,"east",kitchen); this.createDoor(kitchen, "west",bathroom); this.createDoor(kitchen,"south", outOfTheHouse); this.createDoor(outOfTheHouse,"north", kitchen); this.createDoor(outOfTheHouse,"west",car); this.createDoor(car,"east",outOfTheHouse); this.createDoor(car,"south",keepStreet); this.createDoor(keepStreet,"north",car); this.createDoor(keepStreet,"west",turnLeft); this.createDoor(turnLeft,"east",keepStreet); this.createDoor(turnLeft,"south", endOfTheRoad); this.createDoor(endOfTheRoad,"north",turnLeft); this.createDoor(keepStreet,"south",gasStaion); this.createDoor(gasStaion, "north",keepStreet); this.createDoor(gasStaion,"east",trafficSignal); this.createDoor(trafficSignal,"west", gasStaion); this.createDoor(trafficSignal,"north",turnLeft2); this.createDoor(turnLeft2,"south",trafficSignal); this.createDoor(turnLeft2,"north", wrongWay); this.createDoor(wrongWay,"south",turnLeft2); this.createDoor(trafficSignal,"south", turnRight); this.createDoor(turnRight,"north", trafficSignal); this.createDoor(turnRight,"south",closedWay); this.createDoor(closedWay,"north", turnRight); this.createDoor(trafficSignal,"east", keepGoing); this.createDoor(keepGoing, "west",trafficSignal); this.createDoor(keepGoing,"east", parking); this.createDoor(parking,"west",keepGoing); this.createDoor(parking,"southwest",library); this.createDoor(library, "northeast",parking); this.createDoor(library,"east", campusCenter); this.createDoor(campusCenter,"west",library); this.createDoor(parking,"south",square); this.createDoor(square,"north",parking); this.createDoor(square,"east", hallCampus); this.createDoor(hallCampus,"west",square); this.createDoor(square,"west",hBuilding); this.createDoor(hBuilding,"east",square); this.createDoor(square, "southeast",mCBuilding); this.createDoor(mCBuilding,"northwest",square); this.createDoor(square,"south",aBuilding); this.createDoor(aBuilding,"north",square); this.createDoor(aBuilding,"west",stairs); this.createDoor(stairs,"east",aBuilding); this.createDoor(aBuilding,"southwest",classroom); this.createDoor(classroom,"northeast",aBuilding); this.createDoor(aBuilding,"southwest",elevator); this.createDoor(elevator,"northeast",aBuilding); this.createDoor(elevator,"west",floor2); this.createDoor(floor2,"east",elevator); this.createDoor(stairs,"south",floor2); this.createDoor(floor2,"north",stairs); this.createDoor(floor2,"south",classroom204); this.createDoor(classroom204,"north",floor2); this.createDoor(floor2,"east",classroom202); this.createDoor(classroom202,"west",floor2); this.createDoor(floor2,"southeast",classroom201); this.createDoor(classroom201,"northwest",floor2); } }

Lap3/.git/objects/1b/d123b90cefdb98ffd99439dba37ad124da5b9a

Lap3/.git/objects/1b/d123b90cefdb98ffd99439dba37ad124da5b9a

blob 1901� import java.util.HashMap; import java.util.Map; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds an enumeration of all command words known to the game. It is * used to recognize commands as they are typed in. * * @author Maria Jump * @version 2015.02.01 */ public class CommandWords { static Map<String, CommandEnum> commandMap; /** A constant array that holds all valid command words. */ /** * Static block to initialize the fields of CommandWords. **/ static { commandMap = new HashMap<>(); CommandEnum.validCommands[] tempCommands = CommandEnum.validCommands.values(); for(CommandEnum.validCommands s: tempCommands){ commandMap.put(s.name(), CommandEnum.getCommand(s.name())); } } /** * Check whether a given String is a valid command word. * * @param aString The string to determine whether it is a valid command. * @return true if a given string is a valid command, false if it isn't. */ public static boolean isCommand(String aString) { boolean valid = false; for(CommandEnum.validCommands command: CommandEnum.validCommands.values()){ if(command.name().equals(aString)){ //System.out.println(aString + "" + command.name()); valid = true; } //System.out.println(aString + "" + command.name()); } return valid; } /** * Converts a String into a CommandEnum object. * @param theString The String containing the command word. * @return The CommandEnum object representing the command, or null if the command does not exist. */ public static CommandEnum getCommand( String theString){ return commandMap.get(theString); } }

Lap3/.git/objects/23/ecd84efcaeaa901fd60738fb969aff9bc68860

Lap3/.git/objects/23/ecd84efcaeaa901fd60738fb969aff9bc68860

Lap3/.git/objects/4f/0bc3ec6bf8eaed327f3803fe8f9a447bf18d20

Lap3/.git/objects/4f/0bc3ec6bf8eaed327f3803fe8f9a447bf18d20

blob 16060�// Original commands from the game (alphabetical) GO Scenario #1: No direction specified GIVEN : WHEN : "go" is entered THEN: appropriate message is displayed (which direction?) GO Scenario #2: No exit exists GIVEN : there is no exit in the given direction WHEN : "go direction" is entered THEN : appropriate message is displayed (no door) GO Scenario #3: Exit exists GIVEN : there is an exit in the given direction WHEN : "go direction" is entered THEN : player's current room is changed to the room in the given direction and : the current room's points are added to the player's score and : player's current location is displayed HELP Scenario #1: GIVEN : WHEN : "help" is entered THEN : available commands are displayed SCORE Scenario #1: GIVEN : WHEN : "score" is entered THEN : player's current score is displayed TURNS Scenario #1: GIVEN : WHEN : "turns" is entered THEN : current number of turns is displayed to the screen QUIT Scenario #1: GIVEN : WHEN : "quit" is entered THEN : appropriate message is displayed (thanks for playing) and : program quits /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 2 (alphabetical) BACK Scenario #1: no previous room GIVEN : there is no previous room WHEN : "back" is entered THEN : appropriate message is displayed (cannot go back) BACK Scenario #2: there is a previous room GIVEN : there is a previous room WHEN : "back" is entered THEN : player's current location is changed to the previous location and : player's current location is displayed LOOK Scenario #1: GIVEN : WHEN : "look" is entered THEN : player's current location is displayed STATUS Scenario #1: GIVEN : WHEN : "status" is entered THEN : current number of turns is displayed and : player's current score is displayed and : player's current location is displayed /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 3 (alphabetical) DROP Scenario #1: No item specified GIVEN : WHEN : "drop" is entered THEN : appropriate message is displayed (which item?) DROP Scenario #2: Player does not have the specified item GIVEN : player does not have the specified item WHEN : "drop item" is entered THEN : appropriate message is displayed (you don't have it) DROP Scenario #3: Player has the specified item GIVEN : player has the specified item WHEN : "drop item" is entered THEN : "item" is removed from the player's inventory and : "item" is added to the current room and : appropriate message is displayed (you dropped the item) EXAMINE Scenario #1: No item specified GIVEN : WHEN : "examine" is entered THEN : appropriate message is displayed (which item?) EXAMINE Scenario #2: Specified item does not exist GIVEN : specified item is not in the room and : specified item is not in player's inventory WHEN : "examine item" is entered THEN : appropriate message is displayed (no such item) EXAMINE Scenario #3: Specified item does exist GIVEN : specified item is in the room or in the player's inventory WHEN : "examine item" is entered THEN : complete description of the item is displayed including the item's name, description and (optionally) the weight. INVENTORY Scenario #1: GIVEN : WHEN : "inventory" is entered THEN : a list of the items in the players inventory is displayed TAKE Scenario #1: no item specified GIVEN : WHEN : "take" is entered THEN : appropriate message is displayed (take what?) TAKE Scenario #2: specified item does not exist GIVEN : specified item is not in the current room WHEN : "take item" is entered THEN : appropriate message is displayed (no such item) TAKE Scenario #3: specified item is too heavy to lift GIVEN : specified item is in the current room and : specified item by itself exceeds maximum carrying weight WHEN : "take item" is entered THEN : appropriate message is displayed (too heavy to lift) TAKE Scenario #4: specified item makes inventory too heavy GIVEN : specified item is in the current room and : adding specified item to inventory weight exceeds maximum carrying weight WHEN : "take item" is entered THEN : appropriate message is displayed (carrying too much) TAKE Scenario #5: specified item is taken GIVEN : specified item is in the current room and : adding specified item to inventory weight does not exceed maximum carrying weight WHEN : "take item" is entered THEN : item is removed from the current room and : item is added to the player's inventory and : appropriate message is displayed (you took the item) /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 4 (alphabetical) GO Scenario #4: Door is locked GIVEN : there is an exit in the given direction and : that exit is locked WHEN : "go direction" is entered THEN : appropriate message is displayed (door is locked) LOCK Scenario #1: No direction specified GIVEN : WHEN : "lock" is entered THEN : appropriate message is displayed (lock what?) LOCK Scenario #2: No Door GIVEN : there is no door in that direction WHEN : "lock direction" is entered THEN : appropriate message is displayed (no door) LOCK Scenario #3: Door is locked GIVEN : door in "direction" is locked WHEN : "lock direction" is entered THEN : appropriate message is displayed (door is already locked) LOCK Scenario #4: Door cannot be locked GIVEN : door in "direction" has no associated key WHEN : "lock direction" is entered THEN : appropriate message is displayed (door cannot be locked) LOCK Scenario #5: Door can be locked GIVEN : door in "direction" is unlocked and : door in "direction" can be locked WHEN : "lock direction" is entered THEN : user is prompted for key LOCK Scenario #6: Player does not have the key GIVEN : player does not have specific key in inventory WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (you do not have it) LOCK Scenario #7: Incorrect key specified GIVEN : player's inventory has the specific key and : specified key is not the correct key WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (wrong key) LOCK Scenario #8: Correct key specified GIVEN : player's inventory has the specific key and : specified key is the correct key WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : door in "direction" is locked and : appropriate message is displayed (you locked it) PACK Scenario #1: No item specified GIVEN : WHEN : "pack" is entered THEN : appropriate message is displayed (pack what?) PACK Scenario #2: Item is not available GIVEN : item is NOT in the current room and : item is NOT in the players inventory WHEN : "pack item" is entered THEN : appropriate message is displayed (you don't have it) PACK Scenario #3: Item is too heavy GIVEN : item is in the current room and : item is heavier than player's carrying capacity WHEN : "pack item" is entered THEN : appropriate message is displayed (too heavy) PACK Scenario #4: Item is available GIVEN : item is in the current room or : item is in the player's inventory and : there are no weight problems WHEN : "pack item" is entered THEN : user is prompted for the container to put it in PACK Scenario #5: Container is not available GIVEN : container is NOT in the current room and : container is NOT in the player's inventory WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (you don't see the container) PACK Scenario #6: Container is NOT a container GIVEN : container is in the current room or : container is in the player's inventory and : container is not really a container WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (that's not a container) PACK Scenario #7: Container is a container, but item too heavy GIVEN : item is in the current room and : container is in the player's inventory and : item would put player over their inventory weight limit WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (carrying too much) PACK Scenario #8: Packing is possible GIVEN : container is in the current room or : container is in the player's inventory and : container is really a container and : there are no weight problems WHEN : "pack item" had been entered and : user has been prompted for the container THEN : item is removed from the current room or : item is removed from the player's inventory and : item is added to the container and : appropriate message is displayed (you packed it) UNLOCK Scenario #1: No direction specified GIVEN : WHEN : "unlock" is entered THEN : appropriate message is displayed (unlock what?) UNLOCK Scenario #2: No door in that direction GIVEN : there is no door in the "direction" WHEN : "unlock direction" is entered THEN : appropriate message is displayed (there is no door) UNLOCK Scenario #3: Direction is specified and is not locked GIVEN : there is a door in the "direction" and : door in "direction" is NOT locked WHEN : "unlock direction" is entered THEN : appropriate message is displayed (door is not locked) UNLOCK Scenario #4: Direction is specified and is locked GIVEN : there is a door in the "direction" and : door in "direction" is locked WHEN : "unlock direction" is entered THEN : user is prompted for key UNLOCK Scenario #5: Player missing specified key GIVEN : player's inventory does NOT have the specific key WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (you don't have it) UNLOCK Scenario #6: Incorrect key GIVEN : player's inventory has the specific key and : specified key is incorrect item WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (that doesn't fit) UNLOCK Scenario #7: Correct key GIVEN : player's inventory has the specific key and : specified key is the correct object WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : door in "direction" is unlocked and : appropriate message is displayed (you unlocked it) UNPACK Scenario #1: No container specified GIVEN : WHEN : "unpack" is entered THEN : appropriate message is displayed (unpack what?) UNPACK Scenario #2: Specified container is not in the current room GIVEN : specified container is NOT in the current room and : specified container is NOT in the players inventory WHEN : "unpack container" is entered THEN : appropriate message is displayed (you don't see it) UNPACK Scenario #3: Specified item is not a container GIVEN : specified container is in the current room or : specified container is in the player's inventory and : specified container is NOT a container WHEN : "unpack container" is entered THEN : appropriate message is displayed (that's not a container) UNPACK Scenario #4: Container is OK GIVEN : specified container is in the current room or : specified container is in the player's inventory and : specified container is a container WHEN : "unpack container" is entered THEN : user is prompted for an item to unpack UNPACK Scenario #5: Item is NOT in container GIVEN : item to unpack is NOT in the container WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : appropriate message is displayed (you don't find it) UNPACK Scenario #6: Item is in container but too heavy GIVEN : item to unpack is in the container and : container was in the current room and : item would make the player exceed his weight limit WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : appropriate message is displayed (you are already carrying too much) UNPACK Scenario #7: Item can be unpacked GIVEN : item to unpack is in the container and : there is no weight problem WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : item to unpack is removed from the container and : item to unpack is added to the player's inventory and : appropriate message is displayed (you unpack it) EAT Scenario #1: No item is specified GIVEN : WHEN : "eat" is entered THEN : appropriate message is displayed (eat what?) EAT Scenario #2: Specified item is not in the players inventory GIVEN : Food is specified WHEN : "eat food" is entered THEN : appropriate message is displayed (you don't have it) EAT Scenario #3: Specified item is in the players inventory GIVEN : food is specified and : specified item is not food WHEN : "eat food" is entered THEN : appropriate message is displayed (item is not food) EAT Scenario #4: Specified item is in the players inventory GIVEN : food is specified and : specified item is food WHEN : "eat food" is entered THEN : food is removed from players invetory and : players health is increased and : appropriate message is displayed (you have eaten food) DRINK Scenario #1: No item is specified GIVEN : WHEN : "drink" is entered THEN : appropriate message is displayed (drink what?) DRINK Scenario #2: Specified item is not in the players inventory GIVEN : Drink is specified WHEN : "drink Drink" is entered THEN : appropriate message is displayed (you don't have it) DRINK Scenario #3: Specified item is in the players inventory GIVEN : Drink is specified and : specified item is not drink WHEN : "drink Drink" is entered THEN : appropriate message is displayed (item is not a drink) DRINK Scenario #4: Specified item is in the players inventory GIVEN : Drink is specified and : specified item is Drink WHEN : "drink Drink" is entered THEN : drink is removed from players invetory and : players health is increased and : appropriate message is displayed (you have taken a drink) EQUIP Scenario #1: No weapon is specified GIVEN : WHEN : "equip" is entered THEN : appropriate message is displayed (equip what?) EQUIP Scenario #2: Specified weapon is not in the players inventory GIVEN : weapon is specified WHEN : "equip weapon" is entered THEN : appropriate message is displayed (you don't have it) EQUIP Scenario #3: Specified item is in the players inventory GIVEN : weapon is specified and : specified item is not weapon WHEN : "equip weapon" is entered THEN : appropriate message is displayed (item is not a weapon) EQUIP Scenario #4: Specified item is in the players inventory GIVEN : weapon is specified and : specified item is a weapon WHEN : "equip weapon" is entered THEN : weapon is removed from players invetory and : player is equipped with the weapon and : appropriate message is displayed (weapon equipped) UNEQUIP Scenario #1: No weapon is specified GIVEN : WHEN : "unequip" is entered THEN : appropriate message is displayed (unequip what?) UNEQUIP Scenario #2: Specified weapon is not the players current weapon GIVEN : weapon is specified WHEN : "unequip weapon" is entered THEN : appropriate message is displayed (weapon is not equipped) UNEQUIP Scenario #3: Specified item is the players current weapon GIVEN : weapon is specified and : specified item is a weapon WHEN : "unequip weapon" is entered THEN : weapon is added to the players invetory and : players is unequipped and : appropriate message is displayed (weapon unequipped)

Lap3/.git/objects/8d/c3169a6a29c72b490e374cd1bae761d0798656

Lap3/.git/objects/8d/c3169a6a29c72b490e374cd1bae761d0798656

blob 4402�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; /**earn points */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** directions hash map with room item's keys and items values */ private HashMap<String,Item> roomItems = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The rooms name. * @param description * The rooms description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Returns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Return the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting the direction. */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoints */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Add Item. * @param item - The item object to be added */ public void addItem(Item item) { roomItems.put(item.name, item); } /** * get Item * @param name - The name of the item to be added to the room * @return Item - The item in the collection with the key name */ public Item getItem(String name) { return roomItems.get(name); } /** * Remove Item * @param name - The name of the item to be removed from the room * @return item - The item that has been removed from the room */ public Item removeItem(String name) { Item item = roomItems.get(name); roomItems.remove(name); return item; } /** * Returns a string description including all the details of a Room. *Exits : north east south west * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = ""; roomInformation += getName() + " " + getDescription() + "\n"; roomInformation += "Exits : " ; for(String direction : directions.keySet()){ roomInformation += " " + direction; } roomInformation += "\nItems : "; for(String item : roomItems.keySet()){ roomInformation += " " + item + ", "; } return roomInformation; } }

Lap3/.git/objects/15/5417e163f8cd4be5a724376aaf4b84dafda751

Lap3/.git/objects/15/5417e163f8cd4be5a724376aaf4b84dafda751

blob 11217�import java.util.HashMap; /** * This class represents the entire world that makes up the "Campus of Kings" * application. "Campus of Kings" is a very simple, text based adventure game. * Users can walk around some scenery. That's all. It should really be extended * to make it more interesting! * * This world class creates the world where the game takes place. * * @author mohammed alharbi * @version 20/2/2018 */ public class World { /** The rooms in the world. */ private HashMap<String, Room> rooms; /** * Constructor for the world. */ public World() { rooms = new HashMap<String, Room>(); createRooms(); createItems(); } /** * Items can earn point. */ public void createItems(){ Item toothbrush = new Item("tooth brush", 3, "Brushing teeth", 10); Item toothpaste = new Item("tooth paste", 3, "Applied on a tooth brush", 20); Item knife = new Item("knife", 5, "Peel and cut fruits", 100); Item coffee = new Item("coffee", 7, "good for personal health", 150); Item water = new Item("bottle of water", 8, "Quenches thirst", 250); Item broom_stick = new Item("broom btick", 5, "Pick items from the roof", 600); Item back_bag = new Item("back bag", 10, "Carry things in", 200); Item house_key = new Item("House key", 5, "Open locked doors", 50); Item bucket = new Item("water buckets", 15, "carry more items if back is full", 50); for(String room : rooms.keySet()){ System.out.println(room); switch(room){ case "bathroom": getcurrentRoom(room).addItem(toothbrush); getcurrentRoom(room).addItem(toothpaste); break; case "kitchen": getcurrentRoom(room).addItem(knife); getcurrentRoom(room).addItem(coffee); getcurrentRoom(room).addItem(water); break; case "out of the house": getcurrentRoom(room).addItem(broom_stick); break; case "car": getcurrentRoom(room).addItem(back_bag); getcurrentRoom(room).addItem(house_key); break; case "keep street": getcurrentRoom(room).addItem(bucket); break; } } } /** * This method takes care of creating all of the aspects of the world for * the "Campus of Kings" application. * * @param name * The provided name of the room. * @return The room associated with the provided name */ public Room getcurrentRoom(String name) { return rooms.get(name.toLowerCase()); } ///////////////////////////////////////////////////////////////////////////////////// // Start of private helper methods /** * Helper method for recreating a Room. Ensure that the room is created and * installed in to the collection of Rooms. * * @param theRoom * The room to add to the world. */ private void addRoom(Room theRoom) { rooms.put(theRoom.getName().toLowerCase(), theRoom); } /** * Helper method for creating doors between rooms. * * @param from The room where the door originated. * @param direction The direction of the door in the from room. * @param to The room where the door goes. */ private void createDoor(Room from, String direction, Room to){ Door door = new Door(to); from.setDirection(direction,door); } /** * This method creates all of the individual places in this world and all * the doors connecting them. */ private void createRooms() { // Creating all the rooms. int pointScore = 0; Room bathroom = new Room("Bathroom", "there is teeth brush, shower place."); Room kitchen = new Room("Kitchen", "there are two doors, one the way to go out of the house. The second door the way to the living room.."); Room outOfTheHouse = new Room("out Of The House", "the way outside the house to drive to university.."); outOfTheHouse.setPoints(10); pointScore = pointScore + 10; Room car = new Room("Car", "inside the car, back bag, car key with house key.."); car.setPoints(7); pointScore = pointScore + 7; Room keepStreet = new Room("keep Street", "the correct way."); Room turnLeft = new Room("Turn left", "wrong way to go with it.."); Room endOfTheRoad = new Room("End of the road", "closed way."); Room gasStaion = new Room("Gas Staion", "the way to traffic signal."); Room trafficSignal = new Room("Traffic signal", "there are three different ways."); trafficSignal.setPoints(10); pointScore = pointScore + 10; Room turnLeft2 = new Room("Turn left2", "maybe not the right way."); Room wrongWay = new Room("Wrong way","it will take long time to reach the goal."); Room turnRight = new Room("Turn right"," more traffic."); Room closedWay = new Room("Closed Way","no place to go."); Room keepGoing = new Room("KeepGoing","almost arrive to university."); keepGoing.setPoints(10); pointScore = pointScore + 10; Room parking = new Room("Parking","there is a meter parking, 2$ in Hour."); parking.setPoints(17); pointScore = pointScore + 17; Room library = new Room("Library","some books, students, printer, computers."); Room campusCenter = new Room("Campus Center","office for the activity, mailboxes, four floors"); Room hallCampus = new Room("Hall Campus","the building for men."); Room hBuilding = new Room("H Building","Five floors, elevator, six classrooms"); Room square = new Room("Square","the place in the middle of the university, and from there the player can go any building."); square.setPoints(12); pointScore = pointScore + 12; Room mCBuilding = new Room("MCBuilding"," Classes, six floors."); Room aBuilding = new Room("A Building",": the goal to reach the class, stairs, elevator, classroom."); Room stairs = new Room("Stairs","take the player until fourth floor."); stairs.setPoints(18); pointScore = pointScore + 18; Room elevator = new Room("Elevator","take the player until fourth floor."); Room floor2 = new Room("2Floor","entry for classes"); Room classroom = new Room("Classroom","one door, blackboard, tables"); Room classroom201 = new Room ("Classroom201","you reach the goal."); classroom201.setPoints(30); pointScore = pointScore + 30; Room classroom204 = new Room("Classroom204","one door, students."); Room classroom202 = new Room("Classroom202","blackboard, table, students."); // Adding all the rooms to the world. this.addRoom(bathroom); this.addRoom(kitchen); this.addRoom(outOfTheHouse); this.addRoom(car); this.addRoom(keepStreet); this.addRoom(turnLeft); this.addRoom(endOfTheRoad); this.addRoom(gasStaion); this.addRoom(trafficSignal); this.addRoom(turnLeft2); this.addRoom(wrongWay); this.addRoom(turnRight); this.addRoom(closedWay); this.addRoom(keepGoing); this.addRoom(parking); this.addRoom(library); this.addRoom(campusCenter); this.addRoom(hallCampus); this.addRoom(hBuilding); this.addRoom(square); this.addRoom(mCBuilding); this.addRoom(aBuilding); this.addRoom(stairs); this.addRoom(elevator); this.addRoom(floor2); this.addRoom(classroom); this.addRoom(classroom201); this.addRoom(classroom204); this.addRoom(classroom202); // Creating all the doors between the rooms. this.createDoor(bathroom,"east",kitchen); this.createDoor(kitchen, "west",bathroom); this.createDoor(kitchen,"south", outOfTheHouse); this.createDoor(outOfTheHouse,"north", kitchen); this.createDoor(outOfTheHouse,"west",car); this.createDoor(car,"east",outOfTheHouse); this.createDoor(car,"south",keepStreet); this.createDoor(keepStreet,"north",car); this.createDoor(keepStreet,"west",turnLeft); this.createDoor(turnLeft,"east",keepStreet); this.createDoor(turnLeft,"south", endOfTheRoad); this.createDoor(endOfTheRoad,"north",turnLeft); this.createDoor(keepStreet,"south",gasStaion); this.createDoor(gasStaion, "north",keepStreet); this.createDoor(gasStaion,"east",trafficSignal); this.createDoor(trafficSignal,"west", gasStaion); this.createDoor(trafficSignal,"north",turnLeft2); this.createDoor(turnLeft2,"south",trafficSignal); this.createDoor(turnLeft2,"north", wrongWay); this.createDoor(wrongWay,"south",turnLeft2); this.createDoor(trafficSignal,"south", turnRight); this.createDoor(turnRight,"north", trafficSignal); this.createDoor(turnRight,"south",closedWay); this.createDoor(closedWay,"north", turnRight); this.createDoor(trafficSignal,"east", keepGoing); this.createDoor(keepGoing, "west",trafficSignal); this.createDoor(keepGoing,"east", parking); this.createDoor(parking,"west",keepGoing); this.createDoor(parking,"southwest",library); this.createDoor(library, "northeast",parking); this.createDoor(library,"east", campusCenter); this.createDoor(campusCenter,"west",library); this.createDoor(parking,"south",square); this.createDoor(square,"north",parking); this.createDoor(square,"east", hallCampus); this.createDoor(hallCampus,"west",square); this.createDoor(square,"west",hBuilding); this.createDoor(hBuilding,"east",square); this.createDoor(square, "southeast",mCBuilding); this.createDoor(mCBuilding,"northwest",square); this.createDoor(square,"south",aBuilding); this.createDoor(aBuilding,"north",square); this.createDoor(aBuilding,"west",stairs); this.createDoor(stairs,"east",aBuilding); this.createDoor(aBuilding,"southwest",classroom); this.createDoor(classroom,"northeast",aBuilding); this.createDoor(aBuilding,"southwest",elevator); this.createDoor(elevator,"northeast",aBuilding); this.createDoor(elevator,"west",floor2); this.createDoor(floor2,"east",elevator); this.createDoor(stairs,"south",floor2); this.createDoor(floor2,"north",stairs); this.createDoor(floor2,"south",classroom204); this.createDoor(classroom204,"north",floor2); this.createDoor(floor2,"east",classroom202); this.createDoor(classroom202,"west",floor2); this.createDoor(floor2,"southeast",classroom201); this.createDoor(classroom201,"northwest",floor2); } }

Lap3/.git/objects/15/90090e3d46cc37c55e537727c205ed58d6f936

Lap3/.git/objects/15/90090e3d46cc37c55e537727c205ed58d6f936

blob 123� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help.

Lap3/.git/objects/15/c3bb6ee17025f49b7f531253b55aee3e65a6a5

Lap3/.git/objects/15/c3bb6ee17025f49b7f531253b55aee3e65a6a5

Lap3/.git/objects/12/9452564c1a4509bb2b87e55cd40d4fa67f1f97

Lap3/.git/objects/12/9452564c1a4509bb2b87e55cd40d4fa67f1f97

blob 1177� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. eastDescription:east : You are Description:east Exits: east > go east Description:south west : You are Description:south west Exits: south west > go south Description:north west : You are Description:north west Exits: north west > go north Description:south west : You are Description:south west Exits: south west > go south Description:north west : You are Description:north west Exits: north west > go north Description:south west : You are Description:south west Exits: south west > go south Description:north west : You are Description:north west Exits: north west > go north Description:south west : You are Description:south west Exits: south west > go south Description:north west : You are Description:north west Exits: north west > go north Description:south west : You are Description:south west Exits: south west > go west Description:east : You are Description:east Exits: east > go east Description:south west : You are Description:south west Exits: south west > go north There is no door! >

Lap3/.git/objects/85/9e595adf917dafa96ea0b703559571eab33592

Lap3/.git/objects/85/9e595adf917dafa96ea0b703559571eab33592

blob 486� Welcome to the Campus of Kings! Campus of Kings is a new, incredibly boring adventure game. Type 'help' if you need help. You are in Bathroom there is teeth brush, shower place. Exits : east Items : tooth paste, tooth brush, > go east You are in Kitchen there are two doors, one the way to go out of the house. The second door the way to the living room.. Exits : south west Items : knife, bottle of water, coffee, purse, > go south door is locked! > unlock south With what?

Lap3/.git/objects/76/4157d1f431efb74da95a21e2beaeb1ad1257ca

Lap3/.git/objects/76/4157d1f431efb74da95a21e2beaeb1ad1257ca

Lap3/.git/objects/1c/dce7638c4cc5e2aab83eb36a064a6e08f733c0

Lap3/.git/objects/1c/dce7638c4cc5e2aab83eb36a064a6e08f733c0

blob 3858�import java.util.HashMap; /** * Class Room - a room in an adventure game. * * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * A "Room" represents one location in the scenery of the game. It is connected * to other rooms via doors. The doors are labeled north, east, south, west. * For each direction, the room stores a reference to an instance of door. * * @author Mohammed ALharbi * @version 2018.1.26 */ public class Room { /** Counter for the total number of rooms created in the world. */ private static int counter; /** The name of this room. Room names should be unique. */ private String name; /** The description of this room. */ private String description; ///**.*/ //private HashMap<String, Door> exit; /**earn poins */ private int points; /** directions hash map with directions keys and doors values */ private HashMap<String,Door> directions = new HashMap< >(); /** * Static initializer. */ static { counter = 0; } /** * Create a room described "description". Initially, it has no exits. * "description" is something like "a kitchen" or "an open court yard". * @param name The room's name. * @param description * The room's description. */ public Room(String name, String description) { this.name = name; this.description = description; counter++; } /** * Returns the name of this room. * * @return The name of this room. */ public String getName() { return name; } /** * Returns the description of this room. * * @return The description of this room. */ public String getDescription() { return description; } /** * Rerurns the door of this room. * @return The door of this room */ public Door getDirection(String direction){ return directions.get(direction); } /** * Rerutn the rooms that have been created int the world. * @return the rooms that have been created int the world. */ public static int getCounter(){ return counter; } /** * @return getExit for getting thae direction. * @param direction * @return */ public int getPoints(){ int point = points; points = 0; return point; } /** Mutator for setting the points. * @param newPoint */ public void setPoints(int newPoints){ points = newPoints; } /** * Set exit. * @param direction * @param neighbor */ public void setDirection(String direction,Door neighbor) { directions.put(direction, neighbor); } /** * Returns a string description including all the details of a Room. * For example , *Outside : *You are outside in the center of the King's College campus. *Exits : north east south west * * @return A string representing all the details of a Room. */ public String toString(){ String roomInformation = " "; roomInformation = getName() + " " + getDescription(); for(String direction : directions.keySet()){ roomInformation =roomInformation + "Exit" + direction; } for(Door door : directions.values()){ roomInformation = roomInformation + "Door" + door; String RoomInformation = getName() + " " + getDescription(); roomInformation = "Exit:"; roomInformation = "Name:"; roomInformation = "Description:"; for (String Direction : directions.keySet()) { roomInformation += Direction + " "; } } return roomInformation; } }

Lap3/.git/objects/82/99c43d952b4275bebb5b276fbfab12eb687d71

Lap3/.git/objects/82/99c43d952b4275bebb5b276fbfab12eb687d71

Lap3/.git/objects/40/666a187c3d0990208398c96fa737087053a8a7

Lap3/.git/objects/40/666a187c3d0990208398c96fa737087053a8a7

blob 700� /** * class Player. * @author Mohammed Alharbi * @version 2018.1.27 */ public class Player{ /** field in the Player class to store the currentRoom.*/ private Room currentRoom; /** constructor in the Player class. * @param playPlaying play Playing */ public Player(Room PlayPlaying){ currentRoom = PlayPlaying; } /** accessor for the current room the character. * @return cerrentRoom */ public Room getcurrentRoom(){ return currentRoom; } /** a mutator for the current room the character. * @param Playing for the Room */ public void setcurrentRoom(Room Playing){ currentRoom = Playing; } }

Lap3/.git/objects/2e/2dbf6d041de4c42858e8b49d026f7947882a7d

Lap3/.git/objects/2e/2dbf6d041de4c42858e8b49d026f7947882a7d

blob 10792�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord.name()){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; case "examine": examineItem(command); break; case "take": takeItem(command); break; case "drop": dropItem(command); break; case "inventory": inventory(); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } /** * Try to examine a play item. If the item doesn't exist in the * players inventory nor the current room, * print an error message. * * @param command * The command to be processed. */ private void examineItem(Command command) { if (!command.hasSecondWord()) { Writer.println("Which item?"); } else { String itemName = command.getRestOfLine(); Item item = null; //Get item from players inventory item = playerClass.getItem(itemName); //Check the item value has had something added, if no, check for the item in the current room if (item == null) { item = playerClass.getcurrentRoom().getItem(itemName); } //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { Writer.println(item.toString()); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void takeItem(Command command) { if (!command.hasSecondWord()) { Writer.println("take what?"); } else { String itemName = command.getRestOfLine(); Item item = null; //Look for the item in the current room item = playerClass.getcurrentRoom().getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("No such item!"); } else { if(item.getWeight() > playerClass.MAX_WEIGHT){ Writer.println("too heavy to lift"); }else{ if(playerClass.inventoryAddItem(itemName) == false){ Writer.println("Carrying too much"); }else{ playerClass.inventoryAddItem(itemName); playerClass.getcurrentRoom().removeItem(itemName); Writer.println("you took the item"); } } } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void dropItem(Command command) { if (!command.hasSecondWord()) { Writer.println("which item?"); } else { String itemName = command.getRestOfLine(); Item item = null; //Look for the item in the current room item = playerClass.getItem(itemName); //Check if item exists in the current room if (item == null) { Writer.println("you don't have it!"); } else { playerClass.getcurrentRoom().addItem(item); playerClass.removeItem(itemName); Writer.println("you dropped the item"); } } } /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param * The command to be processed. */ private void inventory() { Writer.println("Inventory :" + playerClass.getInventory()); } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } }

Lap3/.git/objects/2b/102abd295cccd8cb318a42b82a2a7b61e968ba

Lap3/.git/objects/2b/102abd295cccd8cb318a42b82a2a7b61e968ba

blob 7188�/** * This class is the main class of the "Campus of Kings" application. * "Campus of Kings" is a very simple, text based adventure game. Users can walk * around some scenery. That's all. It should really be extended to make it more * interesting! * This game class creates and initializes all the others: it creates all rooms, * creates the parser and starts the game. It also evaluates and executes the * commands that the parser returns. * * @author Mohammed Alharbi * @version 2018/1/24 */ public class Game { /** The world where the game takes place. */ private World world; //** stores the character controlled by the Player. */ //private Player Playing; /** the total score. */ private int score ; /** the total number of turns. */ private int turns; /** This is an object for getting the room from the Player class. */ private Player playerClass; /** * Create the game and initialize its internal map. */ public Game() { world = new World(); playerClass = new Player(world.getcurrentRoom("Bathroom")); score = 0; turns = 0; } /** * Main play routine. Loops until end of play. */ public void play() { printWelcome(); // Enter the main game loop. Here we repeatedly read commands and // execute them until the game is over. boolean wantToQuit = false; while (!wantToQuit) { Command command = Reader.getCommand(); wantToQuit = processCommand(command); turns = turns + 1; } printGoodbye(); } /////////////////////////////////////////////////////////////////////////// // Helper methods for processing the commands /** * Given a command, process (that is: execute) the command. * * @param command * The command to be processed. * @return true If the command ends the game, false otherwise. */ private boolean processCommand(Command command) { //private static CommandEnum g(){ boolean wantToQuit = false; if (!CommandEnum.isCommand(command.getCommandWord())) { Writer.println("I don't know what you mean..."); }else { CommandEnum commandWord = command.getCommandWord(); switch(commandWord.name()){ case "help": printHelp(); break; case "go": goGame(command); break; case "look": look(); break; case "quit": wantToQuit = quit(command); break; case "status": printGameStatus(); break; case "back": goBack(); break; default: Writer.println(commandWord + " is not implemented yet!"); break; } } return wantToQuit; } /////////////////////////////////////////////////////////////////////////// // Helper methods for implementing all of the commands. // It helps if you organize these in alphabetical order. /** * Try to go to one direction. If there is an exit, enter the new room, * otherwise print an error message. * * @param command * The command to be processed. */ private void goGame(Command command) { if (!command.hasSecondWord()) { Writer.println("Go where?"); } else { String direction = command.getRestOfLine(); Door doorway = null; doorway = playerClass.getcurrentRoom().getDirection(direction); if (doorway == null) { Writer.println("There is no door!"); } else { Room newRoom = doorway.getDestination(); playerClass.setcurrentRoom(newRoom); score = score + newRoom.getPoints(); printLocationInformation (); } } } /** * Print out the status of the game. */ private void printGameStatus(){ Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); printLocationInformation(); } /** * Take the player back to the previous location. */ private void goBack(){ if(playerClass.getpreviousRoom() != null){ playerClass.setcurrentRoom(playerClass.getpreviousRoom()); printLocationInformation(); }else{ Writer.println("There is no Previous room. Please make a move"); } } /** * Print out the closing message for the player. */ private void printGoodbye() { Writer.println("I hope you weren't too bored here on the Campus of Kings!"); Writer.println("Thank you for playing. Good bye."); Writer.println("You have earned" + " " + score + "points in" + " " + turns + " " + "turns."); } /** * Prints out the current location and exits. */ private void printLocationInformation(){ //Writer.println(playerClass.getcurrentRoom() + " : "); Writer.println("You are in " + playerClass.getcurrentRoom()); //Writer.println("Exits: "); } /** * Print out some help information. Here we print some stupid, cryptic * message and a list of the command words. */ private void printHelp() { Writer.println("You are lost. You are alone. You wander"); Writer.println("around at the university."); Writer.println(); Writer.println("Your command words are:"); Writer.println(CommandEnum.getCommandString()); } /** * Print out the opening message for the player. */ private void printWelcome() { Room currentRoom = playerClass.getcurrentRoom(); Writer.println(); Writer.println("Welcome to the Campus of Kings!"); Writer.println("Campus of Kings is a new, incredibly boring adventure game."); Writer.println("Type 'help' if you need help."); printLocationInformation(); } /** * "Quit" was entered. Check the rest of the command to see whether we * really quit the game. * * @param command * The command to be processed. * @return true, if this command quits the game, false otherwise. */ private boolean quit(Command command) { boolean wantToQuit = true; if (command.hasSecondWord()) { Writer.println("Quit what?"); wantToQuit = false; } return wantToQuit; } /** * prints out the location information. * */ private void look(){ printLocationInformation(); } }

Lap3/.git/objects/8b/e7ab3c9ba458495c2b37bb192dbaed0470f15d

Lap3/.git/objects/8b/e7ab3c9ba458495c2b37bb192dbaed0470f15d

commit 232�tree a50058e243ec0e4732cbdbf794b1dc700fc6a5dd parent 6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a author mohammedalharbi <[email protected]> 1517800310 -0500 committer mohammedalharbi <[email protected]> 1517800310 -0500 Room

Lap3/.git/objects/13/fa88d639bbd894ab9111246d4c7ef5fd5ac0a9

Lap3/.git/objects/13/fa88d639bbd894ab9111246d4c7ef5fd5ac0a9

blob 2719� /** *Class Item - An item in the game that the player can * pick or drop. * The class also describe items in the game by their name, weight etc * @author mohammed alharbi * @version 24/4/2018 */ public class Item { /** the name.*/ private String name; /** the description.*/ private String description; /** the weight.*/ private int weight; /** the pointVal.*/ private int pointVal; /** the Items. * @param name the name. * @param pointValue the pointValue. * @param description the description. * @param weight the weight. */ public Item(String name, int pointValue, String description, int weight) { this.name = name; this.description = description; this.pointVal = pointValue; this.weight = weight; } /** * * Returns the name of an item. * @return The name of an item. * **/ public String getName(){ return name; } /** * * Returns the description of an item. * @return The description of an item. * **/ public String getDescription(){ return description; } /** * * Sets the description of a room. * @param desc the desc. */ public void setDescription(String desc){ description = desc; } /** * Check if an item is a container. * @return return false */ public boolean isContainer(){ return false; } /** * additem the item. * @param item the item. */ public void addItem(Item item){ } /** * removeItem the item. * @param item the item. * @return item. */ public Item removeItem(String item){ return null; } /** * getitem the item. * @param item the item * @return item. */ public Item getItem(String item){ return null; } /** * * Returns the pointValue of an item. * @return The pointValue of an item. * **/ public int getPointValue(){ return pointVal; } /** * * Returns the weight of an item. * @return The weight of an item. * **/ public int getWeight(){ return weight; } @Override public String toString(){ String itemInfo = ""; itemInfo += "Name : " + name + "\n"; itemInfo += "Description : " + description + "\n"; itemInfo += "Weight : " + weight + "grams"; return itemInfo; } }

Lap3/.git/objects/13/01775cc1c2b4fd94c7905c963f5f6cfb914a2d

Lap3/.git/objects/13/01775cc1c2b4fd94c7905c963f5f6cfb914a2d

commit 239�tree df80e5d47e15386febd1a724fdb3c7e087f1d6b4 parent 8be7ab3c9ba458495c2b37bb192dbaed0470f15d author mohammedalharbi <[email protected]> 1518056669 -0500 committer mohammedalharbi <[email protected]> 1518056669 -0500 lap01 lap03

Lap3/.git/objects/7f/2984f031029a31eff42f2d56b2ca097ba240a6

Lap3/.git/objects/7f/2984f031029a31eff42f2d56b2ca097ba240a6

blob 3685� import java.util.ArrayList; /** * This class is part of the "Campus of Kings" application. "Campus of Kings" is a * very simple, text based adventure game. * * This class holds information about a command that was issued by the user. A * command currently consists of two strings: a command word and a second word * (for example, if the command was "take map", then the two strings obviously * are "take" and "map"). * * The way this is used is: Commands are already checked for being valid command * words. If the user entered an invalid command (a word that is not known) then * the command word is <null>. * * If the command had only one word, then the second word is <null>. * * @author Maria Jump * @version 2015.02.01 */ public class Command { /** The command word for this command. */ private CommandEnum commandWord; /** The rest of the line with all the spaces removed. */ private ArrayList<String> restOfLine; /** * Create a command object. First is supplied. The second word is assumed * to be null. * * @param firstWord * The first word of the command. Null if the command was not * recognized. */ public Command(String firstWord) { commandWord = CommandWords.getCommand(firstWord); restOfLine = new ArrayList<String>(); } /** * Create a command object. First and second word must be supplied, but * either one (or both) can be null. * * @param firstWord * The first word of the command. Null if the command was not * recognized. * @param rest * The rest of the command. */ public Command(String firstWord, ArrayList<String> rest) { commandWord = CommandWords.getCommand(firstWord); restOfLine = rest; } /** * Return the command word (the first word) of this command. If the command * was not understood, the result is null. * * @return The command word. */ public CommandEnum getCommandWord() { return commandWord; } /** * Returns if this command was not understood. * * @return true if this command was not understood. */ public boolean isUnknown() { return (commandWord == null); } /** * Returns if this command has a second word. * * @return true if the command has a second word. */ public boolean hasSecondWord() { return restOfLine != null; } /** * Returns if this command has more words. * * @param index The index of the word needed. * @return true if the command has a word at given index. */ public boolean hasWord(int index) { return index >= 0 && index < restOfLine.size(); } /** * Returns the word at the requested index in the command. * * @param index * The index of word in the command that is being requested. * * @return A particular word in the command. Returns null if there is no * word corresponding to that requested index. * */ public String getWord(int index) { String result = null; if (index >= 0 && index < restOfLine.size()) { result = restOfLine.get(index); } return result; } /** * Returns the second word of this command, if it exists. * * @return The second word of this command. Returns null if there was no * second word. */ public String getRestOfLine() { StringBuffer buffer = null; if (restOfLine.size() != 0) { for(String word : restOfLine) { if (buffer == null) { buffer = new StringBuffer(); buffer.append(word); } else { buffer.append(" "); buffer.append(word); } } } String result = ""; if (buffer != null) { result += buffer.toString(); } return result; } }

Lap3/.git/HEAD

ref: refs/heads/master

Lap3/.git/logs/HEAD

0000000000000000000000000000000000000000 6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a moh <[email protected]> 1517797214 -0500
6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a 8be7ab3c9ba458495c2b37bb192dbaed0470f15d mohammedalharbi <[email protected]> 1517800310 -0500 commit: Room
8be7ab3c9ba458495c2b37bb192dbaed0470f15d 1301775cc1c2b4fd94c7905c963f5f6cfb914a2d mohammedalharbi <[email protected]> 1518056669 -0500 commit: lap01 lap03
1301775cc1c2b4fd94c7905c963f5f6cfb914a2d 3f705e964028fab9fe251a0e491df78a19dc12eb mohammedalharbi <[email protected]> 1518056756 -0500 merge a4e2272a137d2dde8a838d9c73be6e8f12967a27: Merge made by recursive.
3f705e964028fab9fe251a0e491df78a19dc12eb d7d6b795300692b2f41957ce72ccdee29cf95ce2 mohammedalharbi <[email protected]> 1519181878 -0500 commit: lap3
d7d6b795300692b2f41957ce72ccdee29cf95ce2 74f5bd1b9585fd8676cf3d1c4382f6ec562680cb mohammedalharbi <[email protected]> 1519181900 -0500 merge 6b3850b5b96aedbd8c8595c8532ad8f7b18af418: Merge made by recursive.
74f5bd1b9585fd8676cf3d1c4382f6ec562680cb 64506a6dd3dac60899bcd529ce6381a5cddbc03c mohammedalharbi <[email protected]> 1520970106 -0400 commit: lap3
64506a6dd3dac60899bcd529ce6381a5cddbc03c 72095e7c283a7b1e57d54464d87b9bc0168482f2 mohammedalharbi <[email protected]> 1520970198 -0400 merge 7b4374acc0bd543c76bea7ab86de61e2d39d2ac7: Merge made by recursive.
72095e7c283a7b1e57d54464d87b9bc0168482f2 28097f950a7d27ad1519536c2b305fc237bfb29c mohammedalharbi <[email protected]> 1521153706 -0400 commit: lap3
28097f950a7d27ad1519536c2b305fc237bfb29c 62aa1fe8f836c8e2f7db3d62521e70180bba71fc mohammedalharbi <[email protected]> 1521414134 -0400 commit: lap3
62aa1fe8f836c8e2f7db3d62521e70180bba71fc a62ed382a705487d7667dbe1cd664e4069257396 mohammedalharbi <[email protected]> 1521574637 -0400 commit: deleted extar deucmnets
a62ed382a705487d7667dbe1cd664e4069257396 304fb2fe31611842f6d5bf4858fa6bf934833ac4 mohammedalharbi <[email protected]> 1522015723 -0400 commit: lap3
304fb2fe31611842f6d5bf4858fa6bf934833ac4 ad5d870ff31474c58eed44ac4f2e8987c743415c mohammedalharbi <[email protected]> 1522116992 -0400 commit: lap3
ad5d870ff31474c58eed44ac4f2e8987c743415c 81f115945636e4599b089905d39fdd48728792fd mohammedalharbi <[email protected]> 1522119231 -0400 commit: lap3
81f115945636e4599b089905d39fdd48728792fd c49849e8c3f66c6936ab6ccff8659cbd2299d069 mohammedalharbi <[email protected]> 1523496123 -0400 merge c49849e8c3f66c6936ab6ccff8659cbd2299d069: Fast-forward
c49849e8c3f66c6936ab6ccff8659cbd2299d069 4662788eea9e09d04bc0241270c52e050b506f37 mohammedalharbi <[email protected]> 1523496155 -0400 commit: lap3
4662788eea9e09d04bc0241270c52e050b506f37 aa5347b62bfc16ef5875b980934596795f9ad4be mohammedalharbi <[email protected]> 1523828244 -0400 commit: stage2
aa5347b62bfc16ef5875b980934596795f9ad4be c2e9a520d044f09221a71a769adbe400f1dafcb9 mohammedalharbi <[email protected]> 1524233532 -0400 commit: stage3
c2e9a520d044f09221a71a769adbe400f1dafcb9 68892ff3d3ee00fb7177f3629010dc7544352b49 mohammedalharbi <[email protected]> 1524253317 -0400 commit: stage3
68892ff3d3ee00fb7177f3629010dc7544352b49 628ca4a5d61987fbc62787fdc61e957944585f37 mohammedalharbi <[email protected]> 1524622546 -0400 commit: stage4
628ca4a5d61987fbc62787fdc61e957944585f37 817f82161c5c0d59090c476bddc0c1bd810cbc5c mohammedalharbi <[email protected]> 1524774656 -0400 commit: stage 4
817f82161c5c0d59090c476bddc0c1bd810cbc5c 2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 mohammedalharbi <[email protected]> 1525021777 -0400 commit: stage5
2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 8a155c761a0a183dd8c7a75b2573b9dcfd9e1854 mohammedalharbi <[email protected]> 1525113583 -0400 commit: stage5

Lap3/.git/logs/refs/heads/master

0000000000000000000000000000000000000000 6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a moh <[email protected]> 1517797214 -0500
6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a 8be7ab3c9ba458495c2b37bb192dbaed0470f15d mohammedalharbi <[email protected]> 1517800310 -0500 commit: Room
8be7ab3c9ba458495c2b37bb192dbaed0470f15d 1301775cc1c2b4fd94c7905c963f5f6cfb914a2d mohammedalharbi <[email protected]> 1518056669 -0500 commit: lap01 lap03
1301775cc1c2b4fd94c7905c963f5f6cfb914a2d 3f705e964028fab9fe251a0e491df78a19dc12eb mohammedalharbi <[email protected]> 1518056756 -0500 merge a4e2272a137d2dde8a838d9c73be6e8f12967a27: Merge made by recursive.
3f705e964028fab9fe251a0e491df78a19dc12eb d7d6b795300692b2f41957ce72ccdee29cf95ce2 mohammedalharbi <[email protected]> 1519181878 -0500 commit: lap3
d7d6b795300692b2f41957ce72ccdee29cf95ce2 74f5bd1b9585fd8676cf3d1c4382f6ec562680cb mohammedalharbi <[email protected]> 1519181900 -0500 merge 6b3850b5b96aedbd8c8595c8532ad8f7b18af418: Merge made by recursive.
74f5bd1b9585fd8676cf3d1c4382f6ec562680cb 64506a6dd3dac60899bcd529ce6381a5cddbc03c mohammedalharbi <[email protected]> 1520970106 -0400 commit: lap3
64506a6dd3dac60899bcd529ce6381a5cddbc03c 72095e7c283a7b1e57d54464d87b9bc0168482f2 mohammedalharbi <[email protected]> 1520970198 -0400 merge 7b4374acc0bd543c76bea7ab86de61e2d39d2ac7: Merge made by recursive.
72095e7c283a7b1e57d54464d87b9bc0168482f2 28097f950a7d27ad1519536c2b305fc237bfb29c mohammedalharbi <[email protected]> 1521153706 -0400 commit: lap3
28097f950a7d27ad1519536c2b305fc237bfb29c 62aa1fe8f836c8e2f7db3d62521e70180bba71fc mohammedalharbi <[email protected]> 1521414134 -0400 commit: lap3
62aa1fe8f836c8e2f7db3d62521e70180bba71fc a62ed382a705487d7667dbe1cd664e4069257396 mohammedalharbi <[email protected]> 1521574637 -0400 commit: deleted extar deucmnets
a62ed382a705487d7667dbe1cd664e4069257396 304fb2fe31611842f6d5bf4858fa6bf934833ac4 mohammedalharbi <[email protected]> 1522015723 -0400 commit: lap3
304fb2fe31611842f6d5bf4858fa6bf934833ac4 ad5d870ff31474c58eed44ac4f2e8987c743415c mohammedalharbi <[email protected]> 1522116992 -0400 commit: lap3
ad5d870ff31474c58eed44ac4f2e8987c743415c 81f115945636e4599b089905d39fdd48728792fd mohammedalharbi <[email protected]> 1522119231 -0400 commit: lap3
81f115945636e4599b089905d39fdd48728792fd c49849e8c3f66c6936ab6ccff8659cbd2299d069 mohammedalharbi <[email protected]> 1523496123 -0400 merge c49849e8c3f66c6936ab6ccff8659cbd2299d069: Fast-forward
c49849e8c3f66c6936ab6ccff8659cbd2299d069 4662788eea9e09d04bc0241270c52e050b506f37 mohammedalharbi <[email protected]> 1523496155 -0400 commit: lap3
4662788eea9e09d04bc0241270c52e050b506f37 aa5347b62bfc16ef5875b980934596795f9ad4be mohammedalharbi <[email protected]> 1523828244 -0400 commit: stage2
aa5347b62bfc16ef5875b980934596795f9ad4be c2e9a520d044f09221a71a769adbe400f1dafcb9 mohammedalharbi <[email protected]> 1524233532 -0400 commit: stage3
c2e9a520d044f09221a71a769adbe400f1dafcb9 68892ff3d3ee00fb7177f3629010dc7544352b49 mohammedalharbi <[email protected]> 1524253317 -0400 commit: stage3
68892ff3d3ee00fb7177f3629010dc7544352b49 628ca4a5d61987fbc62787fdc61e957944585f37 mohammedalharbi <[email protected]> 1524622546 -0400 commit: stage4
628ca4a5d61987fbc62787fdc61e957944585f37 817f82161c5c0d59090c476bddc0c1bd810cbc5c mohammedalharbi <[email protected]> 1524774656 -0400 commit: stage 4
817f82161c5c0d59090c476bddc0c1bd810cbc5c 2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 mohammedalharbi <[email protected]> 1525021777 -0400 commit: stage5
2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 8a155c761a0a183dd8c7a75b2573b9dcfd9e1854 mohammedalharbi <[email protected]> 1525113583 -0400 commit: stage5

Lap3/.git/logs/refs/remotes/origin/master

0000000000000000000000000000000000000000 6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a moh <[email protected]> 1517797214 -0500 fetch: created
6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a 8be7ab3c9ba458495c2b37bb192dbaed0470f15d mohammedalharbi <[email protected]> 1517800316 -0500 push: forced-update
8be7ab3c9ba458495c2b37bb192dbaed0470f15d a4e2272a137d2dde8a838d9c73be6e8f12967a27 mohammedalharbi <[email protected]> 1518056754 -0500 fetch: forced-update
a4e2272a137d2dde8a838d9c73be6e8f12967a27 3f705e964028fab9fe251a0e491df78a19dc12eb mohammedalharbi <[email protected]> 1518056767 -0500 push: forced-update
3f705e964028fab9fe251a0e491df78a19dc12eb 6b3850b5b96aedbd8c8595c8532ad8f7b18af418 mohammedalharbi <[email protected]> 1519181898 -0500 fetch: forced-update
6b3850b5b96aedbd8c8595c8532ad8f7b18af418 74f5bd1b9585fd8676cf3d1c4382f6ec562680cb mohammedalharbi <[email protected]> 1519181914 -0500 push: forced-update
74f5bd1b9585fd8676cf3d1c4382f6ec562680cb 7b4374acc0bd543c76bea7ab86de61e2d39d2ac7 mohammedalharbi <[email protected]> 1520970195 -0400 fetch: forced-update
7b4374acc0bd543c76bea7ab86de61e2d39d2ac7 72095e7c283a7b1e57d54464d87b9bc0168482f2 mohammedalharbi <[email protected]> 1520970209 -0400 push: forced-update
72095e7c283a7b1e57d54464d87b9bc0168482f2 28097f950a7d27ad1519536c2b305fc237bfb29c mohammedalharbi <[email protected]> 1521153711 -0400 push: forced-update
28097f950a7d27ad1519536c2b305fc237bfb29c 62aa1fe8f836c8e2f7db3d62521e70180bba71fc mohammedalharbi <[email protected]> 1521414138 -0400 push: forced-update
62aa1fe8f836c8e2f7db3d62521e70180bba71fc a62ed382a705487d7667dbe1cd664e4069257396 mohammedalharbi <[email protected]> 1521574641 -0400 push: forced-update
a62ed382a705487d7667dbe1cd664e4069257396 304fb2fe31611842f6d5bf4858fa6bf934833ac4 mohammedalharbi <[email protected]> 1522015727 -0400 push: forced-update
304fb2fe31611842f6d5bf4858fa6bf934833ac4 06713f96120d3be7e7f95285736775fc251948c3 mohammedalharbi <[email protected]> 1522117006 -0400 fetch: forced-update
06713f96120d3be7e7f95285736775fc251948c3 81f115945636e4599b089905d39fdd48728792fd mohammedalharbi <[email protected]> 1522119237 -0400 push: forced-update
81f115945636e4599b089905d39fdd48728792fd c49849e8c3f66c6936ab6ccff8659cbd2299d069 mohammedalharbi <[email protected]> 1523496112 -0400 fetch: forced-update
c49849e8c3f66c6936ab6ccff8659cbd2299d069 4662788eea9e09d04bc0241270c52e050b506f37 mohammedalharbi <[email protected]> 1523496180 -0400 push: forced-update
4662788eea9e09d04bc0241270c52e050b506f37 aa5347b62bfc16ef5875b980934596795f9ad4be mohammedalharbi <[email protected]> 1523828253 -0400 push: forced-update
aa5347b62bfc16ef5875b980934596795f9ad4be c2e9a520d044f09221a71a769adbe400f1dafcb9 mohammedalharbi <[email protected]> 1524233540 -0400 push: forced-update
c2e9a520d044f09221a71a769adbe400f1dafcb9 68892ff3d3ee00fb7177f3629010dc7544352b49 mohammedalharbi <[email protected]> 1524253328 -0400 push: forced-update
68892ff3d3ee00fb7177f3629010dc7544352b49 628ca4a5d61987fbc62787fdc61e957944585f37 mohammedalharbi <[email protected]> 1524622551 -0400 push: forced-update
628ca4a5d61987fbc62787fdc61e957944585f37 817f82161c5c0d59090c476bddc0c1bd810cbc5c mohammedalharbi <[email protected]> 1524774660 -0400 push: forced-update
817f82161c5c0d59090c476bddc0c1bd810cbc5c 2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 mohammedalharbi <[email protected]> 1525021783 -0400 push: forced-update
2f0a6ca2c6efb9aedd4ced8e7bdaf738f7d55568 8a155c761a0a183dd8c7a75b2573b9dcfd9e1854 mohammedalharbi <[email protected]> 1525113591 -0400 push: forced-update

Lap3/.git/refs/heads/master

8a155c761a0a183dd8c7a75b2573b9dcfd9e1854

Lap3/.git/refs/remotes/origin/master

8a155c761a0a183dd8c7a75b2573b9dcfd9e1854

Lap3/.git/index

Lap3/.git/packed-refs

# pack-refs with: peeled c49849e8c3f66c6936ab6ccff8659cbd2299d069 refs/remotes/origin/master 4ac879131a87d788dfb3c49288bfe5937d9540e2 refs/tags/stage0-attempt0 3f0677794ccdc4cfbfe0cd1f4e935c4b92e66d21 refs/tags/stage0-attempt1 a4e2272a137d2dde8a838d9c73be6e8f12967a27 refs/tags/stage0-attempt2 ab0d125ad8419d989dbf88c9a8f98a153809b772 refs/tags/stage0-attempt3-accepted 62aa1fe8f836c8e2f7db3d62521e70180bba71fc refs/tags/stage1-attempt0 06713f96120d3be7e7f95285736775fc251948c3 refs/tags/stage1-attempt1 c49849e8c3f66c6936ab6ccff8659cbd2299d069 refs/tags/stage1-attempt2-accepted

Lap3/.git/COMMIT_EDITMSG

stage5

Lap3/.git/FETCH_HEAD

c49849e8c3f66c6936ab6ccff8659cbd2299d069 not-for-merge branch 'master' of https://github.com/kings-cs/CS117-S18-AlharbiMohammed.git c49849e8c3f66c6936ab6ccff8659cbd2299d069 not-for-merge tag 'stage1-attempt2-accepted' of https://github.com/kings-cs/CS117-S18-AlharbiMohammed.git

Lap3/Edible.java

Lap3/Edible.java

/**
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. 
 * 
 *  @author  mohammed alharbi
 *  @version  29/4/2018
 */
public   interface   Edible   {
    
     /**
     * eat .
     *  @param  p the current game character
     *  @return  true
     */
     public   String  eat ( Player  p );
    
}

Lap3/Reader.ctxt

#BlueJ class context comment0.target=Reader comment0.text=\n\ This\ class\ is\ part\ of\ the\ "Campus\ of\ Kings"\ application.\ "Campus\ of\ Kings"\ is\ a\n\ very\ simple,\ text\ based\ adventure\ game.\n\ \n\ This\ parser\ reads\ user\ input\ and\ tries\ to\ interpret\ it\ as\ an\ "Adventure"\n\ command.\ Every\ time\ it\ is\ called\ it\ reads\ a\ line\ from\ the\ terminal\ and\ tries\n\ to\ interpret\ the\ line\ as\ a\ two\ word\ command.\ It\ returns\ the\ command\ as\ an\n\ object\ of\ class\ Command.\n\ \n\ The\ parser\ has\ a\ set\ of\ known\ command\ words.\ It\ checks\ user\ input\ against\ the\n\ known\ commands,\ and\ if\ the\ input\ is\ not\ one\ of\ the\ known\ commands,\ it\ returns\n\ a\ command\ object\ that\ is\ marked\ as\ an\ unknown\ command.\n\ a\n\ @author\ Maria\ Jump\n\ @version\ 2017.12.18\n comment1.params= comment1.target=Command\ getCommand() comment1.text=\n\ Returns\ the\ next\ command\ from\ the\ user.\n\ @return\ The\ next\ command\ from\ the\ user.\n comment2.params= comment2.target=java.lang.String\ getResponse() comment2.text=\n\ Return\ the\ response\ to\ a\ question\ in\ all\ lower\ case.\n\n\ @return\ The\ response\ typed\ in\ by\ the\ user.\n comment3.params= comment3.target=java.lang.String\ getResponseKeepCase() comment3.text=\n\ Return\ the\ response\ to\ a\ question\ in\ the\ case\ used\ by\ the\ player.\n\n\ @return\ The\ response\ typed\ in\ by\ the\ user.\n numComments=4

Lap3/Writer.ctxt

#BlueJ class context comment0.target=Writer comment0.text=\n\ This\ class\ is\ a\ substitute\ for\ printing\ to\ standard\ out\ in\ our\ original\ text\n\ adventure\ game.\ It\ uses\ a\ simple\ console\ to\ display\ the\ messages.\n\ \n\ @author\ Maria\ Jump\n\ @version\ 2016-12-18\n comment1.params=text comment1.target=void\ setTextArea(javax.swing.JTextPane) comment1.text=\n\ Mutator\ for\ the\ text\ component.\n\ \n\ @param\ text\n\ \ \ \ \ \ \ \ \ \ \ \ The\ text\ component.\n comment10.params=toPrint comment10.target=void\ println(java.lang.String) comment10.text=\n\ Prints\ a\ string\ after\ word-wrapping\ it\ to\ 80\ characters\ if\ possible.\ Note\n\ that\ this\ fails\ to\ calculate\ correct\ widths\ if\ the\ string\ contains\ tabs.\n\ Ends\ with\ a\ line\ return.\n\n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ String\ to\ print.\n comment11.params=toPrint comment11.target=void\ print(java.lang.String) comment11.text=\n\ Prints\ a\ string\ after\ word-wrapping\ it\ to\ 80\ characters\ if\ possible.\ Note\n\ that\ this\ fails\ to\ calculate\ correct\ widths\ if\ the\ string\ contains\ tabs.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ String\ to\ print.\n comment12.params=toPrint comment12.target=void\ standardPrint(java.lang.String) comment12.text=\n\ Helper\ method\ for\ standard\ printing.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ String\ to\ print.\n comment13.params=attributes\ toPrint comment13.target=void\ printWithAttributes(javax.swing.text.SimpleAttributeSet,\ java.lang.String) comment13.text=\n\ Helper\ method\ printing\ with\ attributes.\n\n\ @param\ attributes\n\ \ \ \ \ \ \ \ \ \ \ \ A\ set\ of\ attributes\ to\ use\ when\ printing.\n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ String\ to\ print.\n\ @throws\ IllegalStateException\n\ \ \ \ \ \ \ \ \ \ \ \ \ If\ the\ text\ area\ has\ not\ been\ set\ and\ we\ are\ trying\ to\ print\n\ \ \ \ \ \ \ \ \ \ \ \ \ to\ it.\n comment14.params= comment14.target=void\ restartLog() comment14.text=\n\ Restart\ the\ default\ log.\n comment15.params= comment15.target=void\ copyDefaultLog() comment15.text=\n\ Copy\ the\ default\ log.\n comment2.params=input comment2.target=void\ printInput(java.lang.String) comment2.text=\n\ Print\ the\ user\ input\ in\ blue.\n\ \n\ @param\ input\n\ \ \ \ \ \ \ \ \ \ \ \ The\ text\ entered\ by\ the\ user.\n comment3.params= comment3.target=void\ println() comment3.text=\n\ Prints\ an\ empty\ line.\n comment4.params=toPrint comment4.target=void\ println(int) comment4.text=\n\ Prints\ out\ a\ single\ integer\ to\ a\ line.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ integer\ to\ print.\n comment5.params=toPrint comment5.target=void\ print(int) comment5.text=\n\ Prints\ out\ a\ single\ integer.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ integer\ to\ print.\n comment6.params=toPrint comment6.target=void\ println(double) comment6.text=\n\ Prints\ out\ a\ double\ to\ a\ line.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ double\ to\ print.\n comment7.params=toPrint comment7.target=void\ print(double) comment7.text=\n\ Prints\ out\ a\ double.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ double\ to\ print.\n comment8.params=toPrint comment8.target=void\ println(java.lang.Object) comment8.text=\n\ Prints\ out\ an\ object\ to\ a\ line.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ object\ to\ print.\n comment9.params=toPrint comment9.target=void\ print(java.lang.Object) comment9.text=\n\ Prints\ out\ a\ object.\n\ \n\ @param\ toPrint\n\ \ \ \ \ \ \ \ \ \ \ \ The\ object\ to\ print.\n numComments=16

Lap3/Command.java#backup

Lap3/Command.java#backup

 

import  java . util . ArrayList ;


/**
 * This class is part of the "Campus of Kings" application. "Campus of Kings" is a
 * very simple, text based adventure game.
 * 
 * This class holds information about a command that was issued by the user. A
 * command currently consists of two strings: a command word and a second word
 * (for example, if the command was "take map", then the two strings obviously
 * are "take" and "map").
 * 
 * The way this is used is: Commands are already checked for being valid command
 * words. If the user entered an invalid command (a word that is not known) then
 * the command word is <null>.
 * 
 * If the command had only one word, then the second word is <null>.
 * 
 *  @author  Maria Jump
 *  @version  2015.02.01
 */

public   class   Command   {
     /** The command word for this command. */
     private   CommandEnum  commandWord ;
     /** The rest of the line with all the spaces removed. */
     private   ArrayList < String >  restOfLine ;

     /**
     * Create a command object. First is supplied. The second word is assumed
     * to be null.
     * 
     *  @param  firstWord
     *            The first word of the command. Null if the command was not
     *            recognized.
     */
     public   Command ( String  firstWord )   {
        commandWord  =   CommandWords . getCommand ( firstWord );
        restOfLine  =   new   ArrayList < String > ();
                
     }
    
     /**
     * Create a command object. First and second word must be supplied, but
     * either one (or both) can be null.
     * 
     *  @param  firstWord
     *            The first word of the command. Null if the command was not
     *            recognized.
     *  @param  rest
     *            The rest of the command.
     */
     public   Command ( String  firstWord ,   ArrayList < String >  rest )   {
        commandWord  =   CommandWords . getCommand ( firstWord );
        restOfLine  =  rest ;
     }

     /**
     * Return the command word (the first word) of this command. If the command
     * was not understood, the result is null.
     * 
     *  @return  The command word.
     */
     public   CommandEnum  getCommandWord ()   {
            
         return  commandWord ;
     }

     /**
     * Returns if this command was not understood.
     * 
     *  @return  true if this command was not understood.
     */
     public   boolean  isUnknown ()   {
         return   ( commandWord  ==   null );
     }

     /**
     * Returns if this command has a second word.
     * 
     *  @return  true if the command has a second word.
     */
     public   boolean  hasSecondWord ()   {
         return  restOfLine  !=   null ;
     }
    
     /**
     * Returns if this command has more words.
     *
     *  @param  index The index of the word needed.
     *  @return  true if the command has a word at given index.
     */
     public   boolean  hasWord ( int  index )   {
         return  index  >=   0   &&  index  <  restOfLine . size ();
     }
    
     /**
     * Returns the word at the requested index in the command.
     * 
     *  @param  index
     *            The index of word in the command that is being requested.
     * 
     *  @return  A particular word in the command. Returns null if there is no
     *         word corresponding to that requested index.
     * 
     */
     public   String  getWord ( int  index )   {
         String  result  =   null ;
         if   ( index  >=   0   &&  index  <  restOfLine . size ())   {
            result  =  restOfLine . get ( index );
         }
         return  result ;
     }    
    

     /**
     * Returns the second word of this command, if it exists.
     * 
     *  @return  The second word of this command. Returns null if there was no
     *         second word.
     */
     public   String  getRestOfLine ()   {
         StringBuffer  buffer  =   null ;
         if   ( restOfLine . size ()   !=   0 )   {
             for ( String  word  :  restOfLine )   {
                 if   ( buffer  ==   null )   {
                    buffer  =   new   StringBuffer ();
                    buffer . append ( word );
                 }
                 else   {
                    buffer . append ( " " );
                    buffer . append ( word );
                 }
             }
         }
         String  result  =   "" ;
         if   ( buffer  !=   null )   {
            result  +=  buffer . toString ();
         }
         return  result ;
     }
}

Lap3/Drinkable.class

public abstract interface Drinkable {
    public abstract String drink(Player);
}

Lap3/Writer.class

public synchronized class Writer {
    private static final String NEW_LINE;
    private static final String DEFAULT_LOG;
    private static javax.swing.JTextPane textArea;
    public void Writer();
    public static void setTextArea(javax.swing.JTextPane);
    public static void printInput(String);
    public static void println();
    public static void println(int);
    public static void print(int);
    public static void println(double);
    public static void print(double);
    public static void println(Object);
    public static void print(Object);
    public static void println(String);
    public static void print(String);
    private static void standardPrint(String);
    private static void printWithAttributes(javax.swing.text.SimpleAttributeSet, String) throws IllegalStateException;
    public static void restartLog();
    public static void copyDefaultLog();
    static void <clinit>();
}

Lap3/Item.java

Lap3/Item.java

/*
 * Class Item - An item in the game that the player can
 * pick or drop
 * The class also describe items in the game by their name, weight etc
 */

/**
 * Class Item - An item in the game that the player can
 * pick or drop.
 * The class also describe items in the game by their name, weight etc
 * 
 *  @author  Mohammed Alharbi
 *  @version  2018/4/24
 */

public   class   Item   {
     /** the name. */
     private   String  name ;
     /** the description. */
     private   String  description ;
     /** the pointValue . */
     private   int  weight ;
     /** the weight. */
     private   int   pointVal ;
     /** item.
     *  @param  name the name.
     *  @param  pointValue the pointValue
     *  @param  description the description
     *  @param  weight the weight
     */
     public   Item ( String  name ,   int  pointValue ,   String  description ,   int  weight )   {

         this . name  =  name ;

         this . description  =  description ;

         this . pointVal  =  pointValue ;

         this . weight  =  weight ;
     }

     /**
     * 
     * Returns the name of an item.
     *  @return  The name of an item.
     * 
     **/
     public   String  getName (){

         return  name ;
     }

     /**
     * 
     * Returns the description of an item.
     *  @return  The description of an item.
     * 
     **/
     public   String  getDescription (){

         return  description ;
     }

     /**
     * 
     * Sets the description of a room.
     * @param  desc the desc. 
     **/
     public   void  setDescription ( String  desc ){

        description  =  desc ;
     }

     /** item. 
     * @param  item the item.

     */         
     public   void  addItem ( Item  item ){

     }

     /** item. 
     * @param  item the item.
     * @return  item the item.
     */
     public   Item  removeItem ( String  item ){

         return   null ;
     }

     /** item. 
     * @param  item the item.
     * @return  item the item.
     */
     public   Item  getItem ( String  item ){

         return   null ;
     }

     /**
     * 
     * Returns the pointValue of an item.
     *  @return  The pointValue of an item.
     * 
     **/
     public   int  getPointValue (){

         return  pointVal ;
     }

     /**
     * 
     * Returns the weight of an item.
     *  @return  The weight of an item.
     * 
     **/
     public   int  getWeight (){

         return  weight ;
     }

    @ Override
     public   String  toString (){

         String  itemInfo  =   "" ;

        itemInfo  +=   "Name : "   +  getName ()   +   "\n" ;

        itemInfo  +=   "Description : "   +  getDescription ()   +   "\n" ;

        itemInfo  +=   "Weight : "   +  getWeight ()   +   "grams" ;

         return  itemInfo ;
     }
}

Lap3/Weapon.java

Lap3/Weapon.java

/**
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor. 
 * 
 *  @author  mohammed alharbi
 *  @version  29/4/2018
 */
public   class   Weapon   extends   Item   implements   Equippable {
     /**
     * weapon.
     *  @param  name the name
     *  @param  pointValue the pointValue.
     *  @param  description teh description.
     *  @param  weight teh weight.
     */
     public   Weapon ( String  name ,   int  pointValue ,   String  description ,   int  weight )   {
         super ( name ,  pointValue ,  description ,  weight );
     }

    @ Override
     public   String  equip ( Player  p )   {         
        
        p . setCurrentWeapon ( this );
        
        p . removeItem ( this . getName ());
        
         return   "weapon equiped" ;
     }

    @ Override
     public   String  unequip ( Player  p )   {
        
        p . inventoryAddItem ( this );
        
        p . setCurrentWeapon ( null );
        
         return   "weapon unequipped" ;
     }
    
}

__MACOSX/Lap3/._Weapon.java