JAVA简单的打字游戏


package type_Game;

 

import java.util.Scanner;

 

public class Player {

    private int rank;//当前级别

    private int currScore;//分数

//    private String startTime;//开始时间

//    private String elapseTime;//所用时间

    

    public Player () {}

 

    public Player(int rank, int currScore) {

        super();

        this.rank = rank;

        this.currScore = currScore;

//        this.startTime = startTime;

//        this.elapseTime = elapseTime;

    }

    public void Score() {

        int flag = 1;

        String s = "";

        Scanner sc = new Scanner(System.in);

        while(flag == 1 && this.rank < 7) {

            for (int i = 0;i<rank;i++){

                s += (char)(Math.random()*26+'A');//随等级的增加 增加字母数量

            }

            System.out.println("*******请输入和下面相同的字符********");

            System.out.println("*******" + s + "********");

            long startTime=System.currentTimeMillis();   //获取开始时间  

            String a = sc.next();

            long endTime=System.currentTimeMillis(); //获取结束时间 

            if (s.equals(a)) {                 //判断字母与输入的字符是否相等,相等则进入循环,加分进入下一个等级

                this.currScore = this.currScore + 10 ;

                System.out.println("*******输入正确,你的分数为"+this.currScore+"您的级别为"+this.rank);

                System.out.println("*******所用时间为" + (endTime - startTime) /1000 + "秒");

                this.rank++;//等级+1

                flag = 1;//表示没有输入错误,循环继续

                s = "";//清空字符串s

                if (this.rank > 6) {

                    System.out.println("*******恭喜你,你的手速已经天下无敌了,没人比得过你,你已通关!!!!!!!!!");

                }

            }else if(!s.equals(a)) {

                System.out.println("**********对不起你输入错误,游戏结束!!!!********");

                flag = 0;//表示输入错误,循环结束

            }

        }

        

        

    }

   

}

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值