0% found this document useful (0 votes)
60 views6 pages

© OCR 2024. You May Photocopy This

Uploaded by

cvvandradeuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views6 pages

© OCR 2024. You May Photocopy This

Uploaded by

cvvandradeuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

7(a). Kim is writing an object-oriented program for a four player board game.

The board has 26 squares that


players move around, as shown in Fig. 5.1.

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.

The cost to purchase and upgrade the animal is the same.

Each animal can be upgraded to a maximum of level 3.

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.

© OCR 2024. You may photocopy this


Page 1 of 6 Created in ExamBuilder
page.
Fig. 5.3 shows a class diagram for Player. A class diagram describes a class. It contains the class name,
followed by the attributes, then the methods.

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.

Public procedure new(pID)

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.

© OCR 2024. You may photocopy this


Page 2 of 6 Created in ExamBuilder
page.
Write, using pseudocode, the constructor method for the Animal class.

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.

i. Complete, using pseudocode, the function to:


o Roll both dice
o Move the player, the dice number of spaces
o If a double is rolled, calls the procedure pickDeck
o Adds £500 if they have passed or landed on Start
o Calls the procedure missAGo if they land on space 13 or

© OCR 2024. You may photocopy this


Page 3 of 6 Created in ExamBuilder
page.
o Calls the procedure checkAnimal
o Return the new position

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 class diagram for Card is shown in Fig. 5.5.

© OCR 2024. You may photocopy this


Page 4 of 6 Created in ExamBuilder
page.
Fig. 5.5

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.

The procedure pickDeck:

 takes the current player as a parameter


 outputs the text to be displayed from the first card in the queue
 adds or subtracts the amount to/from the current player's money
 increases the head pointer

Write, using pseudocode, the procedure pickDeck.

Procedure pickDeck(curPlayer)
Print(deck(headPointer).getTextToDisplay())
curPlayer.setMoney(curPlayer.getMoney + deck(headPointer).getAmount())
headPointer = headPointer + 1
End procedure
[6]

(d). The procedure checkAnimal:

 Takes the current player as a parameter


 Accesses the data for the animal at the player's position in the array board
 If the animal is free, asks the player if they would like to purchase the animal and outputs its name and
cost, if they choose to buy the animal, it calls the procedure purchase() with the player and animal as
parameters
 If that player owns the animal, and it is not at level 3, it asks if they would like to upgrade the animal
 If they would like to upgrade, it calls the method upgrade for that animal with the current player as a
parameter
 If a different player owns the animal, it calls the method getAmountToCharge() for that animal, sending this
value and the current player as parameters to the procedure chargeStay()

Write, using pseudocode, the procedure checkAnimal.

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)

© OCR 2024. You may photocopy this


Page 5 of 6 Created in ExamBuilder
page.
end if
else
chargeStay(board (curPlayer.getPosition()).getAmountToCharge(), curPlayer)
End Procedure
[10]

© OCR 2024. You may photocopy this


Page 6 of 6 Created in ExamBuilder
page.

You might also like