难度导航2D字符串数组,关联到另一个2D int数组 [英] Difficulty navigating 2d String array that correlates to another 2d int array

查看:194
本文介绍了难度导航2D字符串数组,关联到另一个2D int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有持有一堆统计信息和这样一个关于玩家一类。我试图实施通过RNG均达到某些目标STAT一个模拟奖杯系统。
我有一个2D INT 数组保存值奖杯的等级/水平,即一旦实现升级青铜奖杯,银等及相应的二维字符串数组持有这样的奖杯级别的冠军。在测试什么似乎与现在使用的方法实际上提供了奖杯工作,只有某些类型。我现在已经是我想我需要为了这个工作要遵循的路径。我有一个名为方法 getBadges(INT requestedStat)接受一个索引值另一个数组,查看统计奖杯。在该方法中是一个for循环,这个方法的参数进行比较,以二维数组来确定统计的值(存储在另一个阵列)资格它一个青铜,银或金奖杯。我的主要问题是,我迷路如何在我的二维数组访问这些不同的数据点不用出指数的范围之内。更何况当我设置了一堆中的if-else 陈述我的测试输出总是产生的奖杯的名字,但没有奖杯的水平。喜欢这样:

 小灵:没有徽章
资源管理器:没有徽章
社会名流:没有徽章
贡献者:没有徽章

由于技能点上去所以应该徽章水平(即从无徽到铜奖等去了)。这是一个逻辑或语法错误?我对什么是我的code发生超茫然,尽管我的伪code的努力。这里是玩家类:

 包GamerProject;的Bean;
进口了java.util.Comparator;公共类玩家实现Serializable,可比<&玩家GT; {    私人字符串playerName;
    私有静态最终诠释HEALTH_POINTS_RESD = 23;
    私有静态最终诠释AREAS_VISITED = 200;
    私有静态最终诠释PLAYERS_ENCOUNTERED = 175;
    私有静态最终诠释MAPS_CREATED = 1500;
    私有静态最终诠释ITEMS_GATHERED = 20;
    私有静态最终诠释ITEMS_REPAIRED = 100;
    私有静态最终诠释ITEMS_MERGED = 125;
    私有静态最终诠释TOP_SCORES = 250;
    私有静态最终诠释DMG_POINTS_DEALT = 17;
    私有静态最终诠释MAPS_COMPLETED = 750;
    私有静态最终诠释LEVEL2 = 10000;
    私有静态最终诠释LEVEL3 = 25000;
    私有静态最终诠释LEVEL4 = 80000;
    私有静态最终诠释LEVEL5 = 150000;
    私有静态最终诠释6级= 300000;
    私有静态最终诠释7级= 1000000;
    私有静态最终诠释LEVEL8 = 2200000;
    私有静态最终诠释LEVEL9 = 450;
    私有静态最终诠释LEVEL10 =千万;
    私有静态最终诠释LEVEL11 = 20000000;
    私有静态最终诠释LEVEL12 = 35000000;
    私人最终诠释[] = gamerStatValues​​新INT [10];
    私人最终诠释[] = gamerActions {HEALTH_POINTS_RESD,AREAS_VISITED,PLAYERS_ENCOUNTERED,MAPS_CREATED,
        ITEMS_GATHERED,ITEMS_REPAIRED,ITEMS_MERGED,TOP_SCORES,DMG_POINTS_DEALT,MAPS_COMPLETED};
    私人最终诠释[] = expValues​​ LEVEL2 {,LEVEL3,LEVEL4,LEVEL5,6级,7级,
        LEVEL8,LEVEL9,LEVEL10,LEVEL11,LEVEL12};
    私人最终诠释[] [] = badgePoints {
        {0,2000,10000,30000,100000,200000},
        {0,50,1000,5000,17000,40000},
        {0,100,1000,2000,10000,30000},
        {0,3,10,20,90,150},
        {0,2000,10000,30000,100000,200000},
        {0,100,1000,5000,15000,40000},
        {0,100,500,2000,10000,40000},
        {0,20,200,1000,5000,20000},
        {0,2000,10000,30000,100000 300000},
        {0,10,50,200,500,5000}};
    私人最终的String [] = badgeTitles {小灵,资源管理器,名媛,贡献者,
        囤积,固定器,木,领导者,惩罚者,走火入魔,};
    私人最终的String [] = badgeRanks {没有徽章,天,铜奖,银,黄金,白金};    玩家(){
        playerName =;    }    公众诠释getTotalExp(){
        INT totalExp = 0;
        的for(int i = 0; I< gamerStatValues​​.length;我++){
            totalExp + =(gamerStatValues​​ [I] * gamerActions [I]);
        }
        返回totalExp;
    }    公众诠释getLevel(){
        INT playerLevel = 1;
        INT totalExp = getTotalExp();
        的for(int i = 0; I< expValues​​.length;我++){
            如果(totalExp> = expValues​​ [I]){
                playerLevel + = 1;
                //System.out.println(getTotalExp());
            }
        }
        返回playerLevel;
    }    公共字符串getBadge(INT requestedStat){
        串badgeOutput =;
        //索引= 0;
        如果(requestedStat> = 0&放大器;&放大器; requestedStat&下; = 9){
            的for(int i = 0; I< badgeRanks.length;我++){//不知道如何解决走出去的数组边界
                如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [I]
                        &功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [I + 1]){
                    badgeOutput = badgeTitles [requestedStat] + badgeRanks [I]
                }否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat]第[i + 1]
                        &功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [1 + 2]){
                    badgeOutput = badgeTitles [requestedStat] + badgeRanks [I + 1];
                }
            }
            //这样做作为外来溶液。仍然无法正常工作
