“This is the 24th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

๐Ÿ‘บ takeaway

Recently fat in brush Java after all, studies will have to consider the road behind ah, do not understand the backend Java foundation and learn several mainstream framework how can not say past it. Then I tried to write me this Java novice can complete the king of Glory Rock Kingdom version of the simulation game has not added the front end for the time being, after finishing brushing the frame in the back. All right, let’s cut to the chase

๐Ÿ‘บ Project Introduction

The project uses the MVC+DAO pattern, which is a popular pattern at present. MVC means

The letter Said meaning
M Model, model layer, Javabeans
V View view layer, servlet and JSP front-end page
C The controller control layer

DAO is the data persistence layer. The whole project is very featureless,Its only characteristic is a large amount of simple code with video especially suitable for beginners to practiceIt also covers radiation, regular expressions, and other techniques.

There are many Java classes in each package

๐Ÿ‘บ Function Description

I would like to emphasize that there is no malice in the names that appear in the introduction, but I was personally drawn to them during the creation of Age of Awakening.

King of Glory Lok kingdom version simulation game1System requirements: Users:1Login Enter the user name and password for login2, the selection of heroes for the game includes: hero type, hero attack value, attack hit rate currently type: Daji and Diao Chan3, after the game began, the hero launched an attack, according to the hero's attack value and hit ratio, calculate the score4The score can be recorded after the game is over5, you can view previous game scoresCopy the code
Administrator:1Default user name: admin Password:123, later read the user name and password from the XML file three times wrong input, exit the game2New players3Modify the player4Delete players5, query the player6, query games7Score statistics8, parameter settingCopy the code
2, System interface:1, homepage ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ menu interface ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ the king of glory Locke kingdom1.Players to log in2.Administrator Login3.Quit ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ please enter before you want to choose model number:Copy the code

2, select the"1And gamers "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * players to log in Please enter the user name: please enter a password: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if the user name and password input the correct (need the administrator to add players) appear interface is as follows: congratulations to log in successfully!Copy the code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ King of Glory Rock Kingdom edition1ยท Start the game2ยท View grades0ยท Return to superior ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please select:Copy the code
๏ƒ˜	2.1๏ƒ˜ you open the game to select success! ๏ƒ˜ Begin the game! ๏ƒ˜ welcome to the virtual screen of King of Glory Lok Kingdom Version ๏ƒ˜ Daji: the main magic attack skill ๏ƒ˜ skill ONE: moonblade attack value100๏ƒ˜ Skill II: Charm attack value150๏ƒ˜ Skill THREE: Fox wound attack value300๏ƒ˜ please enter the skill you want to use: ๏ƒ˜1๏ƒ˜ Skill: Moonblade ๏ƒ˜ description: ๏ƒ˜ inflicted spell damage on the enemy. Terrific.Copy the code
๏ƒ˜ Daji: There are three ๏ƒ˜ skills: Moonblade attack value100๏ƒ˜ Skill II: Charm attack value150๏ƒ˜ Skill THREE: Fox wound attack value300๏ƒ˜ please enter the skill you want to use: ๏ƒ˜2๏ƒ˜ blimey, knock off my my! ๏ƒ˜ Daji: There are three ๏ƒ˜ skills: Moonblade attack value100๏ƒ˜ Skill II: Charm attack value150๏ƒ˜ Skill THREE: Fox wound attack value300๏ƒ˜ please enter the skill you want to use: ๏ƒ˜3๏ƒ˜ Skill: The Collapse of the Dog describes: ๏ƒ˜ skill: ๏ƒ˜ damage the place with spell + acceleration and deceleration effect. ๏ƒ˜Copy the code
๏ƒ˜ attack end Lu Xun your score:400๏ƒ˜ whether to continue? ๏ƒ˜ or not2.2View score game time score2021- 08 -07 00:00:00.0		600
2021- 08-0807:56:37.0		450
2021- 08-0816:38:03.0		400
1๏ƒ˜2.3Return to Superior Return to the home pageCopy the code

