Round Table Games liked the work you did on practical 1, and they would like a revamp of their inaugural game, Knight Fight, with a new version Knights of Legend. While they have hired a software architect to design the layout of the game, your job is to implement it in its entirety.
The software architect has provided you with the following two resources:
You should familiarize yourself with the UML. Anything in the UML specification is viable for testing/grading. However, you will notice no private variables or methods are listed (+ == public, # == protected). You will need to have private variables, and free to implement as many private helper methods as you need (we had many). Once you familiarize yourself with the UML, you should use the java documentation as a guideline of what to write for each method.
Setting up the code
When you go into Zybooks, you will see a download button. However, the only things that download are your CSV data files, and a Logger.java. This file is optional for the project, but provided in case you use one for debugging purposes. The rest of the files, you have to create from scratch - so you are better off going first to eclipse, creating a new project, and adding your CSV files into the project.
You should store the files in a data directory on your project root, and the Logger.java file in under the src directory.
Code Tracing?
There is no code tracing for the Project. The focus is on the code (200 points!) and then 50 points for a reflection.
Required Features To Implement
- File Reading and Saving
Program data should be stored in CSV files, that will be read at the launch of the program. There should also be the feature to save the current progress of the knights. There are both default files, and the ability to pass in files via the command line. - Knights
Knights gain experience defeating monsters, and there can only be four active knights on a quest at a time. - Fortunes / Bonus Cards
Before knights start a quest, a random fortune is assigned to them. This fortune provides bonuses or even minuses if the fortune is bad. - MOBS / Monsters
Knights will have random encounters with 1-4 monsters (depending on the number of active knights). - Team Management
When not on a quest, players should be able to view information on each knight, and manage their active knight pool. Knights never “die”, they are just defeated and return to the normal pool. - Text-based game
For now, the entire game is text based to the System console (System.out / System.in), however, it must be done in a way that can easily be replaced.
The above is just for the general picture, and sometimes what clients actually give us developers to work with! This is much easier to see by looking through the javadoc.
Sample Output
The following code is sample output from the game running, so you can get an idea of what your finished product looks like.
Where to Start?!?
The most common struggle when getting an assignment like this, is where to start. The biggest mistake you can make is trying to understand the entire thing before you start. Instead, remember - divide-conquer-glue. You want to start small. Break this problem up into smaller parts, until you come across a part you can solve!
The best place to start is ask yourself, what is one of the smallest pieces you can accomplish. For java programs that is often the interface, as they define your contract, but no code beyond that.
You will notice looking at the UML diagram, you have two interfaces. GameView and Attributes.
You will notice, GameView needs to know what a Knight is as part of the methods, so that is not a good place to start. You will notice Attributes need to know DiceType, and DiceType is just an enum. At this point, the flag of ‘oh, I can write one of those’ should trigger.
Based on that idea, the first classes you should actually look at implementing is
- DiceType
- DiceSet (relatively easy, only one method, only dependent on DiceType)
- Make sure to test!
- Attributes
- Fortune
- Make sure to test!
- MOB
- Make sure to test!
- Knight
- Make sure to test!
Notice, these are not dependant much on the entire programming working for them to work. After you have those classes working, you can then work on getting the data loaded from the CSV files into the objects (GameData), and slowly continue to build your objects. For each object, look at your javadoc and ask yourself only on a method basis:
- what is my quest
- what do I have to work with
- what can I get
- what can I figure out!
A quick hint, you will be starting small, and then adding a bunch of items to ArrayLists once you get going.
Testing
There are multiple ways you can test your objects while writing them. You can use the ‘UnitTest.java’ that is used in the other practicals, and have your Main.java simply call that for now. If you follow this method, you will need to remove all references to UnitTest.java when you submit for grading.
A more common way to test is to actually write separate ‘mains’. In an IDE, it is possible to setup different runtime configs or different entry points into your program. As such, your Knight.java can have a public static void main(String[] args) that tests the methods in Knight.java. You then setup a run configuration that points towards Knight.java. You do this for every file, until your ‘final’ run configuration points towards is Main.java.
This keeps your tests with each class, and won’t cause any issues on submitting your code!
Using Other Code?
You are very free to use code from the other practicals. You are highly encouraged to copy CSVReader.java from P4, and look back through your P1 code. The project is different enough from P1, that you can’t copy it directly, but it will give you an idea!
Other Hints and Guidelines
-
List?
You will notice looking at the UML and javadoc, that we use List a fair amount, but what is a List? The List is the interface for ArrayList. By using the interface List, the coder can choose to use an ArrayList or other structure that implements list. This is the power of polymorphism!Here is an example
1
2
3
4
5
6
7
List<String> myList = new ArrayList<>();
myList.add("hello");
myList.add("world");
for(String item : myList) {
System.out.println(item);
}
- Polymorphic Power
This assignment uses a fair amount, especially with GameData and GameView. By using the abstract class and interface throughout the rest of the code, we can easily swap the type of data and view. For example, what if we wanted a JSONGameData class? Would we want to change all of our code, or just that one class? To make this work in your code, here is a code snippet from our main method as an example:
1
2
3
4
5
6
GameData data = new CSVGameData(pargs.gamedata, pargs.saveData);
GameView view = new ConsoleView();
CombatEngine engine = new CombatEngine(data, view);
GameController controller = new GameController(data, view, engine);
controller.start();
Obviously, your main method will vary based on how you handled the program arguments, but noice that while I am initializing a ConsoleView(), I declare it as GameView.
- Make sure to test!
Over half of the lines in this code are simply accessors/getters. However, it is very, very easy to get lost in code if you don’t test. Make sure a class is working as expected before moving on. - Stay Social
Ask questions, describe algorithms, study together. CS is a very social activity, and remember talking through the problem makes a world of difference. - Take breaks
Half the reason for starting early, is so you can take breaks! If you are stuck, walk way and come back. The solution often presents itself.
Turning In
Turning in your code. You must submit through zybooks, and even if the file doesn’t have anything in it besides the class definition, you will still need to submit it. For all submissions, include the Logger.java even if you didn’t use it. This is required by the autograder.
Reflection
This assignment has a reflection, but for this one, we ask that you reflect on the entire course. What did you learn? Did your way of thinking change?
Software Architecture and Game Design
This assignment really highlights two areas, software architecture and game design. The design and implementation of large programs is difficult. Knowing how to test, knowing how to break up the problem, takes training, practice, practice and more practice. Our Software Engineering concentration specializes in training you to be a software architect in the future! If you really liked the idea of the UI design, and would love to make this a graphical based game - or web based game, then you should consider Human Centered Computing!
Stretch Goals
If you really enjoyed this project, then we recommend extending it over the break. That will continue to have practice coding before your next coding class. Some ideas for extension
- Add javadoc to all your methods, and generate the webpages for it all
- Add the ability to have inventory items, each with their own attributes they provide bonuses to
- Build a ‘choose your own adventure book’ into the game. Based on choices, where does the quest take the knight?