FACULTY OF LAW & BUSINESS
Peter Faber Business School
ITEC313: Object Oriented Programming, Semester 1, 2020 Assessment 3 [Weight 50%]
River Crossing, Game Programming Assignment
Problem Description
One day a farmer goes to the market, taking with him a cabbage and a goat. On the way he captured a wolf, he’s a mighty farmer, and took it with him to the market. They came to a river. And on the Bank, there’s a boat. Now, the problem is that the boat just big enough to carry the farmer and one of the others. If the farmer leaves the wolf and the goat together, in his absence, the wolf would make a meal of the goat. Neither, could be leave the goat and the cabbage alone: the goat would eat the cabbage. Being used to hardship, the farmer was quite prepared to make several trips back and forth, just so long as he could eventually bring them all to the other side and went on to the market. How should he arrange the trips?
Figure 1. CLI version of the river crossing
Part 1 Requirements
Your task as a software developer is to write a Command Line Interface (CLI) application RiverCrossingCLI simulating the river crossing. The farmer (player) can then work out the steps required to safely move all items to the other side of the river. In Part 1 you will need to do two tasks:
Sample 1
Welcome to the CLI version of the River Crossing Game. Farmer crossing a river has boat, cabbage, goat and wolf. Boat can carry two items at the time and cannot leave the cabbage alone with the goat or the goat with the wolf.
North Bank:
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:boat, cabbage, goat, wolf
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 3
North Bank:boat, goat
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:cabbage, wolf
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 1
North Bank:goat
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:boat, cabbage, wolf
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 4
North Bank:boat, goat, wolf
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:cabbage
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 3
North Bank:wolf
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:boat, cabbage, goat
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 2
North Bank:boat, cabbage, wolf
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:goat
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 1
North Bank:cabbage, wolf
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:boat, goat
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 3
North Bank:boat, cabbage, goat, wolf
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:
***** You won *****
Welcome to the CLI version of the River Crossing Game. Farmer crossing a river has boat, cabbage, goat and wolf. Boat can carry two items at the time and cannot leave the cabbage alone with the goat or the goat with the wolf.
North Bank:
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:boat, cabbage, goat, wolf
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 2
North Bank:boat, cabbage
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:goat, wolf The wolf ate the goat
***** Game over *****
Sample 3
Welcome to the CLI version of the River Crossing Game. Farmer crossing a river has boat, cabbage, goat and wolf. Boat can carry two items at the time and cannot leave the cabbage alone with the goat or the goat with the wolf.
North Bank:
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:boat, cabbage, goat, wolf
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 3
North Bank:boat, goat
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:cabbage, wolf
You have the following choices:
What is your choice (1, 2, 3, 4 or 5)? 4
North Bank:boat, goat
────────────────────────────────────────
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
────────────────────────────────────────
South Bank:cabbage, wolf
***** I don't see the wolf on the North Bank You have the following choices:
What is your choice (1, 2, 3, 4 or 5)?
The above dialogs are meant as a sample only. You are at liberty to design the game in any way you like and you should. In particular, you should inform the user the consequences of a bad decision, i.e., the cabbage or the goat was eaten and the game is over
A sample of an UML diagram shows the class diagram for
RiverCrossing class
Instance attributes are all private;
RiverCrossing Methods
() the move successful
1 all items transported to north Bank, player won
(error code)
11 the selected item is already across the river, error code
12 the goat ate the cabbage, end of the game
13 the wolf ate the goat, end of the game
14 the goat ate the cabbage and wolf ate the goat, end of the game.
For solution connect with our online professionals.