已经使用此代码几天了,无法弄清楚为什么技能没有使用我在Attributes.java中指定的数学
如果我为智力分配5分,那么科学应该计算到60分。 相反,科学计算到30。 我认为该程序使用的是原来设定的5分进行计算,而不是升级后的10分
Attributes.java
public class Attributes {
static int strength = 5;
static int perception = 5;
static int endurance = 5;
static int charisma = 5;
static int intelligence = 5;
static int agility = 5;
static int luck = 5;
static int hitpoints = ((endurance * 4) + (strength));
static int armorClass = (endurance + 1);
static int actionPoints = (agility + 1);
static int carryWeight = ((strength * 30) + 5);
static int meleeDamage = (strength / 2);
static int damageResis = (endurance + 1);
static int poisonResis = (endurance * 5);
static int radResis = (endurance * 2);
static int sequence = (perception + agility);
static int healingRate = (endurance / 2);
static int criticalChance = (((luck * 2) + (agility / 3)) + 1);
static int smallGuns = ((perception + agility + luck) * 2);
static int bigGuns = (((strength / 2) + (perception / 2) + agility + luck) * 2);
static int energyWeapons = (((intelligence / 2)+ (perception / 2) + agility + luck) * 2);
static int unarmed = (((strength / 2) + (perception / 2) + (agility / 2) + (endurance / 2) + luck) * 2);
static int meleeWeapons = (((strength / 2) + (perception / 2) + (agility / 2) + (endurance / 2) + luck) * 2);
static int throwing = (((strength / 2) + (perception / 2) + agility + luck) * 2);
static int firstAid = (((intelligence * 2) + perception) * 2);
static int doctor = ((intelligence * 3) * 2);
static int sneak = (((perception / 2) + (luck / 2) + (agility * 2)) * 2);
static int lockpick = (((perception / 2) + (luck / 2) + agility + intelligence) * 2);
static int steal = (((perception / 2) + (luck / 2) + (agility * 2)) * 2);
static int traps = (((perception / 2) + (luck / 2) + agility + intelligence) * 2);
static int science = ((intelligence * 3) * 2);
static int repair = (((agility / 2) + (perception / 2) + (intelligence * 2)) * 2);
static int speech = ((intelligence + (charisma * 2)) * 2);
static int barter = ((intelligence + (charisma * 2)) * 2);
static int gambling = ((luck * 3) * 2);
static int outdoors = (((strength / 2) + (agility / 2) + (intelligence / 2) + (luck / 2) + endurance) * 2);
}
Game.java
import java.util.Scanner;
public class Game extends Attributes{
public static void main(String[] args){
String enter = "Press Enter to continue.";
String name = null;
int age = 0;
String gender = null;
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println(" *** Welcome to Fallout! ***");
System.out.println();
System.out.println("Press Enter to begin character creation.");
Scanner pressEnter = new Scanner(System.in);
pressEnter.nextLine();
Scanner nameScan = new Scanner(System.in);
System.out.println("What is your name?");
name = nameScan.nextLine();
System.out.println("Greetings " + name + "!");
System.out.println();
Scanner ageScan = new Scanner(System.in);
System.out.println("How old are you?");
while (ageScan.hasNextInt()) {
age = ageScan.nextInt();
if ((age <= 82) && (age >=18))
break;
else System.out.println("Please choose a number between 18 & 82");
}
System.out.println(age + ". Got it.");
System.out.println();
Scanner genderScan = new Scanner(System.in);
System.out.println("Are you Male or Female?");
while (genderScan.hasNextLine()) {
gender = genderScan.nextLine();
if (gender.equalsIgnoreCase("Male") || gender.equalsIgnoreCase("Female"))
break;
else System.out.println("Please choose Male or Female");
}
System.out.println(gender + ". Noted.");
System.out.println();
System.out.println(enter);
pressEnter.nextLine();
System.out.println("Your Attributes are as follows:");
System.out.println("Strength: " + strength);
System.out.println("Perception: " + perception);
System.out.println("Endurance: " + endurance);
System.out.println("Charisma: " + charisma);
System.out.println("Intelligence: " + intelligence);
System.out.println("Agility: " + agility);
System.out.println("Luck: " + luck);
System.out.println(enter);
pressEnter.nextLine();
System.out.println();
System.out.println("You have 5 attribute points to allocate.");
System.out.println("What would you like to increase?");
System.out.println("Strength, Perception, Endurance, Charisma, Intelligence, Agility or Luck?");
Scanner scanFirstPoint = new Scanner(System.in);
String inputFirstPoint = null;
while (scanFirstPoint.hasNextLine()) {
inputFirstPoint = scanFirstPoint.nextLine();
if (inputFirstPoint.equalsIgnoreCase("Strength") || inputFirstPoint.equalsIgnoreCase("Perception") ||
inputFirstPoint.equalsIgnoreCase("Endurance") || inputFirstPoint.equalsIgnoreCase("Charisma")
|| inputFirstPoint.equalsIgnoreCase("Intelligence") ||
inputFirstPoint.equalsIgnoreCase("Agility") || inputFirstPoint.equalsIgnoreCase("Luck"))
break;
else System.out.println("Please choose Strength, Perception, Endurance, Charisma, " +
"Intelligence, Agility or Luck");
}
if (inputFirstPoint.equalsIgnoreCase("Strength")) {
System.out.println("Strength Increased by 1!");
strength ++;
System.out.println("Strength: " + strength);
} else if (inputFirstPoint.equalsIgnoreCase("Perception")) {
System.out.println("Perception Increased by 1!");
perception ++;
System.out.println("Perception: " + perception);
} else if (inputFirstPoint.equalsIgnoreCase("Endurance")) {
System.out.println("Endurance Increased by 1!");
endurance ++;
System.out.println("Endurance: " + endurance);
} else if (inputFirstPoint.equalsIgnoreCase("Charisma")) {
System.out.println("Charisma Increased by 1!");
charisma ++;
System.out.println("Charisma: " + charisma);
} else if (inputFirstPoint.equalsIgnoreCase("Intelligence")) {
System.out.println("Intelligence Increased by 1!");
intelligence ++;
System.out.println("Intelligence: " + intelligence);
} else if (inputFirstPoint.equalsIgnoreCase("Agility")) {
System.out.println("Agility Increased by 1!");
agility ++;
System.out.println("Agility: " + agility);
} else if (inputFirstPoint.equalsIgnoreCase("Luck")) {
System.out.println("Luck Increased by 1!");
luck ++;
System.out.println("Luck: " + luck);
}
System.out.println();
System.out.println("You have 4 attribute points to allocate.");
System.out.println("What would you like to increase?");
System.out.println("Strength, Perception, Endurance, Charisma, Intelligence, Agility or Luck?");
Scanner scanSecondPoint = new Scanner(System.in);
String inputSecondPoint = null;
while (scanSecondPoint.hasNextLine()) {
inputSecondPoint = scanSecondPoint.nextLine();
if (inputSecondPoint.equalsIgnoreCase("Strength") || inputSecondPoint.equalsIgnoreCase("Perception") ||
inputSecondPoint.equalsIgnoreCase("Endurance") || inputSecondPoint.equalsIgnoreCase("Charisma")
|| inputSecondPoint.equalsIgnoreCase("Intelligence") ||
inputSecondPoint.equalsIgnoreCase("Agility") || inputSecondPoint.equalsIgnoreCase("Luck"))
break;
else System.out.println("Please choose Strength, Perception, Endurance, Charisma, " +
"Intelligence, Agility or Luck");
}
if (inputSecondPoint.equalsIgnoreCase("Strength")) {
System.out.println("Strength Increased by 1!");
strength ++;
System.out.println("Strength: " + strength);
} else if (inputSecondPoint.equalsIgnoreCase("Perception")) {
System.out.println("Perception Increased by 1!");
perception ++;
System.out.println("Perception: " + perception);
} else if (inputSecondPoint.equalsIgnoreCase("Endurance")) {
System.out.println("Endurance Increased by 1!");
endurance ++;
System.out.println("Endurance: " + endurance);
} else if (inputSecondPoint.equalsIgnoreCase("Charisma")) {
System.out.println("Charisma Increased by 1!");
charisma ++;
System.out.println("Charisma: " + charisma);
} else if (inputSecondPoint.equalsIgnoreCase("Intelligence")) {
System.out.println("Intelligence Increased by 1!");
intelligence ++;
System.out.println("Intelligence: " + intelligence);
} else if (inputSecondPoint.equalsIgnoreCase("Agility")) {
System.out.println("Agility Increased by 1!");
agility ++;
System.out.println("Agility: " + agility);
} else if (inputSecondPoint.equalsIgnoreCase("Luck")) {
System.out.println("Luck Increased by 1!");
luck ++;
System.out.println("Luck: " + luck);
}
System.out.println();
System.out.println("You have 3 attribute points to allocate.");
System.out.println("What would you like to increase?");
System.out.println("Strength, Perception, Endurance, Charisma, Intelligence, Agility or Luck?");
Scanner scanThirdPoint = new Scanner(System.in);
String inputThirdPoint = null;
while (scanThirdPoint.hasNextLine()) {
inputThirdPoint = scanThirdPoint.nextLine();
if (inputThirdPoint.equalsIgnoreCase("Strength") || inputThirdPoint.equalsIgnoreCase("Perception") ||
inputThirdPoint.equalsIgnoreCase("Endurance") || inputThirdPoint.equalsIgnoreCase("Charisma")
|| inputThirdPoint.equalsIgnoreCase("Intelligence") ||
inputThirdPoint.equalsIgnoreCase("Agility") || inputThirdPoint.equalsIgnoreCase("Luck"))
break;
else System.out.println("Please choose Strength, Perception, Endurance, Charisma, " +
"Intelligence, Agility or Luck");
}
if (inputThirdPoint.equalsIgnoreCase("Strength")) {
System.out.println("Strength Increased by 1!");
strength ++;
System.out.println("Strength: " + strength);
} else if (inputThirdPoint.equalsIgnoreCase("Perception")) {
System.out.println("Perception Increased by 1!");
perception ++;
System.out.println("Perception: " + perception);
} else if (inputThirdPoint.equalsIgnoreCase("Endurance")) {
System.out.println("Endurance Increased by 1!");
endurance ++;
System.out.println("Endurance: " + endurance);
} else if (inputThirdPoint.equalsIgnoreCase("Charisma")) {
System.out.println("Charisma Increased by 1!");
charisma ++;
System.out.println("Charisma: " + charisma);
} else if (inputThirdPoint.equalsIgnoreCase("Intelligence")) {
System.out.println("Intelligence Increased by 1!");
intelligence ++;
System.out.println("Intelligence: " + intelligence);
} else if (inputThirdPoint.equalsIgnoreCase("Agility")) {
System.out.println("Agility Increased by 1!");
agility ++;
System.out.println("Agility: " + agility);
} else if (inputThirdPoint.equalsIgnoreCase("Luck")) {
System.out.println("Luck Increased by 1!");
luck ++;
System.out.println("Luck: " + luck);
}
System.out.println();
System.out.println("You have 2 attribute points to allocate.");
System.out.println("What would you like to increase?");
System.out.println("Strength, Perception, Endurance, Charisma, Intelligence, Agility or Luck?");
Scanner scanFourthPoint = new Scanner(System.in);
String inputFourthPoint = null;
while (scanFourthPoint.hasNextLine()) {
inputFourthPoint = scanFourthPoint.nextLine();
if (inputFourthPoint.equalsIgnoreCase("Strength") || inputFourthPoint.equalsIgnoreCase("Perception") ||
inputFourthPoint.equalsIgnoreCase("Endurance") || inputFourthPoint.equalsIgnoreCase("Charisma")
|| inputFourthPoint.equalsIgnoreCase("Intelligence") ||
inputFourthPoint.equalsIgnoreCase("Agility") || inputFourthPoint.equalsIgnoreCase("Luck"))
break;
else System.out.println("Please choose Strength, Perception, Endurance, Charisma, " +
"Intelligence, Agility or Luck");
}
if (inputFourthPoint.equalsIgnoreCase("Strength")) {
System.out.println("Strength Increased by 1!");
strength ++;
System.out.println("Strength: " + strength);
} else if (inputFourthPoint.equalsIgnoreCase("Perception")) {
System.out.println("Perception Increased by 1!");
perception ++;
System.out.println("Perception: " + perception);
} else if (inputFourthPoint.equalsIgnoreCase("Endurance")) {
System.out.println("Endurance Increased by 1!");
endurance ++;
System.out.println("Endurance: " + endurance);
} else if (inputFourthPoint.equalsIgnoreCase("Charisma")) {
System.out.println("Charisma Increased by 1!");
charisma ++;
System.out.println("Charisma: " + charisma);
} else if (inputFourthPoint.equalsIgnoreCase("Intelligence")) {
System.out.println("Intelligence Increased by 1!");
intelligence ++;
System.out.println("Intelligence: " + intelligence);
} else if (inputFourthPoint.equalsIgnoreCase("Agility")) {
System.out.println("Agility Increased by 1!");
agility ++;
System.out.println("Agility: " + agility);
} else if (inputFourthPoint.equalsIgnoreCase("Luck")) {
System.out.println("Luck Increased by 1!");
luck ++;
System.out.println("Luck: " + luck);
}
System.out.println();
System.out.println("You have 1 attribute points to allocate.");
System.out.println("What would you like to increase?");
System.out.println("Strength, Perception, Endurance, Charisma, Intelligence, Agility or Luck?");
Scanner scanFifthPoint = new Scanner(System.in);
String inputFifthPoint = null;
while (scanFifthPoint.hasNextLine()) {
inputFifthPoint = scanFifthPoint.nextLine();
if (inputFifthPoint.equalsIgnoreCase("Strength") || inputFifthPoint.equalsIgnoreCase("Perception") ||
inputFifthPoint.equalsIgnoreCase("Endurance") || inputFifthPoint.equalsIgnoreCase("Charisma")
|| inputFifthPoint.equalsIgnoreCase("Intelligence") ||
inputFifthPoint.equalsIgnoreCase("Agility") || inputFifthPoint.equalsIgnoreCase("Luck"))
break;
else System.out.println("Please choose Strength, Perception, Endurance, Charisma, " +
"Intelligence, Agility or Luck");
}
if (inputFifthPoint.equalsIgnoreCase("Strength")) {
System.out.println("Strength Increased by 1!");
strength ++;
System.out.println("Strength: " + strength);
} else if (inputFifthPoint.equalsIgnoreCase("Perception")) {
System.out.println("Perception Increased by 1!");
perception ++;
System.out.println("Perception: " + perception);
} else if (inputFifthPoint.equalsIgnoreCase("Endurance")) {
System.out.println("Endurance Increased by 1!");
endurance ++;
System.out.println("Endurance: " + endurance);
} else if (inputFifthPoint.equalsIgnoreCase("Charisma")) {
System.out.println("Charisma Increased by 1!");
charisma ++;
System.out.println("Charisma: " + charisma);
} else if (inputFifthPoint.equalsIgnoreCase("Intelligence")) {
System.out.println("Intelligence Increased by 1!");
intelligence ++;
System.out.println("Intelligence: " + intelligence);
} else if (inputFifthPoint.equalsIgnoreCase("Agility")) {
System.out.println("Agility Increased by 1!");
agility ++;
System.out.println("Agility: " + agility);
} else if (inputFifthPoint.equalsIgnoreCase("Luck")) {
System.out.println("Luck Increased by 1!");
luck ++;
System.out.println("Luck: " + luck);
}
System.out.println();
System.out.println("Your new attributes are:");
System.out.println("Strength: " + strength);
System.out.println("Perception: " + perception);
System.out.println("Endurance: " + endurance);
System.out.println("Charisma: " + charisma);
System.out.println("Intelligence: " + intelligence);
System.out.println("Agility: " + agility);
System.out.println("Luck: " + luck);
System.out.println(enter);
pressEnter.nextLine();
System.out.println();
System.out.println("Your Skills are as follows:");
System.out.println("Small Guns: " + smallGuns);
System.out.println("Big Guns: " + bigGuns);
System.out.println("Energy Weapons: " + energyWeapons);
System.out.println("Unarmed: " + unarmed);
System.out.println("Melee Weapons: " + meleeWeapons);
System.out.println("Throwing: " + throwing);
System.out.println("First Aid: " + firstAid);
System.out.println("Doctor: " + doctor);
System.out.println("Sneak: " + sneak);
System.out.println("Lockpick: " + lockpick);
System.out.println("Steal: " + steal);
System.out.println("Traps: " + traps);
System.out.println("Science: " + science);
System.out.println("Repair: " + repair);
System.out.println("Speech: " + speech);
System.out.println("Barter: " + barter);
System.out.println("Gambling: " + gambling);
System.out.println("Outdoors: " + outdoors);
System.out.println(enter);
pressEnter.nextLine();
System.out.println();
}
}
答案 0 :(得分:3)
我需要50个评论的声誉,所以我只是回答你的问题。将点添加到基值时,不会更新计算值。因此,您需要在分配技能点后更新所有值。
编辑:为了使这一点更加清晰 - 你的力量,感知,耐力,智慧,敏捷,魅力和运气都被初始化为5.这些是你可以添加点以增加价值的唯一值。其余所有值(生命值,科学等)都是根据这些值计算出来的。但是,当您选择花费您的技能点时,您不会重新计算依赖于基值的所有其他值。