Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java to realize Minesweeper Mini Game

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to use Java to achieve minesweeper Mini Game". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use Java to achieve minesweeper Mini Game" can help you solve the problem.

Effect display

Main class: GameWin class package com.sxt;import javax.swing.*;import java.awt.*;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;public class GameWin extends JFrame {int width = 2 * GameUtil.OFFSET + GameUtil.MAP_W * GameUtil.SQUARE_LENGTH; int height = 4 * GameUtil.OFFSET + GameUtil.MAP_H * GameUtil.SQUARE_LENGTH; Image offScreenImage = null; MapBottom mapBottom = new MapBottom (); MapTop mapTop = new MapTop () Void launch () {GameUtil.START_TIME=System.currentTimeMillis (); this.setVisible (true); this.setSize (width,height); this.setLocationRelativeTo (null); this.setTitle ("Java Minesweeping Mini Game"); this.setDefaultCloseOperation (EXIT_ON_CLOSE) / / Mouse event this.addMouseListener (new MouseAdapter () {@ Override public void mouseClicked (MouseEvent e) {super.mouseClicked (e)) Switch (GameUtil.state) {case 0: if (e.getButton () = = 1) {GameUtil.MOUSE_X = e.getX (); GameUtil.MOUSE_Y = e.getY (); GameUtil.LEFT = true } if (e.getButton () = = 3) {GameUtil.MOUSE_X = e.getX (); GameUtil.MOUSE_Y = e.getY (); GameUtil.RIGHT = true } / / remove break Listen for mouse events case 1: case 2: if (e.getButton () = = 1) {if (e.getX ()) > GameUtil.OFFSET + GameUtil.SQUARE_LENGTH* (GameUtil.MAP_W/2) & & e at any time .getX () GameUtil.OFFSET & & e.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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report