Below is a simple Role Play Game RPG Simulator program impor

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[]) throws InterruptedException

      {

            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 two players

            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(\"you are the \" + player1);

           

            // define your mission

            number = rand2.nextInt(5) + 1;

           

            System.out.print(\"your mission 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 # of encounters)

            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++;

                  }    

                  else if(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(\"simulation has ended\ \");

            System.out.println(\"results:\ \");

            System.out.println(\"\\t\\t\" + \"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 listed below )

• Add two more missions to the original starter code, which already has five listed missions.

• Add some bonus health and treasure points if the simulation exceeds 5 battle encounters.

• Add an additional else if statement block that will allow for more game play interaction.

• Create a new character that appears only for one of the missions. The character can be friend or foe to either of the protagonist player or the opponent player and can boast or lessen the health and / or treasure values of the two players.

• If the mission is to \"Capture the Castle\", then allow the players to use a cloaking mode, which will automatically boost their health to a level of 100 .

• If the mission is to \"Traverse the Forest\", then allow the protagonist to escape an encounter with his / her opponent.

import java.util.Random;

// Student, Programmer

public class RPGSimulator {

           

      public static void main(String args[]) throws InterruptedException

      {

            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 two players

            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(\"you are the \" + player1);

           

            // define your mission

            number = rand2.nextInt(5) + 1;

           

            System.out.print(\"your mission 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 # of encounters)

            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++;

                  }    

                  else if(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(\"simulation has ended\ \");

            System.out.println(\"results:\ \");

            System.out.println(\"\\t\\t\" + \"health\" + \"\\t\" + \"treasure\");

            System.out.println(player1 + \"\\t\" + health1 + \"\\t\" + treasure1);

            System.out.println(player2 + \"\\t\" + health2 + \"\\t\" + treasure2);

      }

}

Solution

Answer

import java.util.Random;
class RPGSimulator
{
   public static void main(String args[]) throws InterruptedException
   {
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 mission6 = \"Fight the Master of Fists\";
String mission7 = \"Wrath of the Army\";

String player1 = \"\", player2 = \"\";

char letter = \'\\0\', role = \'\\0\';

// initial health and treasures for the two players
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(\"you are the \" + player1);

// define your mission
number = rand2.nextInt(7) + 1;

System.out.print(\"your mission 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;
case 6: System.out.println(mission6); mission = 6; break;
case 7: System.out.println(mission7); mission = 7; break;
}
System.out.println(\"\");

// let the game simulation commence (limit the # of encounters)
for (encounter = 1; encounter <= 20; encounter++)
{
   if(encounter>5)
   {
       health2 += 15; //bonus health
   treasure1 += 10; // treasure points
   }
letter = (char)(rand1.nextInt(5) + \'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;
if (health1 <= 0){ health1=0;}
if (health2 <= 0){ health2=0;}
if (health1 > 100){ health1=100;}
if (health2 > 100){ health2=100;}
if (treasure1 <= 0){ treasure1 =0;}
if (treasure2 <= 0){ treasure2 =0;}
  
//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++;
}
else if(letter == \'c\' || letter == \'d\')
{
health1 += 20;
health2 -= 30;
treasure1 += 40;
treasure2 -= 20;
if (health1 <= 0){ health1=0;}
if (health2 <= 0){ health2=0;}
if (health1 > 100){ health1=100;}
if (health2 > 100){ health2=100;}
if (treasure1 <= 0){ treasure1 =0;}
if (treasure2 <= 0){ treasure2 =0;}
  
//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 if(letter == \'e\' || letter == \'f\')
//if(mission == 1 || mission == 2 || mission == 3)
{
health1 -= 20;
health2 += 25;
treasure1 -= 20;
treasure2 += 10;
if (health1 <= 0){ health1=0;}
if (health2 <= 0){ health2=0;}
if (health1 > 100){ health1=100;}
if (health2 > 100){ health2=100;}
if (treasure1 <= 0){ treasure1 =0;}
if (treasure2 <= 0){ treasure2 =0;}
  
//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++;
}
else
{
health1 += 30;
health2 -= 20;
treasure1 += 30;
treasure2 -= 20;
if (health1 <= 0){ health1=0;}
if (health2 <= 0){ health2=0;}
if (health1 > 100){ health1=100;}
if (health2 > 100){ health2=100;}
if (treasure1 <= 0){ treasure1 =0;}
if (treasure2 <= 0){ treasure2 =0;}
  
//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){ health1=0;}
if (health2 <= 0){ health2=0;}
if (health1 > 100){ health1=100;}
if (health2 > 100){ health2=100;}
if (treasure1 <= 0){ treasure1 =0;}
if (treasure2 <= 0){ treasure2 =0;}
if (health1 <= 0 || health2 <= 0 || treasure1 <= 0 || treasure2 <= 0)
{
//System.out.print(\"encounter: \" + encounter + \" action status: \");
break;
}
}
System.out.println(\"simulation has ended\ \");
System.out.println(\"results:\ \");
System.out.println(\"\\t\\t\" + \"health\" + \"\\t\" + \"treasure\");
System.out.println(player1 + \"\\t\" + health1 + \"\\t\" + treasure1);
System.out.println(player2 + \"\\t\" + health2 + \"\\t\" + treasure2);
}
}

Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St
Below is a simple Role Play Game (RPG) Simulator program. import java.util.Random; // Student, Programmer public class RPGSimulator { public static void main(St

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site