SlideShare a Scribd company logo
Below is a simple Role Play Game (RPG) Simulator program.
importjava.util.Random;
// Student, Programmer
publicclassRPGSimulator {
publicstaticvoidmain(Stringargs[])throwsInterruptedException
{
Randomrand1=newRandom();
Randomrand2=newRandom();
Stringmission1="Capture the Castle";
Stringmission2="Enter the Hidden City";
Stringmission3="Rescue the Princess";
Stringmission4="Traverse the Forest";
Stringmission5="Locate the Tunnel Entrance";
Stringplayer1="",player2="";
charletter='0',role='0';
// initial health and treasures for the two players
intnumber= 0,mission= 0,health1= 100,health2= 100;
inttreasure1= 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)
{
case1: System.out.println(mission1);mission= 1;break;
case2: System.out.println(mission2);mission= 2;break;
case3: System.out.println(mission3);mission= 3;break;
case4: System.out.println(mission4);mission= 4;break;
case5: 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++;
}
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("simulation has 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 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.
importjava.util.Random;
// Student, Programmer
publicclassRPGSimulator {
publicstaticvoidmain(Stringargs[])throwsInterruptedException
{
Randomrand1=newRandom();
Randomrand2=newRandom();
Stringmission1="Capture the Castle";
Stringmission2="Enter the Hidden City";
Stringmission3="Rescue the Princess";
Stringmission4="Traverse the Forest";
Stringmission5="Locate the Tunnel Entrance";
Stringplayer1="",player2="";
charletter='0',role='0';
// initial health and treasures for the two players
intnumber= 0,mission= 0,health1= 100,health2= 100;
inttreasure1= 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)
{
case1: System.out.println(mission1);mission= 1;break;
case2: System.out.println(mission2);mission= 2;break;
case3: System.out.println(mission3);mission= 3;break;
case4: System.out.println(mission4);mission= 4;break;
case5: 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++;
}
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("simulation has 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);
}
}
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("tt" + "health" + "t" + "treasure");
System.out.println(player1 + "t" + health1 + "t" + treasure1);
System.out.println(player2 + "t" + health2 + "t" + treasure2);
}
}

More Related Content

More from jillisacebi75827

Project Communications Management Case StudySeveral issues have a.pdf
Project Communications Management Case StudySeveral issues have a.pdfProject Communications Management Case StudySeveral issues have a.pdf
Project Communications Management Case StudySeveral issues have a.pdf
jillisacebi75827
 
Priority encoders are much more common than non-priority encoders. W.pdf
Priority encoders are much more common than non-priority encoders. W.pdfPriority encoders are much more common than non-priority encoders. W.pdf
Priority encoders are much more common than non-priority encoders. W.pdf
jillisacebi75827
 
Prove that a reversible adiabatic process cannot also be isothermal f.pdf
Prove that a reversible adiabatic process cannot also be isothermal f.pdfProve that a reversible adiabatic process cannot also be isothermal f.pdf
Prove that a reversible adiabatic process cannot also be isothermal f.pdf
jillisacebi75827
 
Passing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdfPassing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdf
jillisacebi75827
 
Organophosphates area. herbicidesb. insecticidesDithiocarbama.pdf
Organophosphates area. herbicidesb. insecticidesDithiocarbama.pdfOrganophosphates area. herbicidesb. insecticidesDithiocarbama.pdf
Organophosphates area. herbicidesb. insecticidesDithiocarbama.pdf
jillisacebi75827
 
Match the functions with the plots. The following pictures are image.pdf
Match the functions with the plots. The following pictures are image.pdfMatch the functions with the plots. The following pictures are image.pdf
Match the functions with the plots. The following pictures are image.pdf
jillisacebi75827
 
July 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdf
July 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdfJuly 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdf
July 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdf
jillisacebi75827
 
Income statements and balance sheets follow for The New York Times C.pdf
Income statements and balance sheets follow for The New York Times C.pdfIncome statements and balance sheets follow for The New York Times C.pdf
Income statements and balance sheets follow for The New York Times C.pdf
jillisacebi75827
 
How do contemporary economic geographers view the economy From a ge.pdf
How do contemporary economic geographers view the economy From a ge.pdfHow do contemporary economic geographers view the economy From a ge.pdf
How do contemporary economic geographers view the economy From a ge.pdf
jillisacebi75827
 
I am solving Rational Inequalities and I am a little confused about .pdf
I am solving Rational Inequalities and I am a little confused about .pdfI am solving Rational Inequalities and I am a little confused about .pdf
I am solving Rational Inequalities and I am a little confused about .pdf
jillisacebi75827
 
How would your plates appear if you incubated agar when they were co.pdf
How would your plates appear if you incubated agar when they were co.pdfHow would your plates appear if you incubated agar when they were co.pdf
How would your plates appear if you incubated agar when they were co.pdf
jillisacebi75827
 
Hormones are distributed throughout the body in blood and other body.pdf
Hormones are distributed throughout the body in blood and other body.pdfHormones are distributed throughout the body in blood and other body.pdf
Hormones are distributed throughout the body in blood and other body.pdf
jillisacebi75827
 
