Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CPTTextRPG {
- // intializes class and will assign stats later to this
- static int[] cclass = { 0, 0, 0, 0 };
- // defines stats as variables for easy access
- // global variables to access in methods
- static int playerHP = cclass[0];
- static int playerminATT = cclass[1];
- static int playermaxATT = cclass[2];
- static int playerDEF = cclass[3];
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Random rand = new Random();
- String name = "";
- // action
- String action = "";
- // list of monsters/enemies
- int[] wolf = { 100, 15, 0 };
- int[] giantape = { 200, 25, 8 };
- // hp,minATT,maxATT,defense
- int[] warrior = { 250, 20, 30, 10 };
- int[] mage = { 150, 15, 25, 4 };
- int[] assassin = { 165, 20, 35, 7 };
- int[] archer = { 140, 15, 30, 6 };
- // intro
- System.out.println("Welcome to The Legend of Heroes!");
- System.out.println("A Text-Based RPG game!");
- // player name and class picker
- System.out.println("");
- System.out.println("May I ask your name squire?");
- name = sc.nextLine();
- System.out.println("Sounds great, " + name + "!");
- System.out.println(
- "Now, choose a class! Pick between Warrior(\"w\"), Mage(\"m\"), Assassin(\"as\"), or Archer(\"ar\")");
- String c = sc.nextLine();
- // warrior
- boolean picked = false;
- while (picked == false) {
- if (c.equalsIgnoreCase("w")) {
- cclass = warrior;
- System.out.println("Great pick, " + name + "! You chose the Warrior class.");
- System.out.println("Here are your stats:");
- System.out.println("HP: " + cclass[0]);
- System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
- System.out.println("DEF: " + cclass[3]);
- System.out.println("I have given you a sword to use!");
- System.out.println("");
- picked = true;
- }
- // mage
- else if (c.equalsIgnoreCase("m")) {
- cclass = mage;
- System.out.println("Great pick, " + name + "! You chose the Mage class.");
- System.out.println("Here are your stats:");
- System.out.println("HP: " + cclass[0]);
- System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
- System.out.println("DEF: " + cclass[3]);
- System.out.println("I have given you a staff to use!");
- System.out.println("");
- picked = true;
- }
- // assassin
- else if (c.equalsIgnoreCase("as")) {
- cclass = assassin;
- System.out.println("Great pick, " + name + "! You chose the Assassin class.");
- System.out.println("Here are your stats:");
- System.out.println("HP: " + cclass[0]);
- System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
- System.out.println("DEF: " + cclass[3]);
- System.out.println("I have given you dual daggers to use!");
- System.out.println("");
- picked = true;
- }
- // archer
- else if (c.equalsIgnoreCase("ar")) {
- cclass = archer;
- System.out.println("Great pick, " + name + "! You chose the Archer class.");
- System.out.println("Here are your stats:");
- System.out.println("HP: " + cclass[0]);
- System.out.println("ATT Range: " + cclass[1] + "-" + cclass[2]);
- System.out.println("DEF: " + cclass[3]);
- System.out.println("I have given you a bow to use!");
- System.out.println("");
- picked = true;
- }
- else {
- System.out.println("Wrong input!");
- System.out.println("Choose again!");
- c = sc.nextLine();
- }
- }
- // Start Adventure
- System.out.println("Look in the distance, a wolf!");
- System.out.println("Kill it to gain better stats!");
- // call the attackMonster method for wolf
- attackMonster(wolf[0], wolf[1], wolf[2], playerHP, playerminATT, playermaxATT, playerDEF, "Wolf");
- System.out.println("");
- System.out.println("Good Job out there " + name + "!");
- System.out.println("You gained better stats by killing your first enemy!");
- // gain stats
- playerHP = playerHP + 50;
- playerminATT = playerminATT + 10;
- playermaxATT = playermaxATT + 15;
- playerDEF = playerDEF + 8;
- System.out.println("");
- System.out.println("Now is no time to rest, " + name + "!");
- System.out.println("There's a giant ape attacking the villagers ahead! Go kill it and defend the villagers!");
- // call the attackMonster method for giantape
- attackMonster(giantape[0], giantape[1], giantape[2], playerHP, playerminATT, playermaxATT, playerDEF, "Giant Ape");
- System.out.println("");
- System.out.println("You saved the villagers, " + name + "!");
- System.out.println("You will need these stats for the final boss battle but first, you need a better weapon!");
- playerHP = playerHP + 200;
- playerminATT = playerminATT + 30;
- playermaxATT = playermaxATT + 50;
- playerDEF = playerDEF + 12;
- System.out.println("Head over to the blacksmith and he can give you a way stronger weapon; however, it will be random!");
- randomItem(c);
- }
- // attack any type of monster method
- public static void attackMonster(int monsterHP, int monsterATT, int monsterDEF, int playerHP, int minAttack, int maxAttack,
- int playerDEF, String monsterName) {
- Scanner sc = new Scanner(System.in);
- // attacking system
- System.out.println("Type \"a\" to attack or \"d\" to defend!");
- Random rand = new Random();
- String action = "";
- while (monsterHP > 0) {
- int pattack = rand.nextInt((maxAttack - minAttack) + 1) + minAttack;
- action = sc.next();
- if (action.equalsIgnoreCase("a")) {
- monsterHP = monsterHP - (pattack - monsterDEF);
- if (monsterHP <= 0) {
- System.out.println("You hit the " + monsterName + " for " + pattack + " damage! " + monsterName + " HP now at "
- + 0);
- }
- else {
- System.out.println("You hit the " + monsterName + " for " + pattack + " damage! " + monsterName + " HP now at "
- + monsterHP);
- System.out.println("The " + monsterName + " hit back for " + (monsterATT - playerDEF) + "! You are now at "
- + (playerHP -= (monsterATT - playerDEF)) + "HP");
- System.out.println("");
- }
- }
- if (action.equalsIgnoreCase("d")) {
- int pdefend = rand.nextInt(3);
- if (pdefend >= 1) {
- System.out.println("You defended against the " + monsterName + ". You took no damage!");
- }
- else {
- System.out.println("The " + monsterName + " went through your block and hit you for " + (monsterATT - playerDEF)
- + "! You are now at " + (playerHP - (monsterATT - playerDEF)) + "HP");
- }
- }
- if (monsterHP < 0 || monsterHP == 0) {
- System.out.println("");
- System.out.println("You have defeated the " + monsterName + "!");
- }
- if (playerHP <= 0) {
- System.out.println("You Lose...");
- }
- }
- }
- public static void randomItem(String c) {
- Scanner sc = new Scanner(System.in);
- Random rand = new Random();
- System.out.println("Welcome to the Blacksmith! I heard you need a new weapon and you have come to the right place!");
- System.out.println("It will be random but it will be stronger than your current weapon!");
- int randomNum = rand.nextInt(100);
- boolean picked = false;
- while (picked == false) {
- if (c.equalsIgnoreCase("w")) {
- if (randomNum <= 50) {
- System.out.println("You got the Dark Sword! +25 Attack!");
- playerminATT += 25;
- playermaxATT += 25;
- picked = true;
- }
- else {
- System.out.println("You got the Holy Excalibur! +30 Attack!");
- playerminATT += 30;
- playermaxATT += 30;
- picked = true;
- }
- }
- else if (c.equalsIgnoreCase("m")) {
- if (randomNum <= 50) {
- System.out.println("You got the Dark Staff! +25 Attack!");
- playerminATT += 25;
- playermaxATT += 25;
- picked = true;
- }
- else if (randomNum > 98) {
- System.out.println("You got the EXPROSION STAFF! +100 Attack!");
- playerminATT += 100;
- playermaxATT += 100;
- picked = true;
- }
- else {
- System.out.println("You got the Holy Staff! +30 Attack!");
- playerminATT += 30;
- playermaxATT += 30;
- picked = true;
- }
- }
- else if (c.equalsIgnoreCase("as")) {
- if (randomNum <= 50) {
- System.out.println("You got the Dark Dual Daggers! +30 Attack!");
- playerminATT += 30;
- playermaxATT += 30;
- picked = true;
- }
- else {
- System.out.println("You got the Holy Dual Daggers! +25 Attack!");
- playerminATT += 25;
- playermaxATT += 25;
- picked = true;
- }
- }
- else if (c.equalsIgnoreCase("ar")) {
- if (randomNum <= 50) {
- System.out.println("You got the Dark Bow! +25 Attack!");
- playerminATT += 25;
- playermaxATT += 25;
- picked = true;
- }
- else if (randomNum > 98) {
- System.out.println("You got Phantom Hecate II! +100 Attack!");
- playerminATT += 100;
- playermaxATT += 100;
- picked = true;
- }
- else {
- System.out.println("You got the Holy Bow! +30 Attack!");
- playerminATT += 30;
- playermaxATT += 30;
- picked = true;
- }
- }
- }
- }
- // final boss battle method
- public static void bossFight(int monsterHP, int monsterATT, int monsterDEF, int playerHP, int minAttack, int maxAttack, int playerDEF,
- String monsterName) {
- Scanner sc = new Scanner(System.in);
- Random rand = new Random();
- System.out.println("Type \"a\" to attack or \"d\" to defend!");
- String action = "";
- while (monsterHP > 0) {
- int pattack = rand.nextInt((maxAttack - minAttack) + 1) + minAttack;
- action = sc.next();
- if (action.equalsIgnoreCase("a")) {
- monsterHP = monsterHP - (pattack - monsterDEF);
- if (monsterHP <= 0) {
- System.out.println("You hit the " + monsterName + " for " + pattack + " damage!" + monsterName + " HP now at "
- + 0);
- }
- else {
- System.out.println("You hit the " + monsterName + " for " + pattack + " damage" + monsterName + " HP now at "
- + monsterHP);
- System.out.println("The " + monsterName + " hit back for " + (monsterATT - playerDEF) + "! You are now at "
- + (playerHP -= (monsterATT - playerDEF)) + "HP");
- System.out.println("");
- }
- }
- if (action.equalsIgnoreCase("d")) {
- int pdefend = rand.nextInt(3);
- if (pdefend >= 1) {
- System.out.println("You defended against the " + monsterName + ". You took no damage!");
- }
- else {
- System.out.println("The " + monsterName + " went through your block and hit you for " + (monsterATT - playerDEF)
- + "! You are now at " + (playerHP - (monsterATT - playerDEF)) + "HP");
- }
- }
- if (monsterHP < 0 || monsterHP == 0) {
- System.out.println("");
- System.out.println("You have defeated the " + monsterName + "!");
- }
- if (playerHP <= 0) {
- System.out.println("You Lose...");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement