import java.util.Scanner; public class finalproject { public static void main(String[] args){ int health = 1000; int money = 540; int sword = 0; int helmet = 0; int armor = 0; int ehealth = 0; int endgame = 0; while (endgame == 0) { String choice; Scanner user_in = new Scanner(System.in); int leavebattle = 0; int payloan = 0; //check for money below 0 if (money < 0) { System.out.println("You had to take out a loan and now have to pay the bank $" + Math.abs(money) + "."); System.out.println("Fight to gain money to pay back loan?"); choice = user_in.nextLine(); //yes or no for paying loan if (choice.equals("yes")) { payloan++; } else if (choice.equals("no")) { System.out.println("Game Over"); System.out.println("Press Enter to restart."); //reset ints to default for restart (health, money, amount of items) health = 1000; money = 540; sword = 0; helmet = 0; armor = 0; //end resetting ints for restart //press enter to restart Scanner sc = new Scanner(System.in); while(!sc.nextLine().equals("")); } //end yes or no for loan } //end money check //start of main System.out.println("Health=" + health); System.out.println("Money=$" + money); System.out.println("What do you want to do? Go to shop, inventory, fight, or sleep."); choice = user_in.nextLine(); //main choices - fight if (choice.equals("fight")) { leavebattle = 0; int enemy = (int)(100.0 * Math.random()) + 1; if (enemy <= 10) { ehealth = 100; System.out.println("Enemy: Knight"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 10) && (enemy <= 20)) { ehealth = 200; System.out.println("Enemy: White Knight"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 20) && (enemy <= 30)) { ehealth = 300; System.out.println("Enemy: Giant Spider"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 30) && (enemy <= 40)) { ehealth = 400; System.out.println("Enemy: Black Knight"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 40) && (enemy <= 50)) { ehealth = 500; System.out.println("Enemy: \"The Thing\""); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 50) && (enemy <= 60)) { ehealth = 600; System.out.println("Enemy: Ogre"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 60) && (enemy <= 70)) { ehealth = 700; System.out.println("Enemy: \"The Creation\""); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 70) && (enemy <= 80)) { ehealth = 800; System.out.println("Enemy: Beast"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 80) && (enemy <= 90)) { ehealth = 900; System.out.println("Enemy: Dark Beast"); System.out.println("Enemy health: " + ehealth); } else if ((enemy > 90) && (enemy <= 100)) { ehealth = 1001; System.out.println("Enemy: Dragon"); System.out.println("Enemy health: " + ehealth); } System.out.println("Use sword or fist?"); choice = user_in.nextLine(); if (choice.equals("sword") && (sword >= 1)) { while (leavebattle == 0) { //begin random number for damage received if (armor == 0) { if (helmet == 0) { int fightnum = (int)(Math.random()*50+100); System.out.println("You receive " + fightnum + " damage and have " + (health - fightnum) + " health left."); health -= fightnum; } else if (helmet >= 1) { int fightnum2 = (int)(Math.random()*20+100); System.out.println("You receive " + fightnum2 + " damage and have " + (health - fightnum2) + " health left."); health -= fightnum2; } } else if (armor >= 1) { if (helmet == 0) { int fightnum3 = (int)(Math.random()*20+50); System.out.println("You receive " + fightnum3 + " damage and have " + (health - fightnum3) + " health left."); health -= fightnum3; } else if (helmet >= 1) { int fightnum4 = (int)(Math.random()*20+20); System.out.println("You receive " + fightnum4 + " damage and have " + (health - fightnum4) + " health left."); health -= fightnum4; } } //end damage received //begin damage given to enemy int playdmg = (int)(Math.random()*100+20); System.out.println("You deal " + playdmg + " damage and the enemy has " + (ehealth - playdmg) + " health left."); ehealth -= playdmg; //end damage given to enemy System.out.println("Press Enter to continue."); Scanner sd = new Scanner(System.in); while(!sd.nextLine().equals("")); if (health <= 0) { System.out.println("You have died. Restart?"); choice = user_in.nextLine(); if (choice.equals("yes")) { //reset ints to default for restart (health, money, amount of items) health = 1000; money = 540; sword = 0; helmet = 0; armor = 0; leavebattle = 1; //end resetting ints for restart //press enter to restart System.out.println("Press Enter to continue."); Scanner sc = new Scanner(System.in); while(!sc.nextLine().equals("")); } else if (choice.equals("no")) { System.out.println("Game Over"); leavebattle++; endgame++; System.exit(0); } } else if (ehealth <= 0) { System.out.println("The enemy has died!"); if (enemy <= 10) { int pay = (int)(Math.random()*10+110); money += pay; System.out.println("You receive $" + pay + " for killing Knight."); leavebattle = 1; } else if ((enemy > 10) && (enemy <= 20)) { int pay = (int)(Math.random()*20+120); money += pay; System.out.println("You receive $" + pay + " for killing White Knight."); leavebattle = 1; } else if ((enemy > 20) && (enemy <= 30)) { int pay = (int)(Math.random()*30+130); money += pay; System.out.println("You receive $" + pay + " for killing Giant Spider."); leavebattle = 1; } else if ((enemy > 30) && (enemy <= 40)) { int pay = (int)(Math.random()*40+140); money += pay; System.out.println("You receive $" + pay + " for killing Black Knight."); leavebattle = 1; } else if ((enemy > 40) && (enemy <= 50)) { int pay = (int)(Math.random()*50+150); money += pay; System.out.println("You receive $" + pay + " for killing \"The Thing\"."); leavebattle = 1; } else if ((enemy > 50) && (enemy <= 60)) { int pay = (int)(Math.random()*60+160); money += pay; System.out.println("You receive $" + pay + " for killing Ogre."); leavebattle = 1; } else if ((enemy > 60) && (enemy <= 70)) { int pay = (int)(Math.random()*70+170); money += pay; System.out.println("You receive $" + pay + " for killing \"The Creation\"."); leavebattle = 1; } else if ((enemy > 70) && (enemy <= 80)) { int pay = (int)(Math.random()*80+180); money += pay; System.out.println("You receive $" + pay + " for killing Beast."); leavebattle = 1; } else if ((enemy > 80) && (enemy <= 90)) { int pay = (int)(Math.random()*90+190); money += pay; System.out.println("You receive $" + pay + " for killing Dark Beast."); leavebattle = 1; } else if (enemy > 90) { int pay = (int)(Math.random()*100+200); money += pay; System.out.println("You receive $" + pay + " for killing Dragon."); System.out.println("Congratulations! You have defeated the strongest enemy!"); leavebattle = 1; } } } } else if (choice.equals("sword") && (sword <= 0)) { System.out.println("You cannot fight with a sword. You must buy one in the shop first."); } else if (choice.equals("fist")) { leavebattle = 0; while (leavebattle == 0) { //begin random number for damage received if (armor == 0) { if (helmet == 0) { int fightnum5 = (int)(Math.random()*50+100); System.out.println("You receive " + fightnum5 + " damage and have " + (health - fightnum5) + " health left."); health -= fightnum5; } else if (helmet >= 1) { int fightnum6 = (int)(Math.random()*20+100); System.out.println("You receive " + fightnum6 + " damage and have " + (health - fightnum6) + " health left."); health -= fightnum6; } } else if (armor >= 1) { if (helmet == 0) { int fightnum7 = (int)(Math.random()*20+50); System.out.println("You receive " + fightnum7 + " damage and have " + (health - fightnum7) + " health left."); health -= fightnum7; } else if (helmet >= 1) { int fightnum8 = (int)(Math.random()*20+20); System.out.println("You receive " + fightnum8 + " damage and have " + (health - fightnum8) + " health left."); health -= fightnum8; } } //end damage received //begin damage given int playdmg2 = (int)(Math.random()*20+100); System.out.println("You deal " + playdmg2 + " damage and the enemy has " + (ehealth - playdmg2) + " health left."); ehealth -= playdmg2; //end damage given //press enter to continue System.out.println("Press Enter to continue."); Scanner se = new Scanner(System.in); while(!se.nextLine().equals("")); if (health <= 0) { System.out.println("You have died. Restart?"); choice = user_in.nextLine(); if (choice.equals("yes")) { //reset ints to default for restart (health, money, amount of items) health = 1000; money = 540; sword = 0; helmet = 0; armor = 0; leavebattle = 1; //end resetting ints for restart //press enter to restart System.out.println("Press Enter to continue."); Scanner sc = new Scanner(System.in); while(!sc.nextLine().equals("")); } else if (choice.equals("no")) { System.out.println("Game Over"); leavebattle++; endgame++; System.exit(0); } } else if (ehealth <= 0) { System.out.println("The enemy has died!"); if (enemy <= 10) { int pay = (int)(Math.random()*100+70); money += pay; System.out.println("You receive $" + pay + " for killing Knight."); leavebattle = 1; } else if ((enemy > 10) && (enemy <= 20)) { int pay = (int)(Math.random()*100+80); money += pay; System.out.println("You receive $" + pay + " for killing White Knight."); leavebattle = 1; } else if ((enemy > 20) && (enemy <= 30)) { int pay = (int)(Math.random()*100+90); money += pay; System.out.println("You receive $" + pay + " for killing Giant Spider."); leavebattle = 1; } else if ((enemy > 30) && (enemy <= 40)) { int pay = (int)(Math.random()*100+100); money += pay; System.out.println("You receive $" + pay + " for killing Black Knight."); leavebattle = 1; } else if ((enemy > 40) && (enemy <= 50)) { int pay = (int)(Math.random()*150+100); money += pay; System.out.println("You receive $" + pay + " for killing \"The Thing\"."); leavebattle = 1; } else if ((enemy > 50) && (enemy <= 60)) { int pay = (int)(Math.random()*200+100); money += pay; System.out.println("You receive $" + pay + " for killing Ogre."); leavebattle = 1; } else if ((enemy > 60) && (enemy <= 70)) { int pay = (int)(Math.random()*250+100); money += pay; System.out.println("You receive $" + pay + " for killing \"The Creation\"."); leavebattle = 1; } else if ((enemy > 70) && (enemy <= 80)) { int pay = (int)(Math.random()*300+100); money += pay; System.out.println("You receive $" + pay + " for killing Beast."); leavebattle = 1; } else if ((enemy > 80) && (enemy <= 90)) { int pay = (int)(Math.random()*350+100); money += pay; System.out.println("You receive $" + pay + " for killing Dark Beast."); leavebattle = 1; } else if (enemy > 90) { int pay = (int)(Math.random()*500+100); money += pay; System.out.println("You receive $" + pay + " for killing Dragon."); System.out.println("Congratulations! You have defeated the strongest enemy!"); leavebattle = 1; } } } //int fightnum = (int)(Math.random()*50+100); //System.out.println("You receive " + fightnum + " damage."); //health -= fightnum; } } //end fight //main choices - shop else if (choice.equals("shop")) { if (payloan == 0) { if ((money <= 1000) && (money > 0)) { System.out.println("What do you want to buy?"); System.out.println("Sword--$50"); System.out.println("Helmet--$250"); System.out.println("Armor--$550"); choice = user_in.nextLine(); //shop choices if (choice.equals("sword")) { money -= 50; System.out.println("You buy a sword, and you now have $"+ money +"."); sword++; } else if (choice.equals("helmet")) { money -= 250; System.out.println("You buy a helmet, and you now have $"+ money +"."); helmet++; } else if (choice.equals("armor")) { money -= 550; System.out.println("You buy a set of armor, and you now have $"+ money +"."); armor++; } else { System.out.println(choice + " is not a valid choice."); } } else { System.out.println("You cannot buy anything else at this time."); } } else if (payloan > 0) { System.out.println("You must fight to pay back your loan first."); System.out.println("Hit Enter to continue."); Scanner sc = new Scanner(System.in); while(!sc.nextLine().equals("")); } } //end shop //main choices - sleep else if (choice.equals("sleep")) { if (payloan == 0) { if (health == 1000) { System.out.println("You have full health."); } else if (health < 1000) { health = 1000; System.out.println("Your health is fully restored."); } } else if (payloan > 0) { System.out.println("You must fight to pay back your loan first."); System.out.println("Hit Enter to continue."); Scanner sc = new Scanner(System.in); while(!sc.nextLine().equals("")); } } //end sleep //main choices - inventory else if (choice.equals("inventory")) { System.out.println("Swords: " + sword); System.out.println("Helmets: " + helmet); System.out.println("Sets of armor: " + armor); System.out.println("Press Enter to continue."); //press enter to continue Scanner sc = new Scanner(System.in); while(!sc.nextLine().equals("")); } //end inventory else { System.out.println(choice + " is not a valid choice."); } } } }