Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class Game {
- static Scanner input = new Scanner(System.in);
- static String charType; // character type
- static Character player; // player info
- static Random rand = new Random();
- public static void main(String[] args) {
- startGame();
- player = new Character(charType);
- //pause();
- intro();
- System.out.println();
- System.out.println();
- System.out.print("Start out by choosing a direction to move: ");
- movePlayer();
- while (player.getX() != 5 || player.getY() != 5) {
- if (player.getX() == 1 && player.getY() == 1) {
- boss();
- }
- if (player.getX() == 2 && player.getY() == 1) {
- advise("South");
- }
- if (player.getX() == 3 && player.getY() == 1) {
- weakVil();
- }
- if (player.getX() == 4 && player.getY() == 1) {
- mislead("East");
- }
- if (player.getX() == 5 && player.getY() == 1) {
- tornado();
- }
- if (player.getX() == 1 && player.getY() == 2) {
- mislead("North");
- }
- if (player.getX() == 2 && player.getY() == 2) {
- playerChoice();
- }
- if (player.getX() == 3 && player.getY() == 2) {
- quickSand();
- }
- if (player.getX() == 4 && player.getY() == 2) {
- System.out.println();
- if (player.getHealth() + 10 > 100) {
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have" + player.getNumPots() + " potions.");
- }
- else {
- System.out.println("You found health.");
- plusHP(10);
- getStats();
- System.out.println();
- }
- }
- if (player.getX() == 5 && player.getY() == 2) {
- weakVil();
- }
- if (player.getX() == 1 && player.getY() == 3) {
- // start
- }
- if (player.getX() == 2 && player.getY() == 3) {
- weakVil();
- }
- if (player.getX() == 3 && player.getY() == 3) {
- System.out.println();
- System.out.println("You found damage.");
- plusDamage(5);
- getStats();
- System.out.println();
- }
- if (player.getX() == 4 && player.getY() == 3) {
- weakVil();
- }
- if (player.getX() == 5 && player.getY() == 3) {
- System.out.println();
- if (player.getHealth() + 10 > 100) {
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have" + player.getNumPots() + " potions.");
- }
- else {
- System.out.println("You found health.");
- plusHP(10);
- getStats();
- System.out.println();
- }
- }
- if (player.getX() == 1 && player.getY() == 4) {
- weakVil();
- }
- if (player.getX() == 2 && player.getY() == 4) {
- System.out.println();
- if (player.getHealth() + 5 > 100) {
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have" + player.getNumPots() + " potions.");
- }
- else {
- System.out.println("You found health.");
- plusHP(5);
- getStats();
- System.out.println();
- }
- }
- if (player.getX() == 3 && player.getY() == 4) {
- weakVil();
- }
- if (player.getX() == 4 && player.getY() == 4) {
- System.out.println();
- if (player.getHealth() + 10 > 100) {
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have" + player.getNumPots() + " potions.");
- }
- else {
- System.out.println("You found health.");
- plusHP(10);
- getStats();
- System.out.println();
- }
- }
- if (player.getX() == 5 && player.getY() == 4) {
- megaBoss();
- }
- if (player.getX() == 1 && player.getY() == 5) {
- System.out.println();
- if (player.getHealth() + 10 > 100) {
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have" + player.getNumPots() + " potions.");
- }
- else {
- System.out.println("You found health.");
- plusHP(10);
- getStats();
- System.out.println();
- }
- }
- if (player.getX() == 2 && player.getY() == 5) {
- weakVil();
- }
- if (player.getX() == 3 && player.getY() == 5) {
- System.out.println();
- if (player.getHealth() + 10 > 100) {
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have " + player.getNumPots() + " potions.");
- System.out.println();
- }
- else {
- System.out.println("You found health.");
- plusHP(10);
- getStats();
- System.out.println();
- }
- }
- if (player.getX() == 4 && player.getY() == 5) {
- megaBoss();
- }
- if (player.getX() == 5 && player.getY() == 5) {
- System.out.println("You defeat the Dark Fantasy and become King.");
- }
- System.out.print("Enter another direction to move: ");
- movePlayer();
- }
- }
- public static void startGame() {
- System.out.println("Welcome to Dark Fantasy");
- System.out.println("Choose a Character: Warrior, Wizard, or Titan");
- charType = input.nextLine();
- System.out.println();
- }
- public static void intro() {
- System.out.println();
- System.out.println("Press enter to continue");
- String dummy = input.nextLine();
- System.out.println();
- System.out.println();
- System.out.println("Welcome to your journey!");
- }
- public static void movePlayer() {
- String direction = input.nextLine();
- if (direction.equalsIgnoreCase("north") || direction.equalsIgnoreCase("south") || direction.equalsIgnoreCase("east") || direction.equalsIgnoreCase("west")) {
- player.updatePos(direction.toLowerCase());
- }
- else {
- System.out.println("Invalid direction, please try again.");
- movePlayer();
- }
- /* Old Method of Direction Input Validation, broken with v1.6
- switch (direction) {
- case "north": player.updatePos(direction); break;
- case "south": player.updatePos(direction); break;
- case "east": player.updatePos(direction); break;
- case "west": player.updatePos(direction); break;
- default: System.out.println("Invalid direction, please try again."); movePlayer(); break;
- }
- */
- }
- public static void pause() {
- String dummy = input.nextLine();
- System.out.println();
- }
- //methods for the levels
- public static void megaBoss() {
- System.out.println();
- System.out.println("------------------------");
- System.out.println();
- System.out.println("A Dragon approaches you!");
- System.out.println("Dragons have a total health of 100 and attack power of 100. Fight off the Dragon to survive.");
- monsterAttack(100,100,"Dragon");
- }
- public static void boss() {
- System.out.println();
- System.out.println("------------------------");
- System.out.println();
- System.out.println("A Cyclops approaches you!");
- System.out.println("Cyclops have a total health of 40 and attack power of 60. Fight off the Cyclops to survive.");
- monsterAttack(40,60,"Cyclops");
- }
- public static void weakVil() {
- System.out.println();
- System.out.println("------------------------");
- System.out.println();
- System.out.println("A Troll approaches you!");
- System.out.println("Troll have a total health of 10 and attack power of 5. Fight off the Troll to survive.");
- monsterAttack(10,5,"Troll");
- }
- public static void tornado() {
- /* generates a random number and then
- * selects a random X,Y position via
- * the switch statement. this allows
- * for us to put the player in a
- * random square
- */
- System.out.println();
- System.out.println("You get sucked into a tornado. The wind places you back into a different square.");
- System.out.println("------------------------------------------------------------------------------------");
- try {
- Thread.sleep(2500);
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- int randInt = rand.nextInt(21) + 1;
- switch (randInt) {
- case 1: player.setX(1); player.setY(1); break;
- case 2: player.setX(1); player.setY(2); break;
- case 3: player.setX(1); player.setY(3); break;
- case 4: player.setX(1); player.setY(4); break;
- case 5: player.setX(1); player.setY(5); break;
- case 6: player.setX(2); player.setY(1); break;
- case 7: player.setX(2); player.setY(2); break;
- case 8: player.setX(2); player.setY(3); break;
- case 9: player.setX(2); player.setY(4); break;
- case 10: player.setX(2); player.setY(5); break;
- case 11: player.setX(3); player.setY(1); break;
- case 12: player.setX(3); player.setY(2); break;
- case 13: player.setX(3); player.setY(3); break;
- case 14: player.setX(3); player.setY(4); break;
- case 15: player.setX(3); player.setY(5); break;
- case 16: player.setX(4); player.setY(1); break;
- case 17: player.setX(4); player.setY(2); break;
- case 18: player.setX(4); player.setY(3); break;
- case 19: player.setX(4); player.setY(4); break;
- case 20: player.setX(5); player.setY(2); break;
- case 21: player.setX(5); player.setY(3); break;
- }
- //System.out.println("The tornado threw you into " + player.getX() + "," + player.getY());
- System.out.println();
- }
- public static void quickSand() { // player chooses to sacrifice -10hp or -10dmg
- System.out.println();
- System.out.println("You have fallen on a patch of quicksand and you must sacrifice either 10HP or 10DMG to escape.");
- Scanner input = new Scanner(System.in);
- System.out.print("Enter 1 to choose HP, Enter 2 to choose DMG: ");
- int choice = input.nextInt();
- if (choice == 1) {
- if (player.getHealth() - 10 <= 0) { // check and see if player died from this sacrifice
- minusHP(10);
- checkHealth();
- }
- else {
- minusHP(10);
- }
- }
- else if (choice == 2)
- minusDamage(10);
- System.out.println();
- getStats();
- System.out.println();
- }
- public static void mislead(String direction) {
- System.out.println();
- System.out.println("Hello sir, Are you on your way to the great land of Finish? Well, I suggest you go " + direction + ". It's quicker!");
- System.out.println();
- }
- public static void advise(String direction) {
- System.out.println();
- System.out.println("Hey, I'm Hero. I suggest you to go " + direction + ".");
- System.out.println();
- }
- public static void playerChoice() { // player is given a choice of +5hp or +10 dmg
- System.out.println();
- System.out.println("You have been given a choice, +5 HP or +10DMG.");
- Scanner input = new Scanner(System.in);
- System.out.print("Enter 1 to choose HP, Enter 2 to choose DMG: ");
- int choice = input.nextInt();
- if (choice == 1) {
- System.out.println();
- if (player.getHealth() + 5 > 100) { // if the additional hp added onto the player hp is greater than 100, craft hp into a potion
- player.setNumPots(player.getNumPots() + 1);
- System.out.println("You already have max health. Instead of getting health, you craft it into a potion. You now have " + player.getNumPots() + " potions.");
- }
- else {
- plusHP(5);
- }
- }
- else if (choice == 2)
- plusDamage(10);
- System.out.println();
- getStats();
- System.out.println();
- }
- public static void plusHP(int ph) {
- int newHealth = player.getHealth() + ph;
- player.setHealth(newHealth);
- }
- public static void minusHP(int mh) {
- int newHealth = player.getHealth() - mh;
- player.setHealth(newHealth);
- }
- public static void plusDamage(int pd) {
- int newDamage = player.getDamage() + pd;
- player.setDamage(newDamage);
- }
- public static void minusDamage(int md) {
- int newDamage = player.getDamage() - md;
- player.setDamage(newDamage);
- }
- public static void getStats() { // displays the players health, dmg, and number of health pots
- System.out.println("----------------------------------------------");
- System.out.print("| HP: " + player.getHealth() + "/100" + " " + "DMG: " + player.getDamage() + "/100" + " " + "Health Pots: " + player.getNumPots());
- System.out.println(" |");
- System.out.println("----------------------------------------------");
- }
- public static void monsterAttack(int mh, int md, String name) {
- /* Really big and complicated method, don't have to go into
- * so much detail commenting, but basically this method is
- * for the random number crit system. It generates a random
- * number from player and monster damage, determines if it
- * is a critical strike, and runs through the monster battle.
- * It also has the ability to randomly drop health potions
- * and apply them when you choose to.
- */
- int randDamageGiven = rand.nextInt(player.getDamage() + 1) + 1;
- int randDamageTaken = rand.nextInt(md + 1) + 1;
- int monsterHP = mh;
- monsterHP-=randDamageGiven;
- System.out.println();
- if (randDamageGiven >= (0.80 * player.getDamage()))
- System.out.println("Critical Strike! You strike the monster for " + randDamageGiven);
- else
- System.out.println("You strike the monster for " + randDamageGiven);
- if (monsterHP > 0) {
- minusHP(randDamageTaken);
- if (player.getHealth() <= 0) {
- System.out.println("The monster strikes you for " + randDamageTaken);
- checkHealth();
- }
- else {
- System.out.println();
- if (randDamageTaken >= (0.80 * md)) {
- System.out.println("The monster crits you for " + randDamageTaken);
- }
- else {
- System.out.println("The monster attacks you for " + randDamageTaken);
- }
- System.out.println();
- System.out.println("---------------------------------------------------");
- System.out.print("| HP: " + player.getHealth() + "/100" + " " + "Monster HP: " + monsterHP + "/100" + " " + "Health Pots: " + player.getNumPots());
- System.out.println(" |");
- System.out.println("---------------------------------------------------");
- System.out.println();
- System.out.println("Do you choose to attack again or use a health potion?");
- System.out.print("Enter 1 to drink a potion, Enter 2 to attack: ");
- Scanner input = new Scanner(System.in);
- int choice = input.nextInt();
- System.out.println();
- if (choice == 1) {
- if (player.getNumPots() > 0) {
- player.setHealth(100);
- player.setNumPots(player.getNumPots() - 1);
- getStats();
- try {
- Thread.sleep(2000);
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- monsterAttack(monsterHP,md,name);
- }
- else {
- System.out.println("You are out of health potions! Fight off the monster to survive.");
- try {
- Thread.sleep(2000);
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- monsterAttack(monsterHP,md,name);
- }
- }
- else if (choice == 2) {
- try {
- Thread.sleep(2000);
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- monsterAttack(monsterHP,md,name);
- }
- }
- }
- else {
- System.out.println();
- System.out.println("You have defeated the " + name + "!");
- if (name.equals("Dragon")) {
- System.out.println();
- System.out.println("You successfully defeated the Dark Fantasy!");
- System.out.println("Thank you for playing!");
- System.exit(0);
- }
- else {
- int randChance = rand.nextInt(2);
- try {
- Thread.sleep(1000);
- } catch(InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- switch (randChance) { // 50/50 chance for a potion to drop
- case 0: player.setNumPots(player.getNumPots() + 1); System.out.println("The " + name + " dropped a health potion! You now have " + player.getNumPots() + " potions."); System.out.println(); System.out.println("------------------------"); System.out.println(); break;
- case 1: System.out.println(); System.out.println("------------------------"); System.out.println(); break;
- }
- }
- }
- }
- public static void checkHealth() {
- //check if players health is less than 0. if less than 0, game is over and program is terminated
- if (player.getHealth() <= 0) {
- System.out.println();
- System.out.println("You were defeated by the monsters of the Dark Fantasy.");
- System.out.println();
- System.out.println("Thank you for playing!");
- System.exit(0);
- }
- }
- // end of level methods
- }
- class Character {
- private int health;
- private int damage;
- private int numPots;
- private String type;
- private int PlayerPosX = 1;
- private int PlayerPosY = 3;
- public Character(String t) {
- if (t.equalsIgnoreCase("Warrior")) {
- this.type = "Warrior";
- health = 50;
- damage = 4;
- numPots = 1;
- }
- if (t.equalsIgnoreCase("Wizard")) {
- this.type = "Wizard";
- health = 75;
- damage = 75;
- numPots = 2;
- }
- if (t.equalsIgnoreCase("Titan")) {
- this.type = "Titan";
- health = 100;
- damage = 50;
- numPots = 1;
- }
- }
- public int getHealth() {return health;}
- public int getDamage() {return damage;}
- public int getNumPots() {return numPots;}
- public int getX() {return PlayerPosX;}
- public int getY() {return PlayerPosY;}
- public void setX(int x) {PlayerPosX = x;}
- public void setY(int y) {PlayerPosY = y;}
- public void setHealth(int h) {health = h;}
- public void setDamage(int d) {damage = d;}
- public void setNumPots(int n) {numPots = n;}
- public void updatePos(String dir) {
- if (dir.equals("west"))
- PlayerPosX--;
- if (dir.equals("east"))
- PlayerPosX++;
- if (dir.equals("north"))
- PlayerPosY--;
- if (dir.equals("south"))
- PlayerPosY++;
- /* Old Movement System, broken with v1.6
- switch(dir) {
- case "west": PlayerPosX--; break;
- case "east": PlayerPosX++; break;
- case "north": PlayerPosY--; break;
- case "south": PlayerPosY++; break;
- }
- */
- if (PlayerPosX < 0) {
- System.out.println("Invalid Move");
- PlayerPosX++;}
- if (PlayerPosY < 0) {
- System.out.println("Invalid Move");
- PlayerPosY++;}
- if (PlayerPosX > 5) {
- System.out.println("Invalid Move");
- PlayerPosX--;}
- if (PlayerPosY > 5) {
- System.out.println("Invalid Move");
- PlayerPosY--;}
- //System.out.println(this.getX() + "," + this.getY());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement