
JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!
2019-03-12 17:01:43
微信公开课小程序热门讨论「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」最新回复-其实是很简单的程序,就是无限循环和条件表达式的运用而已。代码如下:importjava.util.Scanner;publicclassElectronicDog{privatestaticdoubletimeLeft=0;//剩余时间privatestaticinthappiness=1;//幸福值(初始为1)privatestaticintenergy=2;//能量值(初始为2)privatestaticScannersc;privatestaticdoublesleepTimeLeft=10;//睡眠时间间隔,超过则小狗离开privatestaticdoublefeedTimeLeft=0;//饲养时间间隔,小于间隔则无效publicstaticvoidmain(String[]args){sc=newScanner(System.in);intdays=0;//输入天数while(days=0){System.out.print(Playtime(day(s)):);days=sc.nextInt();if(days=0){System.out.println(Pleaseinputavalidtime.);}}//剩余时间就是天数乘以24小时timeLeft=days*24;while(timeLeft0){//如果剩余时间小于0则游戏结束showState();if(happiness=0){//幸福值小于0时结束System.out.println(Thedogisoutofhappinessandhasleft.);break;}if(energy=0){//能量值小于0时结束System.out.println(Thedogisoutofenergyandhasdied.);break;}if(sleepTimeLeft=0){//睡眠时间超过时结束System.out.println(Thedogdoesnotsleepwithin10hoursandhasleft.);break;}Commandops=getCommand();if(ops==Command.Sleep){//如果是让宠物睡觉则睡眠时间重置sleepTimeLeft=10;}else{//如果不是让宠物睡觉则睡眠时间减去任务消耗时间if(ops==Command.Feed){if(feedTimeLeft0){//如果太过频繁喂养,则本次命令无效continue;}else{//如果喂养有效,则喂养时间重置feedTimeLeft=3;}}sleepTimeLeft=ops.timeSpent;}feedTimeLeft=ops.timeSpent;happiness+=ops.happinessGained;energy+=ops.energyConsumed;timeLeft=ops.timeSpent;}if(timeLeft=0){//如果是正常游戏时间结束才能看到这一句System.out.println(Playtimeisover.);}}/***显示宠物状态*/privatestaticvoidshowState(){System.out.println();System.out.println(Timeleft:+getTime());System.out.println(Dogshappiness:+happiness);System.out.println(Dogsenergy:+energy);}/***命令宠物行为*@return返回操作明细*/privatestaticCommandgetCommand(){System.out.println(1.Walk
2.Feed
3.Sleep
4.Play);intchoice=0;while(choice=0||choice4){System.out.print(Choice:);if(sc.hasNextInt()){choice=sc.nextInt();}}Commandcmd=Command.values()[choice1];returncmd;}privatestaticStringgetTime(){inthour=(int)Math.floor(timeLeft);doublemin=timeLefthour;returnString.format(%02d:%02d,hour,(int)(min*60));}}/***对小狗发出的命令*/enumCommand{Walk(1,3,2),Feed(0.5f,1,5),Sleep(8,8,4),Play(2,2,1);publicfloattimeSpent;publicinthappinessGained;publicintenergyConsumed;privateCommand(floattimeSpent,inthappinessGained,intenergyConsumed){this.timeSpent=timeSpent;this.happinessGained=happinessGained;this.energyConsumed=energyConsumed;}}部分截图如下
importjava.util.Scanner;publicclassTest{publicstaticvoidmain(String[]args){ElectronicDogdog=newElectronicDog();while(!dog.isOver()){dog.MenuInput();}}}classElectronicDog{inttime,happiness,energy,lastsleep,lastfeed;Scannersc=newScanner(System.in);publicElectronicDog(){System.out.print(Playtime(day(s)):);intdays=sc.nextInt();time=days*48;happiness=10;energy=10;lastsleep=0;lastfeed=6;}privatevoidMenuHead(){System.out.println(============================);System.out.println(Timeleft:+time/2+:+(time%2==0?00:30));System.out.println(Dogshappiness:+happiness);System.out.println(Dogsenergy:+energy);}publicvoidMenuInput(){MenuHead();System.out.println(1.Walk);System.out.println(2.Feed);System.out.println(3.Sleep);System.out.println(4.Play);System.out.print(Choice:);intcho=sc.nextInt();switch(cho){case1:Walk();break;case2:Feed();break;case3:Sleep();break;case4:Play();break;default:Error();break;}}publicbooleanisOver(){returnisTime()||isDead()||isLeave();}privatevoidWalk(){time-=2;happiness+=3;energy-=2;lastsleep+=2;lastfeed+=2;}privatevoidFeed(){if(lastfeed=6){time-=1;happiness+=1;energy+=5;lastsleep+=1;lastfeed=0;}else{System.out.println(Thedurationoffeedingis3hours.);}}privatevoidSleep(){time-=16;happiness-=8;energy-=4;lastsleep=0;lastfeed+=16;}privatevoidPlay(){time-=4;happiness+=2;energy-=1;lastsleep=4;lastfeed+=4;}privatevoidError(){System.out.println(Choiceinvalid!Pleasechoosefrom1~4.);}privatebooleanisTime(){booleanret=time=0;if(ret){MenuHead();System.out.println(Youcanadoptthedogforever.);sc.close();}returnret;}privatebooleanisDead(){booleanret=energy=0;if(ret){MenuHead();System.out.println(Yourdogisoutofenergyandhasdied.);sc.close();}returnret;}privatebooleanisLeave(){booleanret=happiness=0||lastsleep=20;if(ret){MenuHead();System.out.println(Yourdogisoutofhappinessorsleepandhasleft.);sc.close();}returnret;}} 更多有关「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」的疑问请扫码关注微信公开课+小程序!
importjava.util.Scanner;publicclassTest{publicstaticvoidmain(String[]args){ElectronicDogdog=newElectronicDog();while(!dog.isOver()){dog.MenuInput();}}}classElectronicDog{inttime,happiness,energy,lastsleep,lastfeed;Scannersc=newScanner(System.in);publicElectronicDog(){System.out.print(Playtime(day(s)):);intdays=sc.nextInt();time=days*48;happiness=10;energy=10;lastsleep=0;lastfeed=6;}privatevoidMenuHead(){System.out.println(============================);System.out.println(Timeleft:+time/2+:+(time%2==0?00:30));System.out.println(Dogshappiness:+happiness);System.out.println(Dogsenergy:+energy);}publicvoidMenuInput(){MenuHead();System.out.println(1.Walk);System.out.println(2.Feed);System.out.println(3.Sleep);System.out.println(4.Play);System.out.print(Choice:);intcho=sc.nextInt();switch(cho){case1:Walk();break;case2:Feed();break;case3:Sleep();break;case4:Play();break;default:Error();break;}}publicbooleanisOver(){returnisTime()||isDead()||isLeave();}privatevoidWalk(){time-=2;happiness+=3;energy-=2;lastsleep+=2;lastfeed+=2;}privatevoidFeed(){if(lastfeed=6){time-=1;happiness+=1;energy+=5;lastsleep+=1;lastfeed=0;}else{System.out.println(Thedurationoffeedingis3hours.);}}privatevoidSleep(){time-=16;happiness-=8;energy-=4;lastsleep=0;lastfeed+=16;}privatevoidPlay(){time-=4;happiness+=2;energy-=1;lastsleep=4;lastfeed+=4;}privatevoidError(){System.out.println(Choiceinvalid!Pleasechoosefrom1~4.);}privatebooleanisTime(){booleanret=time=0;if(ret){MenuHead();System.out.println(Youcanadoptthedogforever.);sc.close();}returnret;}privatebooleanisDead(){booleanret=energy=0;if(ret){MenuHead();System.out.println(Yourdogisoutofenergyandhasdied.);sc.close();}returnret;}privatebooleanisLeave(){booleanret=happiness=0||lastsleep=20;if(ret){MenuHead();System.out.println(Yourdogisoutofhappinessorsleepandhasleft.);sc.close();}returnret;}} 更多有关「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」的疑问请扫码关注微信公开课+小程序!
标签:微信公开课,小程序