//如果(gamerActions [requestedStat> = badgePoints [requestedStat] [指数]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 1]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数]
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [索引+ 1]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 2]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [索引+ 1];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 2]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 3]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 2];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 3]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 4]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 3];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 4]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 5]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 4];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 5]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 6]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 5];
//}其他{
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 6];
//}
//        }其他{
            badgeOutput =无可用徽章;
        }
        返回badgeOutput;
    }    //不完整的方法
    公共字符串getBadges(){
        字符串badgeOutput =徽章;
        的for(int i = 0; I< badgeTitles.length;我++){
//如果(gamerActions [I]){
//
//}
        }
        返回badgeOutput;
    }    公共字符串getPlayerName(){
        返回playerName;
    }    公众诠释getHealthPointsResd(){
        返回gamerStatValues​​ [0];
    }    公众诠释getAreasVisited(){
        返回gamerStatValues​​ [1];
    }    公众诠释getPlayersEncountered(){
        返回gamerStatValues​​ [2];
    }    公众诠释getMapsCreated(){
        返回gamerStatValues​​ [3];
    }    公众诠释getItemsGathered(){
        返回gamerStatValues​​ [4];
    }    公众诠释getItemsRepaired(){
        返回gamerStatValues​​ [5];
    }    公众诠释getItemsMerged(){
        返回gamerStatValues​​ [6];
    }    公众诠释getTopScores(){
        返回gamerStatValues​​ [7];
    }    公众诠释getDmgPointsDealt(){
        返回gamerStatValues​​ [8];
    }    公众诠释getMapsCompleted(){
        返回gamerStatValues​​ [9];
    }    //未使用的方法
    公共无效updateRandomGamerAction(INT的intValue){
        如果(==的intValue 0){
            gamerActions [0] + = 1;
        }否则如果(的intValue == 1){
            gamerActions [1] + = 1;
        }否则如果(的intValue == 2){
            gamerActions [2] + = 1;
        }否则如果(的intValue == 3){
            gamerActions [3] + = 1;
        }否则如果(==的intValue 4){
            gamerActions [4] + = 1;
        }否则如果(==的intValue 5){
            gamerActions [5] + = 1;
        }否则如果(==的intValue 6){
            gamerActions [6] + = 1;
        }否则如果(==的intValue 7){
            gamerActions [7] + = 1;
        }否则如果(==的intValue 8){
            gamerActions [8] + = 1;
        }其他{
            gamerActions [9] + = 1;
        }
    }    公共字符串setPlayerName(字符串playerName){
        this.playerName = playerName;
        返回this.playerName;
    }    公众诠释setHealthPointsResd(INT healthPointsResd){
        如果(healthPointsResd> = 0){
            gamerStatValues​​ [0] = healthPointsResd;
            返回gamerStatValues​​ [0];
        }其他{
            返回gamerStatValues​​ [0];
        }
    }    公众诠释setAreasVisited(INT areasVisited){
        如果(areasVisited> = 0){
            gamerStatValues​​ [1] = areasVisited;
            返回gamerStatValues​​ [1];
        }其他{
            返回gamerStatValues​​ [1];
        }
    }    公众诠释setPlayersEncountered(INT playersEncountered){
        如果(playersEncountered> = 0){
            gamerStatValues​​ [2] = playersEncountered;
            返回gamerStatValues​​ [2];
        }其他{
            返回gamerStatValues​​ [2];
        }
    }    公众诠释setMapsCreated(INT mapsCreated){
        如果(mapsCreated> = 0){
            gamerStatValues​​ [3] = mapsCreated;
            返回gamerStatValues​​ [3];
        }其他{
            返回gamerStatValues​​ [3];
        }
    }    公众诠释setItemsGathered(INT itemsGathered){
        如果(itemsGathered> = 0){
            gamerStatValues​​ [4] = itemsGathered;
            返回gamerStatValues​​ [4];
        }其他{
            返回gamerStatValues​​ [4];
        }
    }    公众诠释setItemsRepaired(INT itemsRepaired){
        如果(itemsRepaired> = 0){
            gamerStatValues​​ [5] = itemsRepaired;
            返回gamerStatValues​​ [5];
        }其他{
            返回gamerStatValues​​ [5];
        }
    }    公众诠释setItemsMerged(INT itemsMerged){
        如果(itemsMerged> = 0){
            gamerStatValues​​ [6] = itemsMerged;
            返回gamerStatValues​​ [6];
        }其他{
            返回gamerStatValues​​ [6];
        }
    }    公众诠释setTopScores(INT topScores){
        如果(topScores> = 0){
            gamerStatValues​​ [7] = topScores;
            返回gamerStatValues​​ [7];
        }其他{
            返回gamerStatValues​​ [7];
        }
    }    公众诠释setDmgPointsDealt(INT dmgPointsDealt){
        如果(dmgPointsDealt> = 0){
            gamerStatValues​​ [8] = dmgPointsDealt;
            返回gamerStatValues​​ [8];
        }其他{
            返回gamerStatValues​​ [8];
        }
    }    公众诠释setMapsCompleted(INT mapsCompleted){
        如果(mapsCompleted> = 0){
            gamerStatValues​​ [9] = mapsCompleted;
            返回gamerStatValues​​ [9];
        }其他{
            返回gamerStatValues​​ [9];
        }
    }    公共无效setStatsToZero(){
        的for(int i = 0; I< gamerActions.length;我++){
            gamerActions [I] = 0;
        }
    }
    公共字符串statsString(){
        回归统计:+健康恢复点=+ gamerStatValues​​ [0]
                +\\ n个区域访问=+ gamerStatValues​​ [1] +,PlayersEncountered =+ gamerStatValues​​ [2]
                +,地图创建=+ gamerStatValues​​ [3] +\\ n项云集=+ gamerStatValues​​ [4]
                +,物品修复=+ gamerStatValues​​ [5] +,项目合并=+ gamerStatValues​​ [6]
                +\\ n最高得分=+ gamerStatValues​​ [7] +,点伤害肾阴虚=+ gamerStatValues​​ [8]
                +,地图已完成=+ gamerStatValues​​ [9] +};
    }    公共字符串shortDecription(){
        返回的String.format(%16战斗机:级别%2D,经验表明:%,10D
                playerName,this.getLevel(),this.getTotalExp());
    }    @覆盖
    公共字符串的toString(){
        返回玩家{+玩家名称=+ playerName +玩家资料:
                +健康恢复点=+ gamerStatValues​​ [0]
                +\\ n个区域访问=+ gamerStatValues​​ [1] +,PlayersEncountered =+ gamerStatValues​​ [2]
                +,地图创建=+ gamerStatValues​​ [3] +\\ n项云集=+ gamerStatValues​​ [4]
                +,物品修复=+ gamerStatValues​​ [5] +,项目合并=+ gamerStatValues​​ [6]
                +\\ n最高得分=+ gamerStatValues​​ [7] +,点伤害肾阴虚=+ gamerStatValues​​ [8]
                +,地图已完成=+ gamerStatValues​​ [9] +};
    }    @覆盖
    公众诠释的compareTo(玩家播放器){
        如果(this.getTotalExp()> player.getTotalExp()){
            返回1;
        }否则如果(this.getTotalExp()== player.getTotalExp()){
            返回0;
        }其他{
            返回-1;
        }
    }}

和这里的司机我与测试它:

 包GamerProject;进口了java.util.Random;公共类Program7Driver {    私有静态最终诠释rngRange = 10;
    私有静态最后的玩家[] =玩家新玩家[10];
    私有静态最后的String [] = gamerNames {BestGamer99,CdrShepardN7
        Gandalf_The_Cool,SharpShooter01,TheDragonborn,SithLord01,
        MrWolfenstien,Goldeneye007,DungeonMaster91,MasterThief,TheDarkKnight};    公共静态无效的主要(字串[] args){
        随机兰特=新的随机();
        的for(int i = 0; I< gamers.length;我++){
            玩家[i] =新玩家();
            玩家[I] .setPlayerName(gamerNames [I]);
            玩家[I] .setStatsToZero();        }
//的for(int i = 0; I< 200000;我++){
// INT RNG = rand.nextInt(rngRange);
//玩家[RNG] .setRandomGamerAction(RNG);
//}
        诠释计数= 0;
        的for(int i = 0; I< 20000;我++){
            INT RNG = rand.nextInt(rngRange);
            的System.out.println(玩家[0] .getBadge(计数));
            //System.out.println(玩家[0]的ToString());
            //gamers[0].updateRandomGamerAction(rng);
            如果(RNG == 0){
                玩家[0] .setHealthPointsResd(玩家[0] .getHealthPointsResd()+ 1);
            }否则如果(RNG == 1){
                玩家[0] .setAreasVisited(玩家[0] .getAreasVisited()+ 1);
            }否则如果(RNG == 2){
                玩家[0] .setPlayersEncountered(玩家[0] .getPlayersEncountered()+ 1);
            }否则如果(RNG == 3){
                玩家[0] .setMapsCreated(玩家[0] .getMapsCreated()+ 1);
            }否则如果(RNG == 4){
                玩家[0] .setItemsGathered(玩家[0] .getItemsGathered()+ 1);
            }否则如果(RNG == 5){
                玩家[0] .setItemsRepaired(玩家[0] .getItemsRepaired()+ 1);
            }否则如果(RNG == 6){
                玩家[0] .setItemsMerged(玩家[0] .getItemsMerged()+ 1);
            }否则如果(RNG == 7){
                玩家[0] .setTopScores(玩家[0] .getTopScores()+ 1);
            }否则如果(RNG == 8){
                玩家[0] .setDmgPointsDealt(玩家[0] .getDmgPointsDealt()+ 1);
            }其他{
                玩家[0] .setMapsCompleted(玩家[0] .getMapsCompleted()+ 1);
            }            数+ = 1;
            如果(计数== 10){
                数 - = 10;
            }
           //的System.out.println(玩家[I] .statsString());
        }
    }
}


