题目

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;}}

java做RPG小游戏相关推荐

  1. 自己动手 做rpg小游戏

    我是一位非常狂热的玩家,可以说我的业余时间大部分都用在玩游戏上了.有一天,我突发奇想,决定自己也做一款游戏来试试.后来上网一查,发现市面上有非常多的游戏制作工具,但绝大多数需要美工和程序的基础.就在我 ...

  2. java做h5小游戏服务端_神藏西游H5游戏源码服务端+客户端+搭建教程

    源码预览 源码介绍 教程如下: 1.cd / 把下载好的文件传到服务器根目录下面 2.打开Xshell 安装java 输入 sh sd 回车 输入1 回车 3.安装宝塔 输入 sh sd 回车 输入2 ...

  3. java制作纯字rpg小游戏_求java rpg小游戏源代码 最好是文字rpg 不需要很复杂 只是交作业用...

    展开全部 连连看的小源码 package Lianliankan; import javax.swing.*; import java.awt.*; import java.awt.event.*; ...

  4. python做的RPG小游戏(面向对象思想)

    花一晚上时间做的一个RPG小游戏,欢迎大家联系我,和我交流. 接下来计划做一个基于socket网络连接,可以实现,多人登录进去玩的RPG网络小游戏 游戏效果 // main.pyfrom M1 imp ...

  5. 手把手教你做一个Java贪吃蛇小游戏

    大家好,我是孙不坚1208,这篇博客给大家分享一下:如何做一个贪吃蛇小游戏(Java版)的exe应用程序,希望能给需要帮助的朋友带来方便. 手把手教你做一个Java贪吃蛇小游戏的exe应用程序 一.J ...

  6. 做个小游戏来检验自己的Java学习吧-----(行走的人)

    Java是许多小游戏的基础,经过一个月的抓耳挠腮终于吃透了了这个游戏大概的界面如下,有些像 小时候玩的森林冰火人(当然还不能做的那么高级),勉强是完成了控制人物走动,后面会慢慢改进. --,制作步骤 ...

  7. Java Swing 经典小游戏《飞机大战》———— (四)碰撞检测 游戏状态与得分 玩家升级

    前期回顾 Java Swing 经典小游戏<飞机大战>---- (一)获取素材,创建窗口,添加滚动背景,双缓冲 Java Swing 经典小游戏<飞机大战>---- (二)玩家 ...

  8. Java黄金矿工小游戏,适合新手入门练手项目

    Java初学者的小伙伴们,相信大家肯定缺少很多的练手项目吧!今天就给大家推荐一款特别好上手的一个Java小游戏--黄金矿工. 大家听到这个名字的时候,童年的回忆肯定一下子,涌上心头,那如果让大家制作一 ...

  9. Java黄金矿工小游戏,适合初学者练手项目_java游戏_java项目

    黄金矿工小游戏是一款非常经典的休闲类挖宝游戏!相信绝大多数人小时候应该都玩过.但是你会玩游戏,你会做游戏吗(狗头)?对!你没猜错!我今天就是来给大家说怎么用Java做游戏的,希望看完之后你也会做哦~ ...

最新文章

  1. 非常全面的AutoML资源,看这个就够了!
  2. NB-IoT这块热豆腐公认可口 但勿太心急
  3. pythonweb开发-Web | 浅谈用Python进行Web开发
  4. UVALive 4975 Casting Spells
  5. java中id name_关于DOM对象中的id与name的区别
  6. 【c++ primer读书笔记】【第6章】函数
  7. mysql数据库约束和默认
  8. [计算机网络]七、IP地址规划和静态路由
  9. [Python] 微信for PC自动群发消息、图片以及文件
  10. 油品调和计算软件_燃料油品的调合及计算方法及航空汽油的调合
  11. WinEdt 使用技巧
  12. Fe3O4纳米颗粒的表面接枝修饰/氨基乙酸|L-半胱氨酸(L-Cys)修饰的Fe3O4包裹TiO2(Fe3O4@TiO2/L-Cys)复合纳米粒子
  13. 删除文件夹提示“您需要权限来执行此操作”如何解决?
  14. 微信公众平台开发最佳实践(第2版)
  15. 2022年加氢工艺考试题模拟考试平台操作
  16. 【DFS专题训练】王子救公主 C++程序题
  17. VAE(变分自编码器)原理简介
  18. AOJ-proble-807
  19. sublime text 修改cmd命令_Vim 命令合集
  20. Vue报错: Error compiling template:

热门文章

  1. 24核48线虚拟化服务器,24核48线程的威力:戴尔PowerEdge R910服务器评测
  2. “组件协作”模式----策略模式(Strategy Pattern)
  3. 【计算机网络】5层因特网协议栈 概述
  4. 「开机自启」macOS如何关闭开机自启动软件?
  5. [go]沙盒环境下调用支付宝扫码支付
  6. 华为nova3游戏帧数测试软件,华为nova3最全游戏体验报告:手游玩家一定不能错过...
  7. 26、灭火系统中最不利点处洒水喷头的工作压力是多少
  8. Linux 常用網路指令
  9. 【Java】3分钟学会Java中基本数据类型(建议收藏)
  10. 递归 算法 编程技巧