CS1331 Homework 03 - Card Game

Hello! In this assignment we will be testing your understanding of polymorphism, inheritance, abstract classes, and interfaces by having you create a simple children’s card game. Remember to give this whole guide a good once over before you begin writing.

Download zip

Table of Contents

Introduction

Seto Kaiba has decided that the rules to the card game Duel Monsters are far too complicated, and has decided to do away with most of them and create his own card game, Duel Monsters Abridged. As a proof of concept for the Kaibacorp board of directors, he has hired you to create a simple text simulation of the game.

green hair

Problem Description

You will be writing several classes to represent things such as the player, the game field, and the cards that the game will be played with. A simple frontend/testing program has been provided for you as DuelMonstersAbridged.java. Note that this file will not compile without some other classes being written first. There are alot of moving parts to this assignment, so suggested workflow would be to get it to compile first, so that way you can use the tester as you add functionality. This means you should create files for all the classes, and write the headers for their methods, just making them return some dummy values until you implement them. The tester will not be submitted, so feel free to modify it in whatever way you’d like to best test out different parts of your code.

Background

Tips

// This tag asks the compiler to let you know if you got the method header wrong
@Override
public int hashCode() {
    return 1;
}
super.toString()

Game Rules

The following is the abridged rule set for Duel Monsters Abridged. Some of these rules are implemented by the tester, but you will be responsible for enforcing some of them in your implementation. Pay attention to the solution description for what needs to be done in each class.

Solution Description

As stated in the project description, you should block out all of these classes and their methods to get the tester to compile first. Once that is done, it may make sense to work on the classes in the order they are listed here. Remember that you can compile classes individually to make sure they work before moving to the next one. That way you don’t need to deal with a ton of compiler errors all at the end.

Card.java

Represents a card that can be played in the game. This is an abstract class, and should not be able to be instantiated.

This class has the following private fields, and associated getter and setter methods for them:

This class has the following constructors:

This class has the following public methods in addition of the getters and setters:

Special.java

This is an interface that a card can implement if it can be summoned to the field from the special deck, and instantly cause an effect when summoned.

This interface has the following public methods:

ObjectDeck.java

Represents a Deck of Objects (think a deck of Cards, but not as specific). This is an abstract class and should not be able to be instantiated. It is used to hold a number of items, and can hold them in the form of an array.

This class has the following constructors:

This class has the following public methods:

CardDeck.java

Represents a deck of Cards specifically. This class is concrete, and is an ObjectDeck, making use of inherited methods so as to reuse as much code as possible (points will be deducted for unnecessarily duplicating code).

This class has the following constructors:

This class has the following public methods:

SpecialDeck.java

Represents a deck of Specials specifically. This class is concrete, and is an ObjectDeck, making use of inherited methods so as to reuse as much code as possible (points will be deducted for unnecessarily duplicating code).

This class has the following constructors:

This class has the following public methods:

MonsterCard.java

Represents a Monster card in the game, that can attack other monster cards and thereby inflict damage to the opponent’s life points. This is a Card, and should reuse as much code as possible. Points will be deducted for unnecessarily duplicating code. This is a concrete class.

This class has the following private fields, and associated getter and setter methods for them:

This class has the following constructors:

This class has the following public methods in addition of the getters and setters:

SpellCard.java

Represents a spell card that has an effect that it applies every turn, and also applies some effect when it gets destroyed. This is an abstract class and should not be able to be instantiated. This is a Card, and should reuse as much code as possible.

This class has the following constructors:

This class has the following public methods:

TrapCard.java

Represents a card that has some instant effect and does not actually get placed onto the Field. This is an abstract class that is a Card and also is Special.

This class has the following constructors:

This class has the following public methods:

Field.java

Represents a single player’s side of the game field that the cards can be placed on. There are two of these in the DuelMonstersAbridged class, where their interactions are managed. This is a concrete class.

This class has the following private fields, and associated getter methods for them (you need not write setter methods for this class):

This class has the following public methods:

Player.java

Represents a player in the game that has decks and a hand and such. This is a concrete class.

This class has the following private fields, and associated getter and setter methods for them:

This class has the following constructors:

This class has the following public methods:

BlueEyesWhiteDragon.java

Represents a Blue Eyes White Dragon monster, that also has a Special effect. This is a concrete class.

This class has the following constructors:

This class has the following public methods:

PowerCard.java

Represents a Spell Card that increases the power of monsters on its owner’s side of the field each turn, or decreases their power once destroyed.

This class has the following constructors:

This class has the following public methods:

DestroySpell.java

Represents a Trap Card that has the ability to destroy an opponent’s Spell Card.

This class has the following constructors:

This class has the following public methods:

Running and Testing

A good way to test your implementation is to play games with the tester and make sure that all of the rules of the game are being followed, and that nothing unexpected is happening. You shouldn’t need to modify the tester too much to this end, but within DuelMonstersAbridged.java, there is a method called private static void setupPlayers() that puts together the decks and instantiates the players. If you make your own cards to test functionality, you can add them into the decks here.

Javadocs

Checkstyle

As mentioned in the previous homework, you will be running a style checking program on your code. For each violation the tool finds, you will lose one point on your total grade for this assignment.

To make things easier for you in the beginning of the semester, the first few homeworks will have a checkstyle cap, or a maximum amount of points that can be lost to checkstyle. For this homework, the checkstyle cap is 50, meaning you can lose up to 50 points on this assignment due to style errors. As the semester goes on, this cap will increase with each homework and eventually go away. Run checkstyle early, and get in the habit of writing style compliant code the first time. Don’t wait until 5 minutes before the deadline to find out that you have 100+ violations.

Submitting

You should not import any libraries or packages that trivialize the assignment. This includes data structures other than arrays (so no List, Map, Set, etc). If you are unsure of whether something is allowed, ask on Piazza. In general, if something does a large part of the assignment for you, it is probably not allowed. Important: java.util.Arrays is not allowed. However, that is different from a Java array (e.g int[] nums = new int[10]), which is necessary for this assignment.