解决方案

好吧,我做了一些改动。看看这样做你想要什么:

 包GamerProject;的Bean;
进口了java.util.Comparator;公共类玩家实现Serializable,可比<&玩家GT; {    / **
     *
     * /
    私有静态最后的serialVersionUID长1L =;
    私人字符串playerName;
    私有静态最终诠释HEALTH_POINTS_RESD = 23;
    私有静态最终诠释AREAS_VISITED = 200;
    私有静态最终诠释PLAYERS_ENCOUNTERED = 175;
    私有静态最终诠释MAPS_CREATED = 1500;
    私有静态最终诠释ITEMS_GATHERED = 20;
    私有静态最终诠释ITEMS_REPAIRED = 100;
    私有静态最终诠释ITEMS_MERGED = 125;
    私有静态最终诠释TOP_SCORES = 250;
    私有静态最终诠释DMG_POINTS_DEALT = 17;
    私有静态最终诠释MAPS_COMPLETED = 750;
    私有静态最终诠释LEVEL2 = 10000;
    私有静态最终诠释LEVEL3 = 25000;
    私有静态最终诠释LEVEL4 = 80000;
    私有静态最终诠释LEVEL5 = 150000;
    私有静态最终诠释6级= 300000;
    私有静态最终诠释7级= 1000000;
    私有静态最终诠释LEVEL8 = 2200000;
    私有静态最终诠释LEVEL9 = 450;
    私有静态最终诠释LEVEL10 =千万;
    私有静态最终诠释LEVEL11 = 20000000;
    私有静态最终诠释LEVEL12 = 35000000;
    私人最终诠释[] = gamerStatValues​​新INT [10];
    私人最终诠释[] = gamerActions {HEALTH_POINTS_RESD,AREAS_VISITED,PLAYERS_ENCOUNTERED,MAPS_CREATED,
        ITEMS_GATHERED,ITEMS_REPAIRED,ITEMS_MERGED,TOP_SCORES,DMG_POINTS_DEALT,MAPS_COMPLETED};
    私人最终诠释[] = expValues​​ LEVEL2 {,LEVEL3,LEVEL4,LEVEL5,6级,7级,
        LEVEL8,LEVEL9,LEVEL10,LEVEL11,LEVEL12};
    私人最终诠释[] [] = badgePoints {
        {0,2000,10000,30000,100000,200000},
        {0,50,1000,5000,17000,40000},
        {0,100,1000,2000,10000,30000},
        {0,3,10,20,90,150},
        {0,2000,10000,30000,100000,200000},
        {0,100,1000,5000,15000,40000},
        {0,100,500,2000,10000,40000},
        {0,20,200,1000,5000,20000},
        {0,2000,10000,30000,100000 300000},
        {0,10,50,200,500,5000}};
    私人最终的String [] = badgeTitles {小灵,资源管理器,名媛,贡献者,
        囤积,固定器,木,领导者,惩罚者,走火入魔,};
    私人最终的String [] = badgeRanks {没有徽章,天,铜奖,银,黄金,白金};    玩家(){
        playerName =;    }    公众诠释getTotalExp(){
        INT totalExp = 0;
        的for(int i = 0; I< gamerStatValues​​.length;我++){
            totalExp + =(gamerStatValues​​ [I] * gamerActions [I]);
        }
        返回totalExp;
    }    公众诠释getLevel(){
        INT playerLevel = 1;
        INT totalExp = getTotalExp();
        的for(int i = 0; I< expValues​​.length;我++){
            如果(totalExp> = expValues​​ [I]){
                playerLevel + = 1;
                //System.out.println(getTotalExp());
            }
        }
        返回playerLevel;
    }    公共字符串getBadge(INT requestedStat){
        串badgeOutput =;
        //索引= 0;
        如果(requestedStat> = 0&放大器;&放大器; requestedStat&下; = 9){
            的for(int i = 0; I< badgeRanks.length;我++){//不知道如何解决走出去的数组边界
                如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [I]
                        &功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [I + 1]){
                    badgeOutput = badgeTitles [requestedStat] + badgeRanks [I]
                }否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat]第[i + 1]
                        &功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [1 + 2]){
                    badgeOutput = badgeTitles [requestedStat] + badgeRanks [I + 1];
                }
            }
            //这样做作为外来溶液。仍然无法正常工作
