Question 10
AQA Computer Science Specimen Paper 1 (7517/1)A level19 marks
On the specification
- 3.1 Fundamentals of programming4.1 Fundamentals of programming
Question text
10 This question refers to the Game and Character classes and will extend the functionality of the game. The game should be altered so that once per game the player can shoot an arrow instead of making a move in the cavern. The arrow travels in a straight line, in a direction of the player's choice, from the cell the player is in to the edge of the cavern. If the arrow hits the monster then the player wins the game and a message saying that they have shot the monster should be displayed. For this question you are only required to extend the program so that it checks if the monster is hit by the arrow when the user chooses to shoot an arrow northwards. However, the user should be able to select any of the four possible directions. In Figure 9, the two shaded cells show the cells which, if the monster is in one of them, would result in the player winning the game, as long as the player is in the cell five to the east and three to the south and chooses to shoot an arrow northwards. Figure 9 * Task 1 Modify the DisplayMoveOptions subroutine in the Game class so that the option to enter A to shoot an arrow is added to the menu. Task 2 Create a new Boolean attribute called HasArrow in the Character class. The value of HasArrow should be set to True when a new object of class Character is instantiated. Task 3 Create a new public subroutine called GetHasArrow in the Character class that returns the value of the HasArrow attribute to the calling routine. Task 4 Modify the CheckValidMove subroutine in the Game class so that: • it is a valid move if A is selected and the player does have an arrow • it is not a valid move if A is selected and the player does not have an arrow. Task 5 Create a new public subroutine called GetArrowDirection in the Character class. This subroutine should return a character to the calling routine. The user should be asked in which direction they would like to shoot an arrow (N, S, E or W) and the value entered by the user should be returned to the calling routine. If an invalid direction is entered then the user should be repeatedly asked to enter a new direction, until a valid direction is entered. The value of HasArrow should then be changed to FALSE. Task 6 Modify the Play subroutine in the Game class so that if the move chosen by the user is not M it then checks if the move chosen is A. If the move chosen was A, then there should be a call to the player's GetArrowDirection subroutine. If the user chooses a direction of N then the program should check to see if the monster is in one of the squares directly north of the player's current position. If it is then a message saying "You have shot the monster and it cannot stop you finding the flask" should be displayed. The value of FlaskFound should then be set to TRUE. After the arrow has been shot, if the monster is still alive and awake, it is now the monster's turn to move, the player should remain in the same cell as they were in before the arrow was shot. There is no need to write any code that checks if the monster has been shot when the player chooses to shoot either to the east, to the west or to the south. Task 7: test 1 Test that the changes you have made work by conducting the following test: • play the training game • shoot an arrow • choose a direction of N for the arrow. Task 8: test 2 Test that the changes you have made work by conducting the following test: • play the training game • move east • shoot an arrow • choose a direction of N for the arrow • shoot an arrow. Evidence that you need to provide Include the following in your Electronic Answer Document. 10.1 Your amended PROGRAM SOURCE CODE for the subroutine DisplayMoveOptions. [1 mark] 10.2 Your amended PROGRAM SOURCE CODE for the subroutine CheckValidMove. [2 marks] 10.3 Your amended PROGRAM SOURCE CODE for the class Character. [8 marks] 10.4 Your amended PROGRAM SOURCE CODE for the subroutine Play. [6 marks] 10.5 SCREEN CAPTURE(S) showing the results of Test 1. [1 mark] 10.6 SCREEN CAPTURE(S) showing the results of Test 2. [1 mark]