With the given code:
import java.util.Scanner;
import java.util.Random;
public class Scenario1{
public static void line(){
System.out.println("----------");
}
public static int[] CharacterSheet(int HP, int MaxHP,int MinDMG, int MaxDMG){ // [0] = HP; [1] = MaxHP; [2] = MinDMG; [3] = MaxDMg;
int[] machine;
machine = new int[4];
machine[0] = HP;
machine[1] = MaxHP;
machine[2] = MinDMG;
machine[3] = MaxDMG;
return machine;
}
public static int[] CreatureSheet(int HP, int MaxHP,int MaxDMG, int MinDMG){ // [0] = HP; [1] = MaxHP; [2] = MinDMG; [3] = MaxDMG;
int[] machine;
machine = new int[4];
machine[0] = HP;
machine[1] = MaxHP;
machine[2] = MinDMG;
machine[3] = MaxDMG;
return machine;
}
public static String[] NPC(String race){ // [0] = race; [1] = surname; [2] = lastname;
Random r = new Random();
String surname = "";
String lastname1 = "";
String lastname2 = "";
String lastname = "";
if(race == "dwarf"){
switch(r.nextInt(5)){
case 0:
surname = "Ugbor";
break;
case 1:
surname = "Hegbor";
break;
case 2:
surname = "Kragen";
break;
case 3:
surname = "Ogar";
break;
case 4:
surname = "Nguur";
break;
}
switch(r.nextInt(5)){
case 0:
lastname1 = "Iron";
break;
case 1:
lastname1 = "Oak";
break;
case 2:
lastname1 = "Steel";
break;
case 3:
lastname1 = "Brave";
break;
case 4:
lastname1 = "Coward";
break;
}
switch(r.nextInt(5)){
case 0:
lastname2 = "hammer";
break;
case 1:
lastname2 = "heart";
break;
case 2:
lastname2 = "sword";
break;
case 3:
lastname2 = "shield";
break;
case 4:
lastname2 = "might";
break;
}
lastname = lastname1 + lastname2;
}else if(race == "elf"){
switch(r.nextInt(5)){
case 0:
surname = "Zevvin";
break;
case 1:
surname = "Lukias";
break;
case 2:
surname = "Biinlas";
break;
case 3:
surname = "Lasthandir";
break;
case 4:
surname = "Iskaal";
break;
}
switch(r.nextInt(5)){
case 0:
lastname = "Huulrash";
break;
case 1:
lastname = "Bluurkas";
break;
case 2:
lastname = "Hraataas";
break;
case 3:
lastname = "Lektar";
break;
case 4:
lastname = "Kuulskar";
break;
}
}else{
race = "dwarf";
surname = "Ugbor";
lastname = "Braveshield";
}
String[] code;
code = new String[3];
code[0] = race;
code[1] = surname;
code[2] = lastname;
return code;
}
public static void attack(int[] atkd, int[] atkr){
Random r = new Random();
int rand = (r.nextInt(atkr[3] - atkr[2] + 1) + 1);
atkd[0] -= rand;
}
public static void main(String[] args){
int option2;
String option;
int turn = 0;
turn = 0;
int[] atkr;
int[] atkd;
String temp;
int[] nobody;
nobody = new int[1];
nobody[0] = 0;
int[] Char1Sheet = CharacterSheet(8, 8, 1, 4);
int[] NPC1Sheet = CharacterSheet(15, 15, 1, 4);
int[] Creature1Sheet = CreatureSheet(15, 15, 1, 2);
Scanner sc = new Scanner(System.in);
System.out.println("We kindly ask you to choose only what the program tells you to.");
System.out.println("Press ENTER to proceed...");
temp = sc.nextLine();
System.out.println("Hello, player! Please tell me your character's name:");
String Char1Name = sc.nextLine();
System.out.println("Say hello to " + Char1Name + "! What village is it that he lives in?");
String Village = sc.nextLine();
String NPC1race = "";
Random r = new Random();
switch(r.nextInt(2)){
case 0:
NPC1race = "dwarf";
break;
case 1:
NPC1race = "elf";
}
String[] NPC1 = NPC(NPC1race);
System.out.println(Village + ", I see! So, " + Char1Name +" knows a fellow " + NPC1[0] + ", his name is " + NPC1[1] + " " + NPC1[2] + ". They know each other very well.");
temp = sc.nextLine();
System.out.println("Today, they both go out into the woods next to " + Village + ", in hopes of getting some wood.");
temp = sc.nextLine();
System.out.println("Night falls and " + Char1Name + " and " + NPC1[1] + " are still in the woods. Sadly, they got lost, so they start searching for a shelter.");
temp = sc.nextLine();
System.out.println("A grey creature comes out of nowhere and attacks " + Char1Name + "!");
line();
attack(Char1Sheet, Creature1Sheet);
String Creature1Name = "GreyCreature";
while((NPC1Sheet[0] > 0 && Creature1Sheet[0] > 0) || (Char1Sheet[0] > 0 && Creature1Sheet[0] > 0)){
System.out.println("Stats:");
System.out.println(Char1Name + ": " + Char1Sheet[0] + "/" + Char1Sheet[1] + "HP");
System.out.println(NPC1[1] + ": " + NPC1Sheet[0] + "/" + NPC1Sheet[1] + "HP");
System.out.println(Creature1Name + ": " + Creature1Sheet[0] + "/" + Creature1Sheet[1] + "HP");
if(turn == 0){
atkr = Char1Sheet;
atkd = nobody;
System.out.println("It is " + Char1Name + "'s turn. What does he do?");
System.out.println("1.(a)ttack");
option = sc.nextLine();
if(option=="a"){
System.out.println(Char1Name + " attacks. Who should he attack?");
System.out.println("1.GreyCreature");
option2 = sc.nextInt();
if(option2 == 1){
atkd = Creature1Sheet;
}
attack(atkd, atkr);
}
turn = 1;
temp = sc.nextLine();
}else if(turn == 1){
atkr = NPC1Sheet;
atkd = nobody;
System.out.println("It is " + NPC1[1] + "'s turn. What does he do?");
System.out.println("1.(a)ttack");
option = sc.nextLine();
if(option=="a"){
System.out.println(NPC1[1] + " attacks. Who should he attack?");
System.out.println("1.GreyCreature");
option2 = sc.nextInt();
if(option2 == 1){
atkd = Creature1Sheet;
}
attack(atkd, atkr);
}
turn = 2;
temp = sc.nextLine();
}else if(turn == 2){
atkr = Creature1Sheet;
atkd=nobody;
switch(r.nextInt(2)){
case 0:
atkd = Char1Sheet;
break;
case 1:
atkd = NPC1Sheet;
}
if(atkd == Char1Sheet){
System.out.println(Creature1Name + " attacks " + Char1Name + ".");
}else if(atkd == NPC1Sheet){
System.out.println(Creature1Name + " attacks " + NPC1[1] + ".");
}
attack(atkd, atkr);
turn = 0;
temp = sc.nextLine();
}
}
if(Char1Sheet[0] <= 0 && NPC1Sheet[0] <= 0){
System.out.println("Sadly, the two friends did not survive the wildernees... This was the end of our heroes!");
}else if(Creature1Sheet[0] <= 0){
System.out.println("The two friends continue their search for shelter.");
}
System.out.println("Thank you so much for playing Virtual Sample Session 1 (VSS1) of my game, currently V.Alpha0.0.0!");
System.out.print(temp);
temp = sc.nextLine();
sc.close();
}
}
The attack method won't work! It says "bound must be positive". ??? The way it works is that it takes the attacker's MaxDMG and MinDMG, then use them to give a random number between the values, then substract that number from the attacked's HP.