JAVA
CS117-S18-AlharbiMohammed-master/.gitignore
*.class *.ctxt *.*~ doc /.project default.log defaultlog.txt
CS117-S18-AlharbiMohammed-master/Command.java
CS117-S18-AlharbiMohammed-master/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
;
}
}
CS117-S18-AlharbiMohammed-master/CommandWords.java
CS117-S18-AlharbiMohammed-master/CommandWords.java
/**
* This class is part of the "Campus of Kings" application. "Campus of Kings" is a
* very simple, text based adventure game.
*
* This class holds an enumeration of all command words known to the game. It is
* used to recognize commands as they are typed in.
*
*
@author
Maria Jump
*
@version
2015.02.01
*/
public
class
CommandWords
{
/** A constant array that holds all valid command words. */
private
static
String
[]
validCommands
;
/**
* Static block to initialize the fields of CommandWords.
*/
static
{
String
[]
tempCommands
=
{
"go"
,
"quit"
,
"help"
};
validCommands
=
tempCommands
;
}
/**
* Check whether a given String is a valid command word.
*
*
@param
aString The string to determine whether it is a valid command.
*
@return
true if a given string is a valid command, false if it isn't.
*/
public
static
boolean
isCommand
(
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
;
}
}
CS117-S18-AlharbiMohammed-master/Door.java
CS117-S18-AlharbiMohammed-master/Door.java
/**
* Class Door - a door or portal between two Rooms in an adventure game.
*
* This class is part of the "Campus of Kings" application. "Campus of Kings" is a
* very simple, text based adventure game.
*
* A "Door" represents a door or portal between two locations of the game.
* It stores a reference to the neighboring room and whether that door
* or portal is locked. Doors are not locked by default.
*
*
@author
Maria Jump
*
@version
2015.02.01
*/
public
class
Door
{
/** The room that this door leads to. */
private
Room
destination
;
/** Whether this door is locked. */
private
boolean
locked
;
/**
* 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
;
}
}
CS117-S18-AlharbiMohammed-master/Game.java
CS117-S18-AlharbiMohammed-master/Game.java
//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
;
}
}
CS117-S18-AlharbiMohammed-master/Main.java
CS117-S18-AlharbiMohammed-master/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
;
}
}
}
CS117-S18-AlharbiMohammed-master/Player.java
CS117-S18-AlharbiMohammed-master/Player.java
/**
* 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
;
}
}
CS117-S18-AlharbiMohammed-master/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.
CS117-S18-AlharbiMohammed-master/Reader.java
CS117-S18-AlharbiMohammed-master/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
Maria Jump
*
@version
2017.12.18
*/
public
class
Reader
{
/** The source of command input. */
private
static
Scanner
reader
;
/**
* Create a parser to read from the terminal window.
*/
static
{
reader
=
new
Scanner
(
System
.
in
);
}
/**
* Returns the next command from the user.
*
@return
The next command from the user.
*/
public
static
Command
getCommand
()
{
String
inputLine
;
// will hold the full input line
String
word1
=
null
;
ArrayList
<
String
>
restOfLine
=
null
;
Writer
.
print
(
"> "
);
// print prompt
inputLine
=
reader
.
nextLine
().
toLowerCase
();
Writer
.
printInput
(
inputLine
);
// Find up to two words on the line.
Scanner
tokenizer
=
new
Scanner
(
inputLine
);
if
(
tokenizer
.
hasNext
())
{
word1
=
tokenizer
.
next
();
// get first word
if
(
tokenizer
.
hasNext
())
{
restOfLine
=
new
ArrayList
<
String
>
();
while
(
tokenizer
.
hasNext
())
{
restOfLine
.
add
(
tokenizer
.
next
());
}
}
}
tokenizer
.
close
();
// Now check whether this word is known. If so, create a command
// with it. If not, create a "null" command (for unknown command).
Command
result
=
null
;
if
(
CommandWords
.
isCommand
(
word1
))
{
result
=
new
Command
(
word1
,
restOfLine
);
}
else
{
result
=
new
Command
(
null
,
restOfLine
);
}
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
;
}
}
CS117-S18-AlharbiMohammed-master/Room.java
CS117-S18-AlharbiMohammed-master/Room.java
import
java
.
util
.
HashMap
;
/**
* Class Room - a room in an adventure game.
*
* This class is part of the "Campus of Kings" application. "Campus of Kings" is a
* very simple, text based adventure game.
*
* A "Room" represents one location in the scenery of the game. It is connected
* to other rooms via doors. The doors are labeled north, east, south, west.
* For each direction, the room stores a reference to an instance of door.
*
*
@author
Mohammed ALharbi
*
@version
2018.1.26
*/
public
class
Room
{
/** Counter for the total number of rooms created in the world. */
private
static
int
counter
;
/** The name of this room. Room names should be unique. */
private
String
name
;
/** The description of this room. */
private
String
description
;
/**earn 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
;
}
}
CS117-S18-AlharbiMohammed-master/World.java
CS117-S18-AlharbiMohammed-master/World.java
import
java
.
util
.
HashMap
;
/**
* This class represents the entire world that makes up the "Campus of Kings"
* application. "Campus of Kings" is a very simple, text based adventure game.
* Users can walk around some scenery. That's all. It should really be extended
* to make it more interesting!
*
* This world class creates the world where the game takes place.
*
*
@author
mohammed alharbi
*
@version
20/2/2018
*/
public
class
World
{
/** The rooms in the world. */
private
HashMap
<
String
,
Room
>
rooms
;
/**
* Constructor for the world.
*/
public
World
()
{
rooms
=
new
HashMap
<
String
,
Room
>
();
createRooms
();
}
/**
* 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
);
}
}
CS117-S18-AlharbiMohammed-master/Writer.java
CS117-S18-AlharbiMohammed-master/Writer.java
import
java
.
awt
.
Color
;
import
java
.
io
.
BufferedWriter
;
import
java
.
io
.
File
;
import
java
.
io
.
FileNotFoundException
;
import
java
.
io
.
FileWriter
;
import
java
.
io
.
IOException
;
import
java
.
util
.
Scanner
;
import
javax
.
swing
.
JFileChooser
;
import
javax
.
swing
.
JTextPane
;
import
javax
.
swing
.
text
.
BadLocationException
;
import
javax
.
swing
.
text
.
Document
;
import
javax
.
swing
.
text
.
SimpleAttributeSet
;
import
javax
.
swing
.
text
.
StyleConstants
;
/**
* This class is a substitute for printing to standard out in our original text
* adventure game. It uses a simple console to display the messages.
*
*
@author
Maria Jump
*
@version
2016-12-18
*/
public
class
Writer
{
/** System new line character. */
private
static
final
String
NEW_LINE
;
/** Name of the default log. */
private
static
final
String
DEFAULT_LOG
;
/** The text area that we will be writing to. */
private
static
JTextPane
textArea
;
/** Static block. */
static
{
NEW_LINE
=
System
.
getProperty
(
"line.separator"
);
DEFAULT_LOG
=
"defaultlog.txt"
;
textArea
=
null
;
restartLog
();
}
/**
* Mutator for the text component.
*
*
@param
text
* The text component.
*/
public
static
void
setTextArea
(
JTextPane
text
)
{
textArea
=
text
;
textArea
.
setEditable
(
false
);
}
/**
* Print the user input in blue.
*
*
@param
input
* The text entered by the user.
*/
public
static
void
printInput
(
String
input
)
{
SimpleAttributeSet
attributes
=
new
SimpleAttributeSet
();
StyleConstants
.
setForeground
(
attributes
,
Color
.
BLUE
);
printWithAttributes
(
attributes
,
input
+
NEW_LINE
);
}
/**
* Prints an empty line.
*/
public
static
void
println
()
{
standardPrint
(
NEW_LINE
);
}
/**
* Prints out a single integer to a line.
*
*
@param
toPrint
* The integer to print.
*/
public
static
void
println
(
int
toPrint
)
{
String
text
=
""
+
toPrint
+
NEW_LINE
;
standardPrint
(
text
);
}
/**
* Prints out a single integer.
*
*
@param
toPrint
* The integer to print.
*/
public
static
void
print
(
int
toPrint
)
{
String
text
=
""
+
toPrint
;
standardPrint
(
text
);
}
/**
* Prints out a double to a line.
*
*
@param
toPrint
* The double to print.
*/
public
static
void
println
(
double
toPrint
)
{
String
text
=
""
+
toPrint
+
NEW_LINE
;
standardPrint
(
text
);
}
/**
* Prints out a double.
*
*
@param
toPrint
* The double to print.
*/
public
static
void
print
(
double
toPrint
)
{
String
text
=
""
+
toPrint
;
standardPrint
(
text
);
}
/**
* Prints out an object to a line.
*
*
@param
toPrint
* The object to print.
*/
public
static
void
println
(
Object
toPrint
)
{
String
text
=
""
+
toPrint
+
NEW_LINE
;
standardPrint
(
text
);
}
/**
* Prints out a object.
*
*
@param
toPrint
* The object to print.
*/
public
static
void
print
(
Object
toPrint
)
{
String
text
=
""
+
toPrint
;
standardPrint
(
text
);
}
/**
* Prints a string after word-wrapping it to 80 characters if possible. Note
* that this fails to calculate correct widths if the string contains tabs.
* Ends with a line return.
*
*
@param
toPrint
* The String to print.
*/
public
static
void
println
(
String
toPrint
)
{
String
text
=
toPrint
+
NEW_LINE
;
standardPrint
(
text
);
}
/**
* Prints a string after word-wrapping it to 80 characters if possible. Note
* that this fails to calculate correct widths if the string contains tabs.
*
*
@param
toPrint
* The String to print.
*/
public
static
void
print
(
String
toPrint
)
{
standardPrint
(
toPrint
);
}
/**
* Helper method for standard printing.
*
*
@param
toPrint
* The String to print.
*/
private
static
void
standardPrint
(
String
toPrint
)
{
SimpleAttributeSet
attributes
=
new
SimpleAttributeSet
();
printWithAttributes
(
attributes
,
toPrint
);
}
/**
* Helper method printing with attributes.
*
*
@param
attributes
* A set of attributes to use when printing.
*
@param
toPrint
* The String to print.
*
@throws
IllegalStateException
* If the text area has not been set and we are trying to print
* to it.
*/
private
static
void
printWithAttributes
(
SimpleAttributeSet
attributes
,
String
toPrint
)
throws
IllegalStateException
{
if
(
textArea
==
null
)
{
throw
new
IllegalStateException
(
"Need to set the text area before printing to it."
);
}
try
{
Document
document
=
textArea
.
getDocument
();
document
.
insertString
(
document
.
getLength
(),
toPrint
,
attributes
);
textArea
.
setCaretPosition
(
document
.
getLength
());
BufferedWriter
log
=
new
BufferedWriter
(
new
FileWriter
(
DEFAULT_LOG
,
true
));
log
.
write
(
toPrint
);
log
.
close
();
}
catch
(
BadLocationException
ex
)
{
System
.
err
.
println
(
"ERROR: Should never get this ["
+
toPrint
+
"]"
);
System
.
exit
(
2
);
}
catch
(
IOException
ex
)
{
System
.
err
.
println
(
"ERROR printing to default log (see instructor for help)"
);
System
.
exit
(
1
);
}
}
/**
* Restart the default log.
*/
public
static
void
restartLog
()
{
try
{
BufferedWriter
log
=
new
BufferedWriter
(
new
FileWriter
(
DEFAULT_LOG
,
false
));
log
.
close
();
}
catch
(
IOException
ex
)
{
System
.
err
.
println
(
"ERROR resetting the default log (see instructor for help)"
);
System
.
exit
(
1
);
}
}
/**
* Copy the default log.
*/
public
static
void
copyDefaultLog
()
{
Scanner
input
=
null
;
BufferedWriter
output
=
null
;
try
{
JFileChooser
chooser
=
new
JFileChooser
();
chooser
.
setCurrentDirectory
(
new
File
(
"."
));
int
result
=
chooser
.
showOpenDialog
(
null
);
if
(
result
==
JFileChooser
.
APPROVE_OPTION
)
{
input
=
new
Scanner
(
new
File
(
DEFAULT_LOG
));
output
=
new
BufferedWriter
(
new
FileWriter
(
chooser
.
getSelectedFile
(),
false
));
while
(
input
.
hasNextLine
())
{
String
line
=
input
.
nextLine
();
output
.
write
(
line
+
NEW_LINE
);
}
output
.
close
();
input
.
close
();
}
}
catch
(
FileNotFoundException
exception
)
{
System
.
err
.
println
(
"ERROR: default log file cannot be found"
);
System
.
exit
(
3
);
}
catch
(
IOException
exception
)
{
System
.
err
.
println
(
"ERROR: file for copy cannot be written to"
);
System
.
exit
(
4
);
}
}
}
CS117-S18-AlharbiMohammed-master/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: > 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.
CS117-S18-AlharbiMohammed-master/documents/GWT.txt
/////////////////////////////////////////////////////////////////////////////// // Original commands from the game (alphabetical) GO Scenario #1: No direction specified GIVEN : WHEN : "go" is entered THEN : appropriate message is displayed (which direction?) GO Scenario #2: No exit exists GIVEN : there is no exit in the given direction WHEN : "go direction" is entered THEN : appropriate message is displayed (no door) GO Scenario #3: Exit exists GIVEN : there is an exit in the given direction WHEN : "go direction" is entered THEN : player's current room is changed to the room in the given direction and : the current room's points are added to the player's score and : player's current location is displayed HELP Scenario #1: GIVEN : WHEN : "help" is entered THEN : available commands are displayed SCORE Scenario #1: GIVEN : WHEN : "score" is entered THEN : player's current score is displayed TURNS Scenario #1: GIVEN : WHEN : "turns" is entered THEN : current number of turns is displayed to the screen QUIT Scenario #1: GIVEN : WHEN : "quit" is entered THEN : appropriate message is displayed (thanks for playing) and : program quits /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 2 (alphabetical) BACK Scenario #1: no previous room GIVEN : there is no previous room WHEN : "back" is entered THEN : appropriate message is displayed (cannot go back) BACK Scenario #2: there is a previous room GIVEN : there is a previous room WHEN : "back" is entered THEN : player's current location is changed to the previous location and : player's current location is displayed LOOK Scenario #1: GIVEN : WHEN : "look" is entered THEN : player's current location is displayed STATUS Scenario #1: GIVEN : WHEN : "status" is entered THEN : current number of turns is displayed and : player's current score is displayed and : player's current location is displayed /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 3 (alphabetical) DROP Scenario #1: No item specified GIVEN : WHEN : "drop" is entered THEN : appropriate message is displayed (which item?) DROP Scenario #2: Player does not have the specified item GIVEN : player does not have the specified item WHEN : "drop item" is entered THEN : appropriate message is displayed (you don't have it) DROP Scenario #3: Player has the specified item GIVEN : player has the specified item WHEN : "drop item" is entered THEN : "item" is removed from the player's inventory and : "item" is added to the current room and : appropriate message is displayed (you dropped the item) EXAMINE Scenario #1: No item specified GIVEN : WHEN : "examine" is entered THEN : appropriate message is displayed (which item?) EXAMINE Scenario #2: Specified item does not exist GIVEN : specified item is not in the room and : specified item is not in player's inventory WHEN : "examine item" is entered THEN : appropriate message is displayed (no such item) EXAMINE Scenario #3: Specified item does exist GIVEN : specified item is in the room or in the player's inventory WHEN : "examine item" is entered THEN : complete description of the item is displayed including the item's name, description and (optionally) the weight. INVENTORY Scenario #1: GIVEN : WHEN : "inventory" is entered THEN : a list of the items in the players inventory is displayed TAKE Scenario #1: no item specified GIVEN : WHEN : "take" is entered THEN : appropriate message is displayed (take what?) TAKE Scenario #2: specified item does not exist GIVEN : specified item is not in the current room WHEN : "take item" is entered THEN : appropriate message is displayed (no such item) TAKE Scenario #3: specified item is too heavy to lift GIVEN : specified item is in the current room and : specified item by itself exceeds maximum carrying weight WHEN : "take item" is entered THEN : appropriate message is displayed (too heavy to lift) TAKE Scenario #4: specified item makes inventory too heavy GIVEN : specified item is in the current room and : adding specified item to inventory weight exceeds maximum carrying weight WHEN : "take item" is entered THEN : appropriate message is displayed (carrying too much) TAKE Scenario #5: specified item is taken GIVEN : specified item is in the current room and : adding specified item to inventory weight does not exceed maximum carrying weight WHEN : "take item" is entered THEN : item is removed from the current room and : item is added to the player's inventory and : appropriate message is displayed (you took the item) /////////////////////////////////////////////////////////////////////////////// // Commands added in Stage 4 (alphabetical) GO Scenario #4: Door is locked GIVEN : there is an exit in the given direction and : that exit is locked WHEN : "go direction" is entered THEN : appropriate message is displayed (door is locked) LOCK Scenario #1: No direction specified GIVEN : WHEN : "lock" is entered THEN : appropriate message is displayed (lock what?) LOCK Scenario #2: No Door GIVEN : there is no door in that direction WHEN : "lock direction" is entered THEN : appropriate message is displayed (no door) LOCK Scenario #3: Door is locked GIVEN : door in "direction" is locked WHEN : "lock direction" is entered THEN : appropriate message is displayed (door is already locked) LOCK Scenario #4: Door cannot be locked GIVEN : door in "direction" has no associated key WHEN : "lock direction" is entered THEN : appropriate message is displayed (door cannot be locked) LOCK Scenario #5: Door can be locked GIVEN : door in "direction" is unlocked and : door in "direction" can be locked WHEN : "lock direction" is entered THEN : user is prompted for key LOCK Scenario #6: Player does not have the key GIVEN : player does not have specific key in inventory WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (you do not have it) LOCK Scenario #7: Incorrect key specified GIVEN : player's inventory has the specific key and : specified key is not the correct key WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (wrong key) LOCK Scenario #8: Correct key specified GIVEN : player's inventory has the specific key and : specified key is the correct key WHEN : "lock direction" had been entered and : user has been prompted for specific key THEN : door in "direction" is locked and : appropriate message is displayed (you locked it) PACK Scenario #1: No item specified GIVEN : WHEN : "pack" is entered THEN : appropriate message is displayed (pack what?) PACK Scenario #2: Item is not available GIVEN : item is NOT in the current room and : item is NOT in the players inventory WHEN : "pack item" is entered THEN : appropriate message is displayed (you don't have it) PACK Scenario #3: Item is too heavy GIVEN : item is in the current room and : item is heavier than player's carrying capacity WHEN : "pack item" is entered THEN : appropriate message is displayed (too heavy) PACK Scenario #4: Item is available GIVEN : item is in the current room or : item is in the player's inventory and : there are no weight problems WHEN : "pack item" is entered THEN : user is prompted for the container to put it in PACK Scenario #5: Container is not available GIVEN : container is NOT in the current room and : container is NOT in the player's inventory WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (you don't see the container) PACK Scenario #6: Container is NOT a container GIVEN : container is in the current room or : container is in the player's inventory and : container is not really a container WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (that's not a container) PACK Scenario #7: Container is a container, but item too heavy GIVEN : item is in the current room and : container is in the player's inventory and : item would put player over their inventory weight limit WHEN : "pack item" had been entered and : user has been prompted for the container THEN : appropriate message is displayed (carrying too much) PACK Scenario #8: Packing is possible GIVEN : container is in the current room or : container is in the player's inventory and : container is really a container and : there are no weight problems WHEN : "pack item" had been entered and : user has been prompted for the container THEN : item is removed from the current room or : item is removed from the player's inventory and : item is added to the container and : appropriate message is displayed (you packed it) UNLOCK Scenario #1: No direction specified GIVEN : WHEN : "unlock" is entered THEN : appropriate message is displayed (unlock what?) UNLOCK Scenario #2: No door in that direction GIVEN : there is no door in the "direction" WHEN : "unlock direction" is entered THEN : appropriate message is displayed (there is no door) UNLOCK Scenario #3: Direction is specified and is not locked GIVEN : there is a door in the "direction" and : door in "direction" is NOT locked WHEN : "unlock direction" is entered THEN : appropriate message is displayed (door is not locked) UNLOCK Scenario #4: Direction is specified and is locked GIVEN : there is a door in the "direction" and : door in "direction" is locked WHEN : "unlock direction" is entered THEN : user is prompted for key UNLOCK Scenario #5: Player missing specified key GIVEN : player's inventory does NOT have the specific key WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (you don't have it) UNLOCK Scenario #6: Incorrect key GIVEN : player's inventory has the specific key and : specified key is incorrect item WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : appropriate message is displayed (that doesn't fit) UNLOCK Scenario #7: Correct key GIVEN : player's inventory has the specific key and : specified key is the correct object WHEN : "unlock direction" had been entered and : user has been prompted for specific key THEN : door in "direction" is unlocked and : appropriate message is displayed (you unlocked it) UNPACK Scenario #1: No container specified GIVEN : WHEN : "unpack" is entered THEN : appropriate message is displayed (unpack what?) UNPACK Scenario #2: Specified container is not in the current room GIVEN : specified container is NOT in the current room and : specified container is NOT in the players inventory WHEN : "unpack container" is entered THEN : appropriate message is displayed (you don't see it) UNPACK Scenario #3: Specified item is not a container GIVEN : specified container is in the current room or : specified container is in the player's inventory and : specified container is NOT a container WHEN : "unpack container" is entered THEN : appropriate message is displayed (that's not a container) UNPACK Scenario #4: Container is OK GIVEN : specified container is in the current room or : specified container is in the player's inventory and : specified container is a container WHEN : "unpack container" is entered THEN : user is prompted for an item to unpack UNPACK Scenario #5: Item is NOT in container GIVEN : item to unpack is NOT in the container WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : appropriate message is displayed (you don't find it) UNPACK Scenario #6: Item is in container but too heavy GIVEN : item to unpack is in the container and : container was in the current room and : item would make the player exceed his weight limit WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : appropriate message is displayed (you are already carrying too much) UNPACK Scenario #7: Item can be unpacked GIVEN : item to unpack is in the container and : there is no weight problem WHEN : "unpack container" had been entered and : user has been prompted for the item to unpack THEN : item to unpack is removed from the container and : item to unpack is added to the player's inventory and : appropriate message is displayed (you unpack it)
CS117-S18-AlharbiMohammed-master/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.
CS117-S18-AlharbiMohammed-master/documents/Game.xml
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
CS117-S18-AlharbiMohammed-master/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.
CS117-S18-AlharbiMohammed-master/package.bluej
#BlueJ package file dependency1.from=Reader dependency1.to=Command dependency1.type=UsesDependency dependency10.from=Game dependency10.to=World dependency10.type=UsesDependency dependency11.from=Game dependency11.to=Room dependency11.type=UsesDependency dependency12.from=Game dependency12.to=Command dependency12.type=UsesDependency dependency13.from=Game dependency13.to=Door dependency13.type=UsesDependency dependency14.from=Game dependency14.to=Reader dependency14.type=UsesDependency dependency15.from=Game dependency15.to=Writer dependency15.type=UsesDependency dependency2.from=Reader dependency2.to=Writer dependency2.type=UsesDependency dependency3.from=Reader dependency3.to=CommandWords dependency3.type=UsesDependency dependency4.from=World dependency4.to=Room dependency4.type=UsesDependency dependency5.from=World dependency5.to=Door dependency5.type=UsesDependency dependency6.from=Door dependency6.to=Room dependency6.type=UsesDependency dependency7.from=Room dependency7.to=Door dependency7.type=UsesDependency dependency8.from=Main dependency8.to=Game dependency8.type=UsesDependency dependency9.from=Main dependency9.to=Writer dependency9.type=UsesDependency editor.fx.0.height=674 editor.fx.0.width=664 editor.fx.0.x=230 editor.fx.0.y=84 objectbench.height=101 objectbench.width=776 package.divider.horizontal=0.6 package.divider.vertical=0.8007380073800738 package.editor.height=427 package.editor.width=651 package.editor.x=728 package.editor.y=216 package.frame.height=600 package.frame.width=800 package.numDependencies=15 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