A-level Computing/AQA/Paper 1/Skeleton program/2019

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This is for the AQA A-level Computer Science Specification.

This is where suggestions can be made about what some of the questions might be and how we can solve them.

Please be respectful and do not vandalise or tamper with the page, as this would affect students' preparation for their exams!

If just 'help' is typed, a list of existing commands appear[edit]

Create 'help <instruction>' which lists details about individual instruction,

If just 'help' is typed, a list of existing commands appear.

C#:

Delphi/Pascal:

Java:

Python:

#add into playgame function

    elif Command == "help":
      cmds = ["get","use","go","read","examine","open","close","move","say","playdice"]
      print("Commands:")
      for i in cmds:
        print(i,end="\n")

VB.NET:

Add into Playgame subroutine:

                Case "help"
                    Help(Instruction)

Add new subroutine:

   Sub Help(ByVal Instruction As String)
        'Created by student from Folkestone School for Girls
        Select Case Instruction
            Case "help"
                Console.WriteLine("The Commands are: Go, Get, Use, Examine, Say, Quit, Read, Move, Open, Close, PlayDice")
            Case "go"
                Console.WriteLine("Moves the player from one location to another. The go command needs to be followed by one of the six valid directions: north, south, east, west, up, down.")
            Case "get"
                Console.WriteLine("Allows the player to pick up an object that is in the same location as they are. The get command needs to be followed by the name of the object that the player wants to get. If the object can be got then it is added to the player’s inventory and is no longer in its original location.")
            Case "use"
                Console.WriteLine("Allows the player to use an object that is in their location or their inventory. The use command needs to be followed by the name of the object that the player wants to use. The effect of using an object depends on which object is being used, e.g. using a key in a room with a locked door will unlock the door (if it is the right key for that door).")
            Case "examine"
                Console.WriteLine("Provides the player with a more detailed description of an object or character in the same location as they are or an object in their inventory. The examine command needs to be followed by the name of the object or character that the player wants to examine. Examine inventory will display a list of the items the player is currently carrying.")
            Case "say"
                Console.WriteLine("The player will speak, saying the text that follows the say command.")
            Case "quit"
                Console.WriteLine("Ends the game, quitting the program.")
            Case "read"
                Console.WriteLine("Will display the text of objects that can be read e.g. books, notes, signs.")
            Case "move"
                Console.WriteLine("Allows the player to move an object that is in the same location as they are. The move command needs to be followed by the name of the object that the player wants to move. If the object can be moved then the result of moving the object will be displayed on the screen.")
            Case "open"
                Console.WriteLine("Allows the player to open an openable item that is in the same location as they are. The open command needs to be followed by the name of the item to open. This command is often used to open a door that is in-between two locations.")
            Case "close"
                Console.WriteLine("Allows the player to close a closable item that is in the same location as they are. The close command needs to be followed by the name of the item to close.")
            Case "playdice"
                Console.WriteLine("The player will play a dice game with another character. If the player wins then a list of the items that the losing character is carrying is displayed and the user chooses an item to take; if the player loses, the other character takes a random item from the player’s inventory. The playdice command needs to be followed by the name of a character to play the dice game with. The character and the player need to be in the same location and both need to have a die.")

            Case Else
                Console.WriteLine("Command Unknown.")
        End Select

    End Sub

Create 'teleport <location>' command[edit]

Create 'teleport <location>' command. Useful for testing game..

C#:

Delphi/Pascal:

Java:

Python:


def Teleport(You,Location):
  You.CurrentLocation = int(Location)
  return You, True


#Add into plagame function
elif Command == "teleport":
  Characters[0], Moved = Teleport(Characters[0],Instruction)

VB.NET:

Add the following to Playgame case statement:
         Case "teleport"
             Moved = Teleport(Characters(0), Instruction)




Add new function:

    Function Teleport(ByRef You As Character, ByVal NewPlace As Integer) As Boolean
        'Created by teacher from Folkestone School for Girls
        Dim Moved As Boolean = True

        If NewPlace >= 0 And NewPlace <= 8 Then
            You.CurrentLocation = NewPlace
        Else
            Console.WriteLine("You are unable to teleport to this location")
            Moved = False
        End If

        Return Moved
    End Function

