2016-11-26 57 views
-4

因此对于另一个项目我正在做一个RPG代码。像地牢和龙。我特别的问题是属性。基本上,应用程序向玩家提供统计数据,然后,如果玩家不喜欢他们收到的统计数据,应用程序会给他们重新选择的选项。然而,如果用户选择重新卷动,则第一个卷会很好,这些统计数据(第一个和下一个)会相互添加。这里是我的代码:它只是增加了

Main方法:

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; 
    // } 
} 

游戏高手(这确实整场比赛):

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(); 
    } 
} 
+1

这是关于可怕的标题和一大块代码,可能会超过[MCVE],并提出一个更好的标题。 – rene

+1

它正在添加的事实应该有助于指向正确的方向。这是大量的代码才能转储。使用调试器检查您的过程以设置统计数据,以便您可以看到变量值。某处,你保留了以前的价值。就我个人而言,我会添加xyz.reset()来重置统计信息,然后像您一样重新进行。 (我现在在移动设备上,无法连接到我的开发机器几天,一旦我找到了,我会尽力找到一个确切的解决方案,如果仍然需要的话)。 – SirBagels

回答

0

DiceBag总和应该是rollD6而不是静态的。

相关问题