用JAVA写一款自己的小游戏

用JAVA写一款自己的小游戏

我目前也处于一个学习的阶段,所以代码会有很多的错误,但是经过我几天的瞎调试目前还是可以玩的,但是可玩性还是很差

说一说怎么玩这个游戏把

设计初衷:KoalaChess,顾名思义,我叫他“考拉棋“。灵感来自于微信小程序上的一款叫斗兽棋王者的小程序,我在他的基础上做了修改,斗兽棋众所周知,里面包含了象,狮,虎,豹,狼,狗,猫,鼠,8种动物,除了老鼠可以吃象以外,其他顺次相吃,在一个4*4的方格内进行暗器的玩法。我在他的基础上删除了狗,变成了考拉,考拉并不能移动,只能充当一个木桩(因为我不想他死),也不能被吃,其他均与小程序相同。
吃法:
考拉最大,无法移动也无法被吃
鼠>象>狮>虎>豹>狼>猫>鼠
棋子描述
鼠:
在这里插入图片描述

猫:
在这里插入图片描述

狼:
在这里插入图片描述

豹:(没有找到豹子的图片,暂时拿熊的图片代替)
在这里插入图片描述
虎:
在这里插入图片描述
狮:
在这里插入图片描述
象:
在这里插入图片描述

考拉:(没有找到同画风的考拉的图片,暂时拿兔子的图片代替)
在这里插入图片描述
绿色的块代表空地
?代表还没翻开的棋

胜负:
当一方仅剩下考拉时,另一方获胜
若两方同时只剩余考拉,则为和棋

然后是代码

我也对每一个模块简单的进行了注释

package koalaChess;

import java.awt.Image;
/*

*/

public class Pieces {
	private String name;		//名字,显示该棋子的名字
	private int  intensity;		//强度,分为0,2,4,6,8,10,12,14档,依次为鼠,猫,狼,豹(熊),虎,狮,象,考拉(兔)
	private int LocationX;		//x轴坐标,在wall二维数组中的x坐标,也是第二个值
	private int LocationY;		//y轴坐标,在wall二维数组中的y坐标,也是第一个值
	private boolean state;		//状态  false背面  true 正面,用于描述棋子的正反两面
	private int faction;		//派别	1红,2蓝,用于描述棋子的组别,红蓝方
	private boolean die;		//死了?true 死了,false没死
	private Image image;		//图片,加载对应图片
	
	//构造函数
	//参数为(名字(string),强度(int),派别(int),图片(Image))
	public Pieces(String name,int inten,int fac,Image image) {
		this.name=name;
		this.intensity =inten;
		//this.LocationX =x;
		//this.LocationY =y;
		this.state=false;
		this.faction=fac;
		this.die=false;
		this.image=image;
	}
	
	//构造函数
	//参数为Pieces
	public Pieces(Pieces It) {
		this.name=It.name;
		this.intensity =It.intensity;
		this.LocationX =It.LocationX;
		this.LocationY =It.LocationY;
		this.state=It.state;
		this.faction=It.faction;
		this.die=It.die;
		this.image=It.image;
	}
	
	//复制函数
	//参数是Pieces
	public void copy(Pieces It) {
		this.name=It.name;
		this.intensity =It.intensity;
		this.LocationX =It.LocationX;
		this.LocationY =It.LocationY;
		this.state=It.state;
		this.faction=It.faction;
		this.die=It.die;
		this.image=It.image;
	}
	//基础转移的函数:
	//
	//改变棋子的正反面
	public void setState() {
		this.state=true;
	}
	//判断棋子的正反面状态
	//返回这个值
	public boolean getState() {
		return this.state;
	}
	//返回x坐标
	public int getX() {
		return this.LocationX;
	}
	//设置他的x坐标
	public void setX(int X) {
		this.LocationX=X;
	}
	//返回y坐标
	public int getY() {
		return this.LocationY;
	}
	//设置他的y坐标
	public void setY(int Y) {
		this.LocationY=Y;
	}
	//向左移动
	//对横坐标x进行修改,x=x-1
	public void Left() {
		LocationX--;
	}
	//向右移动
	//对横坐标x进行修改,x=x+1
	public void Right() {
		LocationX++;
	}
	//向上移动
	//对纵坐标y进行修改,y=y-1
	public void Up() {
		LocationY--;
	}
	//向下移动
	//对纵坐标y进行修改,y=y+1
	public void Down() {
		LocationY++;
	}
	//判断棋子的死亡状态
	//返回这个状态
	public boolean getDie() {
		return this.die;
	}
	//
	//
	//吃法:
	//吃子:
	
	public void Eat(Pieces It) {
		/*
		第一步判断It和this的强度值
		
			如果相等  两个子的描述死亡die都变成true,使他们形成互换
			并把他们的强度都修改成-1
			
			如果不相等  把this的x,y都变成It的x,y,使this的位置变成It的位置
			并把It的die变成true,形成this吃掉It
		*/
		if(this.intensity==It.intensity) {
			this.die=true;
			It.intensity=-1;
			this.intensity=-1;
			//It.faction=0;
			//this.faction=0;
			It.die=true;
		}else {
			this.setX(It.getX());
			this.setY(It.getY());
			It.intensity=-1;
			//It.faction=0;
			It.die=true;
		}
	}
	
	//判断能否吃子
	/*
	第一步判断It的die
		如果die为true,则返回true
		如果die为false,则不做任何行动
	第二步判断It的正反状态
		如果为false(背面),则返回false
		如果为true(正面),则不做任何行动
	第三步判断It和this的组别(红蓝方)
		如果相等,二者为一方,返回false
		如果不相等,进入第四步
	第四步判断强度
		如果为It=14(考拉),无法被吃,则返回false
		如果为this=0,It=12,属于this为鼠
  • 36
    点赞
  • 139
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值