COMP 1046 Object-Oriented Programming
Object-Oriented Programming
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
COMP 1046
Object-Oriented Programming
Assignment
Mastermind Game Development
Part 1 - Design
WARNING
This material has been reproduced and communicated to you by or on behalf of the University of
South Australia in accordance with section 113P of the Copyright Act 1968 (Act). The material in
this communication may be subject to copyright under the Act. Any further reproduction or
communication of this material by you may be the subject of copyright protection under the Act.
Introduction
The assignment is intended to provide you with the opportunity to put into practice what you have
learnt in the course by applying your object-oriented programming knowledge and skills. It will
require you to apply object-oriented methods to design, implement, and test a text-based
application software where users can play a Mastermind game.
The assignment is worth for 30% of the assessment in this course, and consists of two parts:
• Part 1 – Design (10%)
• Part 2 – Implementation (20%)
This document specifies the tasks for Part 1 of the assignment, UML design of the software, while
Part 2 is be specified in a separate document.
This assignment is an individual task that will require an individual submission. You are required to
submit your work via the course website as prescribed in the Submission Details section.
This document is a kind of specification of the required end product that will be generated by
implementing the assignment. Like many specifications, it is written in English and hence will contain
some imperfectly specified parts. Please make sure you seek clarification if you are not clear on any
aspect of this assignment.
Course Objectives
By completing this assignment, you are expected to partially fulfill the following course objects:
• CO1. Convert a problem statement into an object oriented solution
• CO2. Use inheritance and polymorphism to solve problems
• CO6. Analyse and explain the behaviour of object oriented programs
Assignment Learning Outcomes
This assignment is for assessing the following learning outcomes:
• Design a UML class diagram using UMLet (or UMLetino)
• Apply object-oriented principles including encapsulation, abstraction, inheritance,
and polymorphism to the software design
Background: Mastermind
Note that this section provides you with a background information while the assignment task should
follow the task specification described in the next section.
The board game is played using:
• a decoding board, with a shield at one end covering a row of four large holes, and a set of
rows containing four large holes next to a set of four small holes;
• code marbles of six different colours (Red, Green, Blue, Yellow, White, Black) are used to
represent a code and placed in the large holes on the board; and
• key pegs, some coloured black, some white, are for providing feedback on the guessed code
placed in the small holes on the board.
Played between two players in a board game, one player becomes the codemaker, the other the
codebreaker.
The codemaker chooses a code, a pattern of four code marbles. Duplicates are allowed depending
on player choice, so the player could even choose four code marbles of the same colour. The chosen
code is placed in the four large holes covered by the shield, visible to the codemaker but not to the
codebreaker.
The codebreaker tries to guess the code, in both order and colour, within a certain number of
attempts. Each guess is made by placing a row of code marbles on the decoding board. Once placed,
the codemaker provides feedback by placing from zero to four key pegs in the small holes of the row
next to the guess. A black key peg is placed for each code marble from the guess which is correct in
both colour and position. A white key peg indicates the existence of a correct colour code marble
placed in the wrong position.
If there are duplicate colours in the guess, they cannot all be awarded a key peg unless they
correspond to the same number of duplicate colours in the hidden code. For example, if the hidden
code is white-white-black-black and the player guesses white-white-white-black, the codemaker will
award two black key pegs for the two correct whites, nothing for the third white as there is not a
third white in the code, and a black key peg for the black. No indication is given of the fact that the
code also includes a second black.
Once feedback is provided, another guess is made by the codebreaker; guesses and feedback
continue to alternate until either the codebreaker guesses correctly, or the number of incorrect
guesses reach the number of attempts allowed. If the code is not guessed correctly within the
number of attempts allowed, then the shield is uncovered to reveal the code.
The following video clip may be also helpful to understand the concept:
https://www.youtube.com/watch?v=wsYPsrzCKiA
The Assignment Task Specification
The task for the Part 1 of the assignment is to produce a UML class diagram of an application
software, called the World of Mastermind (WoM), a text-based application software where users
can play a Mastermind game.
As a text-based application software, WoM will use a command line interface where users type in a
command or input and the relevant output is printed onto the screen in text. When the software is
executed, it will show a greeting message and a list of commands, followed by a command prompt
‘>’ indicating the system is ready to take user’s input. At the prompt, users can give one of the
following commands:
• r: register a new user, which will create a new user
• s: show the score board, which will print the list of the users and their scores
• p: play a game, which will start a new game
• q: quit, which will quit the application
For registering a new user, the system will ask for the name of the new user. The user name is not
allowed to be changed after being registered, and also the name must be unique (i.e. not allowed to
have the same name as an existing user). A new user will always start with a score of 0 point.
Below is an example of the output on the screen (user’s input in bold italic).
Welcome to the World of Mastermind!
Developed by Alan Turing
COMP 1048 Object-Oriented Programming
What would you like to do?
(r) register a new user
(s) show the score board
(p) play a game
(q) quit
> r
What is the name of the new user?
> Alan
Welcome, Alan!
What would you like to do?
(r) register a new user
(s) show the score board
(p) play a game
(q) quit
> r
What is the name of the new user?
> Alan
Sorry, the name is already taken.
What would you like to do?
(r) register a new user
(s) show the score board
(p) play a game
(q) quit
> r
What is the name of the new user?
> Steve
Welcome, Steve!
Once the users are registered, they can play the game of Mastermind. Only one game will be played
at a time, i.e., the game must be finished before playing another game. Before starting the game,
users will be asked questions for setting it up. First, users will be asked how many players (between
2 to 4, inclusive) will play the game, followed by asking for the name of each player. If the name does
not match to a valid registered user or if the user with the name is already in the game, an error
message will be shown and asked again. There will be a special built-in name “HAL9000” and “VIKI”
that are for players controlled by the computer. Users are not allowed to register with these names
assigned to computer players. After the players are selected, the users will be asked to choose how
many attempts (between 5 to 10, inclusive) of guessing the code will be allowed.
What would you like to do?
(r) register a new user
(s) show the score board
(p) play a game
(q) quit
> p
Let’s play the game of Mastermind!
How many players (2-4)?
> 2
What is the name of player #1?
> Bill
Invalid user name.
What is the name of player #1?
> Alan
What is the name of player #2?
> Alan
Alan is already in the game.
What is the name of player #2?
> HAL9000
How many attempts will be allowed for each player (5-10)?
> 5
After it’s all set, the game will start. The game is played in a round-robin manner where each player
takes a turn. First, each player will take a turn to make a code for the next player who has to break it.
Think of it as if each player has a decoding board, and each player sets the code hidden behind the
shield for the next player if it were in an actual board game. For example, if there are three players,
first player sets the code for the second player to break, the second player sets the code for the third
player, and the third player sets the code for the first player.
To set the code, users will enter a string of four characters, each character representing a colour that
consists the code. The characters representing colours are, ‘R’ for red, ‘G’ for green, ‘B’ for blue, ‘Y’
for yellow, ‘W’ for White, and ‘K’ for black. For example, ‘RGBK’ will be a code of red, green, blue,
and black. If the code entered is invalid (i.e. either not having four colours or including any invalid
colour) an error message is printed and asked for entering the code again. If the player in turn is a
computer, it will generate a random code.
* Alan's turn to set the code for HAL9000 to break.
Please enter the code:
> BTWRA
Invalid code.
It must be exactly four characters, each can be R, G, B, Y, W, or K.
Please enter the code:
> BYWR
The code is now set for HAL9000 to break.
* HAL9000's turn to set the code for Alan to break.
The code is now set for Alan to break.
Once all of the players took turn to set the code for the next player, players take turns to guess the
code set for him/her/itself. In each turn, a summary of previous attempts of the player taking the
turn is shown on the screen. Users are then asked to enter their guess, while the computer players
will randomly generate its guess and print it on the screen. The feedback on a guess is automatically
provided by the system. If a player breaks the code (i.e., gives the correct code) the game continues
with the rest of the players until everyone either succeeds to break the code or fails by using up all
the number of attempts allowed.