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

📄 player.java

📁 一个五子棋游戏
💻 JAVA
字号:
import java.awt.*;

public class player{

	private int xPos;
	private int yPos;
	private int xVPos;
	private int yVPos;
	private int speed;
	private int direction;
	private Rectangle Player;
	private int mouthDegree;
	private boolean isMoving = true;
	private boolean mouthOpen, mouthClose;
	private boolean canMoveUp, canMoveDown, canMoveLeft, canMoveRight;
	private boolean dead;

	public player(){
		xPos = 210;
		yPos = 357;
		xVPos = xPos;
		yVPos = yPos;
		direction = 2;
		Player = new Rectangle(xPos - 5, yPos - 5, 11, 11);
		mouthDegree = 30;
		mouthOpen = true;
		speed = 2;
	}

	public void draw(Graphics g){
		int DirectionAngle = 180;
		g.setColor(Color.yellow);
		if(direction == 0)
			DirectionAngle = 90;
		if(direction == 1)
			DirectionAngle = -90;
		if(direction == 2)
			DirectionAngle = 180;
		if(direction == 3)
			DirectionAngle = 0;
		if(dead)
			DirectionAngle = 90;

		g.fillArc(xPos - 10, yPos - 10, 21, 21, mouthDegree + DirectionAngle, 180 - mouthDegree);
		g.fillArc(xPos - 10, yPos - 10, 21, 21, 180 + DirectionAngle, 180 - mouthDegree);
	}

	public void move(wall[] Wall){
		isMoving = true;

		canMoveUp = true;
		canMoveDown = true;
		canMoveLeft = true;
		canMoveRight = true;

		if(!dead){
			if(mouthDegree == 70){
				mouthClose = true;
				mouthOpen = false;
			}
			if(mouthDegree == -10){
				mouthOpen = true;
				mouthClose = false;
			}
		}


		Rectangle R;
		Rectangle UP = new Rectangle(xVPos - 10, yVPos - 12, 21, 21);
		Rectangle DOWN = new Rectangle(xVPos - 10, yVPos - 8, 21, 21);
		Rectangle LEFT = new Rectangle(xVPos - 12, yVPos - 10, 21, 21);
		Rectangle RIGHT = new Rectangle(xVPos - 8, yVPos - 10, 21, 21);

		for(int i = 0; i < Wall.length; i++){
			R = new Rectangle(Wall[i].getxPos() - 10, Wall[i].getyPos() - 10, 21, 21);
			if(R.intersects(UP))
				canMoveUp = false;
			if(R.intersects(UP) && direction == 0)
				yPos = yVPos;

			if(R.intersects(DOWN))
				canMoveDown = false;
			if(R.intersects(DOWN) && direction == 1)
				yPos = yVPos;

			if(R.intersects(LEFT))
				canMoveLeft = false;
			if(R.intersects(LEFT) && direction == 2)
				xPos = xVPos;

			if(R.intersects(RIGHT))
				canMoveRight = false;
			if(R.intersects(RIGHT) && direction == 3)
				xPos = xVPos;
		}

		if(direction == 0 && canMoveUp)
			yPos-=speed;
		else if(direction == 1 && canMoveDown)
			yPos+=speed;
		else if(direction == 2 && canMoveLeft)
			xPos-=speed;
		else if(direction == 3 && canMoveRight)
			xPos+=speed;
		else
			isMoving = false;

		if(direction == 2 && xPos < 0)
			xPos = 420;
		if(direction == 3 && xPos > 420)
			xPos = 0;

		Player = new Rectangle(xPos - 5, yPos - 5, 11, 11);

		int a = (xPos - 10)/21;
		int b = (xPos - 10)%21;
		if(b < 6)
			b = 0;
		if(b > 16)
			b = 21;
		if(b < 17 && b > 5)
			b = 11;
		xVPos = a*21 + b + 10;

		int c = (yPos - 10)/21;
		int d = (yPos - 10)%21;
		if(d < 6)
			d = 0;
		if(d > 16)
			d = 21;
		if(d < 17 && d > 5)
			d = 11;
		yVPos = c*21 + d + 10;

		int angularSpeed = 10;
		if(dead && mouthDegree <= 175){
			isMoving = true;
			mouthOpen = true;
			mouthClose = false;
			angularSpeed = 5;
		}

		if(dead && mouthDegree > 175)
			isMoving = false;

		if(mouthOpen && isMoving)
			mouthDegree+=angularSpeed ;
		if(mouthClose && isMoving)
			mouthDegree-=angularSpeed ;

	}

	public void ChangeDirection(int a){
		if(a == 0 && canMoveUp){
			direction = 0;
			xPos = xVPos;
		}
		if(a == 1 && canMoveDown){
			direction = 1;
			xPos = xVPos;
		}

		if(a == 2 && canMoveLeft){
			direction = 2;
			yPos = yVPos;
		}

		if(a == 3 && canMoveRight){
			direction = 3;
			yPos = yVPos;
		}
	}

	public int getxPos(){
		return xPos;
	}

	public int getyPos(){
		return yPos;
	}

	public Rectangle getBorder(){
		return Player;
	}
	public void stop(){
		speed = 0;
	}

	public void Dead(){
		dead = true;
		mouthDegree = 30;
	}
}

⌨️ 快捷键说明

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