1.4-Software-Development-Principles

Playing with dice

Introduction

Many (board)games use dice to provide a certain level of randomness. Usually dice return a certain number, but other possibilities are available.

This is one of those assigments that doesn’t really have an end. If you can think of other things to do with these generic dice, feel free to build something else.

Assignment 1 (1)

Create a Die class that keep track of a list of values. (Extra points if you use your own generic list).

This way a die will randomly choose from a list of values:

Assignment 2 (2)

Make the Die class generic so that it can roll any type of value. For instance:

Assignment 3 (3)

For many (roleplaying) games we want the player to encounter random groups of enemies. We suggest defining this interface:

public interface Rollable<T> {
    T roll();
} 

Obviously the Die class should implement this interface.

The table below is a list of encounters: Encounter Table

The encounter table has twelve entries that generate a group of monsters. The number of monsters is determined using dice. “2d4+2” Means “2 dice with 4 sides plus 2”. For this you need to roll a dice with sides [1,2,3,4] twice, and add the total, increased by another 2. For more information about dice notation, there is a wiki page.

You may choose to create a Roll<Integer> class that handles this definition through a list of dice, plus a modifier. When rolled, each die is rolled and added to the total plus the modifier.

Create an Encounter class that also implements the Rollable interface. When rolled, the Encounter randomly chooses the number of enemies as specified. Feel free to use a text for this. Extra points if the Bandit Captain has a random name.

Finally create a die that has 12 Encounters as it sides. So when you roll the die, you get a type of encounter. Then you roll the encounter to know the specifics.

You have now created a die that rolls dice…