ITEC313 Object Oriented Programming
Question:
River Crossing, Game Programming
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:
- Your first task is to design and create a RiverCrossing class to represent the river crossing with the appropriate attributes and methods. Assume river flows west to east (left to right of the page), farmer moves north (straight up) and requires to transport items from the South Bank to North Bank of the river. Design class so it can be re-used in Part 2 of the assignment, the GUI version of River Crossing.
(a) Write the RiverCrossing constructor.
(b) Use a boolean (or integer) array elements as place holders for the Farmer’s items (boat, cabbage, goat, wolf). False value to represent an item located on the South Bank and True on the North Bank of river.
(c) Write a row() method to transport an item from one Bank to another Bank.
(d) Write get() methods to return string with inventory (a list of all items, including the boat) located on the North Bank and another get() method for the South Bank.
(e) Write other methods as required.
- Write a Command Line Interface class with main method to allow the user to play the game. A sample of a dialogue between the computer and the user (farmer) trying to cross from the south Bank to the north Bank:
Part 2
Create a Windows GUI (JFrame) application for launching RiverCrossing game.
Part 2
Create a Windows GUI (JFrame) application for launching RiverCrossing game.
//Create JFrame container
public class River
{
public static void main(String[] args) //main method
{
JFrame frame = new JFrame("River Crossinge");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new RiverGUI()); //create GUI
frame.pack();
frame.setVisible(true);
}//end of main method
}//end River class
Choose GUI components that reduce user errors and provide a feedback to the player. For example, there is no need for a “boat” button because “row” button always moves the boat with or without an item.
One simple GUI interface is shown in the Figure 2 below. Click the button “row” to immediately row the boat across or to transport the wolf select button “wolf” followed by click on the “row” button.

Figure 2. Basic river crossing layout.
Once again, this is only a sample interface to illustrate the idea of the game. You are free to choose your own colour scheme and buttons. Movement can be achieved by clicking a button. Make use of layout managers to design colourful and a well-organized game. Consider the following controls as a minimum requirement:
- one button to reset and start the game again,
- a text field for the player’s name (a player may choose to leave it blank).
- a text area to display a warning messages (and the past history), for example, “This is not a good idea” or to inform the player that cabbage or the goat was eaten and game is lost. You can provide your own appropriate messages.
An advanced River crossing is shown in Figure 3. Full marks will be given to fully functional basic layout but additional marks may be given by better GUI as long it is fully functional.

Figure 3. An example of advanced river crossing layout with button icons (pictures) and boat drawing.