Course web page: Introduction to Computer Science for majors II James Tam Return to the course web page

CPSC 233: Full Assignment 3

Tuesday October 27 at 4 PM

New concepts to be applied for this assignment

Description

Write a simple fantasy-oriented combat simulation between an orcish and dwarven forces.


Figure 1: Orcs vs. dwarves

The starting positions will be read in from a text file "data.txt". Figure 2 shows the text file as viewed from MS-Word (where the 'invisible' spaces are shown as dots).


Figure 2: default contents of the data.txt file.

While you can change the contents of the starting file for testing make sure that it always remains 10 characters by 10 characters in size. You must ensure that 'empty' locations are still filled with spaces! Be aware that your markers may produce different versions of input files for testing purposes. They will all conform to the basic requirements (10x10, valid characters will consist only of: 'O', 'D' or spaces) but your program should be able to properly handle anything that they come up with.

The position of a character in the text file will correspond to the position of an array of "Entity" in your program. (Figure 3) Each 'O' in the text file becomes an orcish fighter while the 'D' becomes a dwarven warrior. Both are instances of the Entity class each with a difference appearance and different health or "hit point" scores (10 for the orcs and 15 for the dwarves). Empty spaces will become null elements in the array.


Figure 3: starting view of the game world

You must use the pre-created code in the FileInitialization.class file to read the text information into the 2D Entity array (ensuring that the byte code .class file is the same directory as your source code *.java files and the "input.txt" data file.

public class FileInitialization
{
    public static Entity[][] read() {
        /**
          When this method is called it will look in the current working directory for the
          "data.txt" file. If the file is in this location and in the proper format the
          Entity array will be initialized with Orcs, Dwarves and empty (null) elements.

          The array is returned back to the caller.
        */
    }

}

Usage format:

  FileInitialization.read();

 

Example usage (because the method is static no instance should be created)

  Entity [][] e = FileInitialization.read(); // Array is now initialized with the positions specified in the text file.

 

The game runs on a turn-by-turn basis until either all the dwarves or orcs have been eliminated. Each turn the orcs will move down and right by one square (diagonally 'down') while the dwarves move diagonally 'up'. Movement will stop for an entity when: 1) the edge of the 'world' is reached 2) an obstacle is encountered (another entity) 3) there is an opposing entity an an adjacent square (orcs and dwarves are in opposition). You need some sensible rules for handling special cases that arise during movement (e.g. don't move an entity more than once during a turn and multiple entities should not move into the same location during a turn). When opposing entities are adjacent: each orc will randomly attack an adjacent dwarf while each dwarf does the same to an adjacent orc. Attacks are assumed to occur simultaneously. Each entity will randomly inflict 1- 6 points of damage on an opposing entity (randomly generate a value in this range for each attacking entity). At the end of each turn the game should display information about the all the attack damage inflicted for each entity (entity at (row/column) inflicted 'X points of damage' on the entity at (row/column) and which entities were eliminated - hit points reduced to zero or less). To make it easier to follow the simulation the program should 'pause' at the end of each turn (prompt the user to hit enter and wait for a response before proceeding onto the next turn). The simulation continues until all the entities on one side or the other have been eliminated (or both sides eliminate each other).

Technical details

Classes in the simulation

To help you get started some of the code that you need to write has already been provided. You should not modify the existing starting code but you can add new code to implement the required features (except for the byte code file which of course which cannot be modified):

Program features

Your marks will also be determined by the number of features you implement as well as your adherence to the stylistic conventions taught in class as well your program documentation.

  1. Runs on a turn-by-turn basis

  2. Prompts the user at the end of each turn before proceeding to the next turn

  3. Orcs move in the prescribed fashion

  4. Dwarves move in the prescribed fashion

  5. Orcs won't move past the bounds of the world

  6. Dwarves won't move past the bounds of the world

  7. Orcs stop moving when adjacent to a dwarf

  8. Dwarves stop moving when adjacent to an orc

  9. Correct and complete round-by-round statistics displayed

  10. Orcs will randomly attack adjacent dwarves (damage range is correct)*

  11. Dwarves will randomly attack adjacent orcs (damage range is correct)*

  12. Orcs will be removed from the world when hit points are zero or less*

  13. Dwarves will be removed from the world when hit points are zero or less*

  14. Program can determine when all the opponents on one side or the other (or both) have been eliminated and end the simulation*

  15. The output of the program is graphical rather than using text (input can still be console/text based). You will have to learn the required libraries on your own (bonus feature).
  16. Program employs sound effects to enhance game play. You will have to learn the required libraries on your own (bonus feature).

 

Features marked with a star '*' require that Feature #9 is correctly implemented before credit before credit is awarded for the marked feature

Using pre-written Java code

You will need to use the built in code class Random. Beyond that (and common sense operators and functions such as those for input/output and mathematical operators), unless you told otherwise, you will need to write your own code and cannot use other pre-written Java classes or operators. You must use the starting Java code that has been provided in the assignment directory under: /home/233/assignments/assignment3/code

Submitting your work:

  1. Assignments (source code/'dot-java' files) must be electronically submitted according to [the assignment submission requirements] using [D2L].
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].
  3. Before you submit your assignment to help make sure that you haven't missed anything here is a [checklist] of items to be used in marking.

Images of the orcs and dwarves provided by the educational license to the University of Calgary from www.colourbox.com