Explain the internet infrastructure stack. SolutionInternet inf.pdf
Explain the internet infrastructure stack. SolutionInternet inf.pdfExplain the internet infrastructure stack. SolutionInternet inf.pdf
Explain the internet infrastructure stack. SolutionInternet inf.pdf
jillisacebi75827
 
Each hormone is known to have a specific target tissue. For each of t.pdf
Each hormone is known to have a specific target tissue. For each of t.pdfEach hormone is known to have a specific target tissue. For each of t.pdf
Each hormone is known to have a specific target tissue. For each of t.pdf
jillisacebi75827
 
Describe the differences in the appearance of the sterile tube of Try.pdf
Describe the differences in the appearance of the sterile tube of Try.pdfDescribe the differences in the appearance of the sterile tube of Try.pdf
Describe the differences in the appearance of the sterile tube of Try.pdf
jillisacebi75827
 
As we entered the 21st century, the Human Genome Project, a massive .pdf
As we entered the 21st century, the Human Genome Project, a massive .pdfAs we entered the 21st century, the Human Genome Project, a massive .pdf
As we entered the 21st century, the Human Genome Project, a massive .pdf
jillisacebi75827
 
ActiveX is used by which of the following technologiesA. JavaB..pdf
ActiveX is used by which of the following technologiesA. JavaB..pdfActiveX is used by which of the following technologiesA. JavaB..pdf
ActiveX is used by which of the following technologiesA. JavaB..pdf
jillisacebi75827
 
