java做RPG小游戏

news/2025/2/1 12:59:45/

题目

java课设,一个游戏中有多种角色(Character),例如:国王(King)、皇后(Queen)、骑士(Knight)、老怪(Troll)。
角色之间可能要发生战斗(fight),每场战斗都是一个角色与另一角色之间 的 一 对 一 战 斗 。 每 个 角 色 都 有 自 己 的 生 命 值 (hitPoint) 、 魔法值(magicPoint)、攻击力值(damage)和防御力值(defense)。每种角色都有一种武器进行攻击(fight);在程序运行中,可以动态修改角色的武器(setWeaponBehavior)。
每种角色都有一种魔法对自己或者其他角色施(performMagic);可以动态改变拥有的魔法(setMagicBehavior)
在这里插入图片描述在这里插入图片描述

效果

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

部分代码

角色抽象类

// An highlighted block
/**
* 这是文档注释
* @author 张光远
* @version 创建时间:2020年6月14日 下午2:33:38
*/
package zhangguangyuan5377.characters;import zhangguangyuan5377.behavior.*;// TODO: Auto-generated Javadoc
/*** The Class Characters.*/
public abstract class Characters {/** The Id. *///类的实现private int Id;/** The name. */private String name;/** The hitpoint. */private int hitpoint;//生命值/** The magicpoint. */private int magicpoint;//魔法值/** The damage. */private int damage;//攻击力值/** The defense. */private int defense;//防御力值/** The point. */private int point[]=new int[4];//记录角色自身各项值,切换武器时用以恢复初始值/** The weapon. */protected WeaponBehavior weapon;//武器/** The magic. */protected MagicBehavior magic;//魔法/** The skill. */protected String skill[]=new String[3];//平a技能,武器技能,魔法技能/** The feature. */protected String feature;/*** Instantiates a new characters.*/public Characters() {this.Id=0;this.name="未命名";hitpoint=800;magicpoint=200;damage=80;defense=15;point[0]= hitpoint;point[1]=magicpoint;point[2]=damage;point[3]=defense;}/*** Instantiates a new characters.** @param name the name*/public Characters(String name) {this();this.name=name;/*hitpoint=800;magicpoint=200;damage=80;defense=15;*/}/*** Fight.** @param c the c* @param choice the choice* @return the int*/public int fight(Characters c,boolean choice) {//完成本角色攻击角色 c 的操作		int hurt=0;if(choice) {hurt=weapon.useWeapon(this.getDamage(),c);}else {hurt=-this.getPoint()[2]+c.getDefense()*2;c.setHitpoint(hurt);}if(c.getHitpoint()<=0) {return 1;//游戏胜利}else if(this.getHitpoint()<=0) {return 2;//敌方胜利}elsereturn 0;//游戏未结束}/*** Perform magic.** @param c the c* @param e the e* @return the int*/public int performMagic(Characters c,Characters e) {//if(getMagicpoint()>=50) {return magic.useMagic(c,e);
//			setMagicpoint(-50);
//		}
//		else
//			System.out.println("magicpoint is not enough");}/*** Sets the weapon behavior.** @param w the new weapon behavior*/public void setWeaponBehavior(WeaponBehavior w) {this.weapon=w;this.skill[1]=weapon.getSkill();rePoint();//恢复角色无武器状态值//int a[]=getPoint();setDamage((int)(w.getAt()*getDamage()));setDefense((int)(w.getDe()*getDefense()));/*int t = 0;boolean wea[]=new boolean[4];wea[0]=w instanceof KnifeBehavior;wea[2]=w instanceof AxeBehavior;wea[1]=w instanceof BowAndArrowBehavior;wea[3]=w instanceof SwordBehavior;for(int i=0;i<4;i++) {if(wea[i]) {t=i;break;}}double da = 0,de = 0;switch(t) {case 0:da=0.1;de=0.5;break;case 1:da=0.4;de=-0.1;break;case 2:da=0.3;de=0;break;case 3:da=0.2;de=0.25;break;default:System.out.println("error");}da*=getDamage();de*=getDefense();setDamage((int)da);setDefense((int)de);*/}//改变武器/*** Sets the magic behavior.** @param m the new magic behavior*/public void setMagicBehavior(MagicBehavior m) {this.magic=m;/*int t = 0;boolean wea[]=new boolean[2];wea[0]=m instanceof HealBehavior;wea[1]=m instanceof InvisibleBehavior;for(int i=0;i<2;i++) {if(wea[i]) {t=i;break;}}//double ta = 0;switch(t) {case 0:setHitpoint((int)(0.1*hitpoint));//子类能否看见break;case 1:setDamage((int)(0.1*damage));break;default:System.out.println("error");}setMagicpoint(-50);*/}//改变魔法/*** Gets the id.** @return the id*/public int getId() {return Id;}/*** Gets the name.** @return the name*/public String getName() {return name;}/*** Display.*/public abstract void display();/*** Gets the hitpoint.** @return the hitpoint*/public int getHitpoint() {return hitpoint;}/*** Gets the magicpoint.** @return the magicpoint*/public int getMagicpoint() {return magicpoint;}/*** Gets the damage.** @return the damage*/public int getDamage() {return damage;}/*** Gets the defense.** @return the defense*/public int getDefense() {return defense;}/*** Gets the skill.** @return the skill*/public String[] getSkill(){return skill;}/*** Gets the point.** @return the point*/public int[] getPoint() {int a[]=new int[4];System.arraycopy(point, 0, a, 0, 4);return a;}/*** Gets the feature.** @return the feature*/public String getFeature() {return feature;}/*** Sets the id.** @param id the new id*///能不能用protectedpublic void setId(int id) {this.Id=id;}/*** Sets the name.** @param name the new name*/public void setName(String name) {this.name=name;}/*** Sets the hitpoint.** @param value the new hitpoint*/public void setHitpoint(int value) {hitpoint+=value;}/*** Sets the magicpoint.** @param value the new magicpoint*/public void setMagicpoint(int value) {magicpoint+=value;}/*** Sets the damage.** @param value the new damage*/public void setDamage(int value) {damage+=value;}/*** Sets the defense.** @param value the new defense*/public void setDefense(int value) {defense+=value;}/*** Re point.*/public void rePoint() {//this.hitpoint=point[0];//this.magicpoint=point[1];this.damage=point[2];this.defense=point[3];}
}