//如果(gamerActions [requestedStat> = badgePoints [requestedStat] [指数]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 1]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数]
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [索引+ 1]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 2]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [索引+ 1];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 2]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 3]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 2];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 3]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 4]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 3];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 4]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 5]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 4];
//}否则如果(gamerActions [requestedStat]≥= badgePoints [requestedStat] [指数+ 5]
//&功放;&安培; gamerActions [requestedStat< badgePoints [requestedStat] [指数+ 6]){
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 5];
//}其他{
// badgeOutput = badgeTitles [requestedStat] + badgeRanks [指数+ 6];
//}
//        }其他{
            badgeOutput =无可用徽章;
        }
        返回badgeOutput;
    }    //不完整的方法
    公共字符串getBadges(){
        字符串badgeOutput =徽章;
        的for(int i = 0; I< badgeTitles.length;我++){
//如果(gamerActions [I]){
//
//}
        }        返回badgeOutput;
    }    公共字符串getPlayerName(){
        返回playerName;
    }    公众诠释getHealthPointsResd(){
        返回gamerStatValues​​ [0];
    }    公众诠释getAreasVisited(){
        返回gamerStatValues​​ [1];
    }    公众诠释getPlayersEncountered(){
        返回gamerStatValues​​ [2];
    }    公众诠释getMapsCreated(){
        返回gamerStatValues​​ [3];
    }    公众诠释getItemsGathered(){
        返回gamerStatValues​​ [4];
    }    公众诠释getItemsRepaired(){
        返回gamerStatValues​​ [5];
    }    公众诠释getItemsMerged(){
        返回gamerStatValues​​ [6];
    }    公众诠释getTopScores(){
        返回gamerStatValues​​ [7];
    }    公众诠释getDmgPointsDealt(){
        返回gamerStatValues​​ [8];
    }    公众诠释getMapsCompleted(){
        返回gamerStatValues​​ [9];
    }    //未使用的方法
    公共无效updateRandomGamerAction(INT的intValue){
        如果(==的intValue 0){
            gamerActions [0] + = 1;
        }否则如果(的intValue == 1){
            gamerActions [1] + = 1;
        }否则如果(的intValue == 2){
            gamerActions [2] + = 1;
        }否则如果(的intValue == 3){
            gamerActions [3] + = 1;
        }否则如果(==的intValue 4){
            gamerActions [4] + = 1;
        }否则如果(==的intValue 5){
            gamerActions [5] + = 1;
        }否则如果(==的intValue 6){
            gamerActions [6] + = 1;
        }否则如果(==的intValue 7){
            gamerActions [7] + = 1;
        }否则如果(==的intValue 8){
            gamerActions [8] + = 1;
        }其他{
            gamerActions [9] + = 1;
        }
    }    公共字符串setPlayerName(字符串playerName){
        this.playerName = playerName;
        返回this.playerName;
    }    公众诠释setHealthPointsResd(INT healthPointsResd){
        如果(healthPointsResd> = 0){
            gamerStatValues​​ [0] = healthPointsResd;
            返回gamerStatValues​​ [0];
        }其他{
            返回gamerStatValues​​ [0];
        }
    }    公众诠释setAreasVisited(INT areasVisited){
        如果(areasVisited> = 0){
            gamerStatValues​​ [1] = areasVisited;
            返回gamerStatValues​​ [1];
        }其他{
            返回gamerStatValues​​ [1];
        }
    }    公众诠释setPlayersEncountered(INT playersEncountered){
        如果(playersEncountered> = 0){
            gamerStatValues​​ [2] = playersEncountered;
            返回gamerStatValues​​ [2];
        }其他{
            返回gamerStatValues​​ [2];
        }
    }    公众诠释setMapsCreated(INT mapsCreated){
        如果(mapsCreated> = 0){
            gamerStatValues​​ [3] = mapsCreated;
            返回gamerStatValues​​ [3];
        }其他{
            返回gamerStatValues​​ [3];
        }
    }    公众诠释setItemsGathered(INT itemsGathered){
        如果(itemsGathered> = 0){
            gamerStatValues​​ [4] = itemsGathered;
            返回gamerStatValues​​ [4];
        }其他{
            返回gamerStatValues​​ [4];
        }
    }    公众诠释setItemsRepaired(INT itemsRepaired){
        如果(itemsRepaired> = 0){
            gamerStatValues​​ [5] = itemsRepaired;
            返回gamerStatValues​​ [5];
        }其他{
            返回gamerStatValues​​ [5];
        }
    }    公众诠释setItemsMerged(INT itemsMerged){
        如果(itemsMerged> = 0){
            gamerStatValues​​ [6] = itemsMerged;
            返回gamerStatValues​​ [6];
        }其他{
            返回gamerStatValues​​ [6];
        }
    }    公众诠释setTopScores(INT topScores){
        如果(topScores> = 0){
            gamerStatValues​​ [7] = topScores;
            返回gamerStatValues​​ [7];
        }其他{
            返回gamerStatValues​​ [7];
        }
    }    公众诠释setDmgPointsDealt(INT dmgPointsDealt){
        如果(dmgPointsDealt> = 0){
            gamerStatValues​​ [8] = dmgPointsDealt;
            返回gamerStatValues​​ [8];
        }其他{
            返回gamerStatValues​​ [8];
        }
    }    公众诠释setMapsCompleted(INT mapsCompleted){
        如果(mapsCompleted> = 0){
            gamerStatValues​​ [9] = mapsCompleted;
            返回gamerStatValues​​ [9];
        }其他{
            返回gamerStatValues​​ [9];
        }
    }    公共无效setStatsToZero(){
        的for(int i = 0; I< gamerActions.length;我++){
            gamerActions [I] = 0;
        }
    }
    公共字符串statsString(){
        回归统计:+健康恢复点=+ gamerStatValues​​ [0]
                +\\ n个区域访问=+ gamerStatValues​​ [1] +,PlayersEncountered =+ gamerStatValues​​ [2]
                +,地图创建=+ gamerStatValues​​ [3] +\\ n项云集=+ gamerStatValues​​ [4]
                +,物品修复=+ gamerStatValues​​ [5] +,项目合并=+ gamerStatValues​​ [6]
                +\\ n最高得分=+ gamerStatValues​​ [7] +,点伤害肾阴虚=+ gamerStatValues​​ [8]
                +,地图已完成=+ gamerStatValues​​ [9] +};
    }    公共字符串shortDecription(){
        返回的String.format(%16战斗机:级别%2D,经验表明:%,10D
                playerName,this.getLevel(),this.getTotalExp());
    }    @覆盖
    公共字符串的toString(){
        返回玩家{+玩家名称=+ playerName +玩家资料:
                +健康恢复点=+ gamerStatValues​​ [0]
                +\\ n个区域访问=+ gamerStatValues​​ [1] +,PlayersEncountered =+ gamerStatValues​​ [2]
                +,地图创建=+ gamerStatValues​​ [3] +\\ n项云集=+ gamerStatValues​​ [4]
                +,物品修复=+ gamerStatValues​​ [5] +,项目合并=+ gamerStatValues​​ [6]
                +\\ n最高得分=+ gamerStatValues​​ [7] +,点伤害肾阴虚=+ gamerStatValues​​ [8]
                +,地图已完成=+ gamerStatValues​​ [9] +};
    }    @覆盖
    公众诠释的compareTo(玩家播放器){
        如果(this.getTotalExp()> player.getTotalExp()){
            返回1;
        }否则如果(this.getTotalExp()== player.getTotalExp()){
            返回0;
        }其他{
            返回-1;
        }
    }}

和其他

 包GamerProject;进口了java.util.Random;公共类Program7Driver {    私有静态最终诠释rngRange = 10;
    私有静态最后的玩家[] =玩家新玩家[10];
    私有静态最后的String [] = gamerNames {BestGamer99,CdrShepardN7
        Gandalf_The_Cool,SharpShooter01,TheDragonborn,SithLord01,
        MrWolfenstien,Goldeneye007,DungeonMaster91,MasterThief,TheDarkKnight};    公共静态无效的主要(字串[] args){
        随机兰特=新的随机();
        的for(int i = 0; I< gamers.length;我++){
            玩家[i] =新玩家();
            玩家[I] .setPlayerName(gamerNames [I]);
            玩家[I] .setStatsToZero();
        }
//的for(int i = 0; I< 200000;我++){
// INT RNG = rand.nextInt(rngRange);
//玩家[RNG] .setRandomGamerAction(RNG);
//}
        诠释计数= 0;
        的for(int i = 0; I< gamers.length;我++){
            INT RNG = rand.nextInt(rngRange);
            的System.out.println(玩家[I]);
            //System.out.println(玩家[0]的ToString());
            //gamers[0].updateRandomGamerAction(rng);
            如果(RNG == 0){
                玩家[0] .setHealthPointsResd(玩家[0] .getHealthPointsResd()+ 1);
            }否则如果(RNG == 1){
                玩家[0] .setAreasVisited(玩家[0] .getAreasVisited()+ 1);
            }否则如果(RNG == 2){
                玩家[0] .setPlayersEncountered(玩家[0] .getPlayersEncountered()+ 1);
            }否则如果(RNG == 3){
                玩家[0] .setMapsCreated(玩家[0] .getMapsCreated()+ 1);
            }否则如果(RNG == 4){
                玩家[0] .setItemsGathered(玩家[0] .getItemsGathered()+ 1);
            }否则如果(RNG == 5){
                玩家[0] .setItemsRepaired(玩家[0] .getItemsRepaired()+ 1);
            }否则如果(RNG == 6){
                玩家[0] .setItemsMerged(玩家[0] .getItemsMerged()+ 1);
            }否则如果(RNG == 7){
                玩家[0] .setTopScores(玩家[0] .getTopScores()+ 1);
            }否则如果(RNG == 8){
                玩家[0] .setDmgPointsDealt(玩家[0] .getDmgPointsDealt()+ 1);
            }其他{
                玩家[0] .setMapsCompleted(玩家[0] .getMapsCompleted()+ 1);
            }            数+ = 1;
            如果(计数== 10){
                数 - = 10;
            }
           //的System.out.println(玩家[I] .statsString());
        }
    }
}

