}
package Quickhit;
public class Level {
private int leverNo;
private int strLength;
private int strTimes;
private int limitTime;
private int perScore;
public Level() {
super();
}
public Level(int leverNo, int strLength, int strTimes, int limitTime,
int perScore) {
super();
this.leverNo = leverNo;
this.strLength = strLength;
this.strTimes = strTimes;
this.limitTime = limitTime;
this.perScore = perScore;
}
public int getLeverNo() {
return leverNo;
}
public void setLeverNo(int leverNo) {
this.leverNo = leverNo;
}
public int getStrLength() {
return strLength;
}
public void setStrLength(int strLength) {
this.strLength = strLength;
}
public int getStrTimes() {
return strTimes;
}
public void setStrTimes(int strTimes) {
this.strTimes = strTimes;
}
public int getLimitTime() {
return limitTime;
}
public void setLimitTime(int limitTime) {
this.limitTime = limitTime;
}
public int getPerScore() {
return perScore;
}
public void setPerScore(int perScore) {
this.perScore = perScore;
}
}
package Quickhit;
public class LevelParam {
public final static Level[] levels = new Level[6];
static{
levels[0]=new Level(1, 2, 1, 15, 1);
levels[1]=new Level(2, 3, 5, 14, 2);
levels[2]=new Level(3, 4, 3, 13, 5);
levels[3]=new Level(4, 5, 5, 12, 8);
levels[4]=new Level(5, 6, 3, 15, 10);
levels[5]=new Level(6, 7, 3, 12, 15);
}
}
package Quickhit;
import java.util.Scanner;
public class Player {
private int levelno;// 当前级别
private String name;
private int courrentscore;// 当前积分
private long starttime;
private int elapsetime;// 花费时间
public void play() {
Scanner input = new Scanner(System.in);
System.out.println("欢迎来到quickhit游戏,开始挑战");
Game game = new Game(this);
LLL:
for (int i = 0; i < LevelParam.levels.length; i++) {
for (int times = 0; times < LevelParam.levels[i].getStrTimes(); times++) {
this.levelno=LevelParam.levels[i].getLeverNo();
String out = game.printStr();
System.out.println(out);
// 记录游戏开始时间
this.starttime = System.currentTimeMillis();// 当前系统时间 毫秒数和1970年
// 1月1日午夜之差
// 修改玩家当前级别
this.levelno = LevelParam.levels[i].getLeverNo();
System.out.println("请输入上面的字符:");
String in = input.next();
boolean isSuccess = game.printResult(out, in);
// 判断通关的条件1.当前级别=6 2 times=游戏级别(最后一个(strtimes-1)相等)
// 3 isSuccess必须为true
// 每次晋级的条件 满足2和3即可表示晋级成功 可以给予提示
if (isSuccess
&& times == (LevelParam.levels[i].getStrTimes() - 1)) {
if (LevelParam.levels[i].getLeverNo() == 6) {
System.out.println("您已通关成功,天下无敌");
} else {
System.out.println(LevelParam.levels[i].getLeverNo()
+ "级别挑战成功,欢迎到下一级");
}
}else{
break LLL;
}
}
}
}
public int getLevelno() {
return levelno;
}
public void setLevelno(int levelno) {
this.levelno = levelno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCourrentscore() {
return courrentscore;
}
public void setCourrentscore(int courrentscore) {
this.courrentscore = courrentscore;
}
public long getStarttime() {
return starttime;
}
public void setStarttime(long starttime) {
this.starttime = starttime;
}
public int getElapsetime() {
return elapsetime;
}
public void setElapsetime(int elapsetime) {
this.elapsetime = elapsetime;
}
package Quickhit;
import java.util.Random;
public class Test {
/**
* 种子固定 随机数也固定 伪随机数 如果不传入种子参数的话 那么种子为 当前时间
*
* nextInt(n) 如果传入参数 则产生的随机数在0<= 和
* @param args
*/
/*public static void main(String[] args) {
/*
* Random random = new Random(); for (int i = 0; i < 5; i++) { boolean
* a=random.nextBoolean(); System.out.println(a);
*/
/*Player player = new Player();
player.play();
System.out.println("游戏结束");
}*/
public void add(int i) throws NullPointerException{
if(i==0)
throw new NullPointerException();//已经到这里了所以捕获到了 返回捕获异常
System.out.println("add出现异常");
}
public static void main(String[] args) {
Test t = new Test();
try{
t.add(0);
System.out.println("add方法返回");
}catch(Exception e){
System.out.println("捕获异常");
}
}
}