public class leve {
private int leveNo;
private int strLength;
private int strTimes;
private int timeLimit;
private int perScore; public leve(int leveNo, int strLength, int strTimes, int timeLimit,
int perScore) {
super();
this.leveNo = leveNo;
this.strLength = strLength;
this.strTimes = strTimes;
this.timeLimit = timeLimit;
this.perScore = perScore;
}
public leve() {
super();
}
public int getLeveNo() {
return leveNo;
}
public void setLeveNo(int leveNo) {
this.leveNo = leveNo;
}
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;
} }

Leve

首先编写类,游戏类,玩家类,级别类
玩家类的属性:levelNo玩家编号类,currScore玩家当前积分,stratTime当前级别开始时间,elapsedTime
当前级别已用时间
级别类的属性:levelNo各级别编号,strLengh一次输入的字符串长度,strTime各级别输出字符串的次数,timeLimit各级闯关的时间限制
perScore各级别输入一次正确的得分!
游戏类:player玩家属性(玩家来玩游戏)
因为级别类不包括各个级别的具体参数信息,所以增加一个levelParam类,创建一个长度为6的数组,存放各个级别的参数信息

游戏类Game

public class Game {

    public Player player;

    public Game(Player player) {
super();
this.player = player;
} public Game() {
} public Player getPlayer() {
return player;
} public void setPlayer(Player player) {
this.player = player;
}
Random random = new Random();
public String printstr(){
StringBuffer buffer = new StringBuffer(); int str =Levelparam.leves[player.getLevelNo()-].getStrLength(); for (int i = ; i < str; i++) {
int rand = random.nextInt(str);
switch(rand){
case :
buffer.append("w");
break;
case :
buffer.append("s");
break;
case :
buffer.append("a");
break;
case :
buffer.append("d");
break;
case :
buffer.append("h");
break;
case :
buffer.append("j");
break;
}
}
System.out.println(buffer.toString());
return buffer.toString();
} public void printReslut(String out, String jieshou)
{
if(out.equals(jieshou))
{
long time = System.currentTimeMillis();
//如果超时
if((time-player.getStartTime())/>Levelparam.leves[player.getLevelNo()-].getTimeLimit())
{
System.out.println("已超时,您的速度有待提高");
System.exit();
}
else
{
//当前说获得分值
player.setCurScore(player.getCurScore()+Levelparam.leves[player.getLevelNo()-].getPerScore());
//游戏所需时间
player.setElapsedTime((int)(time-player.getStartTime())/);
int Level = player.getLevelNo();
int score = player.getCurScore();
int usetime = player.getElapsedTime();
System.out.println("输入正确,您的级别是"+Level+"您的积分是"+score+"已用时间"+usetime);
if(Level==)
{
System.exit();
System.out.println("游戏结束");
}
}
}
else
{
System.out.println("游戏失败");
System.exit();
} } }

Came

Leve

public class leve {
private int leveNo;
private int strLength;
private int strTimes;
private int timeLimit;
private int perScore; public leve(int leveNo, int strLength, int strTimes, int timeLimit,
int perScore) {
super();
this.leveNo = leveNo;
this.strLength = strLength;
this.strTimes = strTimes;
this.timeLimit = timeLimit;
this.perScore = perScore;
}
public leve() {
super();
}
public int getLeveNo() {
return leveNo;
}
public void setLeveNo(int leveNo) {
this.leveNo = leveNo;
}
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;
} }

Leve

levelParam类

public class Levelparam {
public final static leve[] leves = new leve[];
static{
leves[]=new leve(,,,,);
leves[]=new leve(,,,,);
leves[]=new leve(,,,,);
leves[]=new leve(,,,,);
leves[]=new leve(,,,,);
leves[]=new leve(,,,,); }
}

levelParam

Player

public class Player {

    private int levelNo;
private int curScore;
private long startTime;
private int elapsedTime; 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 long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public int getElapsedTime() {
return elapsedTime;
}
public void setElapsedTime(int elapsedTime) {
this.elapsedTime = elapsedTime;
}
public void print(){ Scanner input = new Scanner(System.in);
Game game= new Game(this);//创建游戏实例 game.getPlayer().setLevelNo();
for (int i = ; i < Levelparam.leves.length; i++) { setLevelNo(getLevelNo()+);
this.curScore=;
System.out.println("恭喜你进入下一级别");
game.getPlayer().setStartTime(System.currentTimeMillis());//游戏开始,给Player的开始时间赋值
//内层循环
for(int j=;j<Levelparam.leves[game.getPlayer().getLevelNo()-].getStrTimes();j++)
{
String out=game.printstr();//接收游戏输出的字符串
String in=input.next();//接受玩家输入的字符串
game.printReslut(out,in);//判断 }
}
}
}

Player

Text

public class Test {
public static void main(String[] args) {
Player py = new Player();
py.print();
} }

Text

--首先game类(先有游戏才能玩):
方法有二:printStr()
       printResult()
1:printStr()方法:生成随机的字符串,使用switch选择结构以生成的随机数进行判断生成的字符串。字符串的长度不得大于各级别输出字符串的长度。
int strLength=LevelParam.levels[player.getLevelNo()-1].getStrLength();由于数组下标是从0开始的,获取该级别输入
的字符串的长度定位到数组中的一项要使用(级别号-1 )定位数组下标。创建一个0到5的随机数,创建StringBuffer对象来拼接字符串。该方法返回
一个拼接好了的字符串。
2:long time=System.currentTimeMillis();获取系统当前时间的毫秒数(严谨到毫秒)
(time-player.getStartTime())/1000>LevelParam.levels[player.getLevelNo()-1].getTimeLimit()如果游戏所用时间大于
游戏规定的时间,判断出局!
 player.setCurScore(player.getCurScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());加上当前获得的分数
        player.setElapsedTime((int)(time-player.getStartTime())/1000);计算玩游戏所需的时间
输出当前这一关的信息,当进行到第六个级别(最高级别)时,将级别清空,还原为1.
--Player类:创建游戏类(game对象),记录循环的次数,将级别初始为1.
game.getPlayer().setStartTime(System.currentTimeMillis())记录下游戏开始时间!
循环条件,小于输入次数,接收随机生成的字符串,如果用户输入的字符串与该字符串相等,继续游戏,否则,gameOver!
--Text类:直接调用player类的print()方法!

QuickHit项目(输出字符串游戏)的更多相关文章

