博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
快速击键
阅读量:6193 次
发布时间:2019-06-21

本文共 5713 字,大约阅读时间需要 19 分钟。

public class Level {    private int levelNo;// 各级别编号    private int strLength;// 各级别一次输出字符串的长度    private int strTimes;// 各级别输出字符串的次数    private int timeLimit;// 各级别闯关的时间限制    private int perScore;// 各级别正确输入一次的得分    public int getLevelNo() {        return levelNo;    }    public void setLevelNo(int levelNo) {        this.levelNo = levelNo;    }    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 getTimeLimit() {        return timeLimit;    }    public void setTimeLimit(int timeLimit) {        this.timeLimit = timeLimit;    }    public int getPerScore() {        return perScore;    }    public void setPerScore(int perScore) {        this.perScore = perScore;    }    public  Level() {        super();    }    public Level(int levelNo, int strLength, int strTimes, int timeLimit,            int perScore) {        super();        this.levelNo = levelNo;        this.strLength = strLength;        this.strTimes = strTimes;        this.timeLimit = timeLimit;        this.perScore = perScore;    }}
import java.util.Scanner;/** * 玩家类 * @author accp * */public class Player {    private int levelNo;   //等级    private int curScore;   //积分    private int elapsedTime; //已用时间    private long startTime;  //开始时间            public Player() {            }            public Player(int levelNo, int curScore, int elapsedTime, long startTime) {        this.levelNo = levelNo;        this.curScore = curScore;        this.elapsedTime = elapsedTime;        this.startTime = startTime;    }    public int getLevelNo() {        return levelNo;    }    public void setLevelNo(int levelNo) {        this.levelNo = levelNo;    }    public int getCurScore() {        return curScore;    }    public void setCurScore(int curScore) {        this.curScore = curScore;    }    public int getElapsedTime() {        return elapsedTime;    }    public void setElapsedTime(int elapsedTime) {        this.elapsedTime = elapsedTime;    }    public long getStartTime() {        return startTime;    }    public void setStartTime(long startTime) {        this.startTime = startTime;    }        public void play()    {        Game game=new Game(this);//this代表已经创建了的对象引用player        //外层循环,循环一次级别进一级        for (int i = 0; i < LevelParam.levels.length; i++) {            this.levelNo+=1;            //晋级后,记时清零,积分清零            this.startTime=System.currentTimeMillis();            this.curScore=0;            //内层循环,循环一次完成一次字符串的输出,输入,比较。它的限制参数是输出字符串的次数            for (int j = 0; j 
import java.util.Date;import java.util.Random;/** * 游戏类 * @author accp * */public class Game {    private Player player;    public Game() {            }        public Game(Player player) {        this.player = player;    }    public Player getPlayer() {        return player;    }    public void setPlayer(Player player) {        this.player = player;    }        //输出字符串用于和玩家的输入进行比较    public String printStr()    {        //获取当前玩家级别的字符串长度        int strLength=LevelParam.levels[player.getLevelNo()-1].getStrLength();        StringBuffer buffer=new StringBuffer();        Random random=new Random();        for (int i = 0; i < strLength; i++) {            int rand=random.nextInt(strLength);            switch (rand) {            case 0:                buffer.append(">");                break;            case 1:                buffer.append("<");                break;            case 2:                buffer.append("*");                break;            case 3:                buffer.append("&");                break;            case 4:                buffer.append("*");                break;            case 5:                buffer.append("#");                break;            default:                break;            }                    }        String result=buffer.toString();        return result;    }    //比较结果,输出相应信息    public void printResult(String out,String in)    {        if (out.equals(in)) {            //正确输入            Date date=new Date();            long currentTime=date.getTime();            //如果超时            long closeTime=LevelParam.levels[player.getLevelNo()-1].getTimeLimit();            if ((currentTime-player.getStartTime())/1000>closeTime) {                System.out.println("你输入的太慢了,已经超时,退出!");                System.exit(1);            }            else            {                //计算当前玩家积分                //所有的积分相加            player.setCurScore(player.getCurScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());            int score=player.getCurScore();//获取数组内的开始积分            int time=(int)(currentTime-player.getStartTime())/1000;//获取时间差            player.setElapsedTime(player.getElapsedTime()+time);            int alltime=player.getElapsedTime();            int no=player.getLevelNo();            System.out.println("输入正确,您的级别"+no+",您的积分"+score+",已用时间"+alltime+"");            }        }else{            System.out.println("输入错误 !!!,退出");            System.exit(1);            }                                }}
public class LevelParam {     public final static Level levels[]=new Level[6];     static{         levels[0]=new Level(1,2,10,30,1);         levels[1]=new Level(2,3,9,26,2);         levels[2]=new Level(3,4,8,22,5);         levels[3]=new Level(4,5,7,18,8);         levels[4]=new Level(5,6,6,15,10);         levels[5]=new Level(6,7,5,12,15);     }}
public class Test {    public static void main(String[] args) {                Player player=new Player();        player.play();}}

转载于:https://www.cnblogs.com/kai123-qwe/p/6669518.html

你可能感兴趣的文章
给Easyui combobox设定默认值
查看>>
动画效果(兼容各个浏览器)
查看>>
sql点滴42—mysql中的时间转换
查看>>
【推荐系统论文笔记】个性化推荐系统评价方法综述(了解概念——入门篇)...
查看>>
使用 CJSON 在C语言中进行 JSON 的创建和解析的实例讲解
查看>>
J2EE之验证码实现
查看>>
TokuDB 引擎安装测试
查看>>
【转】Java 项目UML反向工程转化工具
查看>>
How to Design Programs, Second Edition
查看>>
[puppet]如何设置全局exec path
查看>>
用jQuery实现一些导航条切换,显示隐藏
查看>>
Fix java version mismatch in windows---stackoverflow
查看>>
39. Combination Sum
查看>>
Android 5中不同效果的Toast
查看>>
yii 10.16
查看>>
python3.4学习笔记(四) 3.x和2.x的区别,持续更新
查看>>
SPOJ QTREE4 lct
查看>>
音乐还在陪伴我
查看>>
Sql Server参数化查询之where in和like实现详解
查看>>
高性能负载均衡之分类架构
查看>>