👺 Reading guide
Recently, Feixue is brushing Java. After all, his studies are coming. He has to consider the road behind. It doesn't make sense to be a back-end person who doesn't understand the basics of Java and learn several mainstream frameworks. Then I tried to write the king glory Locke Kingdom simulation game that I, a novice Java, can complete. For the time being, the front end has not been added. After painting the framework, I will add it. Well, we don't talk much nonsense. Let's have a look
👺 Project introduction
The project uses MVC+DAO mode, which is also a popular mode at present.
MVC means
letter | Express meaning |
---|---|
M | Model, model layer, Java Bean |
V | view layer, servlet and jsp front-end page |
C | controller control layer |
DAO is the data persistence layer.
The whole project has no features. Its only feature is that it is simple and has a large amount of code. The attached video is especially suitable for novices, and the content also covers some technologies such as radiation, regular expression and so on.
There are many Java classes in each package
👺 Function introduction
It is emphasized that the names in the introduction are not malicious, but I was deeply attracted by them in the era of awakening during my creation.
King glory Locke Kingdom simulation game 1,System requirements: User: 1,Login enter the user name and password to log in 2,Select heroes to play Including: Hero type, hero attack value and attack hit rate The current types are Daji and Diao Chan 3,After the game starts, the hero launches an attack and calculates the score according to the hero's attack value and hit rate 4,The score can be recorded at the end of the game 5,You can view previous game scores
Administrator: 1,Login default user name: admin Password: 123 ,Late from XML Read from file If the user name and password are entered incorrectly three times, you will exit the game 2,New players 3,Modify player 4,Delete player 5,Query player 6,Query game 7,Score statistics 8,Parameter setting
2,System interface: 1,home page ~~~~~~~~~~~~~~~Menu interface~~~~~~~~~~~~~~~~~~ Locke Kingdom version of the king's glory 1.Player login 2.Administrator login 3.sign out ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please enter the value before you want to select the mode:
2,Select "1. Player login" ****************************************************** Player login Please enter user name: Please input a password: ****************************************************** If the user name and password are entered correctly (the administrator needs to add players) The interface appears as follows: Congratulations on your successful login!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ King glory Locke Kingdom Edition 1·Start the game 2·View results 0·Return to superior ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please select:
 2.1 Start the game  Your selection succeeded!  Start the game!  Welcome to the king's glory Locke Kingdom virtual screen  Daji: there are three main spell attack skills  Skill 1: Monthly blade attack value 100  Skill 2: enchantment attack value 150  Skill 3: Battle of the fox attack value 300  Please enter the skills you want to use:  1  Skill: Moon blade  Description: deals spell damage to enemies   Great, teach the opposite side to be a man!
  Daji: there are three main spell attack skills  Skill 1: Monthly blade attack value 100  Skill 2: enchantment attack value 150  Skill 3: Battle of the fox attack value 300  Please enter the skills you want to use:  2   Oh, I missed mine!    Daji: there are three main spell attack skills  Skill 1: Monthly blade attack value 100  Skill 2: enchantment attack value 150  Skill 3: Battle of the fox attack value 300  Please enter the skills you want to use:  3  Skill: Fox war  Description: deals spell damage to places+Acceleration and deceleration effect   Success is God! 
 Your score at the end of the attack: 400  Continue?(Yes or no)  2.2 View results Game time fraction 2021-08-07 00:00:00.0 600 2021-08-08 07:56:37.0 450 2021-08-08 16:38:03.0 400 1,Return to superior  2.3 Return to superior Return to home page
