猜数游戏大家都知道吧
规则就是:
猜数字,范围可以在0~100或200以内,具体根据游戏人数来定。
1、先由坐庄的人来写一个数字(必须在提前规定的范围内);
2、让大家轮流猜,并告诉大家正确数字比当前猜的数字大或者小;
3、每猜一次范围就会缩小,最后猜中的人倒霉挨罚;
4、受罚的人需要进行抽签赢得惩罚”大奖“, 下一轮由受罚者再写数字,依此循环。
因为玩过这个游戏觉得比较有趣,就把它用JAVA实现了一下哈哈哈
/**
* @author: Waiting
* @date: 2018/08/02
* @apiName:
* @description: 猜数游戏
*/
import java.util.Random;
import java.util.Scanner;
/**
* 猜数小游戏
*
*/
public class guess_num {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = (int) (Math.random() * 100); // 产生随机数
int guess;// 用户猜的数字
int count = 0;// 猜测次数
int personnum = 0;
int allperson = 0;
System.out.println("请问一共多少人?");
allperson = input.nextInt();
System.out.println("请问这次从几号开始猜的?");
personnum = input.nextInt();
System.out.println("我心里有一个0到100之间的整数,你猜是什么?");
int max = 100;
int min = 1;
// 用户猜测随机数
do {
guess = input.nextInt();
if (number < guess) {
count++;
max = guess;
System.out.println("大了点,再猜!范围是" + min + "-" + max);
if((max-min) == 3 )
{
System.out.println("还有一线希望哦~~~~");
}
if((max-min) == 2 )
{
System.out.println("下一位朋友不用猜了恭喜你哈哈");
count++;
break;
}
} else if (number > guess) {
min = guess;
count++;
System.out.println("小了点,再猜!范围是" + min + "-" + max);
if((max-min) == 3 )
{
System.out.println("还有一线希望哦~~~");
}
if((max-min) == 2 )
{
System.out.println("下一位朋友不用猜了恭喜你哈哈");
count++;
break;
}
} else {
count++;
break;
}
} while (true);
if(count == 1)
{
System.out.println("本次猜数作废");
}
else {
System.out.println("这个数字是" + number + "--你太棒啦竟然猜中了--"+"恭喜"+(personnum+count-1)%allperson+"号哈哈");
}
}
}
欢迎大家找BUG