import java.util.*; public class Game { public static Player user = new Player("You",0,0,50); public static Location currentRoom = null; public static Item[] randItems = {new Item(1,0,0,100, "brown","dirty","water"),new Item(100,0,0,0, "rainbow","smelly","owl products"),new Item(1,0,10, "brown","spacious","backpack"),new Item(1,0,0,0, "white","dead","skull"),new Item(5,0,0,0, "brown","intense","tent"),new Item(0,0,0,100, "light brown","hard","bread"),new Item(weight,damage,armor,hunger, "brown","hot","torch"),new Item(5,0,100,0, "silver","hard","shield")}; public static Location[][] grid = { //*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* {/**/new Location("forest#1","You find yourself in a clearing"+/**/ /**/ /**/ /**/" in the middle of the forest. Your fire is dying as you"+/**/ /**/ /**/ /**/" prepare to continue your journey to defeat God. You pa"+/**/ /**/ /**/ /**/"ck your things and go to a crossroads a few miles from "+/**/ /**/ /**/ /**/"the clearing. (Say \"commands\" to get a list of the po"+/**/ /**/ /**/ /**/"ssible commands).",null,new Item[]{new Item(3,5,0,0, /**/ /**/ /**/ /**/"brown","hot","torch")}), /**/ /**/ /**/ /**/ /**/new Location("denseForest","As you progress into the for"+/**/ /**/ /**/ /**/"est, you begin to notice it is darker and that everythi"+/**/ /**/ /**/ /**/"ng is damp. Something is off about this place, so you w"+/**/ /**/ /**/ /**/"ant to leave as soon as possible.",new Player("Spider",1,/**/ /**/ /**/ /**/2,5),new Item[]{new Item(50,0,0,100, "purple","tasty", /**/ /**/ /**/ /**/"pig")}), /**/ /**/ /**/ /**/ /**/new Location("tundra","For some reason, you are now in "+/**/ /**/ /**/"a tundra past the mountains you crossed for months. Yo"+/**/ /**/ /**/ /**/"u do not know why you did this; it seems pointless. At"+/**/ /**/ /**/ /**/"some point, you meet a polar bear who would like to ea"+/**/ /**/ /**/ /**/"t you. What do you do?",new Player("Polar Bear",2,1,10),/**/ /**/ /**/ /**/new Item[]{new Item(10,0,1,1, "brown","warm", /**/ /**/ /**/ /**/"fur clothing")}) /**/}, //*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* /**/ /**/ {/**/new Location("fabulousDungeon","You step on a trap door "+/**/ /**/ /**/ "in the middle of the forest. Curious and low on supplie"+/**/ /**/ /**/ "s, you decide to try your luck with the basement seeing"+/**/ /**/ /**/ " as you have already tried your luck with the forest. A"+/**/ /**/ /**/ "s you enter, you notice a large excess of glitter on th"+/**/ /**/ /**/ "e floor. Seriously, it will take years to get rid of th"+/**/ /**/ /**/ "is stuff. At the bottom of the staircase, you see that "+/**/ /**/ /**/ "the basement is actually a fabulous dungeon. There is a"+/**/ /**/ /**/ " troll and a prisoner in the corner, who seem not to no"+/**/ /**/ /**/ "tice you.",new Player("Troll",3,2,10),new Item[]{new /**/ /**/ /**/ Item(1,0,1,0, "silver","fabulous","Tiara"),new Item(1,10,1/**/ /**/ /**/ ,0, "gold","shining","sceptre")}), /**/ /**/ /**/ /**/new Location("enemyCamp","You stumble upon an enemy camp"+/**/ /**/ /**/". Generally oblivious, you walked in to the camp withou"+/**/ /**/ /**/"t noticing all of the weapons and people around. Everyo"+/**/ /**/ /**/"ne gets quiet and stares at you. A few seconds later, y"+/**/ /**/ /**/"ou find yourself hugging the ground. No, you do not hav"+/**/ /**/ /**/"e a new affection for the earth; you have been tackled "+/**/ /**/ /**/"and captured. The soldiers bring you to their king, but"+/**/ /**/ /**/" the king is not to smart and let you fight for your fr"+/**/ /**/ /**/"eedom. Your opponent is a veteran war hero who has slai"+/**/ /**/ /**/"n many of your friends. Go get 'em tiger.",new /**/ /**/ /**/Player("Enemy",1,2,5),new Item[]{new Item(10,25,10,0, /**/ /**/ /**/"dull brown","coarse and thick","leather armor")}), /**/ /**/ new Location("abandonedHouse","You see a glimmer in the"+/**/ " forest and decide to investigate. It was a broken win"+/**/ "dow of a long abandoned cabin in the woods. There may "+/**/ "be useful supplies inside, but the door is locked. You"+/**/ " must find a way in.",null,new Item[]{new Item(4,15,0,0,/**/ "brown","dusty","bow")}) /**/}, { new Location("forest#2","You walk through a boring forest" ,null,new Item[]{new Item(0,3,0,1,"gold","cold", /**/ /**/ /**/ /**/"key")})), /**/new Location("castle","You enter s friendly castle full "+ "of pastries and friends and family. You get a feast.", null,null) new Location("orcCamp","",new Player("Spider",1,2,5),null) }, { new Location("heaven","You died and went to heaven. You meet God.",new Player("God",100,100,100),null), new Location("swamp","You enter a swamp. It seems mundane and boring to traverse because of the mud.",new Player("Frog",1,2,5),null), new Location("tradingPost","",null,null) }, { new Location("forest","It's just a boring forest.",null,null), new Location("dangerousForest","This forest is dangerous, but you decided to cross this dangerous path instead of the better paths around you, for some reason.",new Player("Giant",10,10,10),null), new Location("deadlyForest","",new Player("Dragon",50,100,25),null) }, { new Location("secretForest","",new Player("Floating Eye",100,25,25),null), new Location("secretCastle","",null,null), new Location("secretCastle","",new Player("King",100,50,50),null) }, { new Location("secretForest","",null,null), new Location("secretCastle","",null,null), new Location("secretCastle","",new Player("Yourself",100,100,100),null) } }; public static void main(String args[]) { final int ymax = grid.length-1; final int xmax = grid[0].length-1; for(int xLocation=0;xLocation0&&xLocation0&&yLocation user.inventorySpace) { Item randItem = user.inventory.get((int)(Math.rand()*user.inventory.size())); currentRoom.itemList.add(randItem); useless = user.inventory.remove(randItem); } } if(currentRoom.hostile && Math.random()>0.5 && currentRoom.user.healthUpdate((int)(user.lvl*Math.random()*10),user.armor)) { str += "You have died."; } str += "Your health is "+user.health+", your armor is "+user.armor+", your hunger is "+user.hunger+", and your inventory space is "+weight+"/"+user.inventorySpace+". "; user.armor = armor; currentRoom.hostile = true; else if((input.substring(0,3).equals("go ")||input.substring(0,5).equals("walk ")||input.substring(0,7).equals("travel "))&&(input.contains(" south")||input.contains(" north")||input.contains(" east")||input.contains(" west"))) { currentRoom.hostile = false; currentRoom.player = null; if(input.contains("south")) currentRoom = currentRoom.south; else if(input.contains("north")) currentRoom = currentRoom.north; else if(input.contains("east")) currentRoom = currentRoom.east; else if(input.contains("west")) currentRoom = currentRoom.west; currentRoom.player = user; currentRoom.hostile = false; str += currentRoom.move(); } else if(input.substring(0,5).equals("take ")) { str += "You picked up a "; for(Item item: currentRoom.itemList)//convert to String { if(input.contains(item.name)) { user.inventory.add(item); str += item.name; } } str += "."; } else if(input.contains("inventory")) { str += user.listItems(); } else if(input.substring(0,7).equals("attack ")) { if(user.AOE) { //for(Player enemy: enemyList) //{ if(currentRoom.enemy.healthUpdate(user.damageOutput,currentRoom.enemy.armor)) { currentRoom.itemList.addAll(currentRoom.enemy.inventory); //useless = enemyList.remove(enemy); str += currentRoom.enemy.listItems(); } //} } else { //Player currentEnemy = enemyList.get((int)(Math.random()*enemyList.size())); if(currentRoom.enemy.healthUpdate(user.damageOutput,currentRoom.enemy.armor)) { currentRoom.enemy = null; str += "You have killed the "+enemy+"."; //useless = enemyList.remove(enemy); } } } else if(input.substring(0,5).equals("sleep")) { return user.heal(0,0); } else if((input.substring(0,6).equals("unlock")||input.substring(0,5).equals("open"))&&inventoryString.contains("key")) { currentRoom.itemList.add(randItems[(int)(Math.rand()*randItems.length)]); } else if(input.substring(0,3).equals("run")) { currentRoom.player = null; ArrayList roomOptions = new ArrayList<>(); Collections.addAll(roomOptions,currentRoom.west,currentRoom.east,currentRoom.south,currentRoom.north); currentRoom = roomOptions.get((int)(Math.random()*roomOptions.size())); currentRoom.player = user; str += currentRoom.move(); } else if(input.substring(0,5).equals("drink")) { for(Item foodItem: user.inventory)//have subclass { if(input.contains(foodItem+"")&&foodItem.filling == 1) { user.inventory.remove(foodItem);//this returns value str += user.heal(5,5); } } } else if(input.substring(0,4).equals("eat ")) { for(Item foodItem: user.inventory)//have subclass { if(input.contains(foodItem.toString())&&(foodItem.filling>0)) { str += user.heal(foodItem.filling,0); useless = user.inventory.remove(foodItem); } } } else if(input.substring(0,8).equals("commands")) { str += "You think you can walk or go in lines perpenducular or parallel to the equator, take things, inventory, attack enemies, sleep, unlock doors, run, drink, eat, and think about what you can do." } else { str += " Invalid response."; } return str; } }