Lap3 2/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 2/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= comment10.target=void\ look() comment10.text=\n\ prints\ out\ the\ location\ information.\n\ \n comment2.params= comment2.target=void\ play() comment2.text=\n\ Main\ play\ routine.\ Loops\ until\ end\ of\ play.\n comment3.params=command comment3.target=boolean\ processCommand(Command) comment3.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 comment4.params=command comment4.target=void\ goGame(Command) comment4.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 comment5.params= comment5.target=void\ printGoodbye() comment5.text=\n\ Print\ out\ the\ closing\ message\ for\ the\ player.\n comment6.params= comment6.target=void\ printLocationInformation() comment6.text=\n\ Prints\ out\ the\ current\ location\ and\ exits.\n comment7.params= comment7.target=void\ printHelp() comment7.text=\n\ Print\ out\ some\ help\ information.\ Here\ we\ print\ some\ stupid,\ cryptic\n\ message\ and\ a\ list\ of\ the\ command\ words.\n comment8.params= comment8.target=void\ printWelcome() comment8.text=\n\ Print\ out\ the\ opening\ message\ for\ the\ player.\n comment9.params=command comment9.target=boolean\ quit(Command) comment9.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 numComments=11
Lap3 2/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 comment2.params= comment2.target=Room\ getcurrentRoom() comment2.text=\ accessor\ \ for\ the\ current\ room\ the\ character.\n\ @return\ cerrentRoom\n comment3.params=playing comment3.target=void\ setcurrentRoom(Room) comment3.text=\ a\ mutator\ for\ the\ current\ room\ the\ character.\n\ @param\ playing\ for\ the\ Room\n numComments=4
Lap3 2/Room.java
Lap3 2/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
*
@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
;
}
}
__MACOSX/Lap3 2/._Room.java
Lap3 2/Door.java
Lap3 2/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
*
@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
;
}
}
__MACOSX/Lap3 2/._Door.java
Lap3 2/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 2/.DS_Store
__MACOSX/Lap3 2/._.DS_Store
Lap3 2/World.java
Lap3 2/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
*
@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
);
}
}
__MACOSX/Lap3 2/._World.java
Lap3 2/Game.class
public synchronized class Game { private World world; private int score; private int turns; private Player playerClass; public void Game(); public void play(); private boolean processCommand(Command); private void goGame(Command); private void printGoodbye(); private void printLocationInformation(); private void printHelp(); private void printWelcome(); private boolean quit(Command); private void look(); }
Lap3 2/CommandEnum.java
Lap3 2/CommandEnum.java
import
java
.
util
.
HashMap
;
/**
* Write a description of class CommandEnum here.
*
*
@author
(your name)
*
@version
(a version number or a date)
*/
public
class
CommandEnum
{
/** A constant array that holds all valid commandEnum. */
private
static
HashMap
<
String
,
CommandEnum
>
validCommands
=
new
HashMap
<
String
,
CommandEnum
>
();
/**
* Static block to initialize the fields of CommandEnum.
*/
static
{
String
tempCommands
=
{
"look"
,
"go"
,
"quit"
,
"help"
};
validCommands
=
CommandEnum
;
for
(
CommandEnum
value
:
CommandEnum
.
values
())
{
validCommands
.
put
(
value
.
getCommand
(),
value
);
}
}
public
static
CommandEnum
getCommand
(
String
theString
){
return
validCommands
.
get
(
theString
);
}
}
__MACOSX/Lap3 2/._CommandEnum.java
Lap3 2/Writer.java
Lap3 2/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
*
@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
);
}
}
}
__MACOSX/Lap3 2/._Writer.java
Lap3 2/Main$1.class
synchronized class Main$1 extends java.awt.event.ComponentAdapter { void Main$1(Main); public void componentResized(java.awt.event.ComponentEvent); }
Lap3 2/Command.java
Lap3 2/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
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
;
}
}
__MACOSX/Lap3 2/._Command.java
Lap3 2/Command.class
public synchronized class Command { private String commandWord; private java.util.ArrayList restOfLine; public void Command(String); public void Command(String, java.util.ArrayList); public String getCommandWord(); public boolean isUnknown(); public boolean hasSecondWord(); public boolean hasWord(int); public String getWord(int); public String getRestOfLine(); }
Lap3 2/Room.class
public synchronized class Room { private static int counter; private String name; private String description; private int points; private java.util.HashMap directions; 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 String toString(); static void <clinit>(); }
Lap3 2/defaultlog.txt
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 2/Reader.java
Lap3 2/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.
*
*
@author
*
@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
()
{
CommandEnum
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
);
}
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 2/._Reader.java
Lap3 2/team.defs
#Mon Mar 26 22:16:27 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.yourName=mohammedalharbi bluej.teamsettings.ignore7=.*\\\#backup 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 2/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 2/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=name comment2.target=Room\ getcurrentRoom(java.lang.String) comment2.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 comment3.params=theRoom comment3.target=void\ addRoom(Room) comment3.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 comment4.params=from\ direction\ to comment4.target=void\ createDoor(Room,\ java.lang.String,\ Room) comment4.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 comment5.params= comment5.target=void\ createRooms() comment5.text=\n\ This\ method\ creates\ all\ of\ the\ individual\ places\ in\ this\ world\ and\ all\n\ the\ doors\ connecting\ them.\n numComments=6
Lap3 2/.gitignore
*.class *.ctxt *.*~ doc /.project default.log
Lap3 2/Player.java
Lap3 2/Player.java
/**
* class Player.
*
@author
*
@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
;
}
}
__MACOSX/Lap3 2/._Player.java
Lap3 2/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\ room's\ name.\n\ @param\ description\n\ \ \ The\ room's\ description.\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\ Rerurns\ the\ door\ of\ this\ room.\n\ @return\ The\ door\ of\ this\ room\n comment5.params= comment5.target=int\ getCounter() comment5.text=\n\ Rerutn\ 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\ thae\ direction.\n\ @param\ direction\n\ @return\n comment7.params=newPoints comment7.target=void\ setPoints(int) comment7.text=\ Mutator\ for\ setting\ the\ points.\n\ @param\ newPoint\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= comment9.target=java.lang.String\ toString() comment9.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 numComments=10
Lap3 2/Game.java
Lap3 2/Game.java
import
java
.
util
.
HashMap
;
import
java
.
util
.
ArrayList
;
/**
* 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
*
@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
(
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
(
"look 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
;
}
/**
* prints out the location information.
*
*/
private
void
look
(){
printLocationInformation
();
}
}
__MACOSX/Lap3 2/._Game.java
Lap3 2/Main.java
Lap3 2/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 2/._Main.java
Lap3 2/CommandWords.java
Lap3 2/CommandWords.java
import
java
.
util
.
HashMap
;
/**
* 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
*
@version
2015.02.01
*/
public
class
CommandWords
{
/** A constant array that holds all valid command words. */
private
static
HashMap
<
String
,
CommandEnum
>
validCommands
=
new
HashMap
<
String
,
CommandEnum
>
();
/**
* Static block to initialize the fields of CommandWords.
*/
static
{
//String tempCommands = {"look","go", "quit", "help" };
//validCommands = CommandEnum;
for
(
CommandEnum
value
:
CommandEnum
.
values
())
{
validCommands
.
put
(
value
.
getCommand
(),
value
);
}
}
/**
* 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
;
int
index
=
0
;
while
(
!
valid
&&
index
<
validCommands
.
length
)
{
if
(
validCommands
[
index
].
equals
(
aString
))
{
valid
=
true
;
}
index
++
;
}
// if we get here, the string was not found in the commands
return
valid
;
}
/**
* Retuerns 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
(){
return
getCommandString
();
}
/**
* Converts a String into a CommandEnum oblect.
*
@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
validCommands
.
get
(
theString
);
}
}
__MACOSX/Lap3 2/._CommandWords.java
Lap3 2/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 2/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=locked comment4.target=void\ setLocked(boolean) comment4.text=\n\ A\ setter\ for\ whether\ this\ door\ is\ locked.\n\ @param\ locked\ Whether\ this\ door\ is\ locked.\n numComments=5
Lap3 2/Player.class
public synchronized class Player { private Room currentRoom; public void Player(Room); public Room getcurrentRoom(); public void setcurrentRoom(Room); }
Lap3 2/World.class
public synchronized class World { private java.util.HashMap rooms; public void World(); public Room getcurrentRoom(String); private void addRoom(Room); private void createDoor(Room, String, Room); private void createRooms(); }
Lap3 2/documents/.DS_Store
__MACOSX/Lap3 2/documents/._.DS_Store
Lap3 2/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 2/documents/._Game.xml
Lap3 2/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 2/documents/._Game name copy.docx
Lap3 2/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 2/package.bluej
#BlueJ package file dependency1.from=Door dependency1.to=Room dependency1.type=UsesDependency dependency10.from=Game dependency10.to=Room dependency10.type=UsesDependency dependency11.from=Game dependency11.to=Reader dependency11.type=UsesDependency dependency12.from=Game dependency12.to=Writer dependency12.type=UsesDependency dependency13.from=Reader dependency13.to=Command dependency13.type=UsesDependency dependency14.from=Reader dependency14.to=Writer dependency14.type=UsesDependency dependency15.from=Reader dependency15.to=CommandWords dependency15.type=UsesDependency dependency16.from=Main dependency16.to=Game dependency16.type=UsesDependency dependency17.from=Main dependency17.to=Writer dependency17.type=UsesDependency dependency2.from=Player dependency2.to=Room dependency2.type=UsesDependency dependency3.from=World dependency3.to=Room dependency3.type=UsesDependency dependency4.from=World dependency4.to=Door dependency4.type=UsesDependency dependency5.from=Room dependency5.to=Door dependency5.type=UsesDependency dependency6.from=Game dependency6.to=World dependency6.type=UsesDependency dependency7.from=Game dependency7.to=Player dependency7.type=UsesDependency dependency8.from=Game dependency8.to=Command dependency8.type=UsesDependency dependency9.from=Game dependency9.to=Door dependency9.type=UsesDependency editor.fx.0.height=674 editor.fx.0.width=638 editor.fx.0.x=557 editor.fx.0.y=25 objectbench.height=101 objectbench.width=628 package.divider.horizontal=0.6 package.divider.vertical=0.8007380073800738 package.editor.height=411 package.editor.width=503 package.editor.x=714 package.editor.y=96 package.frame.height=600 package.frame.width=652 package.numDependencies=17 package.numTargets=10 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=Player target1.showInterface=false target1.type=ClassTarget target1.width=80 target1.x=390 target1.y=320 target10.height=50 target10.name=Writer target10.showInterface=false target10.type=ClassTarget target10.width=80 target10.x=30 target10.y=170 target2.height=50 target2.name=Game target2.naviview.expanded=true target2.showInterface=false target2.type=ClassTarget target2.width=80 target2.x=240 target2.y=20 target3.height=50 target3.name=Command target3.showInterface=false target3.type=ClassTarget target3.width=90 target3.x=40 target3.y=340 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=World target5.showInterface=false target5.type=ClassTarget target5.width=80 target5.x=370 target5.y=20 target6.height=50 target6.name=CommandWords target6.showInterface=false target6.type=ClassTarget target6.width=130 target6.x=10 target6.y=260 target7.height=50 target7.name=Room target7.showInterface=false target7.type=ClassTarget target7.width=80 target7.x=430 target7.y=220 target8.height=50 target8.name=Main target8.showInterface=false target8.type=ClassTarget target8.width=80 target8.x=70 target8.y=20 target9.height=50 target9.name=Door target9.showInterface=false target9.type=ClassTarget target9.width=80 target9.x=510 target9.y=80
Lap3 2/Door.class
public synchronized class Door { private Room destination; private boolean locked; public void Door(Room); public Room getDestination(); public boolean isLocked(); public void setLocked(boolean); }
Lap3 2/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=java.lang.String\ 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 2/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 2/.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 2/.git/objects/0d/dd05f92f2d9f0d16c6fbea1c09b2ece7b1422f
Lap3 2/.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 2/.git/objects/0d/92bd7810b78525d6937e9395ab078b69ff31ef
Lap3 2/.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 2/.git/objects/0c/efac37058dc468b1bb5e637b68ea8a8abe5e02
Lap3 2/.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 2/.git/objects/3e/d1ad10557200c7dda9781c0163f9dfdf1440d8
Lap3 2/.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 2/.git/objects/51/7feb6375a09bfa2f9de8968ffb458cc34a2904
Lap3 2/.git/objects/51/7feb6375a09bfa2f9de8968ffb458cc34a2904
Lap3 2/.git/objects/67/10927b5418b35dac1bd71c3904707522be1330
Lap3 2/.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 2/.git/objects/0b/54102bee4956f451cecec5e699795e9af23e7a
Lap3 2/.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 2/.git/objects/94/5ebe2b1f73e262c642844596d9a5691a6d343a
Lap3 2/.git/objects/94/5ebe2b1f73e262c642844596d9a5691a6d343a
Lap3 2/.git/objects/0e/98e700ea30820baaedc369b97a8cdb32c8205d
Lap3 2/.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 2/.git/objects/33/c652c2507d0cc360c76895d7f9d431365d070e
Lap3 2/.git/objects/33/c652c2507d0cc360c76895d7f9d431365d070e
Lap3 2/.git/objects/d9/6adf78bc53d4e2b3c81826987cb62150b25863
Lap3 2/.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 2/.git/objects/ac/9a3fc965cae9ddc32aaae75a37c8a71bc452a8
Lap3 2/.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 2/.git/objects/ad/5d870ff31474c58eed44ac4f2e8987c743415c
Lap3 2/.git/objects/ad/5d870ff31474c58eed44ac4f2e8987c743415c
commit 232�tree 3fdab05801a9f2211b9b2cc052c4ccad75e77b45 parent 304fb2fe31611842f6d5bf4858fa6bf934833ac4 author mohammedalharbi <[email protected]> 1522116992 -0400 committer mohammedalharbi <[email protected]> 1522116992 -0400 lap3
Lap3 2/.git/objects/d7/d6b795300692b2f41957ce72ccdee29cf95ce2
Lap3 2/.git/objects/d7/d6b795300692b2f41957ce72ccdee29cf95ce2
commit 232�tree 6cef56a888dd99dcbb0a165075f06b6f04af7b4c parent 3f705e964028fab9fe251a0e491df78a19dc12eb author mohammedalharbi <[email protected]> 1519181878 -0500 committer mohammedalharbi <[email protected]> 1519181878 -0500 lap3
Lap3 2/.git/objects/df/80e5d47e15386febd1a724fdb3c7e087f1d6b4
Lap3 2/.git/objects/df/80e5d47e15386febd1a724fdb3c7e087f1d6b4
Lap3 2/.git/objects/a2/617388ab7ab0565e40091ae75dc874c3d738c2
Lap3 2/.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 2/.git/objects/a5/0058e243ec0e4732cbdbf794b1dc700fc6a5dd
Lap3 2/.git/objects/a5/0058e243ec0e4732cbdbf794b1dc700fc6a5dd
Lap3 2/.git/objects/d6/8020e28958745ee47bc6d264c57309e7791c06
Lap3 2/.git/objects/d6/8020e28958745ee47bc6d264c57309e7791c06
Lap3 2/.git/objects/d6/5e566f4424108f36c75595e355d28fef5d76b8
Lap3 2/.git/objects/d6/5e566f4424108f36c75595e355d28fef5d76b8
Lap3 2/.git/objects/bc/c60a87d35cb11a5f13bb6e067c3ba5b75c3975
Lap3 2/.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 2/.git/objects/c9/c2c1714b00122efc17689d12d9a845a80199e3
Lap3 2/.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 2/.git/objects/f5/7b88c9d1b8ac6a81beaf0ea7f5cd3f157d699c
Lap3 2/.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 2/.git/objects/c6/2063f7af6c984d998530e2af1ed4d51ee9aefa
Lap3 2/.git/objects/c6/2063f7af6c984d998530e2af1ed4d51ee9aefa
Lap3 2/.git/objects/4e/eb29795bd70f62bb6e7ebf829c65b29deb70b6
Lap3 2/.git/objects/4e/eb29795bd70f62bb6e7ebf829c65b29deb70b6
Lap3 2/.git/objects/pack/pack-392afbcc87b5190d2606e3171c0c2d7641a74985.pack
Lap3 2/.git/objects/pack/pack-a7c7707b0757bde831a46640d805439ad5138689.pack
Lap3 2/.git/objects/pack/pack-b29326e846551bdd235e86ee4c6e6b24e01c76c7.idx
Lap3 2/.git/objects/pack/pack-b29326e846551bdd235e86ee4c6e6b24e01c76c7.pack
Lap3 2/.git/objects/pack/pack-a7c7707b0757bde831a46640d805439ad5138689.idx
Lap3 2/.git/objects/pack/pack-8eb9fa29cb40d3109018533e63943a1c9fe207e0.pack
Lap3 2/.git/objects/pack/pack-392afbcc87b5190d2606e3171c0c2d7641a74985.idx
Lap3 2/.git/objects/pack/pack-48d6f0093f364e5ecb7efb7fec999f6493eb0e19.idx
Lap3 2/.git/objects/pack/pack-8eb9fa29cb40d3109018533e63943a1c9fe207e0.idx
Lap3 2/.git/objects/pack/pack-48d6f0093f364e5ecb7efb7fec999f6493eb0e19.pack
Lap3 2/.git/objects/42/d828d2971fdab5da809ed89cc39435907c9f89
Lap3 2/.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 2/.git/objects/45/b4bcc42b3969b307a4b1babef5f2030a73c610
Lap3 2/.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 2/.git/objects/87/29f68f372f137ae0e40ccb51e3345d9f05b78d
Lap3 2/.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 2/.git/objects/74/f5bd1b9585fd8676cf3d1c4382f6ec562680cb
Lap3 2/.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 2/.git/objects/28/097f950a7d27ad1519536c2b305fc237bfb29c
Lap3 2/.git/objects/28/097f950a7d27ad1519536c2b305fc237bfb29c
commit 232�tree 945ebe2b1f73e262c642844596d9a5691a6d343a parent 72095e7c283a7b1e57d54464d87b9bc0168482f2 author mohammedalharbi <[email protected]> 1521153706 -0400 committer mohammedalharbi <[email protected]> 1521153706 -0400 lap3
Lap3 2/.git/objects/8f/6c0ac67d90add1d72c1a79623d9de85ced0915
Lap3 2/.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 2/.git/objects/4c/92ee36c15271f6e9c5ad6388735280db9361d8
Lap3 2/.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 2/.git/objects/81/f115945636e4599b089905d39fdd48728792fd
Lap3 2/.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 2/.git/objects/72/095e7c283a7b1e57d54464d87b9bc0168482f2
Lap3 2/.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 2/.git/objects/72/b4bae1638e99dfe920fb5606cbb891f2a529c2
Lap3 2/.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 2/.git/objects/6b/1e6515c63f643ad52418df4385facb8dc92a20
Lap3 2/.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 2/.git/objects/6b/36ca17784d3d6b46d8d2259854c4694df0dea2
Lap3 2/.git/objects/6b/36ca17784d3d6b46d8d2259854c4694df0dea2
Lap3 2/.git/objects/62/aa1fe8f836c8e2f7db3d62521e70180bba71fc
Lap3 2/.git/objects/62/aa1fe8f836c8e2f7db3d62521e70180bba71fc
commit 233�tree 6b36ca17784d3d6b46d8d2259854c4694df0dea2 parent 28097f950a7d27ad1519536c2b305fc237bfb29c author mohammedalharbi <[email protected]> 1521414134 -0400 committer mohammedalharbi <[email protected]> 1521414134 -0400 lap3
Lap3 2/.git/objects/62/08fab7077ff5d0d4b2a70f1a7399be32fa436a
Lap3 2/.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 2/.git/objects/53/97a1c08eb82f45423d4c4dd7baefe7deca6789
Lap3 2/.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 2/.git/objects/3f/705e964028fab9fe251a0e491df78a19dc12eb
Lap3 2/.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 2/.git/objects/3f/dab05801a9f2211b9b2cc052c4ccad75e77b45
Lap3 2/.git/objects/3f/dab05801a9f2211b9b2cc052c4ccad75e77b45
Lap3 2/.git/objects/30/4fb2fe31611842f6d5bf4858fa6bf934833ac4
Lap3 2/.git/objects/30/4fb2fe31611842f6d5bf4858fa6bf934833ac4
commit 232�tree c62063f7af6c984d998530e2af1ed4d51ee9aefa parent a62ed382a705487d7667dbe1cd664e4069257396 author mohammedalharbi <[email protected]> 1522015723 -0400 committer mohammedalharbi <[email protected]> 1522015723 -0400 lap3
Lap3 2/.git/objects/6d/2f136d37dc8e3582246d1bbf96c0e6f3722fe1
Lap3 2/.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 2/.git/objects/06/3ece284f581d84a9258bc78ff6f0de6d125002
Lap3 2/.git/objects/06/3ece284f581d84a9258bc78ff6f0de6d125002
Lap3 2/.git/objects/6c/ef56a888dd99dcbb0a165075f06b6f04af7b4c
Lap3 2/.git/objects/6c/ef56a888dd99dcbb0a165075f06b6f04af7b4c
Lap3 2/.git/objects/39/739db2aa206ad3fbd7f6641d1d46e83877e910
Lap3 2/.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 2/.git/objects/97/c1e2ca8d9925127f563d5403883b8069b42e30
Lap3 2/.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 2/.git/objects/0a/c2d59359ef610bdef52c4a797a365accb1525e
Lap3 2/.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 2/.git/objects/64/506a6dd3dac60899bcd529ce6381a5cddbc03c
Lap3 2/.git/objects/64/506a6dd3dac60899bcd529ce6381a5cddbc03c
commit 232�tree 4eeb29795bd70f62bb6e7ebf829c65b29deb70b6 parent 74f5bd1b9585fd8676cf3d1c4382f6ec562680cb author mohammedalharbi <[email protected]> 1520970106 -0400 committer mohammedalharbi <[email protected]> 1520970106 -0400 lap3
Lap3 2/.git/objects/64/fe557accb0714fe0f46ac5e1b126585b3ae005
Lap3 2/.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 2/.git/objects/d3/2450f7f906dc3b39627349493d66959269e6ed
Lap3 2/.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 2/.git/objects/b8/f61a8c9ede4c2ded9a1e95bf12ab0fa4914187
Lap3 2/.git/objects/b8/f61a8c9ede4c2ded9a1e95bf12ab0fa4914187
Lap3 2/.git/objects/dd/bfc73deca642fd92018899d2d2bbaad191ce83
Lap3 2/.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 2/.git/objects/a6/2ed382a705487d7667dbe1cd664e4069257396
Lap3 2/.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 2/.git/objects/ef/4a862ad21a9d312eb07a0da38c59e018a11839
Lap3 2/.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 2/.git/objects/cb/94cd5a184fc6660b2fa1c0d0dbabf7d2705f27
Lap3 2/.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 2/.git/objects/79/432f8e5c7112086a4c464cd6305c29175cfa05
Lap3 2/.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 2/.git/objects/1b/cd36d194be9075d3772e4259f78b86d865260f
Lap3 2/.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 2/.git/objects/15/90090e3d46cc37c55e537727c205ed58d6f936
Lap3 2/.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 2/.git/objects/15/c3bb6ee17025f49b7f531253b55aee3e65a6a5
Lap3 2/.git/objects/15/c3bb6ee17025f49b7f531253b55aee3e65a6a5
Lap3 2/.git/objects/12/9452564c1a4509bb2b87e55cd40d4fa67f1f97
Lap3 2/.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 2/.git/objects/1c/dce7638c4cc5e2aab83eb36a064a6e08f733c0
Lap3 2/.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 2/.git/objects/82/99c43d952b4275bebb5b276fbfab12eb687d71
Lap3 2/.git/objects/82/99c43d952b4275bebb5b276fbfab12eb687d71
Lap3 2/.git/objects/40/666a187c3d0990208398c96fa737087053a8a7
Lap3 2/.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 2/.git/objects/8b/e7ab3c9ba458495c2b37bb192dbaed0470f15d
Lap3 2/.git/objects/8b/e7ab3c9ba458495c2b37bb192dbaed0470f15d
commit 232�tree a50058e243ec0e4732cbdbf794b1dc700fc6a5dd parent 6adb8eea7214b74c5ac7a842c5cd5f84ecfa732a author mohammedalharbi <[email protected]> 1517800310 -0500 committer mohammedalharbi <[email protected]> 1517800310 -0500 Room
Lap3 2/.git/objects/13/01775cc1c2b4fd94c7905c963f5f6cfb914a2d
Lap3 2/.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 2/.git/HEAD
ref: refs/heads/master
Lap3 2/.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 |
Lap3 2/.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 |
Lap3 2/.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 |
Lap3 2/.git/refs/heads/master
81f115945636e4599b089905d39fdd48728792fd
Lap3 2/.git/refs/remotes/origin/master
81f115945636e4599b089905d39fdd48728792fd
Lap3 2/.git/index
Lap3 2/.git/packed-refs
# pack-refs with: peeled 06713f96120d3be7e7f95285736775fc251948c3 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
Lap3 2/.git/COMMIT_EDITMSG
lap3
Lap3 2/.git/FETCH_HEAD
06713f96120d3be7e7f95285736775fc251948c3 not-for-merge branch 'master' of https://github.com/kings-cs/CS117-S18-AlharbiMohammed.git 62aa1fe8f836c8e2f7db3d62521e70180bba71fc not-for-merge tag 'stage1-attempt0' of https://github.com/kings-cs/CS117-S18-AlharbiMohammed.git 06713f96120d3be7e7f95285736775fc251948c3 not-for-merge tag 'stage1-attempt1' of https://github.com/kings-cs/CS117-S18-AlharbiMohammed.git
Lap3 2/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\ \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 2/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 2/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>(); }
Name CS117 Project Stage 02: Commands – Page 1
Project Stage 02: Commands
Currently, there are only three commands possible in our game: go, help, and quit. Obviously you will want to add additional commands to the game. In this stage, we will learn how to add commands to our game.
1 Introduction
In order to specify the commands that will be available in our game and how the game will respond to each command, we will use a technique from software engineering. It is becoming more and more common in industry to use behavior driven development (BDD) techniques to specify how a program should behave. The goal of behavior driven development is to develop a clear understanding of how software behaves. It also has the added bonus of enumerating what to test.
BDD specifies the behavior of software using scenarios and uses a particular format. To make this concrete, let’s look at an example:
QUIT Scenario #1:
GIVEN :
WHEN : "quit" is entered
THEN : appropriate message is displayed (thanks for playing)
and : program quits
The first thing to note is that the scenario is given a description (“QUIT Scenario #1”) that is short enough that it can be used to refer to when discussing the behaviors of the command. Each scenario consists of three parts:
• Given describes the initial context of the behavior: what is required for this behavior to be applicable. This part often consists of several short statements connected with and or or. If the behavior is always applicable, like it is for QUIT, this will be empty.
• When describes what event occurs that causes the behavior to be triggered. In the case of our game, this will almost always be some command typed at the prompt by the user. (You can see why we think it is a good way to describe commands in our game.)
• Then describes what happens in the game as a result of the trigger described above. This part often consists of several short statements connected with and or or.
Since every scenario consists of all three parts, these are often referred to as GWTs. We will be writing GWTs to help us specify the behavior of each of the commands in the game. In the beginning, we will provide GWTs for your commands. In the end, you will be writing them yourself.
2 Exploring GWTs
To make this clearer, let us specify the other two commands that are already implemented in our game. With each one, run the game and see if the behavior matches what is described:
HELP Scenario #1:
GIVEN :
WHEN : "help" is entered
THEN : available commands are displayed
Name CS117 Project Stage 02: Commands – Page 2
Here’s one for the “go” command:
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
Notice that in this scenario the command word is followed by a second word. We used a generic term for the direction in the command that was issued. Many of our commands will require multiple words. If the player had just entered “go” without a direction, we would have a different scenario:
GO Scenario #1: No direction specified
GIVEN :
WHEN : "go" is entered
THEN : appropriate message is displayed (which direction?)
Furthermore, if the player asks to go in a direction where there is no exit:
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)
Now the “go” command is fully specified and we can move on.
3 Implementation
The next thing we are going to do is to learn how to add commands to your project.
3.1 Adding Your First Command
Let’s look at what it would take to add a new command to our game: the look command. The purpose of look is merely to print out the description of the room and exits again. Let’s start by writing a GWT for it:
LOOK Scenario #1:
GIVEN :
WHEN : "look" is entered
THEN : player’s current location is displayed
Since look is a single word command that always succeeds, this should be the only scenario we need. To get started implementing look, identify all the locations in the code that will need to be changed in
order to add a look command. How many are there? In order to add a look command to your game you need to do the following:
1. Add look as a new command word by adding it to the array of known words in the validCommands array in the CommandWords class. Execute the game and type the command look. What happens?
Name CS117 Project Stage 02: Commands – Page 3
2. Implement an action for the look command by adding a private method in the Game class with the following signature. For now, this method should simply call the printLocationInformation method. We will keep its implementation separate so that we can enhance its functionality later.
1 /∗ ∗ 2 ∗ P r i n t s o u t t h e l o c a t i o n i n f o r m a t i o n . 3 ∗/ 4 private void look()
3. Add a case for the look command in the processCommand method of the Game class that calls the method you wrote in part (2).
4. Test your game and be sure that your new command is complete. One good way to do this is go to back through all of the GTWs that have already been specified and tested and make sure that they all work. When you are sure that it is, commit and push your changes.
3.2 Removing Implicit Coupling
In one of the early labs, you were asked to make improvements to your text adventure game making it possible to add additional directions of movement. The changes you made fixed an example of explicit coupling. The coupling was obvious because of the public fields in the Room class. This code base also has an even worse form of coupling: implicit coupling. Implicit coupling is a situation when one class depends on the internal information of another, but this dependence is not immediately obvious. In our current game, we notice this when we test the getting help scenario. Do you notice that it does not include our newly added look command? We want to fix this now.
Since the CommandWords class is responsible for the command words, it should also be responsible for generating a String containing all the command words that we can then use the Game class. Let’s do this now.
1. Add the following method to the CommandWords class:
1 /∗ ∗ 2 ∗ R e t u r n s a l i s t o f t h e a v a i l a b l e commands , o f t h e f o r m : 3 ∗ Your command w o r d s a r e : 4 ∗ l o o k g o q u i t h e l p 5 ∗ 6 ∗ @ r e t u r n A s t r i n g c o n t a i n i n g t h e l i s t o f a v a i l a b l e commands . 7 ∗/ 8 public static String getCommandString ()
2. In the Game class, when the user asks for help, we should use this new method as part of providing that help.
3.3 Removing String Comparison
To further enhance our project, we would like to remove some of the string comparisons that our game is currently doing. String comparisons are very inefficient and tend to be error-prone as many beginning (and advanced) programmers forget that they cannot use == to compare strings. In order to do this we need to change the CommandWords class where the valid list of commands is stored, and the Game class
Name CS117 Project Stage 02: Commands – Page 4
where the processCommand method explicitly compares each command word. We are going to do this using enumerations.
Start by adding an enumeration to the project called CommandEnum. Your enumeration should include values for each valid command. Include a field for the text (in all lower case) that would be entered by the person playing the game.
Great! Now let’s refactor the game to use this new enumeration:
1. Change the implementation of validCommands from an array of string to define valid commands to a map between strings and CommandEnum objects. This will make it easy to convert the command typed by a user into its corresponding enumerated type value. You should put the commands into the HashMap in the static initializer of the CommandWords class. HINT: You can do this without CommandWords knowing what the commands are.
2. Modify any methods that were using the array to now use the map. Use the compiler to help you identify every place that the validCommands is used.
3. Add a method to the CommandWords class which will convert a String into a CommandEnum object. It should have the following signature:
1 /∗ ∗ 2 ∗ C o n v e r t s a S t r i n g i n t o a CommandEnum o b j e c t . 3 ∗ 4 ∗ @param t h e S t r i n g The S t r i n g c o n t a i n i n g t h e command word . 5 ∗ @ r e t u r n The CommandEnum o b j e c t r e p r e s e n t i n g t h e command , o r n u l l i f
t h e command d o e s n o t e x i s t . 6 ∗/ 7 public static CommandEnum getCommand(String theString)
4. Change the implementation of Command so that the “command word” is now a CommandEnum object instead of a String. You should change the commandWord field, the constructors, and the accessor.
5. In the Reader class, we need to change the implementation of the getCommand method in the Reader to use the CommandEnum instead of a String. Be careful here because word1 is what was entered on the command line and must remain a String. (HINT: Didn’t you write a method that converts a String into a CommandEnum? You have the opportunity to simplify some code here too.)
6. Modify the processCommand method of Game to use a switch command instead of if-else statements.
When you are done, test your program to be sure that it works the same as it did before you started (HINT: the GWTs can help here) and then commit and push your changes. When you do this, make sure that the new CommandEnum.java file gets added to the repository.
3.4 Adding More Commands
All this refactoring has left us in a great place for adding additional commands. We have started you off by providing GWTs that fully specify the behavior each command in a text file in your “documents” folder.1
Implement each of the following commands using the provided GWTs:
1Notice that this is a text file, not a Word document. You can open this file up using gedit on the school machines. Notepad++ is a powerful text editor for Windows which you can download and install for free from https://notepad-plus-plus.org/.
Name CS117 Project Stage 02: Commands – Page 5
Command Description
status Prints out current state of the game including the player’s score, the number of turns that the player has used so far, and the complete description of the current room.
back Takes the player into the previous room he/she was in. To keep it simple, your back command only has to remember the last place the player was, not the entire path the player took through the game. Be sure to think about what happens if the player enters ’back’ more than once or before moving for the first time. HINT: Why not update the previous room whenever the current room is updated?
4 Finishing
When you are ready double check that you have been using good style (HINT: use Checkstyle to help you) and that all the code you have implemented is properly documented. Be sure that all of your changes are commited and pushed to Github.
Instead of uploading an archive of your project, you will be uploading a commit marker called an secure hash algorithm (SHA). Every commit in GitHub has a SHA marker attached to it. When you are happy with your submission, commit and push your changes to GitHub. Go to the GitHub website and check to make sure your last commit has made it to the server. Now copy the commit link by right-clicking on the “Latest commit” and selecting “Copy Link Location” (see figure):
Once you have copied the link, go to the submission page on Moodle and paste it into the sub- mission text area. The link that you get will read something like: https://github.com/kings-cs/ CS117-S16-JumpMaria/commit/2076ab47397891666d11a2474208f24e73fe576d. Don’t forget to “Submit Assignment”.
Name CS117 Project Stage 01: World – Page 1
Project Stage 01: World In this stage, you will spend some time implementing the map of the world that you created in your
design. The goal is to create a world that the player can walk around in. At this stage we are not concerned with the accuracy of room descriptions, whether a door is locked, or if there are goblins blocking a doorway. Our goal is to create all the rooms and connect them with doors in a way that is consistent and make sense.
1 Design
Before we start any kind of implementation, we usually start with some element of design. Taking the time to design, makes software easier to implement. Keep any and all files you create while designing your game in the “documents” folder in your repository. This should include your design document (but not the temporary files), any maps you create on http://www.draw.io, and anything that is not in your design document. Remember that source control keeps track of the changes so there is no reason for you to keep multiple copies of any of the files! We are going to start this stage focusing on the World.
If you have not already done so, draw a block-map of your world. In a block-map, each room in your world is represented by a block (or some shape). The ability to travel from one room to another in your world is represented by a line between two blocks. Bidirectional movement is indicated with a solid line, while one-way movement is indicated with an arrow. For cardinal directions (e.g., north, east, southwest) draw straight line following the directions on a compass. Movement in directions not related to a compass should be tagged with the direction pair indicating the direction the player must travel to get there.
To make this easy, I recommend that you can use: www.draw.io. I will recognize this file format if you use it. Feel free to have several block maps to represent your world if it will make it easier to represent all of the rooms of your world but be sure to include how they are all connected together. Place these files in the “documents” directory of your code repository.
Here is an example from the Campus of King’s:
Each block in your block-map represents a room (an area) in the game. At this point, write descriptions so that it is obvious where you are in the world when the player walks around. You should not include the
Name CS117 Project Stage 01: World – Page 2
items found in the room in your description unless the item is permanently in the room. Don’t spend too much time worrying about having complete descriptions we will work on refining these as we go.
One way to be sure that your room descriptions are free of typographical errors is to write descriptions in your design document. Many of you have already started this. If you have not, add a section to the end of the document entitled “Room Descriptions” and list each room in your game with its description. Once you have it written there, then it will be easy to cut and paste it from your game contract document to your code (watch out with special characters that Word allows but regular text does not).
2 Implementation
Before you start with this stage’s implementation, you should check your issues on GitHub and resolve any outstanding issues you have from previous stages. Only then, should you start with the implementation of this stage. Make sure that you commit and push often throughout this process, checking afterward to make sure that the server has your latest changes.
1. Modify the World’s createRooms method to include all of the rooms in your game. This method does three things. The first part is where the Room objects are created. In the next part, each room is added to a HashMap which will be used later in the implementation. In the end, the HashMap needs to store every room in the world. This will require that each room you create has a unique name. In the third part you create the doors between the rooms connecting them together. This will allow the player to move from one room to another.
2. Run Checkstyle and correct any reported style issues.
At the end, your goal is to have an implementation of your world that player can walk around. Make sure that you test this by walking around in the game and checking that the connections match
what you have listed on your map.
3 Scoring
For many of you, the player will earn points by finding their way into particular special rooms in your game. We are going to go ahead and add the code needed for this now. The steps to do this are:
1. Add support to the Room class so that each room knows the number of points a player gets for entering the room for the first time.
• Add a points field to your Room class which will contain the number of points a player gets for entering the room for the first time.
• Add a mutator for the points field in the Room class. Use this mutator in the createRooms method of the World class to set the points associated with those special rooms in the game that the player earns points for entering.
• Add an accessor for the points field in the Room class. In addition to doing the classic thing of returning the points associated with the room, the accessor method should also ensure that the points field is reset to 0 so that the player will earn points for entering the room the first time only.
2. Every time the player moves (e.g., the current room is set), get the points from the room and add it to the total score.
Name CS117 Project Stage 01: World – Page 3
4 Finishing
In order to continue you must:
• Add a description of each room in your world to your design document.
• Include a block-map of your world as it is described in your design document in your “documents” folder.
• Have all of your rooms and doors correctly entered in to your code.
• Have added the ability for entering rooms to increase the player’s score to the code.
When you are ready double check that you have been using good style (HINT: use Checkstyle to help you) and that all the code you have implemented is properly documented. Be sure that all of your changes are commited and pushed to GitHub.
Instead of uploading an archive of your project, you will be uploading a commit marker called an secure hash algorithm (SHA). Every commit in GitHub has a SHA marker attached to it. When you are happy with your submission, commit and push your changes to GitHub. Go to the GitHub website and check to make sure your last commit has made it to the server. Now copy the commit link by right-clicking on the “Latest commit” and selecting “Copy Link Location” (see figure):
Once you have copied the link, go to the submission page on Moodle and paste it into the sub- mission text area. The link that you get will read something like: https://github.com/kings-cs/ CS117-S16-JumpMaria/commit/2076ab47397891666d11a2474208f24e73fe576d. Don’t forget to “Submit Assignment” to notify the grader.

Get help from top-rated tutors in any subject.
Efficiently complete your homework and academic assignments by getting help from the experts at homeworkarchive.com