© OCR 2024. You May Photocopy This
© OCR 2024. You May Photocopy This
Fig. 5.1
Each player takes it in turn to roll two dice. They then move that number of spaces on the board. If they roll a
double (both dice have the same value), they then take a card from the deck. The deck contains 40 cards that
each include a sentence (such as “You have won the lottery”). The sentence on the card determines if money is
given or taken away from the player.
Fig. 5.2
Each square (apart from Start and Miss a turn) has an animal associated with it that the player can purchase, if
it has not been purchased already, for example square 6 has a Squirrel. Fig. 5.2 shows an example of one of
these animals. Once a player has purchased the animal, any opposing player which subsequently lands on the
square/animal has to pay a fine.
Each animal can be upgraded, with each upgrade the game charges more each time a player stops on them. For
example, with no upgrade the level 0 squirrel costs £10 when a player stops on it. If £1000 is paid to upgrade,
the squirrel is then a level 1 animal and now charges £50 for a stop.
When a player lands on, or passes the square ‘Start’ (position 0), they receive £500. If they land on ‘Miss a turn’
(position 13), they miss their next turn.
i. A class, Player, stores the player's ID (P1, P2, P3, P4), their current board position and the amount of
money they have.
Fig. 5.3
The constructor creates a new instance of Player, taking the player's ID as a parameter. The board
position is set to 0, and money to £2000.
Write, using pseudocode, the constructor method for the Player class.
playerID = pID
boardPosition = 0
money = 2000
End procedure
[3]
ii. A class, Animal, define the attributes and methods for the animals stored in each square.
Fig. 5.4 shows a class diagram for Animal.
Fig. 5.4
The constructor takes the required data as parameters and then sets currentLevel to 0, and assigns the
parameters as the remaining attributes for the new object.
Public procedure new(pName, pCost,, pL0, pL1, pL2, pL3, pLink, pSquare, pOwned)
name = pName
currentLevel = 0
cost = pCost
L0 = pL0
L1 = pL1
L2 = pL2
L3 = pL3
imageLink = pLink
setsquare = pSquare
owned = pOwned
End Procedure
[4]
iii. Write, using pseudocode, the code to create an instance of Animal for the Squirrel shown in Fig. 5.2,
positioned on square number 6, for the constructor function you wrote in part (a)(ii).
Squirrell = new Animal(“Squirrel”, 1000, 10, 50, 100, 500, “squirrel.bmp”, 6, “free”)
[2]
(b). The board is stored as a 1D array, board, of data type Animal. The spaces at 0, and 13, are left as empty
elements that are checked using separate functions.
currentPlayer.getPosition()
dice1
500
26
13
Return position
[6]
ii. *The parameter currentPlayer from part (b)(i) can be passed by value or by reference.
Explain the difference, benefits and drawbacks between passing by value and by reference. Recommend
which should be used for currentPlayer, justifying your decision.
[9]
(c). The deck is stored as a zero-indexed 1D array, named deck, of type Card.
The array, deck, is treated as a queue, with a variable, headPointer, identifying the first card in the deck. When a
card has been used, the head pointer increases to move to the next position. If the end of the deck is reached,
the head pointer returns to 0 and starts again.
Procedure pickDeck(curPlayer)
Print(deck(headPointer).getTextToDisplay())
curPlayer.setMoney(curPlayer.getMoney + deck(headPointer).getAmount())
headPointer = headPointer + 1
End procedure
[6]
Procedure checkAnimal(curPlayer)
if board (curPlayer.getPosition()).getOwned() == “free” then
buy = input(“Would you like to buy ” + board (curPlayer.getPosition()).getName() + “ for £” + board
(curPlayer.getPosition()).getCost() + “? (y/n)”)
if buy == “y” then
purchase(curPlayer, board (curPlayer.getPosition()))
end if
elseif board (curPlayer.getPosition()).getOwned() == curPlayer AND board
(curPlayer.getPosition()).getCurrentLevel < 3 then
upg = input(print(“Would you like to upgrade ” + board (curPlayer.getPosition()).getName() + “ for £” + board
(curPlayer.getPosition()).getCost() + “? (y/n)”))
if upg == “y” then
board (curPlayer.getPosition()).upgrade(curPlayer)