给游戏设计一种指令码,玩家可以输入指定字符,来实现一些特定功能.
先说流程:
0.设计指令,如下图
1.修改按钮,比如我的是左上角的国旗图案, 实现弹框,获取玩家输入的指令
private Input.TextInputListener listener; //指令功能监视 listener= new Input.TextInputListener() { @Override public void input(String text) { smapGameStage.getsMapDAO().parseCommand(text); } @Override public void canceled() { } }; //按钮中监听 case 16://指令功能 随后还得弄好奖杯功能后与其互斥.即作弊后关闭奖杯并清空记录 button.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { Gdx.input.getTextInput(listener, "Console", "","type index name value"); } }); break;
2.在屏幕中加个label.辅助提示,比如玩家选择的空军index,或点击的坐标
3.截取输入的命令,并实现对应功能
public void parseCommand(String text) { //Gdx.app.log("parseCommand",text); String[] rs=text.split(" "); if(rs.length==4){ String type=rs[0]; if(!ComUtil.isNumeric(rs[1])){ game.sMapScreen.commandStr="error command :potion not is Numer "+rs[1]; return; } if(!ComUtil.isNumeric(rs[3])){ game.sMapScreen.commandStr="error command :value not is Numer "+rs[1]; return; } int value=Integer.parseInt(rs[3]); switch (rs[0]){ case "masterData": switch (rs[2]){ case "ifColor":game.sMapScreen.commandStr=text+" updOk"; return; case "ifHBuff":masterData.setIfHBuff(value);game.sMapScreen.commandStr=text+" updOk"; return; case "roundNow":masterData.setRoundNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "incomeRate":masterData.setIncomeRate(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airAddRange":masterData.setAirAddRange(value);game.sMapScreen.commandStr=text+" updOk"; return; case "unitAddMove":masterData.setUnitAddMove(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ifDeadByTime":masterData.setIfDeadByTime(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ifRandomEvent":masterData.setIfRandomEvent(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ifRandDialogue":masterData.setIfRandDialogue(value);game.sMapScreen.commandStr=text+" updOk"; return; case "playerLegionIndex":masterData.setPlayerLegionIndex(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; case "legionData": LegionData l= getLegionDataByli(Integer.parseInt(rs[1])); if(l==null){ game.sMapScreen.commandStr="error command :potion is invalid "+rs[1]; return; } switch (rs[2]){ case "updUnitLv": updUnitLv(l.getLegionIndex(),value);game.sMapScreen.commandStr=text+" updOk"; return; case "updAirLv": updAirLv(l.getLegionIndex(),value);game.sMapScreen.commandStr=text+" updOk"; return; case "updBuildLv": updBuildLv(l.getLegionIndex(),value);game.sMapScreen.commandStr=text+" updOk"; return; case "updLegionLv": updLegionLv(l,value);game.sMapScreen.commandStr=text+" updOk"; return; case "whosYourDaddy":whosYourDaddy(l,value);game.sMapScreen.commandStr=text+" updOk"; return; case "resetAllState": resetAllState(l,value);game.sMapScreen.commandStr=text+" updOk"; return; case "superFirendly":setSuperFirendly(l.getLegionIndex(),value);game.sMapScreen.commandStr=text+" updOk"; return; case "internIndex":l.setInternIndex(value);game.sMapScreen.commandStr=text+" updOk"; return; case "suzerainLi":l.setSuzerainLi(value);game.sMapScreen.commandStr=text+" updOk"; return; case "countryId":l.setCountryId(value);game.sMapScreen.commandStr=text+" updOk"; return; case "money":l.setMoney(value);game.sMapScreen.commandStr=text+" updOk"; return; case "industry":l.setIndustry(value);game.sMapScreen.commandStr=text+" updOk"; return; case "material":l.setMaterial(value);game.sMapScreen.commandStr=text+" updOk"; return; case "tradeCount":l.setTradeCount(value);game.sMapScreen.commandStr=text+" updOk"; return; case "tech":l.setTech(value);game.sMapScreen.commandStr=text+" updOk"; return; case "level":l.setLevel(value);game.sMapScreen.commandStr=text+" updOk"; return; case "medal":l.setMedal(value);game.sMapScreen.commandStr=text+" updOk"; return; case "lifeBonus":l.setLifeBonus(value);game.sMapScreen.commandStr=text+" updOk"; return; case "taxBonus":l.setTaxBonus(value);game.sMapScreen.commandStr=text+" updOk"; return; case "capitalId":l.setCapitalId(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cityLvMax":l.setCityLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "industLvMax":l.setIndustLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "techLvMax":l.setTechLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "energyLvMax":l.setEnergyLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "transportLvMax":l.setTransportLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "infantryLvMax":l.setInfantryLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cannonLvMax":l.setCannonLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "tankLvMax":l.setTankLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "fortLvMax":l.setFortLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "navyLvMax":l.setNavyLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airLvMax":l.setAirLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "supplyLvMax":l.setSupplyLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "defenceLvMax":l.setDefenceLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "missileLvMax":l.setMissileLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "nuclearLvMax":l.setNuclearLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "financialLvMax":l.setFinancialLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "tradeLvMax":l.setTradeLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cultureLvMax":l.setCultureLvMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "miracleNow":l.setMiracleNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "recruitGeneralLvNow":l.setRecruitGeneralLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "infantryCardMax":l.setInfantryCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "armorCardMax":l.setArmorCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "artilleryCardMax":l.setArtilleryCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "navyCardMax":l.setNavyCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airCardMax":l.setAirCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "nuclearCardMax":l.setNuclearCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "missileCardMax":l.setMissileCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "submarineCardMax":l.setSubmarineCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "defenceCardMax":l.setDefenceCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "generalCardMax":l.setGeneralCardMax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionRound":l.setLegionRound(value);game.sMapScreen.commandStr=text+" updOk"; return; case "civilSpec":l.setCivilSpec(value);game.sMapScreen.commandStr=text+" updOk"; return; case "color":l.setColorByCommand(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeature1":l.setLegionFeature1(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeatureLv1":l.setLegionFeatureLv1(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeature2":l.setLegionFeature2(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeatureLv2":l.setLegionFeatureLv2(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeature3":l.setLegionFeature3(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeatureLv3":l.setLegionFeatureLv3(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeature4":l.setLegionFeature4(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeatureLv4":l.setLegionFeatureLv4(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeature5":l.setLegionFeature5(value);game.sMapScreen.commandStr=text+" updOk"; return; case "legionFeatureLv5":l.setLegionFeatureLv5(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; case "buildData": BuildData b= getBuildDataByRegion(getRegionId(Integer.parseInt(rs[1]))); if(b==null){ game.sMapScreen.commandStr="error command :potion is invalid "+rs[1]; return; } switch (rs[2]){ case "buildType":b.setBuildType(value);game.sMapScreen.commandStr=text+" updOk"; return; case "buildName":b.setBuildName(value);game.sMapScreen.commandStr=text+" updOk"; return; case "buildPolarity":b.setBuildPolarity(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cityStability":b.setCityStability(value);game.sMapScreen.commandStr=text+" updOk"; return; case "developLv":b.setDevelopLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cityTax":b.setCityTax(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cityLvNow":b.setCityLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "industryLvNow":b.setIndustryLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "materialLvNow":b.setMaterialLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "techLvNow":b.setTechLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "energyLvNow":b.setEnergyLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "transportLvNow":b.setTransportLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "armyLvNow":b.setArmyLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airLvNow":b.setAirLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "supplyLvNow":b.setSupplyLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "defenceLvNow":b.setDefenceLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "missileLvNow":b.setMissileLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "nuclearLvNow":b.setNuclearLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "cultureLvNow":b.setCultureLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "tradeLvNow":b.setTradeLvNow(value);game.sMapScreen.commandStr=text+" updOk"; return; case "buildRound":b.setBuildRound(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; case "airData": AirData air= getAirData(Integer.parseInt(rs[1])); if(air==null){ game.sMapScreen.commandStr="error command :potion is invalid "+rs[1]; return; } switch (rs[2]){ case "airKills":air.setAirKills(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ackLv":air.setAckLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "defLv":air.setDefLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "resLv":air.setResLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "supLv":air.setSupLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "actLv":air.setActLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "weaLv":air.setWeaLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airRank":air.setAirRank(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airMorale":air.setAirMorale(value);game.sMapScreen.commandStr=text+" updOk"; return; case "airRound":air.setAirRound(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; case "armyData": ArmyData army= getArmyDataByHexagon(Integer.parseInt(rs[1])); if(army==null){ game.sMapScreen.commandStr="error command :potion is invalid "+rs[1]; return; } switch (rs[2]){ case "armyKills":army.setArmyKills(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ackLv":army.setAckLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "defLv":army.setDefLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "resLv":army.setResLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "supLv":army.setSupLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "actLv":army.setActLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "weaLv":army.setWeaLv(value);game.sMapScreen.commandStr=text+" updOk"; return; case "armyRank":army.setArmyRank(value);game.sMapScreen.commandStr=text+" updOk"; return; case "armyRound":army.setArmyRound(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; case "foreignData": ForeignData f= getForeignData(Integer.parseInt(rs[1])); if(f==null){ game.sMapScreen.commandStr="error command :potion is invalid "+rs[1]; return; } switch (rs[2]){ case "favor":f.setFavor(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; case "hexagonData": HexagonData h= getHexagonData(Integer.parseInt(rs[1])); if(h==null){ game.sMapScreen.commandStr="error command :potion is invalid "+rs[1]; return; } switch (rs[2]){ case "regionId":h.setRegionId(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ifCoast":h.setIfCoast(value);game.sMapScreen.commandStr=text+" updOk"; return; case "ifFog":h.setIfFog(value);game.sMapScreen.commandStr=text+" updOk"; return; case "terrainType":h.setTerrainType(value);game.sMapScreen.commandStr=text+" updOk"; return; default: game.sMapScreen.commandStr="error command :function is invalid "+rs[2]; break; } return; default: game.sMapScreen.commandStr="error command :type is invalid "+rs[0]; return; } }else { game.sMapScreen.commandStr="error command for length by split space"; } }
4.输入指令,测试
错误时:
成功时: