⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 food.java

📁 Java贪吃蛇游戏 原代码和.jar文件 Java贪吃蛇游戏
💻 JAVA
字号:
package snakegame;

import java.awt.*;
import java.awt.geom.*;

public class Food implements Data
{
	public Food()
	{
		x = (int)(Math.random() * RIGHT);
		y = (int)(Math.random() * DOWN);
		isLife = true;
	}
	
	public void draw(Graphics2D g2)
	{
		Point point = clientPoint(x, y);
		Rectangle2D.Double rect = new Rectangle2D.Double(point.x, point.y, LONG, LONG);
		g2.setColor(Color.YELLOW);
		g2.fill(rect);
		g2.setColor(Color.BLACK);
		g2.draw(rect);
	}
	
	public Point clientPoint(int x, int y)
	{
		int clientX = ACTUALLEFT + x * LONG;
		int clientY = ACTUALUP + y * LONG;
		
		return new Point(clientX, clientY);
	}
	
	public Point clientPoint(Point point)
	{
		return clientPoint(point.x, point.y);
	}
	
	public int x;
	public int y;
	public boolean isLife;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -