尝试用java制作一个cookieclicker风格的游戏。我是初学者,所以很糟糕。。。以下是我所拥有的:
static double money = 50;
static double mps = 0; //money per second
public static void main(String[] args) throws InterruptedException{
System.out.println("\n*You have $50*"
+ "\n*Use this money to make more money*"
+ "\n*Type \"stats\" To see what you can buy*");
String statsString = "*Type Numbers To Buy, You Can Only Buy If You Have Enough Money!*"
+ "\n1 = $50 = 1 $/sec"
+ "\n2 = $100 = 2.2 $/sec"
+ "\n3 = $300 = 7.2 $/sec"
+ "\n4 = $1,200 = 31.2 $/sec"
+ "\n5 = $6,000 = 168 $/sec"
+ "\n6 = $36,000 = 1,080 $/sec"
+ "\n7 = $253,000 = 5,060 $/sec"
+ "\n8 = $2,024,000 = 68,816 $/sec"
+ "\n9 = $18,216,000 = 6 $/sec";
while (true) {
String input;
try {
Scanner stats = new Scanner(System.in);
input = stats.next();
if(input.matches("stats")){ //if user inputs "stats", print stats
System.out.println(statsString);
} else if(input.matches("1") && money >= 50) { //if user inputs 1 and has 50+ money, buy one, subtract 50 from money and add 1 to money per second
money = money - 50;
mps = mps + 1;
System.out.println(current money per second is " + mps);
} else if(input.matches("2") && money >= 100) { //same as last comment, but different numbers
money = money - 100;
mps = mps + 2.20;
System.out.println(current money per second is " + mps);
} else if(input.matches("3") && money >= 300) { //same as last comment, but different numbers
money = money - 300;
mps = mps + 7.20;
System.out.println(current money per second is " + mps);
} else if(input.matches("4") && money >= 1200) { //same as last comment, but different numbers
money = money - 1200;
mps = mps + 31.20;
System.out.println(current money per second is " + mps);
} else if(input.matches("5") && money >= 6000) { //same as last comment, but different numbers
money = money - 6000;
mps = mps + 168;
System.out.println(current money per second is " + mps);
} else if(input.matches("6") && money >= 36000) { //same as last comment, but different numbers
money = money - 36000;
mps = mps + 1080;
System.out.println(current money per second is " + mps);
} else if(input.matches("7") && money >= 253000) { //same as last comment, but different numbers
money = money - 253000;
mps = mps +5060;
System.out.println(current money per second is " + mps);
} else if(input.matches("8") && money >= 2024000) { //same as last comment, but different numbers
money = money - 2024000;
mps = mps + 68816;
System.out.println(current money per second is " + mps);
} else if(input.matches("9") && money >= 18216000) { //same as last comment, but different numbers
money = money - 18216000;
mps = mps + 655776;
System.out.println(current money per second is " + mps);
} else{ //if none of the above inputs are input, say something is wrong, either not enough money or not a chosen valid input
System.out.println("you don't have enough money for that!");
}//end else
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//end catch
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("You have $" + money + "!");
money = money + mps;
}//end public void run
}, 0, 1000);//timer task
}//end while true loop
}//end string
每当一个else if语句起作用时,它不是每秒输出一次钱,而是每秒输出两次,然后如果另一个else if语句起作用,则每秒输出三次钱。。。基本上,每次按1-9,每秒的钱都比每秒增加的多。
1条答案
按热度按时间cnwbcb6i1#
现在,每次用户购买商品时都会启动一个新的计时器任务。如果将任务计时器移到while循环上方,则确保只有一个计时器正在执行。
附言:在终端上玩饼干点击器很有趣。