Java模拟微信打飞机游戏,大家参考使用吧
自己手动做游戏不香吗?
快来康康呀~
package com.beancore.ui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import com.beancore.config.Config;
import com.beancore.config.ImageConstants;
import com.beancore.entity.Score;
import com.beancore.util.FileUtil;
import com.beancore.util.ImageLoader;
import com.beancore.util.Images;
import com.beancore.util.SoundPlayer;
public class MainFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private ImageLoader imgLoader;
private GameLoadingPanel gameLoadingPanel;
private GamePlayingPanel gamePlayingPanel;
private PopupMenuPanel popupMenuPanel;
private Top10ScorePanel popupScorePanel;
private HelpDialog helpDialog;
private SoundPlayer achievementSoundPlayer;
private List<Score> scoreList;
public MainFrame() throws IOException, LineUnavailableException, UnsupportedAudioFileException {
try {
this.scoreList = FileUtil.readScore(Config.SCORE_FILE);
} catch (Exception e) {
this.scoreList = new ArrayList<Score>();
}
this.loadImage();
this.initSoundPlayer();
this.initComponents();
this.setBackgroundImage();
}
/**
* Load the image part from the whole image, shoot_background.png shoot.png
* are both extracted from the weixin apk file
* */
private void loadImage() throws IOException {
this.imgLoader = new ImageLoader(Config.SHOOT_BACKGROUND_IMG);
Images.GAME_LOADING_IMG1 = this.imgLoader.getImage(ImageConstants.GAME_LOADING_PLANE_1_POS_X,
ImageConstants.GAME_LOADING_PLANE_1_POS_Y, ImageConstants.GAME_LOADING_PLANE_1_WIDTH,
ImageConstants.GAME_LOADING_PLANE_1_HEIGHT);
Images.GAME_LOADING_IMG2 = this.imgLoader.getImage(ImageConstants.GAME_LOADING_PLANE_2_POS_X,
ImageConstants.GAME_LOADING_PLANE_2_POS_Y, ImageConstants.GAME_LOADING_PLANE_2_WIDTH,
ImageConstants.GAME_LOADING_PLANE_2_HEIGHT);
Images.GAME_LOADING_IMG3 = this.imgLoader.getImage(ImageConstants.GAME_LOADING_PLANE_3_POS_X,
ImageConstants.GAME_LOADING_PLANE_3_POS_Y, ImageConstants.GAME_LOADING_PLANE_3_WIDTH,
ImageConstants.GAME_LOADING_PLANE_3_HEIGHT);
Images.SHOOT_BACKGROUND_IMG = this.imgLoader.getImage(ImageConstants.GAME_BACKGROUND_IMG_POS_X,
ImageConstants.GAME_BACKGROUND_IMG_POS_Y, ImageConstants.GAME_BACKGROUND_IMG_WIDTH,
ImageConstants.GAME_BACKGROUND_IMG_HEIGHT);
Images.GAME_LOADING_TEXT_IMG = this.imgLoader.getImage(ImageConstants.GAME_LOADING_TEXT_IMG_POS_X,
ImageConstants.GAME_LOADING_TEXT_IMG_POS_Y, ImageConstants.GAME_LOADING_TEXT_IMG_WIDTH,
ImageConstants.GAME_LOADING_TEXT_IMG_HEIGHT);
this.imgLoader = new ImageLoader(Config.SHOOT_IMG);
Images.YELLOW_BULLET_IMG = this.imgLoader.getImage(ImageConstants.YELLOW_BULLET_POS_X,
ImageConstants.YELLOW_BULLET_POS_Y, ImageConstants.YELLOW_BULLET_WIDTH,
ImageConstants.YELLOW_BULLET_HEIGHT);
Images.BLUE_BULLET_IMG = this.imgLoader.getImage(ImageConstants.BLUE_BULLET_POS_X,
ImageConstants.BLUE_BULLET_POS_Y, ImageConstants.BLUE_BULLET_WIDTH, ImageConstants.BLUE_BULLET_HEIGHT);
Images.MY_PLANE_IMG =