/* Kitsune: World by Kris Schnee */ import java.util.Random; import java.util.Hashtable; public class KitsuneWorld { final int NORTH = 0; final int EAST = 1; final int SOUTH = 2; final int WEST = 3; final String INTRO = "* The Kitsune Game *\n"+ "You've become a kitsune. Currently you're stuck as a non-morphic fox.\n"+ "Explore and become stronger!"; Random rand; String playerName; Place startingPlace; Place[][] grid; public Creature player; public KitsuneWorld() { rand = new Random(); playerName = "Kauai"; grid = new Place[100][100]; for(int x=0;x<=99;x++) { for(int y=0;y<=99;y++) { int[] coords = {x,y}; makePlace("Wilderness","Empty land, as though undefined.",coords); } } int[] coords = {50,50}; Place p = makePlace("Pond","A fancy pond.",coords); startingPlace = p; int[] coords1 = {50,49}; makePlace("North of Pond","Yup, you're north of it.",coords1); int[] coords2 = {50,51}; makePlace("South of Pond","You seem to be south of the pond.",coords2); int[] coords3 = {49,50}; makePlace("Dojo","A cool fighting dojo.",coords3); player = new Creature(playerName); System.out.println(player.name); player.SetAttack(5); player.SetCoords(startingPlace.coords); } public Place makePlace(String name, String desc, int[] coords) { Place p = new Place(name, desc, coords); grid[coords[0]][coords[1]] = p; return p; } public String getPlayerCoordsString() { return "X " + player.coords[0] + " Y " + player.coords[1]; } public Place getPlace(int[] coords) { return grid[coords[0]][coords[1]]; } public void tryToMoveCreature(int dir) { // Change to specify the creature. Assumes player now. if( okToMove(player.coords, dir) ) { System.out.println("Coords 1: "+getPlayerCoordsString()); int[] newCoords = getNeighborCoords(player.coords, dir); System.out.println("Coords 2: "+getPlayerCoordsString()); player.SetCoords(newCoords); System.out.println("Moved: "+dir); System.out.println("New coords: "+getPlayerCoordsString()); System.out.println(getPlace(player.coords)); } } public boolean okToMove(int[] coords,int dir) { int[] newCoords = getNeighborCoords(coords, dir); if( getPlace( newCoords ).name == "" ) { System.out.println("Null"); return false; } System.out.println("Seems to exist."); return true; } public int[] getNeighborCoords(int[] coords, int dir) { // Get the coordinates of the room in some direction from here. int[] newCoords = {coords[0],coords[1]}; switch(dir) { case NORTH: newCoords[1]--; break; case SOUTH: newCoords[1]++; break; case EAST: newCoords[0]++; break; case WEST: newCoords[0]--; break; default: break; } return newCoords; } public Place getCreaturePlace(Creature c) { return getPlace(c.coords); } public String getPlayerName() { return player.name; } ///* public static void main(String[] args) { // Temp KitsuneWorld k = new KitsuneWorld(); int[] coords = {2,3}; k.makePlace("Dojo","A cool dojo",coords); } //*/ }