So I have a class that holds a bunch of stat info and such about a "gamer". I'm trying to implement a mock trophy system for certain stat goals that were achieved through an RNG. I have a 2d int array that holds values for the grade/level of the trophy, that once achieved upgrades the trophy from bronze, to silver, etc and a corresponding 2d String array that holds the titles of such trophy levels. In testing what seemed to work with a now unused method actually provided trophies to only certain types. What I have now is a path I think I need to follow in order for this to work. I have a method called getBadges(int requestedStat) that takes an index value for another array to view that stats trophies. In that method is a for loop that compares the method's argument to both 2d arrays to determine if the stat's value (stored in another array) qualifies it for a bronze, silver, or gold trophy. My main problem is I'm getting lost in how to access these different data points in my 2d arrays without going out of the index's range. Not to mention when I set up a bunch of if-else statements my test output always produced the trophy's name, but no trophy level. Like such:

Healer: No Badge 
Explorer: No Badge 
Socialite: No Badge 
Contributor: No Badge 

As the skill points go up so should the badge levels (i.e. go from "No Badge" to "Bronze" etc). Is this a logic or syntax error? I'm super confused on what is happening in my code, despite my pseudo-code efforts. Here is the Gamer class:

package GamerProject;

import java.io.Serializable;
import java.util.Comparator;

public class Gamer implements Serializable, Comparable<Gamer> {

    private String playerName;
    private static final int HEALTH_POINTS_RESD = 23;
    private static final int AREAS_VISITED = 200;
    private static final int PLAYERS_ENCOUNTERED = 175;
    private static final int MAPS_CREATED = 1500;
    private static final int ITEMS_GATHERED = 20;
    private static final int ITEMS_REPAIRED = 100;
    private static final int ITEMS_MERGED = 125;
    private static final int TOP_SCORES = 250;
    private static final int DMG_POINTS_DEALT = 17;
    private static final int MAPS_COMPLETED = 750;
    private static final int LEVEL2 = 10000;
    private static final int LEVEL3 = 25000;
    private static final int LEVEL4 = 80000;
    private static final int LEVEL5 = 150000;
    private static final int LEVEL6 = 300000;
    private static final int LEVEL7 = 1000000;
    private static final int LEVEL8 = 2200000;
    private static final int LEVEL9 = 4500000;
    private static final int LEVEL10 = 10000000;
    private static final int LEVEL11 = 20000000;
    private static final int LEVEL12 = 35000000;
    private final int[] gamerStatValues = new int[10];
    private final int[] gamerActions = {HEALTH_POINTS_RESD, AREAS_VISITED, PLAYERS_ENCOUNTERED, MAPS_CREATED,
        ITEMS_GATHERED, ITEMS_REPAIRED, ITEMS_MERGED, TOP_SCORES, DMG_POINTS_DEALT, MAPS_COMPLETED};
    private final int[] expValues = {LEVEL2, LEVEL3, LEVEL4, LEVEL5, LEVEL6, LEVEL7,
        LEVEL8, LEVEL9, LEVEL10, LEVEL11, LEVEL12};
    private final int[][] badgePoints = {
        {0, 2000, 10000, 30000, 100000, 200000},
        {0, 50, 1000, 5000, 17000, 40000},
        {0, 100, 1000, 2000, 10000, 30000},
        {0, 3, 10, 20, 90, 150},
        {0, 2000, 10000, 30000, 100000, 200000},
        {0, 100, 1000, 5000, 15000, 40000},
        {0, 100, 500, 2000, 10000, 40000},
        {0, 20, 200, 1000, 5000, 20000},
        {0, 2000, 10000, 30000, 100000, 300000},
        {0, 10, 50, 200, 500, 5000}};
    private final String[] badgeTitles = {"Healer: ", "Explorer: ", "Socialite: ", "Contributor: ",
        "Hoarder: ", "Fixer: ", "Joiner: ", "Leader: ", "Punisher: ", "Obsessed: ",};
    private final String[] badgeRanks = {"No Badge ", "Tin ", "Bronze ", "Silver ", "Gold ", "Platinum "};

    Gamer() {
        playerName = "";

    }

    public int getTotalExp() {
        int totalExp = 0;
        for (int i = 0; i < gamerStatValues.length; i++) {
            totalExp += (gamerStatValues[i] * gamerActions[i]);
        }
        return totalExp;
    }

    public int getLevel() {
        int playerLevel = 1;
        int totalExp = getTotalExp();
        for (int i = 0; i < expValues.length; i++) {
            if (totalExp >= expValues[i]) {
                playerLevel += 1;
                //System.out.println(getTotalExp());
            }
        }
        return playerLevel;
    }

