java - 票务系统+定时器
问题描述
我目前正在开发一个离线 Jackpot 系统以获得乐趣,但我遇到了票务问题。基本上我希望它是(在我看来这是最好的方法),所以用户每输入 10 美元,你就会得到 1 张票。所以假设 Jason 存入 250 美元,然后他得到 1-25 票,Bob 存入 100 美元,然后他得到 26-36 票。等等等等然后最后它会选择一个随机数,然后它会选择一个在他的范围内有这个数字的玩家。这是当前代码:
public class Main {
private static int totalPlayers = 0;
private static int totalMoney = 0;
private static int playerDeposit = 0;
private static ArrayList<String> players = new ArrayList<String>();
private static ArrayList<Integer> botsMoney = new ArrayList<Integer>();
private static Timer timer;
private static Random random = new Random();
private static int playerMoney = 500;
private static String playerName;
private static double playerChance;
public static void main(String[] args) {
onUserEnter();
}
public static boolean onUserEnter(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter your name:");
playerName = scan.nextLine();
System.out.println("Money: 500$");
System.out.println("How much would you like to deposit?");
try{
playerDeposit = scan.nextInt();
}catch(NumberFormatException ex) {
System.out.println(playerDeposit + " is not a proper number!");
playerDeposit = 0;
return false;
}
if(playerDeposit <= 0) {
System.out.println("You can't deposit " + playerDeposit + "$");
return false;
}else if(playerDeposit > playerMoney){
System.out.println("You can't deposit more money than what you have!");
return false;
}
playerMoney -= playerDeposit;
System.out.println("You now have: " + playerMoney + "$");
players.add(playerName);
totalPlayers = players.size();
totalMoney += playerDeposit;
System.out.println(totalPlayers + " Players: " + players);
System.out.println("Total Pot: " + totalMoney + ", Your chances: 100%");
TimerTask tasknew = new TimerTask() {
@Override
public void run() {
}
};
timer = new Timer();
timer.schedule(tasknew, 20000);
botJoin();
return true;
}
public static boolean botJoin(){
botsMoney.add(5355);
int x = 0;
while(true){
int willBotJoin = random.nextInt(1000000000);
if(willBotJoin <= 2){
if(players.size() >= 10) {
break;
}
int moneyBotDeposits = random.nextInt(1100);
botsMoney.add(moneyBotDeposits);
double tickets = (double) moneyBotDeposits / 10;
x++;
players.add("Bob #" + x);
totalPlayers = players.size();
totalMoney += moneyBotDeposits;
System.out.println(totalPlayers + " Players: " + players);
playerChance = ((double) playerDeposit / totalMoney) * 100;
System.out.println("Total Pot: " + totalMoney + "$, Your chances: " + playerChance + "%");
}
}
botsPrecentage();
return true;
}
public static boolean botsPrecentage(){
for (int i = 1; i <= 9; i++){
double botPrecent = ((double) botsMoney.get(i) / totalMoney) * 100;
String botName = players.get(i);
System.out.println(botName + " has " + botPrecent + "%");
}
System.out.println(playerName + " has " + playerChance + "%");
return true;
}
我也尝试设置一个我不明白的计时器,我在网上查了计时器,但我就是看不懂解释。
解决方案
推荐阅读
- java - Java:具有所有依赖项的瘦 jar
- javascript - 在 IIFE 中两次声明一个变量
- arrays - 如何从字典数组中检索具有相同名称的所有键的值
- javascript - 我在使用语义 ui 反应下拉菜单时得到了“未捕获的类型错误:_this.ref.querySelector 不是函数”
- java - Java Swing Graphics2d 旋转跳跃
- mysql - 如何在 Node JS 中处理 MySQL 连接的正确方法
- vba - 每次出现表单时(隐藏而不是关闭之后)如何运行代码?
- python - Django按两个字段的总和排序不起作用
- express - 如何更新嵌套对象
- reactjs - 反应 CSSTransition 不过渡