基本信息
源码名称:java贪吃蛇代码
源码大小:2.24M
文件格式:.zip
开发语言:Java
更新时间:2020-11-21
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.snake.game;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.snake.controller.Controller;
import com.snake.entities.Food;
import com.snake.entities.Ground;
import com.snake.entities.Snake;
import com.snake.util.Global;
import com.snake.view.BottonPanel;
import com.snake.view.GameMenu;
import com.snake.view.GamePanel;
public class GameFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new GameFrame(new Controller(new Snake(), new Food(), new Ground(),
new GamePanel(), new GameMenu(),new BottonPanel()));
}
//各对象
private GamePanel gamePanel;
private GameMenu gameMenu;
private Snake snake;
//private Food food;
//private Ground ground;
private Controller controller;
private JPanel buttonPanel;
public GameFrame(Controller c) {
this.controller = c;
snake = controller.getSnake();
gameMenu = controller.getGameMenu();
gamePanel = controller.getGamePanel();
buttonPanel = controller.getBottonPanel();
setTitle("Snake");
setBounds(300,100,Global.WIDTH*Global.CELL_SIZE 250,Global.HEIGHT*Global.CELL_SIZE 60);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = this.getContentPane();
this.setJMenuBar(gameMenu);
contentPane.add(gamePanel);
contentPane.add(buttonPanel);
setResizable(false);
setVisible(true);
/* 让窗口居中显示 */
this.setLocation(this.getToolkit().getScreenSize().width / 2
- this.getWidth() / 2, this.getToolkit().getScreenSize().height
/ 2 - this.getHeight() / 2);
gamePanel.addKeyListener(controller);
snake.addSnakeListener(controller);
controller.newGame();
}
}