    public String getBadge(int requestedStat) {
        String badgeOutput = "";
        //index = 0;
        if (requestedStat >= 0 && requestedStat <=9) {
            for (int i = 0; i < badgeRanks.length; i++) {//not sure how to get around going out of the array bounds
                if (gamerActions[requestedStat] >= badgePoints[requestedStat][i]
                        && gamerActions[requestedStat] < badgePoints[requestedStat][i + 1]) {
                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[i];
                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][i+1]
                        && gamerActions[requestedStat] < badgePoints[requestedStat][i + 2]) {
                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[i+1];
                }
            }
            //did this as an extraneous solution. Still doesn't work
//            if (gamerActions[requestedStat] >= badgePoints[requestedStat][index]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 1]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+1]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 2]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+1];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+2]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 3]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+2];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+3]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 4]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+3];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+4]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 5]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+4];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+5]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 6]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+5];
//                } else {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+6];
//                }
//            

        } else {
            badgeOutput = "No Badges Available";
        }
        return badgeOutput;
    }

    //Incomplete Method
    public String getBadges() {
        String badgeOutput = "Badges: ";
        for (int i = 0; i < badgeTitles.length; i++) {
//            if (gamerActions[i]) {
//                
//            }
        }
        return badgeOutput;
    }

    public String getPlayerName() {
        return playerName;
    }

    public int getHealthPointsResd() {
        return gamerStatValues[0];
    }

    public int getAreasVisited() {
        return gamerStatValues[1];
    }

    public int getPlayersEncountered() {
        return gamerStatValues[2];
    }

    public int getMapsCreated() {
        return gamerStatValues[3];
    }

    public int getItemsGathered() {
        return gamerStatValues[4];
    }

    public int getItemsRepaired() {
        return gamerStatValues[5];
    }

    public int getItemsMerged() {
        return gamerStatValues[6];
    }

    public int getTopScores() {
        return gamerStatValues[7];
    }

    public int getDmgPointsDealt() {
        return gamerStatValues[8];
    }

    public int getMapsCompleted() {
        return gamerStatValues[9];
    }

    //Unused Method
    public void updateRandomGamerAction(int intValue) {
        if (intValue == 0) {
            gamerActions[0]+=1;
        } else if (intValue == 1) {
            gamerActions[1]+=1;
        } else if (intValue == 2) {
            gamerActions[2]+=1;
        } else if (intValue == 3) {
            gamerActions[3]+=1;
        } else if (intValue == 4) {
            gamerActions[4]+=1;
        } else if (intValue == 5) {
            gamerActions[5]+=1;
        } else if (intValue == 6) {
            gamerActions[6]+=1;
        } else if (intValue == 7) {
            gamerActions[7]+=1;
        } else if (intValue == 8) {
            gamerActions[8]+=1;
        } else {
            gamerActions[9]+=1;
        }
    }

    public String setPlayerName(String playerName) {
        this.playerName = playerName;
        return this.playerName;
    }

    public int setHealthPointsResd(int healthPointsResd) {
        if (healthPointsResd >= 0) {
            gamerStatValues[0] = healthPointsResd;
            return gamerStatValues[0];
        } else {
            return gamerStatValues[0];
        }
    }

    public int setAreasVisited(int areasVisited) {
        if (areasVisited >= 0) {
            gamerStatValues[1] = areasVisited;
            return gamerStatValues[1];
        } else {
            return gamerStatValues[1];
        }
    }

    public int setPlayersEncountered(int playersEncountered) {
        if (playersEncountered >= 0) {
            gamerStatValues[2] = playersEncountered;
            return gamerStatValues[2];
        } else {
            return gamerStatValues[2];
        }
    }

    public int setMapsCreated(int mapsCreated) {
        if (mapsCreated >= 0) {
            gamerStatValues[3] = mapsCreated;
            return gamerStatValues[3];
        } else {
            return gamerStatValues[3];
        }
    }

    public int setItemsGathered(int itemsGathered) {
        if (itemsGathered >= 0) {
            gamerStatValues[4] = itemsGathered;
            return gamerStatValues[4];
        } else {
            return gamerStatValues[4];
        }
    }

    public int setItemsRepaired(int itemsRepaired) {
        if (itemsRepaired >= 0) {
            gamerStatValues[5] = itemsRepaired;
            return gamerStatValues[5];
        } else {
            return gamerStatValues[5];
        }
    }

    public int setItemsMerged(int itemsMerged) {
        if (itemsMerged >= 0) {
            gamerStatValues[6] = itemsMerged;
            return gamerStatValues[6];
        } else {
            return gamerStatValues[6];
        }
    }

    public int setTopScores(int topScores) {
        if (topScores >= 0) {
            gamerStatValues[7] = topScores;
            return gamerStatValues[7];
        } else {
            return gamerStatValues[7];
        }
    }

    public int setDmgPointsDealt(int dmgPointsDealt) {
        if (dmgPointsDealt >= 0) {
            gamerStatValues[8] = dmgPointsDealt;
            return gamerStatValues[8];
        } else {
            return gamerStatValues[8];
        }
    }

    public int setMapsCompleted(int mapsCompleted) {
        if (mapsCompleted >= 0) {
            gamerStatValues[9] = mapsCompleted;
            return gamerStatValues[9];
        } else {
            return gamerStatValues[9];
        }
    }

    public void setStatsToZero(){
        for (int i = 0; i < gamerActions.length; i++) {
            gamerActions[i] = 0;
        }
    }
    public String statsString() {
        return "Stats: " + "Health Points Restored = " + gamerStatValues[0]
                + ",\n Areas Visited = " + gamerStatValues[1] + ", PlayersEncountered = " + gamerStatValues[2]
                + ", Maps Created = " + gamerStatValues[3] + ",\n Items Gathered = " + gamerStatValues[4]
                + ", Items Repaired = " + gamerStatValues[5] + ", Items Merged = " + gamerStatValues[6]
                + ",\n Top Scores = " + gamerStatValues[7] + ", Damage Points Dealt =  " + gamerStatValues[8]
                + ", Maps Completed = " + gamerStatValues[9] + '}';
    }

    public String shortDecription() {
        return String.format("%16s: Level %2d, Experience Points: %,10d",
                playerName, this.getLevel(), this.getTotalExp());
    }

    @Override
    public String toString() {
        return "Gamer{" + "Player Name = " + playerName + " Player Stats: "
                + "Health Points Restored = " + gamerStatValues[0]
                + ",\n Areas Visited = " + gamerStatValues[1] + ", PlayersEncountered = " + gamerStatValues[2]
                + ", Maps Created = " + gamerStatValues[3] + ",\n Items Gathered = " + gamerStatValues[4]
                + ", Items Repaired = " + gamerStatValues[5] + ", Items Merged = " + gamerStatValues[6]
                + ",\n Top Scores = " + gamerStatValues[7] + ", Damage Points Dealt =  " + gamerStatValues[8]
                + ", Maps Completed = " + gamerStatValues[9] + '}';
    }

    @Override
    public int compareTo(Gamer player) {
        if (this.getTotalExp() > player.getTotalExp()) {
            return 1;
        } else if (this.getTotalExp() == player.getTotalExp()) {
            return 0;
        } else {
            return -1;
        }
    }

}

and here is the driver I'm testing it with:

package GamerProject;

import java.util.Random;

public class Program7Driver {

    private static final int rngRange = 10;
    private static final Gamer[] gamers = new Gamer[10];
    private static final String[] gamerNames = {"BestGamer99", "CdrShepardN7",
        "Gandalf_The_Cool", "SharpShooter01", "TheDragonborn", "SithLord01",
        "MrWolfenstien", "Goldeneye007", "DungeonMaster91", "MasterThief","TheDarkKnight"};



    public static void main(String[] args) {
        Random rand = new Random();
        for (int i = 0; i < gamers.length; i++) {
            gamers[i] = new Gamer();
            gamers[i].setPlayerName(gamerNames[i]);
            gamers[i].setStatsToZero();

        }
//        for (int i = 0; i < 200000; i++) {
//            int rng = rand.nextInt(rngRange);
//            gamers[rng].setRandomGamerAction(rng);
//        }
        int count = 0;
        for (int i = 0; i < 20000; i++) {
            int rng = rand.nextInt(rngRange);
            System.out.println(gamers[0].getBadge(count));
            //System.out.println(gamers[0].toString());
            //gamers[0].updateRandomGamerAction(rng);
            if (rng == 0) {
                gamers[0].setHealthPointsResd(gamers[0].getHealthPointsResd()+1);
            } else if (rng == 1) {
                gamers[0].setAreasVisited(gamers[0].getAreasVisited()+1);
            } else if (rng == 2) {
                gamers[0].setPlayersEncountered(gamers[0].getPlayersEncountered()+1);
            } else if (rng == 3) {
                gamers[0].setMapsCreated(gamers[0].getMapsCreated()+1);
            } else if (rng == 4) {
                gamers[0].setItemsGathered(gamers[0].getItemsGathered()+1);
            } else if (rng == 5) {
                gamers[0].setItemsRepaired(gamers[0].getItemsRepaired()+1);
            } else if (rng == 6) {
                gamers[0].setItemsMerged(gamers[0].getItemsMerged()+1);
            } else if (rng == 7) {
                gamers[0].setTopScores(gamers[0].getTopScores()+1);
            } else if (rng == 8) {
                gamers[0].setDmgPointsDealt(gamers[0].getDmgPointsDealt()+1);
            } else  {
                gamers[0].setMapsCompleted(gamers[0].getMapsCompleted()+1);
            }

            count += 1;
            if (count == 10) {
                count -= 10;
            }
           // System.out.println(gamers[i].statsString());     
        }
    }
}

解决方案

Okay, I made some changes. See if this does what you were wanting:

package GamerProject;

import java.io.Serializable;
import java.util.Comparator;

public class Gamer implements Serializable, Comparable<Gamer> {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private String playerName;
    private static final int HEALTH_POINTS_RESD = 23;
    private static final int AREAS_VISITED = 200;
    private static final int PLAYERS_ENCOUNTERED = 175;
    private static final int MAPS_CREATED = 1500;
    private static final int ITEMS_GATHERED = 20;
    private static final int ITEMS_REPAIRED = 100;
    private static final int ITEMS_MERGED = 125;
    private static final int TOP_SCORES = 250;
    private static final int DMG_POINTS_DEALT = 17;
    private static final int MAPS_COMPLETED = 750;
    private static final int LEVEL2 = 10000;
    private static final int LEVEL3 = 25000;
    private static final int LEVEL4 = 80000;
    private static final int LEVEL5 = 150000;
    private static final int LEVEL6 = 300000;
    private static final int LEVEL7 = 1000000;
    private static final int LEVEL8 = 2200000;
    private static final int LEVEL9 = 4500000;
    private static final int LEVEL10 = 10000000;
    private static final int LEVEL11 = 20000000;
    private static final int LEVEL12 = 35000000;
    private final int[] gamerStatValues = new int[10];
    private final int[] gamerActions = {HEALTH_POINTS_RESD, AREAS_VISITED, PLAYERS_ENCOUNTERED, MAPS_CREATED,
        ITEMS_GATHERED, ITEMS_REPAIRED, ITEMS_MERGED, TOP_SCORES, DMG_POINTS_DEALT, MAPS_COMPLETED};
    private final int[] expValues = {LEVEL2, LEVEL3, LEVEL4, LEVEL5, LEVEL6, LEVEL7,
        LEVEL8, LEVEL9, LEVEL10, LEVEL11, LEVEL12};
    private final int[][] badgePoints = {
        {0, 2000, 10000, 30000, 100000, 200000},
        {0, 50, 1000, 5000, 17000, 40000},
        {0, 100, 1000, 2000, 10000, 30000},
        {0, 3, 10, 20, 90, 150},
        {0, 2000, 10000, 30000, 100000, 200000},
        {0, 100, 1000, 5000, 15000, 40000},
        {0, 100, 500, 2000, 10000, 40000},
        {0, 20, 200, 1000, 5000, 20000},
        {0, 2000, 10000, 30000, 100000, 300000},
        {0, 10, 50, 200, 500, 5000}};
    private final String[] badgeTitles = {"Healer: ", "Explorer: ", "Socialite: ", "Contributor: ",
        "Hoarder: ", "Fixer: ", "Joiner: ", "Leader: ", "Punisher: ", "Obsessed: ",};
    private final String[] badgeRanks = {"No Badge ", "Tin ", "Bronze ", "Silver ", "Gold ", "Platinum "};

    Gamer() {
        playerName = "";

    }

    public int getTotalExp() {
        int totalExp = 0;
        for (int i = 0; i < gamerStatValues.length; i++) {
            totalExp += (gamerStatValues[i] * gamerActions[i]);
        }
        return totalExp;
    }

    public int getLevel() {
        int playerLevel = 1;
        int totalExp = getTotalExp();
        for (int i = 0; i < expValues.length; i++) {
            if (totalExp >= expValues[i]) {
                playerLevel += 1;
                //System.out.println(getTotalExp());
            }
        }
        return playerLevel;
    }

