package com.qdmmy6.snake;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SnakeFrame extends JFrame {
private SnakeMap map;
private JPanel timePanel = new JPanel();
public SnakeFrame(SnakeMap map) {
this.map = map;
this.init();
}
private void init() {
this.add(map);
this.setSize(500, 400);
map.setFocusable(true);
map.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
switch(key) {
case KeyEvent.VK_ENTER:execute();break;
case KeyEvent.VK_A:quickenUp();break;
case KeyEvent.VK_D:slowdown();break;
case KeyEvent.VK_DOWN:map.getSnake().move(key);break;
case KeyEvent.VK_UP:map.getSnake().move(key);break;
case KeyEvent.VK_LEFT:map.getSnake().move(key);break;
case KeyEvent.VK_RIGHT:map.getSnake().move(key);break;
}
}
});
}
private void execute() {
map.getSnake().execute();
}
public void quickenUp() {
}
public void slowdown() {
}
public static void main(String[] args) {
SnakeMap map = new SnakeMap();
Snake snake = new Snake(map);
map.setSnake(snake);
JFrame frame = new SnakeFrame(map);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
} |
|