Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
00e3075
book reader
Apr 20, 2016
c9af86c
items
Apr 20, 2016
51a9400
sfgdsf
Apr 20, 2016
8051a54
slkdjf
Apr 21, 2016
a5fd4e3
read structure
Apr 22, 2016
731f368
Added an interactions package.
ajamesVISD Apr 25, 2016
fb37f0f
Actors and AvailableInteractions work.
ajamesVISD May 5, 2016
8e78fb8
Progress, some documentation
ajamesVISD May 6, 2016
63a0996
Shaky but functional
ajamesVISD May 6, 2016
e0cbee2
Now can add items to WorldBuilder
ajamesVISD May 6, 2016
6459728
Looking at a Location no longer includes the Player in the result
ajamesVISD May 7, 2016
0049cea
Locations can now be traversed with the Go command
ajamesVISD May 8, 2016
1b61c91
Moved Player to Interactions package, added "exit" word to Game
ajamesVISD May 8, 2016
ad9114e
About to break everything. Roll back to here to get functional.
ajamesVISD May 9, 2016
58a1599
AvailableInteractions now runs more sanely, grouping like items
ajamesVISD May 9, 2016
1a6abd7
Latest.
ajamesVISD May 9, 2016
3159cf0
Fixed bug where Actors were not being removed properly.
ajamesVISD May 9, 2016
91c7826
Minigames now adapt
ajamesVISD May 10, 2016
35b0452
Game room now works.
ajamesVISD May 10, 2016
2708305
Pokemon battle minigame
May 13, 2016
346a945
sdfhaweognfd
May 17, 2016
9f8c648
poke
May 20, 2016
004567c
lksdjf
May 20, 2016
a830085
Unstash fix
Jun 2, 2016
1f679f2
pokeworld
Jun 2, 2016
13b7fa1
PokeWorld
okayThen Jun 3, 2016
cb7202c
dryh
Jun 6, 2016
176f3f6
isldnfo
Jun 6, 2016
e5580df
min
Jun 6, 2016
80a48a1
choosePokemon initial
okayThen Jun 7, 2016
174c019
choosePokemon initial commit
okayThen Jun 7, 2016
929d748
finished ChoosePokemon
okayThen Jun 7, 2016
fbc28b4
djsoiwreg
Jun 9, 2016
b06f887
ljsdoifj
okayThen Jun 13, 2016
c9f3a13
mwahahaha
okayThen Jun 14, 2016
1f90b29
mwamw
Jun 15, 2016
caf55b0
mehhh
Jun 15, 2016
4c5b8d2
meerrrrpp
Jun 15, 2016
667b7a0
fix
Jun 16, 2016
a67098b
hp fix
Jun 16, 2016
e0f7233
hp fixx
Jun 16, 2016
b90c123
print fix
Jun 16, 2016
22026c2
posdjf
Jun 16, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/vashonsd/pirateship/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class App
{
public static void main( String[] args ) throws IOException
{
Game g = new Game("Busytown");
Game g = new Game("Poke");
g.Run();
}
}
148 changes: 29 additions & 119 deletions src/main/java/org/vashonsd/pirateship/Game.java
Original file line number Diff line number Diff line change
@@ -1,150 +1,60 @@
package org.vashonsd.pirateship;

import java.io.IOException;
import java.util.HashMap;

import org.vashonsd.pirateship.interactions.Player;
import org.vashonsd.pirateship.interactions.Request;
import org.vashonsd.pirateship.io.*;
import org.vashonsd.pirateship.structure.*;
import org.vashonsd.pirateship.minigame.*;
import org.vashonsd.pirateship.itemStuff.*;

public class Game {
private StringRead reader;
private StringWrite writer;

//Worlds act as namespaces. That is, two locations can have the same identifier as long as they exist in separate Worlds.
private HashMap<String, World> worlds;

private DatabaseWriter db = new DatabaseWriter();
//This is our register of current Players, each with a unique ID.
private PlayerRegistry players;

private World thisWorld;

//private HashMap<String, Player> players;

private Player player;

private LocationMiniRunner runner;
private String quitWord;

public Game(String world) throws IOException {
super();

quitWord = "exit";

//thisWorld = WorldBuilder.makeWorld(world);
//thisWorld = WorldBuilder.makeWorldByFile(world);
thisWorld = WorldBuilder.busyWorld();
player = new Player("Ronaldo");
player.setCurrentLocation(thisWorld.getStartingLocation());

//players.put(player.getName(), player);

World thisWorld = WorldBuilder.makeWorld(world);

this.players = new PlayerRegistry();
Player p = new Player("Demo", "Just a player");
p.setLocation(thisWorld.getStartingLocation());
String pid = players.EnrollPlayer(p);

reader = new UserInput();
writer = new ConsoleOut();

}

public void Run() throws IOException {
String ave;
String end;

//For now we are just going to take the first Player off the registry.
//Later we will want to be able to enroll players on the fly.
Player p = players.get("Demo");
writer.write(p.handle("look").getText() + "\n");
while(true) {

if(player.getCurrentLocation().getGames().isEmpty() == false)
{
ave = "Available games: \n";
end = "[Type 'play' then select a game]";
}
else
{
ave = "";
end = "";
}

writer.write(player.getCurrentLocation().toString());
writer.write(ave + player.getCurrentLocation().getGames().toString() + end);
String[] s = evalCommand();
handle(s);
}
}

/*
* Gets the player's command, checking for valid/invalid input.
*/

private String center(String c)
{
String center = "";
String see = c;
int dashes = (15 - c.length())/2;
for(int i = 0; i < dashes; i++)
{
center += "-";
}
see += center;
center += see;
if(c.length()%2 == 0)
center += "-";
if (c.length() > 15)
center = c;
return center;
}

public String[] evalCommand() throws IOException {
String c = reader.read();
c = c.toLowerCase();
String[] one;
one = c.split(" ");
return one;
}

public void handle(String[] array) throws IOException {
int i = 0;
if(array[i].equals("exit")) {
quitGracefully();
}
else if(array[i].equals("go")) {
i++;
player.setCurrentLocation(player.getCurrentLocation().travel(array[i]));
}
else if(array[i].equals("play"))
{
playMinigame(player.getCurrentLocation());
}
else {
String command = "";
for(int a = 0; a < array.length; a++) {
command+=array[a];
}
writer.write("---Error 314---"
+ "\n" + center(command) + "\n" +
"place not found");
String command = reader.read();
if (p.getTarget() == null && command.equals(quitWord)) {
break;
}
writer.write(p.handle(command).getText());;
}
writer.write("Thanks for playing!");
}

public void evalCommand(String c) {
player.setCurrentLocation(player.getCurrentLocation().travel(c));
}

public void quitGracefully() throws IOException {
//db.worldWriter(thisWorld);
writer.write("Thank you for exploring " + thisWorld.getName() +".");
writer.close();
reader.close();
System.exit(1);
}

public void playMinigame(Location place) throws IOException
{
runner = new LocationMiniRunner(place.getGames());

writer.write(runner.printGreeting());

while(true)
{
String r = runner.Run(reader.read());

if(r.equals("Thanks for playing! Goodbye."))
{
writer.write(r);
break;
}
else
{
writer.write(r);
}
}
}
}
34 changes: 0 additions & 34 deletions src/main/java/org/vashonsd/pirateship/Player.java

