此问题已在此处有答案:
Passing values between methods(2个答案)
Java passing value between two classes(1个答案)
Passing string array values directly to setter method(6个答案)
5小时前关闭
所以我正在为《黑暗之魂》创作一款类似《Zork》的游戏我想接受玩家输入的职业类型,然后显示他们选择的属性(例如:他们选择战士,所以他们有10维生素,12强度等)
我为fighterAttributes创建了一个类,然后在一个名为classBuilder的方法中创建了对象。
任何帮助将不胜感激!
这是我的代码:
import java.util.Scanner;
public class Intro {
public static void intro() {
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("~~ Welcome to Dark Souls Zork! ~~");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
public static int input() {
System.out.println("What is your name, undead?");
Scanner scan = new Scanner(System.in);
String playerName = scan.nextLine();
System.out.println("Welcome " + playerName);
System.out.println("What class are you? (Please enter a number)");
System.out.println("1: Warrior");
System.out.println("2: Knight");
System.out.println("3: Wanderer");
System.out.println("4: Thief");
System.out.println("5: Bandit");
System.out.println("6: Hunter");
System.out.println("7: Sorcerer");
System.out.println("8: Pyromancer");
System.out.println("9: Cleric");
System.out.println("10: Deprived");
int playerClassNum = scan.nextInt();
String[] classes = {"Warrior", "Knight", "Wanderer", "Thief", "Bandit", "Hunter", "Sorcerer", "Pyromancer", "Cleric", "Deprived"};
System.out.println("You have chosen: " + classes[playerClassNum-1]);
return playerClassNum;
}
public static class fighterAttributes {
String playerClass;
int Level;
int Vitality;
int Attunement;
int Endurance;
int Strength;
int Dexterity;
int Resistance;
int Intelligence;
int Faith;
}
public static void classBuilder() {
fighterAttributes Warrior = new fighterAttributes();
Warrior.Level= 4;
Warrior.Vitality= 11;
Warrior.Attunement= 8;
Warrior.Endurance= 12;
Warrior.Strength= 13;
Warrior.Dexterity= 13;
Warrior.Resistance= 11;
Warrior.Intelligence= 9;
Warrior.Faith= 9;
fighterAttributes Knight = new fighterAttributes();
Knight.Level= 5;
Knight.Vitality= 14;
Knight.Attunement= 10;
Knight.Endurance= 10;
Knight.Strength= 11;
Knight.Dexterity= 11;
Knight.Resistance= 10;
Knight.Intelligence= 9;
Knight.Faith= 11;
fighterAttributes Wanderer = new fighterAttributes();
Wanderer.Level= 3;
Wanderer.Vitality= 10;
Wanderer.Attunement= 11;
Wanderer.Endurance= 10;
Wanderer.Strength= 10;
Wanderer.Dexterity= 14;
Wanderer.Resistance= 12;
Wanderer.Intelligence= 11;
Wanderer.Faith= 8;
fighterAttributes Thief = new fighterAttributes();
Thief.Level= 5;
Thief.Vitality= 9;
Thief.Attunement= 11;
Thief.Endurance= 9;
Thief.Strength= 9;
Thief.Dexterity= 15;
Thief.Resistance= 10;
Thief.Intelligence= 12;
Thief.Faith= 11;
fighterAttributes Bandit = new fighterAttributes();
Bandit.Level= 4;
Bandit.Vitality= 12;
Bandit.Attunement= 8;
Bandit.Endurance= 14;
Bandit.Strength= 14;
Bandit.Dexterity= 9;
Bandit.Resistance= 11;
Bandit.Intelligence= 8;
Bandit.Faith= 10;
fighterAttributes Hunter = new fighterAttributes();
Hunter.Level= 4;
Hunter.Vitality= 11;
Hunter.Attunement= 9;
Hunter.Endurance= 11;
Hunter.Strength= 12;
Hunter.Dexterity= 14;
Hunter.Resistance= 11;
Hunter.Intelligence= 9;
Hunter.Faith= 9;
fighterAttributes Sorcerer = new fighterAttributes();
Sorcerer.Level= 3;
Sorcerer.Vitality= 8;
Sorcerer.Attunement= 15;
Sorcerer.Endurance= 8;
Sorcerer.Strength= 9;
Sorcerer.Dexterity= 11;
Sorcerer.Resistance= 8;
Sorcerer.Intelligence= 15;
Sorcerer.Faith= 8;
fighterAttributes Pyromancer = new fighterAttributes();
Pyromancer.Level= 1;
Pyromancer.Vitality= 10;
Pyromancer.Attunement= 12;
Pyromancer.Endurance= 11;
Pyromancer.Strength= 12;
Pyromancer.Dexterity= 9;
Pyromancer.Resistance= 12;
Pyromancer.Intelligence= 10;
Pyromancer.Faith= 8;
fighterAttributes Cleric = new fighterAttributes();
Cleric.Level= 2;
Cleric.Vitality= 11;
Cleric.Attunement= 11;
Cleric.Endurance= 9;
Cleric.Strength= 12;
Cleric.Dexterity= 8;
Cleric.Resistance= 11;
Cleric.Intelligence= 8;
Cleric.Faith= 14;
fighterAttributes Deprived = new fighterAttributes();
Deprived.Level= 6;
Deprived.Vitality= 11;
Deprived.Attunement= 11;
Deprived.Endurance= 11;
Deprived.Strength= 11;
Deprived.Dexterity= 11;
Deprived.Resistance= 11;
Deprived.Intelligence= 11;
Deprived.Faith= 11;
}
public static void main(String[] args) {
intro();
input();
/* In Here I want to write some kind of code to take the return value from input(); and print out the chosen object attributes*/
}
}
1条答案
按热度按时间wgx48brx1#