Code Monkey home page Code Monkey logo

dungeonsanddragons-java-game's Introduction

WorldOfMarcel

This project implements a story-based adventure game and showcases Java OOP principles. Most classes are identically created to the pattern offered as guide.

  • The Game class is the parent class for both GUI and CLI modes and holds useful game-related information, such as stories, accounts and methods for running the game.
  • The Account class holds the game-related information that belongs to an account, including its Information (Credentials, favorite games and personal information).
  • The Grid class holds the data belonging to the game grid, such as width height, traversal methods, generation method. The grid must have at least 2 shops and 4 enemies, which was implemented with a Random object (as with many other features in the game). The grid itself is an ArrayList of ArrayLists (matrix) of Cells.
  • A Cell has coordinates, a type (Empty, Shop, Enemy or Finish) and a visited boolean, which helps with printing the grid and making sure a revisited cell doesn't behave like a non-visited one.
  • The Entity class is parent for both Character and Enemy and has common attributes to both children, such as mana, life, protection to spells, spell list, methods for regenerations, damage-received and damage-done computing methods.
  • The Character class is the parent class for Mage, Warrior and Rogue, which only differ by several characteristics such as the weight of the inventory, immunity to spells and main attribute. It holds the name, the Inventory, game-related features (xp, current level), attributes, potion buying method.
  • The Enemy behaves like a character, only more rudimentary, as in its actions are randomized.
  • The Inventory holds the potions, the current number of coins, methods for adding and removing potions from the list.
  • The Potions are HealthPotion and ManaPotion, which both regenerate their element.
  • Inside the Shop, the Character can buy potions, however, he is limited by the current Inventory weight and number of coins left.

The data (account information and cell stories) is parsed from a JSON file with an open source package (github.com/stleary/JSON-java).
For the GUI, I decided to make it a bit more intuitive than specified, just to make sure I have a playable end-product. Most of it is a combination of JPanels, JFrames, JLabels, JButtons, JOptionPanes and the grid itself is a JPanel with a GridLayout, containing JLabels, which in turn, hold images, which are rendered every time a move is made. The login page lets the user select one account and then input the password. In case of a wrong password, the user is prompted to try again. Then, the user chooses the character and inputs the desired dimensions of the game. The game then starts and shows information inside the story area.
Inside the shop, the character is only allowed to add to the cart as many objects as possible according to the inventory weight and coins remaining. During combat, in case of no spells left or no mana left, the character is prompted to choose one of the remaining options.
This project took somewhere around 30-40 hours of work, spread throughout a month (1 or more hours per day) and I found it to be really fun to write, in this way. As opposed to non-OOP, this approach was more puzzle-like, as in pieces of code are written in the beginning, only to be assembled later on.

dungeonsanddragons-java-game's People

Contributors

magynon avatar

Watchers

 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.