Giter VIP home page Giter VIP logo

huluwa's Introduction

葫芦娃大战妖精

效果图

gif

构建与运行

git clone [email protected]:xulj-cs/HuLuWa.git
cd HuLuWa
mvn clean test package
java -jar target/HuLuWa-1.0.jar

游戏介绍

此游戏并非真正的“游戏”:玩家并不具有真正控制游戏角色行动的能力。 游戏阵营分为HumanMonster,游戏结束条件是某一方角色全部阵亡。 本游戏有多个关卡(LEVEL),每个关卡双方具有不同的阵法(ZhenFa)。 游戏具有基本的记录和回放(replay)功能。

当不同阵营的双方试图进入同一位置时,会进行Fight,结果有且只有一个生物存活,另一个生物死亡。

游戏操作

本游戏为按键操作,操作指南如下:

  • S :加载游戏阵法
  • SPACE :开始游戏
  • N :进入下一关卡
  • L :加载游戏记录,进行回放

类图

uml

JavaFx

本次使用的GUI框架是JavaFx:

  • Parent节点使用的是子类Pane,方便调整子节点位置;
  • 所有生物Creature均继承自ImageView,利用setImage方法来设置图像,利用setLayoutX/Y方法来实现移动move操作
  • 状态栏statusBarText实例,用来显示游戏的状态输出和按键提示

用到的Java知识

  • 继承与多态

    生物体Creature用到了继承和多态,这是纯粹的subtype

  • RTTI

    在区分Human/Monste时,用到了instanceOf关键字,这是java的RTTI机制

  • 集合框架

    为了方便管理多个生物体,利用了ArrayList集合框架

  • 多进程

    生物体Creature实现了Runnable接口。当游戏开始时,每个生物具有一个线程,这里线程的执行用到了newFixedExecutePool,减小线程开销。为了防止线程处突,对临界区利用synchronized关键字进行互斥访问

  • 输入输出

    为了游戏的记录和加载,这里用到了文件的输入输出,FileWriter以及FileReader

  • 异常处理

    对于IO处理的IO异常和多线程的sleep操作的Interrupted异常,用到了try-catch-finally来进行异常处理

  • 注解

    使用@Override检查方法覆盖,使用@Test进行单元测试

  • 测试与构建

    利用Maven来进行项目自动化测试和构建;利用Junit进行单元测试

  • 设计模式

    装饰器模式:在IO操作时,用BufferedWriter来装饰FileWriter,以及对应的BufferedReader来装饰FileReader

    代理模式:通过组合来实现功能的代理

致谢

本项目中图像资源采用自tangruize/huluwa

huluwa's People

Contributors

xulj-cs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.