Create 'save <filename>' command[edit]

Create 'save <filename>' command. Saves the current status of game.

C#:

Delphi/Pascal:

Java:

Python:

def Save(Characters,Items,Places):
  print("What would you like to save the file as?")
  filename = input("> ")
  f = open(filename+".gme","wb")
  pickle.dump(len(Characters),f)
  for Count in range(len(Characters)):
    pickle.dump(Characters[Count].ID,f)
    pickle.dump(Characters[Count].Name,f)
    pickle.dump(Characters[Count].Description,f)
    pickle.dump(Characters[Count].CurrentLocation,f)
  pickle.dump(len(Places),f)
  for Count in range(len(Places)):
    pickle.dump(Places[Count].ID,f)
    pickle.dump(Places[Count].Description,f)
    pickle.dump(Places[Count].North,f)
    pickle.dump(Places[Count].East,f)
    pickle.dump(Places[Count].South,f)
    pickle.dump(Places[Count].West,f)
    pickle.dump(Places[Count].Up,f)
    pickle.dump(Places[Count].Down,f)
  pickle.dump(len(Items),f)
  for Count in range(len(Items)):
    pickle.dump(Items[Count].ID,f)
    pickle.dump(Items[Count].Description,f)
    pickle.dump(Items[Count].Status,f)
    pickle.dump(Items[Count].Location,f)
    pickle.dump(Items[Count].Name,f)
    pickle.dump(Items[Count].Commands,f)
    pickle.dump(Items[Count].Results,f)
  f.close()


#Add into playgame function
    elif Command == "save":
      Save(Characters,Items,Places)

VB.NET:

Add the following to Playgame case statement:

     Case "save"
         Save(Instruction, Characters, Items, Places)


Add new subroutine (error trapping code omitted for simplicity):

    Sub Save(ByVal Filename As String, ByVal Characters As ArrayList, ByVal Items As ArrayList, ByVal Places As ArrayList)
        'Created by teacher from Folkestone School for Girls

        Try
            Using Writer As BinaryWriter = New BinaryWriter(File.Open(Filename, FileMode.Create))

                Writer.Write(Characters.Count)
                For Each Character In Characters
                    Writer.Write(Character.ID)
                    Writer.Write(Character.Name)
                    Writer.Write(Character.Description)
                    Writer.Write(Character.CurrentLocation)
                Next

                Writer.Write(Places.Count)
                For Each Place In Places
                    Writer.Write(Place.ID)
                    Writer.Write(Place.Description)
                    Writer.Write(Place.North)
                    Writer.Write(Place.East)
                    Writer.Write(Place.South)
                    Writer.Write(Place.West)
                    Writer.Write(Place.Up)
                    Writer.Write(Place.Down)
                Next

                Writer.Write(Items.Count)
                For Each Item In Items

                    Writer.Write(Item.ID)
                    Writer.Write(Item.Description)
                    Writer.Write(Item.Status)
                    Writer.Write(Item.Location)
                    Writer.Write(Item.Name)
                    Writer.Write(Item.Commands)
                    Writer.Write(Item.Results)

                Next
            End Using
            Console.WriteLine("Save Successful")

        Catch
            Console.WriteLine("Unable to Save")
        End Try

    End Sub

Add instruction to add a new character to game[edit]

Add instruction to add a new character to game. eg 'addcharacter <name>'

C#:

Delphi/Pascal:

Java:

Python:

def AddCharacter():
  TempCharacter = Character()
  TempCharacter.Name = input("Input the name of the character: ")
  TempCharacter.Description = input("Input the description of the character: ")
  TempCharacter.ID = int(input("Input the ID of the character: "))
  TempCharacter.CurrentLocation = int(input("Input the current location of the character: "))
  return TempCharacter

#Add to playgame function
    elif Command == "addcharacter":
      Characters.append(AddCharacter())

VB.NET:

Add the following to Playgame case statement:
     Case "addcharacter"
        AddCharacter(Instruction, Characters, Places)

