package cn.tcc.snake.tcc.View;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

import cn.tcc.snake.antition.Food;
import cn.tcc.snake.antition.Ground;
import cn.tcc.snake.antition.Sanke;
import cn.tcc.snake.util.Global;

public class GamePanel extends JPanel{
    private Sanke snake;
    private Food food;
    private Ground ground;
    //保存这三个对象的引用;
@Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        //重新显示
    g.setColor(new Color(0xcfcfcf));
    g.fillRect(0, 0, Global.WIDTH*Global.CELL_SIZE, Global.HEIGHT*Global.CELL_SIZE);
    if(ground !=null && snake != null && food != null){
    this.snake.drawMe(g);
    this.food.drawMe(g);
    this.ground.drawMe(g);
    }
    }

public void display(Sanke snake,Food food,Ground ground){
    System.out.println("GamePanel");
    this.snake= snake;
    this.food=food;
    this.ground=ground;
    this.repaint();
}
}

贪吃蛇GamePanel Java实现(二)的更多相关文章

  1. 贪吃蛇Controller Java实现(二)

    package cn.tcc.snake.Controller; import java.awt.Point;import java.awt.event.KeyAdapter;import java. ...

  2. 贪吃蛇snake Java实现(二)

    package cn.tcc.snake.antition; import java.awt.Color;import java.awt.Graphics;import java.awt.Point; ...

  3. 贪吃蛇Food Java实现(二)

    1.antition包Food类 package cn.tcc.snake.antition; import java.awt.Graphics;import java.awt.Point;publi ...

  4. 贪吃蛇Ground Java实现(二)

    package cn.tcc.snake.antition; import java.awt.Color;import java.awt.Graphics; import java.awt.Point ...

  5. 贪吃蛇Global Java实现(二)

    package cn.tcc.snake.util; public class Global {public static final int CELL_SIZE=20;public static f ...

  6. 贪吃蛇Listener Java实现(二)

    package cn.tcc.snake.listener; import cn.tcc.snake.antition.Sanke;//接口//处理用户按键事件public interface Sna ...

  7. 贪吃蛇的java代码分析(二)

    代码剖析 贪吃蛇是一款十分经典的小游戏,对初入coding的朋友来说,拿贪吃蛇这样一个案例来练手十分合适,并不高的难度和成功后的成就感都是学习所必须的.下面我将依照我当时的思路,来逐步分析实现的整个过 ...

  8. 贪吃蛇的java代码分析(一)

    自我审视 最近自己学习java已经有了一个多月的时间,从一开始对变量常量的概念一无所知,到现在能勉强写几个小程序玩玩,已经有了长足的进步.今天没有去学习,学校里要进行毕业答辩和拍毕业照了,于是请了几天 ...

  9. 贪吃蛇的java代码分析(三)

    代码剖析 在上一篇文章中,我们完成了贪吃蛇部分代码的构造.回头审视我们写的代码与思路,会发现我们遗漏了一个重要的地方,那就是:贪吃蛇的自身移动.想必大家都知道,贪吃蛇自身是会自己移动的,并且会跟随你的 ...

随机推荐

  1. django之paginator

    class Paginator(object):#分页器 def __init__(self, object_list, per_page, orphans=0, allow_empty_first_ ...

  2. django之setup()

    #django包的__init__.py包含setup函数def setup(): """ Configure the settings (this happens as ...

  3. PHP 服务 php-fpm 的一些常见配置

    < 操作系统 Centos7,PHP版本7.2.7 > 已下所有配置涉及到时间单位均使用 => 秒(s) 分 (m) 时 (h) 天(d) [ 以下为全局配置 ] 01,关于,进程文 ...

  4. Notepadd ++ PluginManager安装

    下载地址https://github.com/bruderstein/nppPluginManager/releases 解压后有2个包plugins和updater 分别放入C:\Program F ...

  5. UI5-学习篇-5-SAP创建OData服务-Structure

    本文介绍SAP后端系统基于数据结构创建OData服务过程. 1.创建数据字典 2.创建OData service 2.1创建Gateway service project 事务码:SEGW 点击Cre ...

  6. Nexus3忘记admin密码时的解决办法

    其实具体步骤官网上也已经说的挺清楚了-- https://support.sonatype.com/hc/en-us/articles/213467158-How-to-reset-a-forgott ...

  7. Object-c 调用unity的 UIViewController和UnitySendMessage

    .mm文件中实现 #import <UIKit/UIKit.h> extern UIViewController *UnityGetGLViewController(); extern & ...

  8. linux 3.10 gro的理解和改进

    gro,将同一个flow的一定时间范围之内的skb进行合并,减少协议栈的消耗,用于收包性能提升.gro网上的资料很多,但是都很少谈到gro的改进,刚好身边有个同事也想改这块的内容, 所以将最近看的gr ...

  9. eclipce导入java 项目不可用

  10. 检测浏览器是否支持cookie功能

    <script> if(navigator.cookieEnabled) { document.write("你的浏览器支持cookie功能!"); } else{ d ...