Question
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(String args [])
Below is a simple Role Play Game (RPG) Simulator program.
import java.util.Random; // Student, Programmer public classRPGSimulator {
publicstatic voidmain(Stringargs[]) throwsInterruptedException { Random rand1 =new Random(); Random rand2 =new Random();
String mission1 ="Capture the Castle"; String mission2 ="Enter the Hidden City"; String mission3 ="Rescue the Princess"; String mission4 ="Traverse the Forest"; String mission5 ="Locate the Tunnel Entrance";
String player1 ="", player2= "";
char letter ='0', role= '0';
// initial health and treasures for the twoplayers int number = 0,mission = 0,health1 = 100,health2 = 100; int treasure1 =100, treasure2 = 100,encounter = 0;
// define your role role =(char)(rand1.nextInt(26)+ 'a'); if(role>= 'a'&& role<= 'm') { player1 ="protagonist"; player2 ="opponent"; } else { player1 ="opponent"; player2 ="protagonist"; } System.out.println("youare the " +player1);
// define your mission number =rand2.nextInt(5) + 1;
System.out.print("yourmission is: "); switch(number) { case 1:System.out.println(mission1);mission = 1;break; case 2:System.out.println(mission2);mission = 2;break; case 3:System.out.println(mission3);mission = 3;break; case 4:System.out.println(mission4);mission = 4;break; case 5:System.out.println(mission5);mission = 5;break; } System.out.println("");
// let the game simulation commence (limit the # ofencounters) for (encounter= 1; encounter <=20; encounter++) { letter =(char)(rand1.nextInt(3)+ 'a'); number =rand2.nextInt(10) + 1;
// randomly encounter the enemy if(letter== 'a' ||letter =='b') //if(mission == 1 || mission == 2 || mission ==3) { health1 -= 10; health2 += 15; treasure1 += 10; treasure2 -= 10; //Thread.sleep(5000); System.out.print("battle:" +encounter); System.out.println("t"+ "health" +"t" +"treasure"); System.out.println(player1+ "t" +health1 + "t"+treasure1); System.out.println(player2+ "t" +health2 + "t"+treasure2); System.out.println(""); //encounter++; } elseif(letter== 'c' ||letter =='d') { health1 += 20; health2 -= 30; treasure1 += 40; treasure2 -= 20; //Thread.sleep(500); System.out.print("battle:" +encounter); System.out.println("t"+ "health" +"t" +"treasure"); System.out.println(player1+ "t" +health1 + "t"+treasure1); System.out.println(player2+ "t" +health2 + "t"+treasure2); System.out.println(""); //break; } else { health1 += 30; health2 -= 20; treasure1 -= 30; treasure2 += 20; //Thread.sleep(500); System.out.print("battle:" +encounter); System.out.println("t"+ "health" +"t" +"treasure"); System.out.println(player1+ "t" +health1 + "t"+treasure1); System.out.println(player2+ "t" +health2 + "t"+treasure2); System.out.println(""); //break; }
health1 -=5; health2 -=5; treasure1 -=5; treasure2 -=5; if(health1 <= 0|| health2 <= 0 ||treasure1 <= 0 ||treasure2 <= 0) { //System.out.print("encounter: " + encounter + "action status: "); break; } } System.out.println("simulationhas ended"); System.out.println("results:"); System.out.println("tt"+ "health" +"t" +"treasure"); System.out.println(player1+ "t" +health1 + "t"+treasure1); System.out.println(player2+ "t" +health2 + "t"+treasure2); } }
|
Modify Your Program
Modify your existing code as follows:
( complete at least FOUR of the modifications that are listedbelow )
• Add two more missions to the original starter code,which already has five listed missions.
• Add some bonus health and treasure points if the simulationexceeds 5 battle encounters.
• Add an additional else if statement block that will allow formore game play interaction.
• Create a new character that appears only for one of themissions. The character can be friend or foe to either of theprotagonist player or the opponent player and can boast or lessenthe health and / or treasure values of the two players.
• If the mission is to "Capture the Castle", then allow theplayers to use a cloaking mode, which will automatically boosttheir health to a level of 100 .
• If the mission is to "Traverse the Forest", then allow theprotagonist to escape an encounter with his / heropponent.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started