Hey! Below is the source code to a simple game I created a few years back as a final project for my AP CS class. It’s written in java and was inspired by the game “A Dark Room”, created by Amir Rajan & released in 2013.
Below is some gameplay!
Very simple but an interesting play! Here is the code:
import java.util.Scanner; import java.awt.event.*; public class GameMain { /** * Main runs intro sequence and then calls <code> explore </code> method */ public static void main(String []args) { System.out.println("WELCOME to 9"); System.out.println(" "); System.out.println(" "); System.out.println("Instructions: use w,d,s,a and 'Enter' to guide yourself through missions."); System.out.println("(Make sure your window fits the entire map) "); System.out.println(" "); System.out.println("Object guide:"); System.out.println("1: you"); System.out.println("2: home"); System.out.println("3: northern base"); System.out.println("4: southern wall"); System.out.println("5: hospital"); System.out.println("6: market"); System.out.println("7: motel"); System.out.println("8: object"); System.out.println("9: family"); System.out.println("(type any of these numbers at any time in the game for a quick reminder)"); System.out.println(" "); System.out.println("When you are ready to begin, type 'start'"); Scanner start = new Scanner(System.in); String begin = start.next(); if(begin.indexOf("start") >= 0) { System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); try { Thread.sleep(7000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("It's dark here..."); System.out.println(" "); try { Thread.sleep(7000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("It wasn't always like this."); try { Thread.sleep(7000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.print("My home..."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("My family..."); try { Thread.sleep(7000); } catch(Interrupt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2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,9,2,2,2,2,2,2,2}, {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2} }; for(int print1 = 0; print1 < 26; print1++ ) { for(int print2 = 0; print2 < 40; print2++) { System.out.print(myArray[print1][print2]); System.out.print(" "); } System.out.println(" "); } System.out.println("energy = 20"); boolean first = true; boolean exploring = true; int currentRep = 0; int currentCount = 0; int energy = 19; int progress = 0; int clue = 0; int food = 5; int finish = 0; while(first == true) { int xx = 23; int yy = 9; myArray = move(xx,yy, myArray); mapPrint(myArray, energy, progress); energy --; first = false; } while(exploring == true) { for(int rep = 0; rep < 26; rep ++) { for(int count = 0; count < 40; count++) { if(myArray[rep][count] == 1) { currentRep = rep; currentCount = count; } } } if(energy > -1 && progress <= 5) { myArray = move(currentRep,currentCount, myArray); mapPrint(myArray, energy, progress); myArray = significance(currentCount, currentRep, myArray, progress); energy = energizer(energy, currentCount,currentRep, progress); progress = progress(progress,currentCount, currentRep); energy --; } if(energy > -1 && progress >= 6 && clue < 20) { myArray = advancedMove(currentRep, currentCount, myArray, myMapKey); mapPrint2(myArray, energy, food); clue = clue(currentCount, currentRep, myMapKey, clue); energy = home(energy,currentCount, currentRep); food = foodSupply(currentCount, currentRep, food); energy --; } if(clue == 20 && finish == 0) { myArray = finalMove(currentRep, currentCount, myArray, myMapKey); mapPrint2(myArray, energy, food); energy = home(energy,currentCount, currentRep); food = foodSupply(currentCount, currentRep, food); finish = family(currentCount, currentRep, finish); energy --; } if(finish == 1) { gameFinish(); exploring = false; } if(energy == -1) { gameOver(); exploring = false; } if(food == 0) { starve(); exploring = false; } } } public static int[][] move(int x, int y, int[][] myNewArray) { Scanner input2 = new Scanner(System.in); String direction = input2.next(); boolean moving = true; boolean answered = false; while(moving == true) { if(direction.indexOf("w") >= 0 && myNewArray[x-1][y] != 4) { myNewArray[x][y] = 0; myNewArray[x-1][y] = 1; answered = true; moving = false; } if(direction.indexOf("d") >= 0 && myNewArray[x][y+1] != 4) { myNewArray[x][y] = 0; myNewArray[x][y+1] = 1; answered = true; moving = false; } if(direction.indexOf("s") >= 0 && myNewArray[x+1][y] != 4) { myNewArray[x][y] = 0; myNewArray[x+1][y] = 1; answered = true; moving = false; } if(direction.indexOf("a") >= 0 && myNewArray[x][y-1] != 4) { myNewArray[x][y] = 0; myNewArray[x][y-1] = 1; answered = true; moving = false; } if(direction.indexOf("1") >= 0) { System.out.println(" This is you."); direction = input2.next(); } if(direction.indexOf("2") >= 0) { System.out.println(" This is your old home."); direction = input2.next(); } if(direction.indexOf("3") >= 0) { System.out.println(" This is the base to the north."); direction = input2.next(); } if(direction.indexOf("4") >= 0) { System.out.println(" This is a large wall which surrounded the southern base."); direction = input2.next(); } if(direction.indexOf("5") >= 0) { System.out.println(" This is an old hospital. They must have some medical supplies."); direction = input2.next(); } if(direction.indexOf("6") >= 0) { System.out.println(" This is the old market. I'll visit here when my food supply is low."); direction = input2.next(); } if(direction.indexOf("7") >= 0) { System.out.println(" This is an old motel, and my current refuge. Here i can replenish my energy."); direction = input2.next(); } if(direction.indexOf("8") >= 0) { System.out.println(" This is an object. It could possibly help me find them.."); direction = input2.next(); } if(direction.indexOf("9") >= 0) { System.out.println(" My Family.."); direction = input2.next(); } /*if(answered = false) *{ * System.out.println("Invalid"); * direction = input.next(); *} */ } return myNewArray; } public static int[][] mapPrint(int[][]myArray, int energy, int progress) { for(int print1 = 0; print1 < 26; print1++ ) { for(int print2 = 0; print2 < 40; print2++) { System.out.print(myArray[print1][print2]); System.out.print(" "); } System.out.println(" "); } if(progress >= 1) { myArray[10][5] = 2; } if(progress >= 2) { myArray[4][14] = 3; } if(progress >= 3) { myArray[22][20] = 4; myArray[22][21] = 4; myArray[23][20] = 4; myArray[24][20] = 4; myArray[25][20] = 4; myArray[22][22] = 4; myArray[22][23] = 4; myArray[22][24] = 4; myArray[22][25] = 4; myArray[22][26] = 4; myArray[22][27] = 4; myArray[22][28] = 4; myArray[22][29] = 4; myArray[22][30] = 4; myArray[22][31] = 4; myArray[22][31] = 4; myArray[22][32] = 4; myArray[22][33] = 4; myArray[22][34] = 4; myArray[22][35] = 4; myArray[22][36] = 4; myArray[22][37] = 4; myArray[22][38] = 4; myArray[22][39] = 4; } if(progress >= 4) { myArray[14][15] = 5; } if(progress >= 5) { myArray[9][34] = 6; } if(progress >=6) { myArray[17][10] = 7; } if(energy >= 4) { System.out.println("energy = " + energy); } if(energy < 4) { System.out.println("ENERGY = " + energy); } return myArray; } public static int[][] significance(int xSpot, int ySpot, int[][] nextLocation, int progress) { if(xSpot == 5 && ySpot == 10 && progress == 0) { System.out.println("I can't believe what this world has come to..."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("an engraving on the wall reads:"); System.out.println("'To the north we are safe.'"); try { Thread.sleep(7000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("I must go to the north base"); try { Thread.sleep(3000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } nextLocation[4][15] = 3; System.out.println("Energy replenished"); System.out.println("(Exit to the North)"); progress++; return nextLocation; } if(xSpot == 14 && ySpot == 4 && progress == 1) { System.out.println("More wreckage.."); try { Thread.sleep(6000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("The North is nothing now."); System.out.println(" "); try { Thread.sleep(3000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("It makes me wonder of the south..."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } nextLocation[22][20] = 4; System.out.println("Energy upgraded"); System.out.println("(Exit to the South)"); progress++; return nextLocation; } if(xSpot == 18 && ySpot == 21 && progress == 2 || xSpot == 19 && ySpot == 22 && progress == 2 || xSpot == 18 && ySpot == 22 && progress == 2) { System.out.println("It's hard to believe how much has changed.."); try { Thread.sleep(6000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("A huge wall seperates me from the far south now.."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("There used to be a hospital around here.. Maybe they're safe..."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } nextLocation[14][14] = 5; System.out.println("Energy replenished"); System.out.println("(Exit to the North)"); progress++; return nextLocation; } if(xSpot == 15 && ySpot == 14 && progress == 3) { System.out.println("How can I be the only one?"); try { Thread.sleep(6000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("The only.."); try { Thread.sleep(1500); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("Survivor.?"); try { Thread.sleep(5000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("To survive I must find food.."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } nextLocation[9][34] = 6; System.out.println("Energy upgraded"); System.out.println("(Exit to the North)"); progress++; return nextLocation; } if(xSpot == 33 && ySpot == 9 && progress == 4) { System.out.println("The world has been brought to nothing.."); try { Thread.sleep(6000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("I can only carry enough food for 5 days.."); System.out.println("A place to take refuge is necesary."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } nextLocation[17][10] = 7; System.out.println("Energy upgraded"); System.out.println("(Exit to the South)"); progress++; return nextLocation; } if(xSpot == 11 && ySpot == 17 && progress == 5) { System.out.println("This motel will suffice."); System.out.println(" "); try { Thread.sleep(6000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("I am starting to feel the effects of the radiation.."); try { Thread.sleep(3000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("I can only imagine how they feel..."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("My search truly begins here."); try { Thread.sleep(2000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("This will be my home for now. Here I will rest after each day."); System.out.println("But only for now.."); System.out.println(" "); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("(Find clues (8) in order to find your family"); System.out.println("All clues are different. Some can only be seen from an angle.."); System.out.println("Some aren't clues at all."); System.out.println("The '8' only represents an area in which a possible clue is near."); System.out.println("Therefore, be sure to search the immediate surrounding area as well."); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println(" "); System.out.println("As winds speed up, the dust of everything that once was has limited your vision."); System.out.println("The '2' now represents explored territory as well as range of vision.)"); try { Thread.sleep(4000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("(Exit to the North)"); progress++; return nextLocation; } else { return nextLocation; } } public static int energizer(int energy,int xSpot, int ySpot, int progress) { if(xSpot == 5 && ySpot == 10) { return 20; } if(xSpot == 14 && ySpot == 4 && progress == 1) { return 25; } if(xSpot == 19 && ySpot == 22 && progress == 2 || xSpot == 18 && ySpot == 21 && progress == 2 || xSpot == 18 && ySpot == 22 && progress == 2) { return 25; } if(xSpot == 15 && ySpot == 14 && progress == 3) { return 30; } if(xSpot == 33 && ySpot == 9 && progress == 4) { return 35; } if(xSpot == 11 && ySpot == 17 && progress == 5) { return 40; } else { return energy; } } public static int progress(int progress, int xSpot, int ySpot) { if(xSpot == 5 && ySpot == 10) { progress++; } if(xSpot == 14 && ySpot == 4 && progress == 1) { progress++; } if(xSpot == 19 && ySpot == 22 && progress == 2 || xSpot == 18 && ySpot == 21 && progress == 2 || xSpot == 18 && ySpot == 22 && progress == 2) { progress++; } if(xSpot == 15 && ySpot == 14 && progress == 3) { progress++; } if(xSpot == 33 && ySpot == 9 && progress == 4) { progress++; } if(xSpot == 11 && ySpot == 17 && progress == 5) { progress++; } return progress; } public static int[][] mapPrint2(int[][]myArray, int energy, int food) { for(int print1 = 0; print1 < 26; print1++ ) { for(int print2 = 0; print2 < 40; print2++) { System.out.print(myArray[print1][print2]); System.out.print(" "); } System.out.println(" "); } myArray[10][5] = 2; myArray[4][14] = 3; myArray[22][20] = 4; myArray[22][21] = 4; myArray[23][20] = 4; myArray[24][20] = 4; myArray[25][20] = 4; myArray[22][22] = 4; myArray[22][23] = 4; myArray[22][24] = 4; myArray[22][25] = 4; myArray[22][26] = 4; myArray[22][27] = 4; myArray[22][28] = 4; myArray[22][29] = 4; myArray[22][30] = 4; myArray[22][31] = 4; myArray[22][31] = 4; myArray[22][32] = 4; myArray[22][33] = 4; myArray[22][34] = 4; myArray[22][35] = 4; myArray[22][36] = 4; myArray[22][37] = 4; myArray[22][38] = 4; myArray[22][39] = 4; myArray[14][15] = 5; myArray[9][34] = 6; myArray[17][10] = 7; if(energy >= 4) { System.out.println("energy = " + energy); } if(energy < 4) { System.out.println("ENERGY = " + energy); } if(food > 2) { System.out.println("food supply = " + food + " days"); } if(food <= 2) { System.out.println("food supply = " + food + " days"); System.out.println("food supply dangerously low!"); } return myArray; } public static int[][] advancedMove(int x, int y, int[][] myNewArray, int[][] keyMap) { Scanner input = new Scanner(System.in); String direction = input.next(); boolean moving = true; boolean answered = false; while(moving == true) { if(direction.indexOf("w") >= 0 && myNewArray[x-1][y] != 4) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x-1][y] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x][y+1] == 0) { myNewArray[x][y+1] = keyMap[x][y+1]; } if(myNewArray[x][y-1] == 0) { myNewArray[x][y-1] = keyMap[x][y-1]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } if(myNewArray[x+1][y] == 0) { myNewArray[x+1][y] = keyMap[x+1][y]; } answered = true; moving = false; } if(direction.indexOf("d") >= 0 && myNewArray[x][y+1] != 4) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x][y+1] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x-1][y] == 0) { myNewArray[x-1][y] = keyMap[x-1][y]; } if(myNewArray[x][y-1] == 0) { myNewArray[x][y-1] = keyMap[x][y-1]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } if(myNewArray[x+1][y] == 0) { myNewArray[x+1][y] = keyMap[x+1][y]; } answered = true; moving = false; } if(direction.indexOf("s") >= 0 && myNewArray[x+1][y] != 4) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x+1][y] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x][y+1] == 0) { myNewArray[x][y+1] = keyMap[x][y+1]; } if(myNewArray[x][y-1] == 0) { myNewArray[x][y-1] = keyMap[x][y-1]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } answered = true; moving = false; } if(direction.indexOf("a") >= 0 && myNewArray[x][y-1] != 4) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x][y-1] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x-1][y] == 0) { myNewArray[x-1][y] = keyMap[x][y+1]; } if(myNewArray[x-1][y] == 0) { myNewArray[x-1][y] = keyMap[x-1][y]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } if(myNewArray[x+1][y] == 0) { myNewArray[x+1][y] = keyMap[x+1][y]; } answered = true; moving = false; } if(direction.indexOf("1") >= 0) { System.out.println(" This is you."); direction = input.next(); } if(direction.indexOf("2") >= 0) { System.out.println(" This is your old home. This also will represent your vision/ explored territory."); direction = input.next(); } if(direction.indexOf("3") >= 0) { System.out.println(" This is the base to the north."); direction = input.next(); } if(direction.indexOf("4") >= 0) { System.out.println(" This is a large wall which surrounded the southern base."); direction = input.next(); } if(direction.indexOf("5") >= 0) { System.out.println(" This is an old hospital. They must have some medical supplies."); direction = input.next(); } if(direction.indexOf("6") >= 0) { System.out.println(" This is the old market. I'll visit here when my food supply is low."); direction = input.next(); } if(direction.indexOf("7") >= 0) { System.out.println(" This is an old motel, and my current refuge. Here i can replenish my energy."); direction = input.next(); } if(direction.indexOf("8") >= 0) { System.out.println(" This is a clue, necesary for finding them."); direction = input.next(); } if(direction.indexOf("9") >= 0) { System.out.println(" My Family.."); direction = input.next(); } } return myNewArray; } public static int[][] finalMove(int x, int y, int[][] myNewArray, int[][] keyMap) { Scanner input = new Scanner(System.in); String direction = input.next(); boolean moving = true; boolean answered = false; while(moving == true) { if(direction.indexOf("w") >= 0) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x-1][y] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x][y+1] == 0) { myNewArray[x][y+1] = keyMap[x][y+1]; } if(myNewArray[x][y-1] == 0) { myNewArray[x][y-1] = keyMap[x][y-1]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } if(myNewArray[x+1][y] == 0) { myNewArray[x+1][y] = keyMap[x+1][y]; } answered = true; moving = false; } if(direction.indexOf("d") >= 0) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x][y+1] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x-1][y] == 0) { myNewArray[x-1][y] = keyMap[x-1][y]; } if(myNewArray[x][y-1] == 0) { myNewArray[x][y-1] = keyMap[x][y-1]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } if(myNewArray[x+1][y] == 0) { myNewArray[x+1][y] = keyMap[x+1][y]; } answered = true; moving = false; } if(direction.indexOf("s") >= 0) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x+1][y] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x][y+1] == 0) { myNewArray[x][y+1] = keyMap[x][y+1]; } if(myNewArray[x][y-1] == 0) { myNewArray[x][y-1] = keyMap[x][y-1]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } answered = true; moving = false; } if(direction.indexOf("a") >= 0) { myNewArray[x][y] = keyMap[x][y]; myNewArray[x][y-1] = 1; if(myNewArray[x-2][y] == 0) { myNewArray[x-2][y] = keyMap[x-2][y]; } if(myNewArray[x-3][y] == 0) { myNewArray[x-3][y] = keyMap[x-3][y]; } if(myNewArray[x-1][y-1] == 0) { myNewArray[x-1][y-1] = keyMap[x-1][y-1]; } if(myNewArray[x+1][y+1] == 0) { myNewArray[x+1][y+1] = keyMap[x+1][y+1]; } if(myNewArray[x-1][y+1] == 0) { myNewArray[x-1][y+1] = keyMap[x-1][y+1]; } if(myNewArray[x+1][y-1] == 0) { myNewArray[x+1][y-1] = keyMap[x+1][y-1]; } if(myNewArray[x-1][y] == 0) { myNewArray[x-1][y] = keyMap[x][y+1]; } if(myNewArray[x-1][y] == 0) { myNewArray[x-1][y] = keyMap[x-1][y]; } if(myNewArray[x][y+2] == 0) { myNewArray[x][y+2] = keyMap[x][y+2]; } if(myNewArray[x][y-2] == 0) { myNewArray[x][y-2] = keyMap[x][y-2]; } if(myNewArray[x+1][y] == 0) { myNewArray[x+1][y] = keyMap[x+1][y]; } answered = true; moving = false; } if(direction.indexOf("1") >= 0) { System.out.println(" This is you."); direction = input.next(); } if(direction.indexOf("2") >= 0) { System.out.println(" This is your old home. This also will represent your vision/ explored territory."); direction = input.next(); } if(direction.indexOf("3") >= 0) { System.out.println(" This is the base to the north."); direction = input.next(); } if(direction.indexOf("4") >= 0) { System.out.println(" This is a large wall which surrounded the southern base."); direction = input.next(); } if(direction.indexOf("5") >= 0) { System.out.println(" This is an old hospital. They must have some medical supplies."); direction = input.next(); } if(direction.indexOf("6") >= 0) { System.out.println(" This is the old market. I'll visit here when my food supply is low."); direction = input.next(); } if(direction.indexOf("7") >= 0) { System.out.println(" This is an old motel, and my current refuge. Here i can replenish my energy."); direction = input.next(); } if(direction.indexOf("8") >= 0) { System.out.println(" This is a clue, necesary for finding them."); direction = input.next(); } if(direction.indexOf("9") >= 0) { System.out.println(" My Family.."); direction = input.next(); } } return myNewArray; } public static int clue(int y, int x, int[][] key, int clue) { if(key[x][y] == 8) { clue++; key[x][y] = 0; } if(clue == 1) { System.out.println("The remains of some sort of animal.. it makes me sick to my stomach"); clue++; } if(clue == 3) { System.out.println("Death is everywhere.."); clue++; } if(clue == 5) { Scanner input20 = new Scanner(System.in); String choice = input20.next(); System.out.println("A man. He looks so ill.."); System.out.println("I have a choice to make:"); System.out.println(" "); System.out.println("(a) I give him a day's worth of my food."); System.out.println("(b) I leave him to die."); System.out.println(" "); if(choice.indexOf("a")>=0) { System.out.println("The man's eyes flutter, and he asks to be left to die."); } if(choice.indexOf("b")>=0) { System.out.println("As I'm walking away, the world feels quieter than ever."); } clue++; } if(clue == 7) { System.out.println("Ever since 'the end', these burrows seem to have popped up everywhere."); clue++; } if(clue == 9) { System.out.println("This bracelet smells exactly like home... It was one of theirs."); clue++; } if(clue == 11) { System.out.println("A single tree.."); clue++; } if(clue == 13) { System.out.println("Dogs, resorted to their primal instinct. Their meal looks too familiar."); clue++; } if(clue == 15) { System.out.println("These are her shoes. I'm absolutely sure of it. They're covered in mud."); clue++; } if(clue == 17) { System.out.println("Blood. It's not theirs. It's not theirs.."); clue++; } if(clue == 19) { System.out.println("A tattered piece of paper. it's addressed to me.."); System.out.println("'South'. thats all it says. How do i get past the wall. How."); finalThoughts(); clue++; } return clue; } public static int home(int energy, int xSpot, int ySpot) { if(xSpot == 10 && ySpot == 18) { System.out.println("Home sweet home.."); System.out.println("(exit to the east or west)"); energy = 50; } if(xSpot == 33 && ySpot == 9) { energy = 50; } return energy; } public static int foodSupply(int xSpot, int ySpot, int food) { if(xSpot == 11 && ySpot == 17 && food > 0) { food --; } if(xSpot == 11 && ySpot == 17 && food == 0) { starve(); } if(xSpot == 33 && ySpot == 9 && food <span data-mce-type="bookmark" id="mce_SELREST_start" data-mce-style="overflow:hidden;line-height:0" style="overflow:hidden;line-height:0" ></span>< 5) { System.out.println( 5 - food + " more days worth of food. Good."); food = 5; } return food; } public static int family(int xSpot, int ySpot, int finish) { if(xSpot == 32 && ySpot == 24) { finish = 1; } return finish; } public static void finalThoughts() { System.out.println(" "); System.out.println("it's so tall..."); try { Thread.sleep(3000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("But nothing will keep me from them. I know what I must do."); } public static void gameOver() { System.out.println("ENERGY = 0"); System.out.println("GAME OVER"); } public static void starve() { System.out.println("You lack the necesary food to venture on."); System.out.println("GAME OVER"); } public static void gameFinish() { System.out.print("My"); try { Thread.sleep(1000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.print("."); try { Thread.sleep(1000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.print("."); try { Thread.sleep(1000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.print("."); try { Thread.sleep(3000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("family.."); try { Thread.sleep(7000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } System.out.println("I'm Home."); } }