本周项目进展

·游戏整体架构设计基本实现

·确定贪吃蛇的形态及移动速度

·实现食物的随机出现

·初始化图形界面的布局,确定游戏和规则

·实现用户操作控制蛇的移动

成员贡献

20145228江苒:设定蛇的形态和移动速度,实现食物随机出现
20145230熊佳炜:初始化蛇与食物的位置,实现蛇吃到食物后蛇身加长
20145232韩文浩:实现用户操作控制蛇的移动,优化游戏规则

整体框架代码

import java.awt.Graphics;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;

public class Frame extends JFrame implements KeyListener {

    /**
     *
     */

    Boolean isAlive;
    Boolean isPause;
    Panel panel;
    Character direction;
    private static final long serialVersionUID = 1L;

    public Frame(){
        // TODO Auto-generated constructor stub
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(300,300);
        addKeyListener(this);
        panel = new Panel();
        add(panel);
        setVisible(true);
        isAlive = true;
        isPause = false;
        direction = new Character('d');
        MenuBar menuBar = new MenuBar();
        Menu menu = new Menu("menu");
        MenuItem reset = new MenuItem("newgame");
        MenuItem pause= new MenuItem("pause");

        pause.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                if(!isPause) isPause= true;
                else     isPause= false;
            }

        });

        reset.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                reset();
            }

        });

        menu.add(reset);
        menu.add(pause);
        menuBar.add(menu);
        setMenuBar(menuBar);


    }

    public void reset(){
        panel.reset();
        isAlive = true;
    }

    @Override
    public void keyTyped(KeyEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void keyPressed(KeyEvent e) {
        // TODO Auto-generated method stub
        if(e.getKeyCode()==KeyEvent.VK_UP)  direction = 'w';
        if(e.getKeyCode()==KeyEvent.VK_DOWN) direction = 's';
        if(e.getKeyCode()==KeyEvent.VK_LEFT) direction = 'a';
        if(e.getKeyCode()==KeyEvent.VK_RIGHT) direction = 'd';
    }

    @Override
    public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub

    }

    public void paint(Graphics g){
        panel.repaint();
    }

}

与计划相符情况

基本相符

改进措施

小组成员明确分工合作,使程序在已有的基础上提升质量,给用户最佳体验。

posted on 2016-05-29 22:55  无敌最寂寞  阅读(276)  评论(0编辑  收藏  举报