3, select the"2, the administrator login "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * administrator login Please enter the user name: please enter a password: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if the user name and password input the correct (default is admin) appear interface is as follows: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~1ยท New players2ยท Modify the player3ยท Delete players4ยท Query players5ยท Search for game heroes6ยท Score statistics7ยท Parameter setting0, return to the superior ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ if you mistyped your password three times, out of the game. System shut downCopy the code


๏ƒ˜	3.1New Player New player: Please enter the player's login name: (must have letters and be unique in the system) Please enter the player's password: (must have at least letters and numbers6Bit) Please enter player's nickname: Please enter player's gender: (male or female only) Please enter player's age: (Positive integer only, and the maximum value cannot be greater than99New player added successfully!1Continue to add new players0Return to the upper levelCopy the code

๏ƒ˜	3.2Please select the player you want to modify:1, xx12, xx23, xx34, XX4 choose"1"Modify XX1 Select the property to modify:1Player password :(must have letters and numbers, at least not less6A)2, player's nickname:3, player's gender :(male or female only)4, player's age :(only positive integers can be entered, and the maximum value cannot be greater than100)0Return to superiorCopy the code


๏ƒ˜	3.3Please select the player to delete:1, xx12, xx23, xx34, XX4 choose"1"Delete XX1 After all deletion, it cannot be deleted again0Return to superiorCopy the code

๏ƒ˜	3.4Query player1๏ƒ˜ Query all players2ยท Search ๏ƒ˜ according to the login name0๏ƒ˜ loginname nickname sex age ๏ƒ˜ Shu Lu Xun male18๏ƒ˜ SHOWo leader male20๏ƒ˜ Li Dazhao defends chang Male19๏ƒ˜ 123a Fat Man23


0And return back to the higher * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Copy the code


๏ƒ˜	3.5Query hero game * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * hero name: da ji a skill: on blade damage to:100Shooting:90Two skills: Charm Attack:150Shooting:80Three skills: Fox's Wounds300Shooting:60Hero Name: Diao Chan skill: Solo Attack:90Shooting:90Two skills: Slanderous attack:150Shooting:80Three skills: Worship the moon200Shooting:80
Copy the code

๏ƒ˜	3.6Score statistics player total score combat force index ๏ƒ˜ Zhoushuren1450Because problem because problem problemCopy the code

๏ƒ˜	3.7Parameter setting ๏ƒ˜1ยท Administrator's login name2ยท Administrator password3๏ƒ˜ hero ID is presented only in the following manner:1๏ƒ˜ Hero: Daji skill - damage value:100: Hit ratio:90๏ƒ˜ Skill two Damage value:150: Hit ratio:80๏ƒ˜ Skill three damage value:300: Hit ratio:60๏ƒ˜ ~~~ hero ID:2๏ƒ˜ hero: Diao Cicada Skill One damage value:90: Hit ratio:90๏ƒ˜ Skill two Damage value:150: Hit ratio:80๏ƒ˜ Skill three damage value:200: Hit ratio:80๏ƒ˜ ~ ~ ~4, select the"0The system prompts "Game over..." System shut downCopy the code

The data table created by ๐Ÿ‘บ

Part of code display

