Moti Barski super


Posts : 511 Join date : 2011-08-02
 | Subject: guess the number mini game skill Tue Dec 29, 2020 7:43 pm | |
| MiniGame1(java) - Code:
-
package com.yotamarker.lgkotlin1;
public class MiniGame1 { private int n = 0; private int min = 0; private int limit = 1000; private int max = limit; private ZeroTimeGate zeroTimeGate = new ZeroTimeGate(0); private RegexUtil regexUtil = new RegexUtil();
public void init() { n = getRandomInt(limit); zeroTimeGate.open(5); int min = 0; int limit = 1000; int max = limit; }
public int getRandomInt(int max) { // 3 : 0,1,2 return (int) Math.floor(Math.random() * Math.floor(max)); }
public String play(String ear) { if (zeroTimeGate.isClosed()) { return "time out you lose"; } String numStr = regexUtil.numberRegex(ear); if (numStr.isEmpty()) { return ""; } int guess = Integer.parseInt(numStr); if (guess == n) { return "you win"; } if (min > guess) { return "that number is too small you lose"; } if (max < guess) { return "that number is too big you lose"; } if (n > guess) { min = guess; return "guess a bigger number"; } if (n < guess) { max=guess; return "guess a smaller number"; } return ""; } }
DiMiniGamer (java) : - Code:
-
public class DiMiniGamer extends DISkill { private int gameMode = 0; private DISkillUtils diSkillUtils = new DISkillUtils(); private String outStr = ""; private MiniGame1 miniGame1 = new MiniGame1(); public DiMiniGamer(Kokoro kokoro) { super(kokoro); }
@Override public void input(String ear, String skin, String eye) { if (ear.contains("i want to play a little game")) { gameMode = 1; outStr = "yes your majesty"; miniGame1.init(); return; } switch (gameMode) { case 1: outStr = miniGame1.play(ear); if (outStr.isEmpty() || outStr.contains("you lose") || outStr.contains("you win")) { gameMode = 0; } break; default: break; } }
@Override public void output(Neuron noiron) { if (!outStr.isEmpty()) { String temp = outStr; outStr = ""; noiron.algParts.add(diSkillUtils.verbatimGorithm("mini game", new APVerbatim(temp))); } } }
good skill _________________ MB over and out  | |
|