blood.java

来自「简单的贪吃蛇源码」· Java 代码 · 共 40 行

JAVA
40
字号
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;


public class Blood extends Block{
	public static final int BloodSize = 20 ;	
	public static final Color BloodColor = Color.RED ;	
	private static Random r = new Random();
	 Snake s;	
	public Blood(int x,int y,Snake s){
		super(x,y,BloodColor);
		this.s = s;
		 this.x = x;
		 this.y = y;		 
	}
	
	public void paint(Graphics g){			
		super.Draw(g);		
	}
	
	public void chang(){			
			this.x = r.nextInt(Snake.GameWidth-20);			
			this.y = r.nextInt(Snake.GameHeight-50)+30;
			if(s.h.EatBlood(this)){
				chang();
			}
			else if(s.y.pongBlood(this)){
				chang();
			}
	}	

	public Rectangle getRect() {
		return new Rectangle(x, y, BloodSize , BloodSize);
	}
	
	
}

⌨️ 快捷键说明

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