  1. 通过游戏学python 3.6 第一季 第二章 实例项目 猜数字游戏--核心代码--猜测次数 可复制直接使用 娱乐 可封装 函数

      猜数字游戏--核心代码--猜测次数   #猜数字--核心代码--猜测次数 number=33 amount=3 count=0 while count<=amount: conversion ...

  2. 快速击键(MyEclipse编写的QuickHit项目)

    public class Level { private int levelNo;// 各级别编号 private int strLength;// 各级别一次输出字符串的长度 private int ...

  3. BZOJ2121 字符串游戏

    Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其 他一些字符串的集合S,然后他可以进行以下操作:对于一个在集合S中的字符串p,如果p在L中出现,BX就可以选择是否将其删 ...

  4. QuickHit 项目

    package cn.javaoppday01; import java.util.Random; public class Game { public Player player; public G ...

  5. BZOJ2121: 字符串游戏(DP)(字符串删单词,求最多可以删去多少)

    2121: 字符串游戏 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 672  Solved: 376[Submit][Status][Discuss ...

  6. 面向对象-QuickHit项目

    package com.ketang.game; /** * 游戏级别类 * @author * */ public class Level { private int levelNo; //各级别编 ...

  7. 20181228 模拟赛 T3 字符串游戏 strGame 博弈论 字符串

    3  字符串游戏(strGame.c/cpp/pas) 3.1  题目描述 pure 和 dirty 决定玩 T 局游戏.对于每一局游戏,有n个字符串,并且每一局游戏由K轮组成.具体规则如下:在每一轮 ...

  8. BZOJ 2121: 字符串游戏 区间DP + 思维

    Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其他一些字符串的集合S,然后他可以进行以下操作:对 于一个在集合S中的字符串p,如果p在L中出现,BX就可以选择是否将其删 ...

  9. 通过游戏学python 3.6 第一季 第三章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码 可复制直接使用 娱乐 可封装 函数

       猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码   #猜数字--核心代码--猜测次数--随机函数和屏蔽错误代码 import random secrst = random.rand ...

随机推荐

  1. 墙裂推荐4款js网页烟花特效

    以下是几款网页特效和一款软件: http://keleyi.com/keleyi/phtml/jstexiao/1.htm  http://keleyi.com/keleyi/phtml/jstexi ...

  2. 背水一战 Windows 10 (20) - 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换

    [源码下载] 背水一战 Windows 10 (20) - 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换 作者:webabcd 介 ...

  3. 微信JSApi支付~微信支付代理模式的实现(原创)

    返回目录 起因(大叔原创) 对于微信支付来说,你的发起者需要配置对应的域名来获取code(获取用户信息接口),而这意味着,你的多个项目(域名不同)不能同时使用一个公众号,这是一件很操蛋的事,对于我们开 ...

  4. PHP流程控制之循环结构

    计算机程序最擅长的功能之一就是按规定的条件,重复执行某些操作.循环结构可以减少源程序重复书写的工作量,即在给定条件成立时,反复执行某程序段,直到条件不成立为止.给定的条件称为循环条件,反复执行的程序段 ...

  5. Lind.DDD.Paging分页模块介绍

    回到目录 分页组件网上有很多,MVC.Pager,JSPager等,通过实现方式大体分为前端分页和后端分页,前端分页是前台对list内存本地集合进行分页,缺点就是在大数据情况下,内存占用过高:后端分页 ...

  6. [原创小工具]软件内存、CPU使用率监视,应用程序性能监测器 v3.0 绿色版

    应用程序性能监测器 V3.0 更新内容:    1.对一些代码进行了修改,软件本身的性能有所提升. 应用程序性能监测器 V2.0 更新内容:     1.鼠标移动到曲线区域,显示相关的曲线值      ...

  7. springmvc的类型转换

     一.springmvc的类型转换 (一)默认情况下,springmvc内置的类型转换器只能 将"yyyy/MM/dd"类型的字符串转换为Date类型的日期 情境一: 而现在我们无 ...

  8. [转载]C#使用Interlocked进行原子操作

    原文链接:王旭博客 » C# 使用Interlocked进行原子操作 什么是原子操作? 原子(atom)本意是"不能被进一步分割的最小粒子",而原子操作(atomic operat ...

  9. 2015年最佳的12个 CSS 开发工具推荐

    CSS所能做的就是改变网页的布局.排版和调整字间距等,但编写 CSS 并不是一项容易的任务,当你接触新的 CSS3 属性及其各自的浏览器前缀的时候,你会发现很伤脑经.值得庆幸的是一些优秀的开发人员提供 ...

  10. CSS学习

    标签选择器,标签名{},作用于所有此标签. 类选择器, .class{},在标签内定义class="",属图形结构. ID选择器,#ID{}, 在标签内定义id="&qu ...