    public String getBadge(int requestedStat) {
        String badgeOutput = "";
        //index = 0;
        if (requestedStat >= 0 && requestedStat <=9) {
            for (int i = 0; i < badgeRanks.length; i++) {//not sure how to get around going out of the array bounds
                if (gamerActions[requestedStat] >= badgePoints[requestedStat][i]
                        && gamerActions[requestedStat] < badgePoints[requestedStat][i + 1]) {
                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[i];
                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][i+1]
                        && gamerActions[requestedStat] < badgePoints[requestedStat][i + 2]) {
                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[i+1];
                }
            }
            //did this as an extraneous solution. Still doesn't work
//            if (gamerActions[requestedStat] >= badgePoints[requestedStat][index]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 1]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+1]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 2]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+1];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+2]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 3]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+2];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+3]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 4]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+3];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+4]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 5]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+4];
//                } else if (gamerActions[requestedStat] >= badgePoints[requestedStat][index+5]
//                        && gamerActions[requestedStat] < badgePoints[requestedStat][index + 6]) {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+5];
//                } else {
//                    badgeOutput = badgeTitles[requestedStat] + badgeRanks[index+6];
//                }
//            

        } else {
            badgeOutput = "No Badges Available";
        }
        return badgeOutput;
    }

    //Incomplete Method
    public String getBadges() {
        String badgeOutput = "Badges: ";
        for (int i = 0; i < badgeTitles.length; i++) {
//            if (gamerActions[i]) {
//                
//            }
        }

        return badgeOutput;
    }

    public String getPlayerName() {
        return playerName;
    }

    public int getHealthPointsResd() {
        return gamerStatValues[0];
    }

    public int getAreasVisited() {
        return gamerStatValues[1];
    }

    public int getPlayersEncountered() {
        return gamerStatValues[2];
    }

    public int getMapsCreated() {
        return gamerStatValues[3];
    }

    public int getItemsGathered() {
        return gamerStatValues[4];
    }

    public int getItemsRepaired() {
        return gamerStatValues[5];
    }

    public int getItemsMerged() {
        return gamerStatValues[6];
    }

    public int getTopScores() {
        return gamerStatValues[7];
    }

    public int getDmgPointsDealt() {
        return gamerStatValues[8];
    }

    public int getMapsCompleted() {
        return gamerStatValues[9];
    }

    //Unused Method
    public void updateRandomGamerAction(int intValue) {
        if (intValue == 0) {
            gamerActions[0]+=1;
        } else if (intValue == 1) {
            gamerActions[1]+=1;
        } else if (intValue == 2) {
            gamerActions[2]+=1;
        } else if (intValue == 3) {
            gamerActions[3]+=1;
        } else if (intValue == 4) {
            gamerActions[4]+=1;
        } else if (intValue == 5) {
            gamerActions[5]+=1;
        } else if (intValue == 6) {
            gamerActions[6]+=1;
        } else if (intValue == 7) {
            gamerActions[7]+=1;
        } else if (intValue == 8) {
            gamerActions[8]+=1;
        } else {
            gamerActions[9]+=1;
        }
    }

    public String setPlayerName(String playerName) {
        this.playerName = playerName;
        return this.playerName;
    }

    public int setHealthPointsResd(int healthPointsResd) {
        if (healthPointsResd >= 0) {
            gamerStatValues[0] = healthPointsResd;
            return gamerStatValues[0];
        } else {
            return gamerStatValues[0];
        }
    }

    public int setAreasVisited(int areasVisited) {
        if (areasVisited >= 0) {
            gamerStatValues[1] = areasVisited;
            return gamerStatValues[1];
        } else {
            return gamerStatValues[1];
        }
    }

    public int setPlayersEncountered(int playersEncountered) {
        if (playersEncountered >= 0) {
            gamerStatValues[2] = playersEncountered;
            return gamerStatValues[2];
        } else {
            return gamerStatValues[2];
        }
    }

    public int setMapsCreated(int mapsCreated) {
        if (mapsCreated >= 0) {
            gamerStatValues[3] = mapsCreated;
            return gamerStatValues[3];
        } else {
            return gamerStatValues[3];
        }
    }

    public int setItemsGathered(int itemsGathered) {
        if (itemsGathered >= 0) {
            gamerStatValues[4] = itemsGathered;
            return gamerStatValues[4];
        } else {
            return gamerStatValues[4];
        }
    }

    public int setItemsRepaired(int itemsRepaired) {
        if (itemsRepaired >= 0) {
            gamerStatValues[5] = itemsRepaired;
            return gamerStatValues[5];
        } else {
            return gamerStatValues[5];
        }
    }

    public int setItemsMerged(int itemsMerged) {
        if (itemsMerged >= 0) {
            gamerStatValues[6] = itemsMerged;
            return gamerStatValues[6];
        } else {
            return gamerStatValues[6];
        }
    }

    public int setTopScores(int topScores) {
        if (topScores >= 0) {
            gamerStatValues[7] = topScores;
            return gamerStatValues[7];
        } else {
            return gamerStatValues[7];
        }
    }

    public int setDmgPointsDealt(int dmgPointsDealt) {
        if (dmgPointsDealt >= 0) {
            gamerStatValues[8] = dmgPointsDealt;
            return gamerStatValues[8];
        } else {
            return gamerStatValues[8];
        }
    }

    public int setMapsCompleted(int mapsCompleted) {
        if (mapsCompleted >= 0) {
            gamerStatValues[9] = mapsCompleted;
            return gamerStatValues[9];
        } else {
            return gamerStatValues[9];
        }
    }

    public void setStatsToZero(){
        for (int i = 0; i < gamerActions.length; i++) {
            gamerActions[i] = 0;
        }
    }
    public String statsString() {
        return "Stats: " + "Health Points Restored = " + gamerStatValues[0]
                + ",\n Areas Visited = " + gamerStatValues[1] + ", PlayersEncountered = " + gamerStatValues[2]
                + ", Maps Created = " + gamerStatValues[3] + ",\n Items Gathered = " + gamerStatValues[4]
                + ", Items Repaired = " + gamerStatValues[5] + ", Items Merged = " + gamerStatValues[6]
                + ",\n Top Scores = " + gamerStatValues[7] + ", Damage Points Dealt =  " + gamerStatValues[8]
                + ", Maps Completed = " + gamerStatValues[9] + '}';
    }

    public String shortDecription() {
        return String.format("%16s: Level %2d, Experience Points: %,10d",
                playerName, this.getLevel(), this.getTotalExp());
    }

    @Override
    public String toString() {
        return "Gamer{" + "Player Name = " + playerName + " Player Stats: "
                + "Health Points Restored = " + gamerStatValues[0]
                + ",\n Areas Visited = " + gamerStatValues[1] + ", PlayersEncountered = " + gamerStatValues[2]
                + ", Maps Created = " + gamerStatValues[3] + ",\n Items Gathered = " + gamerStatValues[4]
                + ", Items Repaired = " + gamerStatValues[5] + ", Items Merged = " + gamerStatValues[6]
                + ",\n Top Scores = " + gamerStatValues[7] + ", Damage Points Dealt =  " + gamerStatValues[8]
                + ", Maps Completed = " + gamerStatValues[9] + '}';
    }

    @Override
    public int compareTo(Gamer player) {
        if (this.getTotalExp() > player.getTotalExp()) {
            return 1;
        } else if (this.getTotalExp() == player.getTotalExp()) {
            return 0;
        } else {
            return -1;
        }
    }

}

And the other:

package GamerProject;

import java.util.Random;

public class Program7Driver {

    private static final int rngRange = 10;
    private static final Gamer[] gamers = new Gamer[10];
    private static final String[] gamerNames = {"BestGamer99", "CdrShepardN7",
        "Gandalf_The_Cool", "SharpShooter01", "TheDragonborn", "SithLord01",
        "MrWolfenstien", "Goldeneye007", "DungeonMaster91", "MasterThief","TheDarkKnight"};



    public static void main(String[] args) {
        Random rand = new Random();
        for (int i = 0; i < gamers.length; i++) {
            gamers[i] = new Gamer();
            gamers[i].setPlayerName(gamerNames[i]);
            gamers[i].setStatsToZero();
        }
//        for (int i = 0; i < 200000; i++) {
//            int rng = rand.nextInt(rngRange);
//            gamers[rng].setRandomGamerAction(rng);
//        }
        int count = 0;
        for (int i = 0; i < gamers.length; i++) {
            int rng = rand.nextInt(rngRange);
            System.out.println(gamers[i]);
            //System.out.println(gamers[0].toString());
            //gamers[0].updateRandomGamerAction(rng);
            if (rng == 0) {
                gamers[0].setHealthPointsResd(gamers[0].getHealthPointsResd()+1);
            } else if (rng == 1) {
                gamers[0].setAreasVisited(gamers[0].getAreasVisited()+1);
            } else if (rng == 2) {
                gamers[0].setPlayersEncountered(gamers[0].getPlayersEncountered()+1);
            } else if (rng == 3) {
                gamers[0].setMapsCreated(gamers[0].getMapsCreated()+1);
            } else if (rng == 4) {
                gamers[0].setItemsGathered(gamers[0].getItemsGathered()+1);
            } else if (rng == 5) {
                gamers[0].setItemsRepaired(gamers[0].getItemsRepaired()+1);
            } else if (rng == 6) {
                gamers[0].setItemsMerged(gamers[0].getItemsMerged()+1);
            } else if (rng == 7) {
                gamers[0].setTopScores(gamers[0].getTopScores()+1);
            } else if (rng == 8) {
                gamers[0].setDmgPointsDealt(gamers[0].getDmgPointsDealt()+1);
            } else  {
                gamers[0].setMapsCompleted(gamers[0].getMapsCompleted()+1);
            }

            count += 1;
            if (count == 10) {
                count -= 10;
            }
           // System.out.println(gamers[i].statsString());     
        }
    }
}

这篇关于难度导航2D字符串数组,关联到另一个2D int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