具体英雄类
下面展示一些 内联代码片

// A code block
var foo = 'bar';
// An highlighted block
/*** */
package zhangguangyuan5377.characters;// TODO: Auto-generated Javadoc
/*** The Class King.*/
public class King extends Characters {/*** Instantiates a new king.** @param name the name*/public King(String name) {this();setName(name);// TODO Auto-generated constructor stub//this.hipoint=0;/*setHitpoint(50);setMagicpoint(100);setDamage(0);setDefense(3);*/}/*** Instantiates a new king.*/public King() {// TODO Auto-generated constructor stub//setId(1);setHitpoint(50);setMagicpoint(100);setDamage(0);setDefense(3);this.skill[0]="王之圣裁";this.feature="末代皇帝,一声令下,群臣应之";}/*** Display.*/@Overridepublic void display() {// TODO Auto-generated method stubSystem.out.println("This is King showtime!");}}

武器接口

// An highlighted block
/*** */
package zhangguangyuan5377.behavior;import zhangguangyuan5377.characters.Characters;// TODO: Auto-generated Javadoc
/*** The Interface WeaponBehavior.*/
public interface WeaponBehavior {/*** Use weapon.** @param damage the damage* @param enemy the enemy* @return the int*/public int useWeapon(int damage,Characters enemy);/*** Gets the at.** @return the at*/public double getAt();/*** Gets the de.** @return the de*/public double getDe();/*** Gets the skill.** @return the skill*/public String getSkill();
}

武器类

// An highlighted block
/*** */
package zhangguangyuan5377.behavior;import zhangguangyuan5377.characters.Characters;// TODO: Auto-generated Javadoc
/*** The Class SwordBehavior.*/
public class SwordBehavior implements WeaponBehavior {/** The id. */private int id=4;/** The at. */private double at=0.2;/** The de. */private double de=0.25;/** The skill. */private String skill="一剑化三清";/*** Use weapon.** @param damage the damage* @param enemy the enemy* @return the int*/@Overridepublic int useWeapon(int damage,Characters enemy) {// TODO Auto-generated method stubint a=-damage+enemy.getDefense();enemy.setHitpoint(a);return a;}/*** Gets the at.** @return the at*/@Overridepublic double getAt() {// TODO Auto-generated method stubreturn at;}/*** Gets the de.** @return the de*/@Overridepublic double getDe() {// TODO Auto-generated method stubreturn de;}/*** Gets the skill.** @return the skill*/public String getSkill() {return skill;}/*** Gets the id.** @return the id*/public int getId() {return id;}}

http://www.ppmy.cn/news/578807.html

相关文章

3D~RPG游戏的制作

@作者 : SYFStrive @博客首页 : HomePage @创建时间 : 2022/7/29 10:00 📜:UnityRPG核心文章(代码加起来7万字🤮) 📌:个人社区(欢迎大佬们加入) 👉:社区链接🔗 📌:觉得文章不错可以点点关注 👉:

简单的RPG游戏制作教程

□企划部份 ◎第一步&#xff1a;决定资料格式 在进入游戏制作的初期&#xff0c;由于有许多和程式有关的资料需要编整&#xff0c;因此担任企划的人员常会忙得乱七八糟。在这个阶段&#xff0c;企划人员必需要和程式商量游戏中资料的格式。举个例子来说&#xff0c;在程式要开…

好嗨游戏 || 20款全世界最佳移动RPG角色扮演游戏(下)

文章首发于&#xff1a;好嗨游戏 紧接上周&#xff0c;我们将为大家带来剩下11款&#xff08;多赠送1款&#xff09;全球最佳的RPG游戏&#xff0c;这些游戏同样也是史诗级作品&#xff0c;或有趣或宏大的故事背景、良心的制作&#xff0c;让它们能够经久不衰的在RPG游戏排行榜…

什么是RPG游戏

RPG Role-playing Game∶角色扮演游戏角色扮演的基本概念从1981年第一款电子RPG游戏软件至今&#xff0c;RPG游戏已经随着电子游戏产业的发展走了三十多年的历程&#xff0c;成为电子游戏发展的一个缩影。什么是RPG游戏类型呢&#xff1f;英文全称“Role-playing game”&#x…

【游戏开发】2D RPG游戏

前言 通过对游戏《原神》的功能复刻来学习游戏开发 截止到10月&#xff0c;本项目已经开发的差不多了&#xff0c;不是开发的完善了&#xff0c;而是通过这个项目已经学会了Unity开发游戏的技巧&#xff0c;就不继续开发了。 这里展示一下目前的成果&#xff0c;并简述一下各…

JAVA RPG游戏

回顾 刚开始写的毕业设计&#xff0c;我拿出来分享了下&#xff0c;真丑&#xff01;&#xff01;&#xff01;&#xff01;链接如下&#xff0c;主要写逻辑什么的&#xff0c;还未关注于画面。 初界面展示 算是成品的展示↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓(毕竟觉得槽点很…

单机模式RPG网游

熬完考试&#xff0c;室友回家疯狂网游&#xff0c;欲同乐。 上官网了解游戏模式&#xff0c;与以前的RPG网游区别不大&#xff0c;相比自己最早玩的《传奇》在模式上仅任务系统得到发展&#xff0c;然后在团队精神上有所强调。 唉&#xff0c;那样还不如单机RPG。 每个游戏迷都…

RPG游戏

1、功能描述&#xff1a; 几乎所有的RPG游戏&#xff08;一种源自《龙与地下城》的游戏类型&#xff09;在进入游戏时都会让用户自己来创建自己喜欢的角色。本次上机要求编写一个简化的创建游戏角色的程序。 2、游戏角色应有的属性 本题目要求的游戏角色应有以下属性&#xff1…