Add new subroutine:

    Sub AddCharacter(ByVal Character As String, ByVal Characters As ArrayList, ByVal Places As ArrayList)
        ' Created by teacher from Folkestone School for Girls
        ' Error trapping omitted to keep the code simple/short

        Dim TempCharacter As Character
        Dim TempPlace As Place
        Dim Counter As Integer = 0
        Dim RoomDescription As String

        ' Get details for new character including a description of character when room is described
        Console.WriteLine("Please enter the details the character called " & Character)
        Console.Write("ID (eg 1003):")
        TempCharacter.ID = Console.ReadLine()
        Console.Write("Name:")
        TempCharacter.Name = Console.ReadLine()
        Console.Write("Description:")
        TempCharacter.Description = Console.ReadLine()
        Console.Write("Initial Location (eg 1-8):")
        TempCharacter.CurrentLocation = Console.ReadLine()
        Console.Write("Room Description (how it describes your character found in room):")
        RoomDescription = Console.ReadLine()

        ' Adds the characters details to arraylist
        Characters.Add(TempCharacter)


        ' You need to add a description to the room that the character is in or you will not know about it.
        ' You need to locate where the room details are stored in the array so that you update the room description.
        For Each Place In Places
            If Place.ID = TempCharacter.CurrentLocation Then
                Exit For
            End If
            Counter += 1
        Next

        TempPlace.ID = Places(Counter).ID
        TempPlace.Description = Places(Counter).Description + " " + RoomDescription
        TempPlace.North = Places(Counter).North
        TempPlace.East = Places(Counter).East
        TempPlace.South = Places(Counter).South
        TempPlace.West = Places(Counter).West
        TempPlace.Up = Places(Counter).Up
        TempPlace.Down = Places(Counter).Down


        Places(Counter) = TempPlace

    End Sub

Add 'examine room' option to view details of room again[edit]

Add 'examine room' option to view details of room again. Fairly simple but a useful option when developing 'addcharacter' or 'additem'.

C#:

Delphi/Pascal:

Java:

Python:

Answer 1 - Alter Examine function to take in Places as well.

def Examine(Items, Characters, ItemToExamine, CurrentLocation, Places):
  Count = 0
  if ItemToExamine == "inventory":
    DisplayInventory(Items)
  elif ItemToExamine == "room":
    print(Places[Characters[0].CurrentLocation - 1].Description)
    DisplayGettableItemsInLocation(Items, Characters[0].CurrentLocation)
  else:
    IndexOfItem = GetIndexOfItem...

Answer 2 - alter the selection statement in PlayGame

elif Command == "examine":
      if Instruction == "room":
        Moved = True
      else: 
        Examine(Items, Characters, Instruction, Characters[0].CurrentLocation, Places)

VB.NET:

Adjust case statement within Playgame subroutine:

                Case "examine"
                    If Instruction = "room" Then
                        Moved = True
                    Else
                        Examine(Items, Characters, Instruction, Characters(0).CurrentLocation)
                    End If

Create new items for the game via an 'additem <name>'[edit]

Create new items for the game via an 'additem <name>' command. Useful once you have created 'save <filename>' option.

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:

Create a new 'drop <item>' command.[edit]

Create 'drop <item>' command that drops the item selected from the user's Inventory

C#:

Delphi/Pascal:

Java:

Python:

def Drop(Items, Characters, ItemToDrop, CurrentLocation):
  Count = 0
  IndexOfItem = GetIndexOfItem(ItemToDrop, -1, Items)
  if IndexOfItem != -1:
    if Items[IndexOfItem].Name == ItemToDrop and Items[IndexOfItem].Location == INVENTORY:
      print(Items[IndexOfItem].Name+" was dropped")
      Items[IndexOfItem].Location = CurrentLocation
      return Items
  print("You cannot find " + ItemToExamine + " to drop.")
  return Items

#Add into PlayGame Function
    elif Command == "drop":
      Items = Drop(Items,Characters,Instruction,Characters[0].CurrentLocation)

VB.NET:

Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:

Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:


Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:


Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:

Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:

Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:

Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET:

Question[edit]

Description of question

C#:

Delphi/Pascal:

Java:

Python:

VB.NET: