Java 它只是增加了

Java 它只是增加了,java,Java,所以对于另一个项目,我正在做一个RPG代码。就像地下城和龙一样。我的特殊问题是属性。基本上,应用程序会向玩家提供统计信息,然后,如果玩家不喜欢他们收到的统计信息,应用程序会向他们提供重新掷骰的选项。但是,如果用户选择重新掷骰,则第一个掷骰和下一个掷骰的统计信息会相互增加。这是我的密码: 主要方法是: package bagOfHolding; public class Advanced { public static void main(String [] args){

所以对于另一个项目,我正在做一个RPG代码。就像地下城和龙一样。我的特殊问题是属性。基本上,应用程序会向玩家提供统计信息,然后,如果玩家不喜欢他们收到的统计信息,应用程序会向他们提供重新掷骰的选项。但是,如果用户选择重新掷骰,则第一个掷骰和下一个掷骰的统计信息会相互增加。这是我的密码:

主要方法是:

   package bagOfHolding;

    public class Advanced {
    public static void main(String [] args){
    GameMaster.game();

    }
    }

The Dice Class (this rolls the stats for the statistics):

package bagOfHolding;

import java.util.Random;

public class DiceBag {
    private static int sum;

    public static int rollD6() {
        int[] Dice = new int[3];
        Random num = new Random();

        for (int i = 0; i < Dice.length; i++) {
            Dice[i] = num.nextInt((6)) + 1;
        }

        for (int i : Dice) {
            sum += i;
        }
        return sum;
    }
    // public static int getSum() {
    // return sum;
    // }
    // public static void setSum(int sum) {
    // DiceBag.sum = sum;
    // }
}
还有英雄类(这里有所有的统计数据):

包装袋包装;
导入java.io.BufferedReader;
导入java.io.IOException;
导入java.io.InputStreamReader;
公众阶级英雄{
/*
*属性-由3d6随机确定
* 
*/
/*
*-3属性-力量-伤害加成-如果每点超过15点=+1(++)
*-负伤害加成-如果低于10,则每点=-1(——;)-敏捷度
*-攻击加成-每2点超过14=(%2+1)-负攻击加成-
*10以下每2点=(%2-1)-闪避奖励-15以上每2点=
*(%2+1)-负闪避奖励-每低于11分2点=(%2-1)-
*智力-法术强度加成-每超过15点=(++2)-负
*法术强度加成-每点低于11=(-2)
* 
*基本属性-健康-力量*10-MP-智力*5
*/
私有静态int-strength=DiceBag.rollD6();
private static int intelligence=DiceBag.rollD6();
私有静态int-dextrity=DiceBag.rollD6();
公共静态int getIntelligence(){
返回情报;
}
公共静态智能(int智能){
英雄。智慧=智慧;
}
公共静态int getDexterty(){
返回灵巧度;
}
公共静态void setdextrity(int-dextrity){
英雄。灵巧=灵巧;
}
公共静态int getStrength(){
回归力量;
}
公共静强度(内部强度){
英雄。力量=力量;
}
公共静态void属性(){
强度=getStrength();
System.out.println(“这是你的英雄:”);
//DiceBag.rollD6();
System.out.println(“强度=”+强度);
如果(强度>15){
System.out.println(“伤害加成=”+“+”+”+(强度-15));
}否则,如果(强度<10){
System.out.println(“负伤害加成=”+“-”+(10-强度));
}否则{
System.out.println(“您没有伤害加成”);
}
intelligence=getIntelligence();
System.out.println(“Intelligence=“+Intelligence”);
如果(智能>15){
System.out.println(“法术强度加成=”+“+”+((智力-15)*2));
}否则,如果(强度<11){
System.out.println(“负法术强度加成=”+“-”+((11-智力)*2));
}否则{
System.out.println(“你没有法术强度加成”);
}
灵巧度=GetDextrity();
System.out.println(“灵巧度=”+灵巧度);
如果(灵巧度>15&&灵巧度%2==0){
System.out.println(“道奇奖励=”+“+”+”+(灵巧度-15));
}else if(灵巧度<11&&灵巧度%2==0){
System.out.println(“负道奇奖励=”+“-”+(11-灵巧度));
}否则{
System.out.println(“您没有道奇奖励”);
}
如果(灵巧度>14&&灵巧度%2==0){
System.out.println(“罢工奖金=”+“+”+”+(敏捷-14));
}else if(灵巧度<10&&灵巧度%2==0){
System.out.println(“负打击加成=”+“-”+(10-敏捷));
}否则{
System.out.println(“您没有罢工奖金”);
}
智力健康=力量*10;
System.out.println(“Health=“+Health”);
int MP=智力*5;
System.out.println(“MP=“+MP”);
GameMaster.ReRoll();
}
}

DiceBag sum应该是本地的,而不是静态的。

这是一个糟糕的标题和一大段代码,也许可以翻看一下,找到一个更好的标题。它添加的事实应该会帮助你找到正确的方向。这是一大堆要转储的代码。使用调试器检查设置统计信息的过程,以便查看变量值。在某些地方,您保留了以前的值。就我个人而言,我会添加xyz.reset()来重置统计数据,然后像您那样重新滚动它们。(我现在使用移动设备,几天内无法访问我的开发机器。一旦访问,如果仍然需要,我将尝试为您找到精确的解决方案。)
package bagOfHolding;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GameMaster {
    public static void game() {
        Hero.attributes();
    }

    public static void ReRoll() {
        BufferedReader delta = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Would you like to reroll your hero? 1) Yes or 2) No");
        System.out.println("Please enter a number");
        System.out.println("Any number other than 1 or 2 will exit the application");
        try {
            String userInput = delta.readLine();
            int input = Integer.parseInt(userInput);
            if (input == 1) {
                Hero.setStrength(DiceBag.rollD6());
                Hero.setDexterity(DiceBag.rollD6());
                Hero.setIntelligence(DiceBag.rollD6());
                Hero.attributes();
            } else if (input == 2) {
                System.exit(0);
            } else {
                System.exit(0);
            }
        } catch (NumberFormatException NFE) {
            System.out.println("Invalid");
        } catch (IOException IOE) {
            System.out.println("Invalid");
        }
    }
}
package bagOfHolding;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Hero {
    /*
     * Attributes - Randomly determined by 3d6
     * 
     */
    /*
     * -3 attributes - Strength - Damage bonus - If over 15 every pt = +1 (_++;)
     * - Negative Damage Bonus - If under 10 every pt = -1 (_--;) - Dexterity
     * -Strike bonus - every 2 pts over 14 = (_%2 + 1) - Negative Strike bonus -
     * every 2 pts below 10 = (_%2 -1) - Dodge bonus - every 2 pts over 15 =
     * (_%2 + 1) - Negative dodge bonus - every 2 pts below 11 = (_%2 -1) -
     * Intelligence -Spell Strength Bonus - every pt over 15 = (++2) - Negative
     * Spell Strength Bonus - every pt below 11 = (--2)
     * 
     * Base Attributes - Health -Strength * 10 - MP - Intelligence *5
     */
    private static int strength = DiceBag.rollD6();
    private static int intelligence = DiceBag.rollD6();
    private static int dexterity = DiceBag.rollD6();

    public static int getIntelligence() {
        return intelligence;
    }

    public static void setIntelligence(int intelligence) {
        Hero.intelligence = intelligence;
    }

    public static int getDexterity() {
        return dexterity;
    }

    public static void setDexterity(int dexterity) {
        Hero.dexterity = dexterity;
    }

    public static int getStrength() {
        return strength;
    }

    public static void setStrength(int strength) {
        Hero.strength = strength;
    }

    public static void attributes() {
        strength = getStrength();
        System.out.println("Here is your hero: ");
        // DiceBag.rollD6();
        System.out.println("Strength = " + strength);
        if (strength > 15) {
            System.out.println("Damage Bonus = " + "+" + (strength - 15));
        } else if (strength < 10) {
            System.out.println("Negative Damage Bonus = " + "-" + (10 - strength));
        } else {
            System.out.println("You do not have damage bonus");
        }

        intelligence = getIntelligence();
        System.out.println("Intelligence = " + intelligence);
        if (intelligence > 15) {
            System.out.println("Spell Strength Bonus = " + "+" + ((intelligence - 15) * 2));
        } else if (strength < 11) {
            System.out.println("Negative Spell Strength Bonus = " + "-" + ((11 - intelligence) * 2));
        } else {
            System.out.println("You do not have a spell strength bonus");
        }

        dexterity = getDexterity();
        System.out.println("Dexterity = " + dexterity);
        if (dexterity > 15 && dexterity % 2 == 0) {
            System.out.println("Dodge Bonus = " + "+" + (dexterity - 15));
        } else if (dexterity < 11 && dexterity % 2 == 0) {
            System.out.println("Negative Dodge Bonus = " + "-" + (11 - dexterity));
        } else {
            System.out.println("You do not have a dodge bonus");
        }
        if (dexterity > 14 && dexterity % 2 == 0) {
            System.out.println("Strike Bonus = " + "+" + (dexterity - 14));
        } else if (dexterity < 10 && dexterity % 2 == 0) {
            System.out.println("Negative Strike bonus = " + "-" + (10 - dexterity));
        } else {
            System.out.println("You do not have a strike bonus");
        }

        int health = strength * 10;
        System.out.println("Health = " + health);

        int MP = intelligence * 5;
        System.out.println("MP = " + MP);

        GameMaster.ReRoll();
    }
}