Properties的游戏次数小游戏

package com.czie.iot1913.lps.Array.Properties;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
* FileName: PropertiesTest
* Author: lps
* Date: 2022/3/28 21:01
* Sign:刘品水 Q:1944900433
*/
public class PropertiesTest {
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
FileReader fr = new FileReader("F:\\JavaCode\\game.txt");
prop.load(fr);
fr.close();
String count = prop.getProperty("count");
int number=Integer.parseInt(count);
if (number>=3){
System.out.println("游戏试玩结束,想玩请找刘品水重置");
}else{
GameNumbers.start();
number++;
prop.setProperty("count",String.valueOf(number));
FileWriter fw = new FileWriter("F:\\JavaCode\\game.txt");
prop.store(fw,null);
fw.close();
}


}
}

package com.czie.iot1913.lps.Array.Properties;

import java.util.Random;
import java.util.Scanner;

/**
* FileName: GameNumbers
* Author: lps
* Date: 2022/3/28 20:34
* Sign:刘品水 Q:1944900433
*/
public class GameNumbers {
private GameNumbers(){

}


public static void start() {
Random ra = new Random();
int randomnumber = ra.nextInt(100) + 1;

while (true) {
System.out.println("您好请输入你猜的数字:");
Scanner sc = new Scanner(System.in);
int gueesNumber = sc.nextInt();
System.out.println("您输入的数字为:" + gueesNumber);
if (gueesNumber > randomnumber) {
System.out.println("您猜大了");
} else if (gueesNumber < randomnumber) {
System.out.println("您猜小了");
} else {
System.out.println("猜对啦!!!!!!!!!!!");
break;
}
}

}
}
posted @ 2022-03-29 12:04  刘品水  阅读(669)  评论(0编辑  收藏  举报