「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」热议话题订阅
方法1:微信扫描微信公开课小程序码即可订阅热议话题「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」
方法2:微信搜索微信公开课小程序名称进入,即可订阅热议话题「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」
方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热议话题「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」
微信公开课小程序热议话题「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。
微信公开课热议话题「JAVA大神来帮忙啊,ECLIPSE编写一个小程序类似于电子宠物的。弄完截图过来也行,行了就加大悬赏,谢谢!」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。
微信公开课小程序
更新时间:2019-03-12 17:01:43
>
__methodCallerx27;ofundefined
>-404011cloudfunctionexecutionerror
>,请补充选择商家自营-预付卡销售-发行方类目,并在基础信息处申请该类目,通过
>:host在模拟器中显示无效
>:请在小程序服务页面上架正式(非测试)内容或商品后重新提交审核
>.net 微信小程序 上传图片
>'setTimeout'的问题
>‘三朵里熙SPA主题减压空间’为什么搜索关键词‘三朵里‘搜不到
>‘扫普通链接二维码打开小程序‘中设置为体验版,扫码打开是线上版本
>“cloudfunctions**indexjs”gitignore
>“NO ULINK DEVICE FOUND”是怎么回事
>“万马掌上校园”的类目审核
>“上线了”公司开发的微信小程序怎么样?
>“产品是否一定需要条形码”
>