Java 爪哇语;攻击“;韩元';行不通
使用给定的代码:Java 爪哇语;攻击“;韩元';行不通,java,Java,使用给定的代码: 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)
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();
}
}
import java.util.Scanner;
导入java.util.Random;
公共类场景1{
公共静态虚线(){
System.out.println(“--------------”;
}
公共静态int[]字符表(int-HP,int-MaxHP,int-MinDMG,int-MaxDMG){/[0]=HP;[1]=MaxHP;[2]=MinDMG;[3]=MaxDMG;
int[]机器;
机器=新整数[4];
机器[0]=马力;
机器[1]=最大马力;
机器[2]=MinDMG;
machine[3]=MaxDMG;
返回机;
}
公共静态int[]创建表(int-HP,int-MaxHP,int-MaxDMG,int-MinDMG){/[0]=HP;[1]=MaxHP;[2]=MinDMG;[3]=MaxDMG;
int[]机器;
机器=新整数[4];
机器[0]=马力;
机器[1]=最大马力;
机器[2]=MinDMG;
machine[3]=MaxDMG;
返回机;
}
公共静态字符串[]NPC(字符串种族){//[0]=种族;[1]=姓氏;[2]=姓氏;
随机r=新随机();
字符串姓氏=”;
字符串lastname1=“”;
字符串lastname2=“”;
字符串lastname=“”;
如果(种族==“矮人”){
开关(r.nextInt(5)){
案例0:
姓氏=“Ugbor”;
打破
案例1:
姓氏=“Hegbor”;
打破
案例2:
姓氏=“克拉根”;
打破
案例3:
姓氏=“奥加尔”;
打破
案例4:
姓氏=“Nguur”;
打破
}
开关(r.nextInt(5)){
案例0:
lastname1=“铁”;
打破
案例1:
lastname1=“橡树”;
打破
案例2:
lastname1=“钢”;
打破
案例3:
lastname1=“勇敢”;
打破
案例4:
lastname1=“懦夫”;
打破
}
开关(r.nextInt(5)){
案例0:
lastname2=“锤子”;
打破
案例1:
lastname2=“心脏”;
打破
案例2:
lastname2=“剑”;
打破
案例3:
lastname2=“盾牌”;
打破
案例4:
lastname2=“可能”;
打破
}
lastname=lastname1+lastname2;
}else if(种族==“elf”){
开关(r.nextInt(5)){
案例0:
姓氏=“Zevvin”;
打破
案例1:
姓氏=“卢卡斯”;
打破
案例2:
姓氏=“比因拉斯”;
打破
案例3:
姓氏=“Lasthandir”;
打破
案例4:
姓氏=“伊斯卡尔”;
打破
}
开关(r.nextInt(5)){
案例0:
lastname=“Huulrash”;
打破
案例1:
lastname=“Bluurkas”;
打破
案例2:
lastname=“hrataas”;
打破
案例3:
lastname=“Lektar”;
打破
案例4:
lastname=“Kuulskar”;
打破
}
}否则{
种族=“矮人”;
姓氏=“Ugbor”;
lastname=“Braveshield”;
}
字符串[]代码;
代码=新字符串[3];
代码[0]=种族;
代码[1]=姓氏;
代码[2]=姓氏;
返回码;
}
公共静态无效攻击(int[]atkd,int[]atkr){
随机r=新随机();
int rand=(r.nextInt(atkr[3]-atkr[2]+1)+1);
atkd[0]=兰特;
}
公共静态void main(字符串[]args){
int选项2;
字符串选项;
整圈=0;
匝数=0;
int[]atkr;
int[]atkd;
字符串温度;
int[]无人;
nobody=newint[1];
没有人[0]=0;
int[]Char1Sheet=字符表(8,8,1,4);
int[]NPC1Sheet=字符表(15,15,1,4);
int[]Creature1Sheet=CreatureSheet(15,15,1,2);
扫描仪sc=新的扫描仪(System.in);
System.out.println(“我们恳请您只选择程序告诉您的内容。”);
System.out.println(“按回车键继续…”);
温度=sc.nextLine();
System.out.println(“你好,玩家!请告诉我你的角色的名字:”);
字符串Char1Name=sc.nextLine();
System.out.println(“向“+Char1Name+”问好!他住在哪个村庄?”);
String Village=sc.nextLine();
字符串NPC1race=“”;
随机r=新随机();
开关(r.nextInt(2)){
案例0:
NPC1race=“dwarf”;
打破
案例1:
NPC1race=“elf”;
}
字符串[]NPC1=NPC(NPC1race);
我明白了!所以,“+Char1Name+”认识一个家伙“+NPC1[0]+”,他的名字是“+NPC1[1]+”+NPC1[2]+”。他们彼此非常了解。”;
温度=sc.nextLine();
println(“今天,他们两人都到“+村庄+”旁边的树林里去,希望能得到一些木材。”);
温度=sc.nextLine();
System.out.println(“夜幕降临,“+Char1Name+”和“+NPC1[1]+”仍在树林中。遗憾的是,他们迷路了,所以他们开始寻找避难所。”);
温度=sc.nextLine();
System.out.println(“一个灰色生物不知从哪里冒出来并攻击”+Char1Name+“!”);
第()行;
攻击(Char1Sheet,Creature1Sheet);
String Creature1Name=“GreyCreature”;
而((NPC1Sheet[0]>0&&Creature1Sheet[0]>0)| |(Char1Sheet[0]>0&&Creature1Sheet[0]>0
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 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 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 = 2;
rand = atkr[3] - atkr[2] + 1;
atkd[0] -= r.nextInt(rand) + 1;
}
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(40, 40, 1, 4);
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 % 3 == 0 && Char1Sheet[0] > 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.equals("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);
}
temp = sc.nextLine();
}else if(turn % 3 == 1 && NPC1Sheet[0] > 0){
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.equals("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);
}
temp = sc.nextLine();
}else if(turn % 3 == 2 && Creature1Sheet[0] > 0){
atkr = Creature1Sheet;
atkd=nobody;
switch(r.nextInt(2)){
case 0:
atkd = Char1Sheet;
break;
case 1:
atkd = NPC1Sheet;
}
if(atkd == Char1Sheet && Char1Sheet[0] > 0){
System.out.println(Creature1Name + " attacks " + Char1Name + ".");
}else{
atkd = NPC1Sheet;
System.out.println(Creature1Name + " attacks " + NPC1[1] + ".");
}
attack(atkd, atkr);
temp = sc.nextLine();
}
turn++;
}
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();
}
}