public class AdminManager {
	/** * login *@throws SQLException 
	 */
	//
	DBUtil db=new DBUtil();
	SysManager sm=new SysManager();
	PlayerDao pd=new PlayerDao();
	GameDao gd=new GameDao();
	public boolean AdminOperate(a) throws SQLException {
		boolean b=false;
		for(int i=0; i<DataInit.login.getLogintime(); i++) { Login login=Menu.getLoginUI(); b=this.checkoutLogin(login);
			if(b) {
				System.out.println("Congratulations on login!! \n\n");
				// Loop through the admin interface so that you do not return to the previous level until you press 0
				boolean feixue=true;
				while(feixue) {
				int c=Menu.getAdminUI();
				
				feixue=this.adminOperate2(c); }}else {
				System.out.println("Please log back in!");
				if(DataInit.login.getLogintime()-i>0) {
					System.out.println(I can also type in+(DataInit.login.getLogintime()-i)+"Time"); }}}return b;
	}
Copy the code
// The game process
	public void play(a) throws SQLException {
		System.out.println("Welcome to king of Glory Rourke Kingdom Virtual screen.");
		int score=0;
		// Select the hero
		hero h=heros;
		for(int i=0; i<3; i++){ score=this.selectSkill(h)+score;
		System.out.println("\n");
		}
		System.out.println("Attack over."+player.get("nickname") +"Your score:"+score);
		// Save the game record
		Game game=new Game();
		game.setPid(Integer.parseInt(player.get("id")));
		game.setScore(score);
		gd.insertGame(game);
	}
	
	// Show your skills
	public int selectSkill(hero h) {
		// Generate a random number
		double ran=Math.random()*10;
		// Display each hero's skills
		h.display();
		System.out.println("Please enter the skill you want to use:");
		int s=InputHelper.getInt();

		switch(s) {
		case 1:
			
			int pro1 =h.probability1/10;
			if(ran<=pro1) {
				h.skill1();
				System.out.println("\n Great teach opposite person!");
				return h.skill1;
			}else {
				System.out.println("\n Oops, missed!");
			}
			break;
		case 2:
			
			int pro2 =h.probability2/10;
			if(ran<=pro2) {
				h.skill2();
				System.out.println("\n666");
				return h.skill2;
			}
			else {
				System.out.println("\n Oops, miss my my!");
			}
			break;
		case 3:
			int pro3 =h.probability3/10;
			if(ran<=pro3) {
				h.skill3();
				System.out.println("\n Success super god!");
				return h.skill3;
			}else {
				System.out.println("\n eldest brother your technique is no good!");
			}
			break;
		default:
			System.out.println("Please enter the correct skill!");
		
		}
		return 0;
	}
	
Copy the code
public class GameDao {
	DBUtil db=new DBUtil();
	// A new game is a restart
	public int insertGame(Game game) throws SQLException {
		// The now () function gets the current file time
		String sql="insert into wzry_game(pid,playtime,score) values(? ,now(),?) ";
		Object[] obj= {game.getPid(),game.getScore()};
		return db.upDate(sql, obj);
	}
	// Players query their game records
	public List<Map<String,String>> queryGameByPid(int id) throws SQLException{
		String sql="select b.*,a.loginname from wzry_player a,wzry_game b where a.id=b.pid and pid=?";
		Object[] obj= {id};
		List<Map<String,String>> list=db.query(sql, obj);
		return list;
	}
	/ / query
	public List<Map<String,String>> queryAllGame() throws SQLException{
		String sql="select b.*,a.loginname from wzry_player a,wzry_game b where a.id=b.pid";
		List<Map<String,String>>list=db.query(sql, null);
		
		return list;
		
	}
	// Score statistics
	
	public List<Map<String,String>> queryGameScore() throws SQLException {
		String sql=Select a.loginname as player,sum(b.core) as total score,case"
		            +"When sum(b.core)>=500 then 'ยคยคยคยค'"
				    +"When sum(B.core)>=400 and sum(B.core)<500 then 'ยคยคยค' else 'ยคยค' end 'lucky'"
		            +" from wzry_player as a inner join wzry_game as b on a.id=b.pid"
					+" group by a.loginname";
		
		return db.query(sql, null);
	}
	// Query all heroes
	public List<Map<String,String>> queryAllHeros() throws SQLException{
		String sql="select * from heros";
		List<Map<String,String>> heros=db.query(sql, null);
		returnheros; }}Copy the code

๐Ÿ‘บ pay special attention

In addition, if you want to get the basic knowledge and resources of MySQL, you can go to the home page of my information, the source code is also in it