CBE 20. The following information is from financial statements (in mi.pdf
CBE 20. The following information is from financial statements (in mi.pdfCBE 20. The following information is from financial statements (in mi.pdf
CBE 20. The following information is from financial statements (in mi.pdf
jillisacebi75827
 
A swim bladder allows a fish to Regulate its water content in sea wa.pdf
A swim bladder allows a fish to  Regulate its water content in sea wa.pdfA swim bladder allows a fish to  Regulate its water content in sea wa.pdf
A swim bladder allows a fish to Regulate its water content in sea wa.pdf
jillisacebi75827
 
12. You want to extract dsDNA from live tissue. Which of the followi.pdf
12. You want to extract dsDNA from live tissue. Which of the followi.pdf12. You want to extract dsDNA from live tissue. Which of the followi.pdf
12. You want to extract dsDNA from live tissue. Which of the followi.pdf
jillisacebi75827
 

More from jillisacebi75827 (20)

Project Communications Management Case StudySeveral issues have a.pdf
Project Communications Management Case StudySeveral issues have a.pdfProject Communications Management Case StudySeveral issues have a.pdf
Project Communications Management Case StudySeveral issues have a.pdf
 
Priority encoders are much more common than non-priority encoders. W.pdf
Priority encoders are much more common than non-priority encoders. W.pdfPriority encoders are much more common than non-priority encoders. W.pdf
Priority encoders are much more common than non-priority encoders. W.pdf
 
Prove that a reversible adiabatic process cannot also be isothermal f.pdf
Prove that a reversible adiabatic process cannot also be isothermal f.pdfProve that a reversible adiabatic process cannot also be isothermal f.pdf
Prove that a reversible adiabatic process cannot also be isothermal f.pdf
 
Passing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdfPassing arguments by-Value and using return types.#includeiost.pdf
Passing arguments by-Value and using return types.#includeiost.pdf
 
Organophosphates area. herbicidesb. insecticidesDithiocarbama.pdf
Organophosphates area. herbicidesb. insecticidesDithiocarbama.pdfOrganophosphates area. herbicidesb. insecticidesDithiocarbama.pdf
Organophosphates area. herbicidesb. insecticidesDithiocarbama.pdf
 
Match the functions with the plots. The following pictures are image.pdf
Match the functions with the plots. The following pictures are image.pdfMatch the functions with the plots. The following pictures are image.pdf
Match the functions with the plots. The following pictures are image.pdf
 
July 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdf
July 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdfJuly 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdf
July 4 Paid utilities expense of $370 Cash Accounts Payable Service .pdf
 
Income statements and balance sheets follow for The New York Times C.pdf
Income statements and balance sheets follow for The New York Times C.pdfIncome statements and balance sheets follow for The New York Times C.pdf
Income statements and balance sheets follow for The New York Times C.pdf
 
How do contemporary economic geographers view the economy From a ge.pdf
How do contemporary economic geographers view the economy From a ge.pdfHow do contemporary economic geographers view the economy From a ge.pdf
How do contemporary economic geographers view the economy From a ge.pdf
 
I am solving Rational Inequalities and I am a little confused about .pdf
I am solving Rational Inequalities and I am a little confused about .pdfI am solving Rational Inequalities and I am a little confused about .pdf
I am solving Rational Inequalities and I am a little confused about .pdf
 
How would your plates appear if you incubated agar when they were co.pdf
How would your plates appear if you incubated agar when they were co.pdfHow would your plates appear if you incubated agar when they were co.pdf
How would your plates appear if you incubated agar when they were co.pdf
 
Hormones are distributed throughout the body in blood and other body.pdf
Hormones are distributed throughout the body in blood and other body.pdfHormones are distributed throughout the body in blood and other body.pdf
Hormones are distributed throughout the body in blood and other body.pdf
 
Explain the internet infrastructure stack. SolutionInternet inf.pdf
Explain the internet infrastructure stack. SolutionInternet inf.pdfExplain the internet infrastructure stack. SolutionInternet inf.pdf
Explain the internet infrastructure stack. SolutionInternet inf.pdf
 
Each hormone is known to have a specific target tissue. For each of t.pdf
Each hormone is known to have a specific target tissue. For each of t.pdfEach hormone is known to have a specific target tissue. For each of t.pdf
Each hormone is known to have a specific target tissue. For each of t.pdf
 
Describe the differences in the appearance of the sterile tube of Try.pdf
Describe the differences in the appearance of the sterile tube of Try.pdfDescribe the differences in the appearance of the sterile tube of Try.pdf
Describe the differences in the appearance of the sterile tube of Try.pdf
 
As we entered the 21st century, the Human Genome Project, a massive .pdf
As we entered the 21st century, the Human Genome Project, a massive .pdfAs we entered the 21st century, the Human Genome Project, a massive .pdf
As we entered the 21st century, the Human Genome Project, a massive .pdf
 
ActiveX is used by which of the following technologiesA. JavaB..pdf
ActiveX is used by which of the following technologiesA. JavaB..pdfActiveX is used by which of the following technologiesA. JavaB..pdf
ActiveX is used by which of the following technologiesA. JavaB..pdf
 
CBE 20. The following information is from financial statements (in mi.pdf
CBE 20. The following information is from financial statements (in mi.pdfCBE 20. The following information is from financial statements (in mi.pdf
CBE 20. The following information is from financial statements (in mi.pdf
 
A swim bladder allows a fish to Regulate its water content in sea wa.pdf
A swim bladder allows a fish to  Regulate its water content in sea wa.pdfA swim bladder allows a fish to  Regulate its water content in sea wa.pdf
A swim bladder allows a fish to Regulate its water content in sea wa.pdf
 
12. You want to extract dsDNA from live tissue. Which of the followi.pdf
12. You want to extract dsDNA from live tissue. Which of the followi.pdf12. You want to extract dsDNA from live tissue. Which of the followi.pdf
12. You want to extract dsDNA from live tissue. Which of the followi.pdf
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 

Below is a simple Role Play Game (RPG) Simulator program.importjav.pdf

  • 1. Below is a simple Role Play Game (RPG) Simulator program. importjava.util.Random; // Student, Programmer publicclassRPGSimulator { publicstaticvoidmain(Stringargs[])throwsInterruptedException { Randomrand1=newRandom(); Randomrand2=newRandom(); Stringmission1="Capture the Castle"; Stringmission2="Enter the Hidden City"; Stringmission3="Rescue the Princess"; Stringmission4="Traverse the Forest"; Stringmission5="Locate the Tunnel Entrance"; Stringplayer1="",player2=""; charletter='0',role='0'; // initial health and treasures for the two players intnumber= 0,mission= 0,health1= 100,health2= 100; inttreasure1= 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";
  • 2. } System.out.println("you are the "+player1); // define your mission number=rand2.nextInt(5) + 1; System.out.print("your mission is: "); switch(number) { case1: System.out.println(mission1);mission= 1;break; case2: System.out.println(mission2);mission= 2;break; case3: System.out.println(mission3);mission= 3;break; case4: System.out.println(mission4);mission= 4;break; case5: 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);
  • 3. 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;
  • 4. 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("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 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. importjava.util.Random; // Student, Programmer publicclassRPGSimulator { publicstaticvoidmain(Stringargs[])throwsInterruptedException { Randomrand1=newRandom(); Randomrand2=newRandom();
  • 5. Stringmission1="Capture the Castle"; Stringmission2="Enter the Hidden City"; Stringmission3="Rescue the Princess"; Stringmission4="Traverse the Forest"; Stringmission5="Locate the Tunnel Entrance"; Stringplayer1="",player2=""; charletter='0',role='0'; // initial health and treasures for the two players intnumber= 0,mission= 0,health1= 100,health2= 100; inttreasure1= 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) { case1: System.out.println(mission1);mission= 1;break; case2: System.out.println(mission2);mission= 2;break;
  • 6. case3: System.out.println(mission3);mission= 3;break; case4: System.out.println(mission4);mission= 4;break; case5: 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++; } elseif(letter=='c'||letter=='d') { health1+= 20; health2-= 30; treasure1+= 40; treasure2-= 20; //Thread.sleep(500); System.out.print("battle: "+encounter);
  • 7. 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("tt"+"health"+"t"+"treasure"); System.out.println(player1+"t"+health1+"t"+treasure1);
  • 8. 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";
  • 9. } 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
  • 10. 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);
  • 11. 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;}
  • 12. 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("tt" + "health" + "t" + "treasure"); System.out.println(player1 + "t" + health1 + "t" + treasure1);
  • 13. System.out.println(player2 + "t" + health2 + "t" + treasure2); } }