import javax.swing.JOptionPane;
import java.util.Random;
import java.util.Random;
public class d129 {
public static void main(String[] args) {
int start=JOptionPane.showConfirmDialog(null,
"猜字游戏开始?",
"游戏开始",
JOptionPane.YES_NO_OPTION);
if(start==JOptionPane.YES_OPTION){
int num=(new Random()).nextInt(100);
String inputValue;
int inputnumber;
int i=1;
while(i<8){
inputValue=JOptionPane.showInputDialog(
"请输入一个0到100的整数");
inputnumber=Integer.parseInt(inputValue);
if(inputnumber==num){
JOptionPane.showMessageDialog(null,
"恭喜您 猜对了",
"猜字游戏",
JOptionPane.INFORMATION_MESSAGE);
break;
}
else if(inputnumber>num)
JOptionPane.showMessageDialog(null,
"您猜的数字偏大",
"猜字游戏",
JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showMessageDialog(null,
"您猜的数字偏小",
"猜字游戏",
JOptionPane.WARNING_MESSAGE);
}
if(i>8)
JOptionPane.showMessageDialog(null,
"8次机会用尽,游戏结束",
"游戏结束",
JOptionPane.ERROR_MESSAGE);}
else JOptionPane.showMessageDialog(null,
"退出游戏",
"猜数字游戏",
JOptionPane.INFORMATION_MESSAGE);
}
int start=JOptionPane.showConfirmDialog(null,
"猜字游戏开始?",
"游戏开始",
JOptionPane.YES_NO_OPTION);
if(start==JOptionPane.YES_OPTION){
int num=(new Random()).nextInt(100);
String inputValue;
int inputnumber;
int i=1;
while(i<8){
inputValue=JOptionPane.showInputDialog(
"请输入一个0到100的整数");
inputnumber=Integer.parseInt(inputValue);
if(inputnumber==num){
JOptionPane.showMessageDialog(null,
"恭喜您 猜对了",
"猜字游戏",
JOptionPane.INFORMATION_MESSAGE);
break;
}
else if(inputnumber>num)
JOptionPane.showMessageDialog(null,
"您猜的数字偏大",
"猜字游戏",
JOptionPane.WARNING_MESSAGE);
else
JOptionPane.showMessageDialog(null,
"您猜的数字偏小",
"猜字游戏",
JOptionPane.WARNING_MESSAGE);
}
if(i>8)
JOptionPane.showMessageDialog(null,
"8次机会用尽,游戏结束",
"游戏结束",
JOptionPane.ERROR_MESSAGE);}
else JOptionPane.showMessageDialog(null,
"退出游戏",
"猜数字游戏",
JOptionPane.INFORMATION_MESSAGE);
}
}