This file was deleted.

50 changes: 50 additions & 0 deletions src/main/java/org/vashonsd/pirateship/PlayerRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.vashonsd.pirateship;

import java.util.HashMap;

import org.vashonsd.pirateship.interactions.Player;
import org.vashonsd.pirateship.structure.Location;

public class PlayerRegistry {
private HashMap<String, Player> registry;

public PlayerRegistry() {
super();
this.registry = new HashMap<String, Player>();
}

/**
* Use this
* @param id -- the id of the player
* @param p -- the player object created for this player.
*/
public void add(String id, Player p) {
this.registry.put(id, p);
}

public boolean has(String id) {
return registry.containsKey(id);
}

public Player get(String id) {
return registry.get(id);
}

/**
* Checks to see if the name is enrolled in the PlayerRegistry with its unique ID.
* If the given name does not represent a unique ID, it auto-generated a new unique ID by adding an integer
* value to the end of the name.
* @param name
* @return the id by which the player is registered.
*/
public String EnrollPlayer(Player p) {
String id = p.getName();
int incr = 0;
while (this.has(id)) {
incr++;
id = p.getName() + String.valueOf(incr);
}
add(id, p);
return id;
}
}
68 changes: 68 additions & 0 deletions src/main/java/org/vashonsd/pirateship/commands/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.vashonsd.pirateship.commands;


import java.util.ArrayList;

import org.vashonsd.pirateship.interactions.Actor;
import org.vashonsd.pirateship.interactions.Player;
import org.vashonsd.pirateship.interactions.Response;
import org.vashonsd.pirateship.interactions.VisibilityLevel;

/**
* A Command represents potential action to take, given an accessor word.
*
* For instance, the "examine" command acts on a given object and returns its description. For this, the object
* needs a public method for getting its description. We must rely on these public methods within the given object.
* @author andy
*
*/
public abstract class Command {
protected ArrayList<String> keywords;
protected boolean keepAlive = false;

protected VisibilityLevel visibility;

public Command() {
keywords = new ArrayList<String>();
visibility = VisibilityLevel.HELP;
}

/**
*
* @param obj -- the Actor that is the target of this execution.
* @param player -- the Player that issued the command.
* @return -- a Response. Most crucial: swap in the new PlayerState, formulate a text response, and set the KeepAlive to true or false.
*/
public abstract Response execute(Actor obj, Player player);

public ArrayList<String> getKeywords() {
return keywords;
}

public void addKeywords(String... keywords) {
for (String k : keywords) {
addKeyword(k);
}
}

public void addKeyword(String s) {
this.keywords.add(s);
}

public boolean isKeepAlive() {
return keepAlive;
}

public void setKeepAlive(boolean keepAlive) {
this.keepAlive = keepAlive;
}

public VisibilityLevel getVisibility() {
return visibility;
}

public void setVisibility(VisibilityLevel visibility) {
this.visibility = visibility;
}

}
14 changes: 14 additions & 0 deletions src/main/java/org/vashonsd/pirateship/commands/CommandSets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.vashonsd.pirateship.commands;

import java.util.ArrayList;

public class CommandSets {

public static ArrayList<Command> basic() {
ArrayList<Command> results = new ArrayList<Command>();
results.add(new Examine());
results.add(new Take());
return results;
}

}
12 changes: 12 additions & 0 deletions src/main/java/org/vashonsd/pirateship/commands/EasterEgg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.vashonsd.pirateship.commands;

import org.vashonsd.pirateship.interactions.VisibilityLevel;

public abstract class EasterEgg extends Command {

public EasterEgg() {
super();
this.visibility = VisibilityLevel.NEVER;
}

}
Loading