In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Java how to achieve the classic Tetris game, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Preface
Tetris is a puzzle video game originally designed and programmed by Alexei Pajitnov in the Soviet Union.
The basic rule of Tetris is to move, rotate, and place the various squares automatically output by the game, so that they are arranged into a complete one or more lines and eliminate scores.
It is implemented in java language, the interface processing is carried out by using swing technology, and the object-oriented idea is used in the design.
Main demand
Plates of different shapes composed of small squares fall from the top of the screen one after another, and players adjust the position and direction of the plates to make them form a complete one or more at the bottom of the screen. These complete stripes will then disappear, making room for the newly fallen plate, while players will be rewarded with points. Squares that have not been eliminated continue to pile up, and once they reach the top of the screen, the player loses and the game is over.
Main design
1. Use the keyboard to move "←" to the left, "→" to the right, "↑" to rotate the square, and ↓ to drop the square (the square falls to the bottom)
2. Once heaped to the top of the screen, the game is over
3. Design different squares
4. The falling speed of the design box
5. Design the score system
Function screenshot
Game launch page
Start the game.
Game over
Code implementation
Window design class
Public class Windows extends JFrame {private Toolkit took = null; private static int width= 470; / / wide private static int height = 680; / / High private static int width_g = 10; / / Game area private static int height_g = 22; / / private static int size = 30; / / Square size private static int space= 10 / / coordinate distance boundary interval Map map = new Map (width_g,height_g); / / Map coordinates ArrayList ds = new ArrayList (); / / Square array private boolean game=false; / / Game start private int flag = 0; / / Game status [pause: 0, continue: 1] private JLabel jl2; private JButton jb1 Private int speed = 500; / / Speed private int score = 0; / / score private int [] scores = new int [4]; / / ranking public static void main (String [] args) {Windows win = new Windows (); win.run () } public void run () {init (); try {while (true) {if (game&&flag==1) {ds.get (ds.size ()-2) .Movement (map) If (! ds.get (ds.size ()-2). IsStatus () {/ / judge whether the game fails if (ds.get ((ds.size ()-2)) .getY ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.