3,Select "2. Administrator login" ****************************************************** Administrator login Please enter user name: Please input a password: ****************************************************** If the user name and password are entered correctly (the default is admin) The interface appears as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1·New players 2·Modify player 3·Delete player 4·Query player 5·Query game hero 6·Score statistics 7·Parameter setting 0·Return to superior ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you enter the wrong password three times, you will exit the game. The system will be shut down
 3.1 New players New players: Please enter the player's login name: (it must have letters and be unique in the system) Please enter the player's password: (there must be letters and numbers, and at least 6 characters) Please enter the player's nickname: Please enter the gender of the player: (male or female only) Please enter the age of the player: (only positive integers can be entered, and the maximum can not be greater than 99) New player succeeded! 1,Continue to add players 0,Return to superior
 3.2 Modify player Please select the player to modify: 1,xx1 2,xx2 3,xx3 4,XX4 Select "1" to modify xx1 Select the attribute to modify: 1,Player's password: (must have letters and numbers, and at least 6 digits) 2,Player's nickname: 3,Gender of player: (only male or female can be entered) 4,Player's age: (only positive integers can be entered, and the maximum can not be greater than 100) 0,Return to superior
 3.3 Delete player Please select the player to delete: 1,xx1 2,xx2 3,xx3 4,XX4 Select "1" to delete xx1 You cannot delete after deleting all 0,Return to superior
 3.4 Query player  1·Query all players  2·Search by login name  0·Back off  loginname nickname sex age  writer better known as Lu Xun Lu Xun male 18  Ah Xiu leader male 20  Li Dazhao stick to tradition male 19  123a Fertilizer science male 23 0,Return to superior ********************************************************************
 3.5 Query game hero ******************************************************************************* Hero name: Daji Skill 1: Moon blade attack power: 100 hit rate: 90 Second skill: Charm attack power: 150 hit rate: 80 Three skills: Fox war attack power: 300 hit rate: 60 Hero name: Diao Chan One skill: Solo attack: 90 hit rate: 90 Second skill: slander and seduction attack power: 150 hit rate: 80 Three skills: worship the moon attack power: 200 hit rate: 80
 3.6 Score statistics game player Total score Combat power index  Zhou Shuren 1450 ¤¤¤¤¤
 3.7 Parameter setting  1·Login name of administrator  2·Administrator password  3·Maximum login times for administrators   The following is only for hero details  hero ID: 1 Hero name: Daji  Skill 1 damage value: 100: Hit rate: 90  Skill 2 damage value: 150: Hit rate: 80  Skill 3 damage value: 300: Hit rate: 60  ~~~  hero ID: 2 Hero name: Diao Chan  Skill 1 damage value: 90: Hit rate: 90  Skill 2 damage value: 150: Hit rate: 80  Skill 3 damage value: 200: Hit rate: 80  ~~~ 4,Select "0, exit" The system prompts "the game is over..." and the system is closed
👺 Established data sheet
Partial code display
public class AdminManager { /** * Sign in * @throws SQLException */ // DBUtil db=new DBUtil(); SysManager sm=new SysManager(); PlayerDao pd=new PlayerDao(); GameDao gd=new GameDao(); public boolean AdminOperate() 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 your successful login!!!\n\n"); //Loop through the administrator interface so that if you don't press 0, you won't return to the previous layer boolean feixue=true; while(feixue) { int c=Menu.getAdminUI(); feixue=this.adminOperate2(c); } } else { System.out.println("Please log in again!"); if(DataInit.login.getLogintime()-i>0) { System.out.println("You can also enter"+(DataInit.login.getLogintime()-i)+"second"); } } } return b; }
//Game process public void play() throws SQLException { System.out.println("Welcome to the king's glory Locke Kingdom virtual screen"); int score=0; //Select hero hero h=heros; for(int i=0;i<3;i++){ score=this.selectSkill(h)+score; System.out.println("\n"); } System.out.println("The attack is over"+player.get("nickname")+"Your score:"+score); //Save game records Game game=new Game(); game.setPid(Integer.parseInt(player.get("id"))); game.setScore(score); gd.insertGame(game); } //Skill display public int selectSkill(hero h) { //Generate random number double ran=Math.random()*10; //Show each hero's skills h.display(); System.out.println("Please enter the skills 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 the opposite side to be a man!"); return h.skill1; }else { System.out.println("\n Oh, 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 Oh, I missed mine!"); } break; case 3: int pro3 =h.probability3/10; if(ran<=pro3) { h.skill3(); System.out.println("\n Success is God!"); return h.skill3; }else { System.out.println("\n Brother, you are not skilled!"); } break; default: System.out.println("Please enter the correct skills!"); } return 0; }
public class GameDao { DBUtil db=new DBUtil(); //The new game starts again public int insertGame(Game game) throws SQLException { //now() has its own function to obtain the current time of the file 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 own 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 game player,sum(b.score) as Total score,case " +" when sum(b.score)>=500 then '¤¤¤¤¤' " +" when sum(b.score)>=400 and sum(b.score)<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); return heros; } }
👺 Particular attention
In addition, if you want to obtain the basic knowledge and resources of MySQL, you can come here to have a look: Portal The source code will be sent to csdn later. If you need to practice urgently, you can send a private letter first. I'll send it to you separately first.
If you have any questions, you can send me a private letter and recommend some good columns to you
📣 Xiaobai training column is suitable for newcomers who have just started. Welcome to subscribe Programming Xiaobai advanced
📣 The interesting Python hand training project includes interesting articles such as robot awkward chat and spoof program, which can make you happy to learn python Training project column
📣 In addition, students who want to learn java web can take a look at this column: Teleporters
📣 This is a sprint big factory interview and competition algorithm practice, let's cheer together The way ashore
Click to receive the data directly
There are python, Java learning materials, interesting programming projects and various resources that are hard to find. It's not a loss to look at it anyway.