public class RPGTtributeGeneratorApp { public static void main(String[] args) { X.getAttributes(); } static class X{ /** * 核心属性 数 */ public static final int ATTRIBUTE_COUNT = 6; /** * 核心属性 较大值 */ public static final int ATTRIBUTE_VALUE_MA = 15; /** * 核心属性 最大值 */ public static final int ATTRIBUTE_VALUE_MAX = 18; /** * 核心属性 总和:最小值 */ public static final int ATTRIBUTE_VALUE_SUN_MIN = 75; /** * utils 随机器 */ private static final java.util.Random dice; /** * 静态函数 */ static{ dice = new java.util.Random(); } /** * 获取随机属性值 * @return 3 - 18 */ public static int getAttributeValue(){ int[] sumArray = {dice.nextInt(6)+1, dice.nextInt(6)+1, dice.nextInt(6)+1, dice.nextInt(6)+1}; java.util.Arrays.sort(sumArray); return (sumArray[1] + sumArray[2] + sumArray[3]); } public static int[] getAttributes(){ int[] attributes = new int[X.ATTRIBUTE_COUNT]; int attributeValueMaxCount = 0; //获取 for (int i = 0; i < X.ATTRIBUTE_COUNT-1; i++) { attributes[i] = X.getAttributeValue(); if(attributes[i] >= X.ATTRIBUTE_VALUE_MA){ attributeValueMaxCount++; } System.out.printf("第%s个属性 %s\n",i+1,attributes[i]); } //鉴定 if(attributeValueMaxCount < 1 || java.util.Arrays.stream(attributes).sum() < X.ATTRIBUTE_VALUE_SUN_MIN-X.ATTRIBUTE_VALUE_MAX){ //初级鉴定 System.out.printf("需要重新生成!%s %s\n",java.util.Arrays.stream(attributes).sum(),attributeValueMaxCount); System.out.println("----------------------------"); attributes = getAttributes(); }else{ //深度鉴定 attributes[X.ATTRIBUTE_COUNT-1] = X.getAttributeValue(); System.out.printf("第%s个属性 %s\n",X.ATTRIBUTE_COUNT,attributes[X.ATTRIBUTE_COUNT-1]); if(attributes[X.ATTRIBUTE_COUNT-1] >= X.ATTRIBUTE_VALUE_MA){ attributeValueMaxCount++; } if(java.util.Arrays.stream(attributes).sum() < X.ATTRIBUTE_VALUE_SUN_MIN || attributeValueMaxCount < 2 ){ System.out.printf("需要重新生成!%s %s\n",java.util.Arrays.stream(attributes).sum(),attributeValueMaxCount); System.out.println("----------------------------"); attributes = getAttributes(); }else{ System.out.printf("XX通过 %s %s\n",java.util.Arrays.stream(attributes).sum(),attributeValueMaxCount); return attributes; } } return attributes; } } }
全部评论
(0) 回帖