Javaoop Fifth Chapter

Source: Internet
Author: User
 player class 
Package Bao;
	Import Java.util.Scanner; Player class public class player {private int levelno;//player current level number private int curscore;///player current level integral private long strattime;//
		Current level start time private int elapsetime;//current level time/package public int Getlevelno () {return levelno;
		The public void Setlevelno (int levelno) {this.levelno = Levelno;
		public int Getcurscore () {return curscore;
		The public void Setcurscore (int curscore) {this.curscore = Curscore;
		Public long Getstrattime () {return strattime;
		} public void Setstrattime (long strattime) {this.strattime = Strattime;
		public int Getelapsetime () {return elapsetime;
		The public void setelapsetime (int elapsetime) {this.elapsetime = Elapsetime;
		//Player to play the game method public void plays () {Game game=new Game (this);
		Scanner input=new Scanner (system.in);
			The outer layer is broken once, the game promotion first level for (int i = 0; i < Levelprogram. levels.length; i++) {//qualify for this.levelno+=1; After the promotion time clear zero, points 0 This.strattime=system.currEnttimemillis ();
			this.curscore=0; Inner Loop completes once at a time string output input comparison for (int j = 0; J < Levelprogram. Levels[levelno-1].getstrtime (); j + +) {string Outstr=gam
				E.printstr ();
				System.out.println (OUTSTR);
				String Instr=input.next ();
			Game.printresult (Outstr, InStr);
 }
		}
		}


		

		
		

}



Game class

Package Bao;
Game class import Java.util.Random;
	public class Game {private player player;
	Public Game (player player) {This.player=player;
		Public String Printstr () {StringBuffer buffer=new stringbuffer ();
		Random random=new Random ();
			Generates the string for output by looping for (int i = 0; I <2; i++) {int rand=random.nextint (2);
				Concatenation of strings by random number 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
		} return buffer.tostring (); } public void Printresult (String out,string in) {if (Out.equals (in)) {long Time=system.currenttim
    		Emillis ();
				if ((Time-player.getstrattime ())/1000>levelprogram.levels[player.getlevelno () -1].gettimelimit ()) {
				System.out.println ("You enter too slow, have timed out, quit");
			System.exit (1); }else {
				Current FETCH score Player.setcurscore (Player.getcurscore () + Levelprogram.levels[player.getlevelno ()-1].getperscore ());
				Player.setelapsetime ((int) (Time-player.getstrattime ())/1000);
				int Levelno=player.getlevelno ();
				int Score=player.getcurscore ();
				int Elapsedtime=player.getelapsetime (); SYSTEM.OUT.PRINTLN ("Input is correct, your level" +levelno+ "Your Integral" +score+ "has been spent" +elapsedtime+ "seconds.
				");
					if (levelno==6) {System.out.println ("Game Over");
				System.exit (1);
			}}else{System.out.println ("Input error, exit");
		System.exit (1);
 }
    	
    }
    
}

                                                              level

Package bao;//class public class levels {private int levelno;//level number private int strlength;//each level output string length private int strtime;//the number of output strings at each level private int timelimit;//The time limit for entry at various levels private int perscore;//the score//package public int at each level correctly Getleveln
	O () {return levelno;
	The public void Setlevelno (int levelno) {this.levelno = Levelno;
	public int getstrlength () {return strlength;
	The public void setstrlength (int strlength) {this.strlength = Strlength;
	public int Getstrtime () {return strtime;
	The public void setstrtime (int strtime) {this.strtime = Strtime;
	public int Gettimelimit () {return timelimit;
	The public void settimelimit (int timelimit) {this.timelimit = TimeLimit;
	public int Getperscore () {return perscore;
	The public void Setperscore (int perscore) {this.perscore = Perscore;
	}//Parameterless construct public level () {}///The parameter construct public level (int levelno,int strinlength,int strtime,int timelimit,int perscore)
		{This.levelno=levelno; This.strlength=striNlength;
		This.strtime=strtime;
		This.timelimit=timelimit;
	This.perscore=perscore; }
}
Package Bao;







public class Levelprogram extends level {

	
//Inherit parent class parameterless construct public
	Levelprogram () {
		super ();
		TODO auto-generated constructor stub
	}
//Inherit parent class with parameter construct public
	levelprogram (int levelno, int strinlength, int Strtime,
			int timelimit, int perscore) {
		super (Levelno, Strinlength, Strtime, TimeLimit, perscore);
		TODO auto-generated constructor stub
		
		} 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,14,10);
		Levels[5]=new level (6,7,5,10,15);
	}

Test class

Package Bao;

public class Test {

	/**
	 * @param args */public
	static void Main (string[] args) {
		//TODO Auto-generat Ed method stub
player player=new player ();
Player.play ();
	}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.