Jump to content

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

From Wikibooks, open books for an open world

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 the page, as this would affect students' preparation for exams!
Please do not discuss questions on this page. Instead use the discussion page.

Section C Predictions

[edit | edit source]

The 2022 paper 1 will contain 5 questions worth 17 marks. As long as you know the program well, this will be a walk in the park.

06. This question is about the Breakthrough class.

06.1 State the name of a Boolean attribute in the Breakthrough class. [1 mark]

06.2 State the name of a method in the Breakthrough class that uses exception handling. [1 mark]

06.3 With reference to the CreateStandardDeck and AddDifficultyCardsToDeck methods and the "game1.txt" file - how many cards in total are in the deck? [1 mark]

06.4 With reference to the "game1.txt" saved game file, state what each line of the saved game file represents. [2 marks]


07. This question is about the method __Loadlocks in the Breakthrough class.

07.1 State the datatype used for __Locks. [1 mark]

07.2 State a correctly formatted single line which could be added to the "locks.txt" file to represent a 3-challenge lock needing an Acute Pick, Basic File and a Crude Key to open it. [1 mark]


08. This question is about the CreateStandardDeck and AddDifficultyCardsToDeck methods in the Breakthrough class.

08.1 State the type of iteration used. [1 mark]

08.2 State how many difficulty cards are generated when the game is run.

08.3 State how many other cards are generated when the game is run.

08.4 If we wished to make the game less difficult (reducing the number of difficulty cards from five to three), describe the necessary code changes which would need to be made assuming we wanted to keep the overall total number of cards the same.

  • Question about a class?
  • Question about a second class?
  • Question about a third class?
  • Question about a class diagram?
  • Question about a game functionality such as how to tell if game is ended?
  • Question about why text files were used over other file types to store data?

These predictions are made based on last year's Advanced Subsidiary paper

Section D Predictions

[edit | edit source]

Programming Questions on Skeleton Program

  • The 2022 paper 1 contains 4 questions: a 5 mark, a 9 mark question, a 10 mark question and one 13 mark question - these marks include the screen capture(s), so the likely marks for the coding will be 1-2 marks lower.
  • The 2021 paper 1 contained ...
  • The 2020 paper 1 contained 4 questions: a 6 mark, an 8 mark question, a 11 mark question and one 12 mark question - these marks include the screen capture(s), so the likely marks for the coding will be 1-2 marks lower.
  • The 2019 paper 1 contained 4 questions: a 5 mark, an 8 mark question, a 9 mark question and one 13 mark question - these marks include the screen capture(s), so the marks for the coding will be 1-2 marks lower.
  • The 2018 paper 1 contained one 2 mark question, a 5 mark question, two 9 mark questions, and one 12 mark question - these marks include the screen capture(s).
  • The 2017 paper 1 contained a 5 mark question, three 6 mark questions, and one 12 mark question.

Current questions are speculation by contributors to this page.

Fix Key 1-5.

[edit | edit source]

Fix "IndexOutOfRange" exception caused by inputting a card number not in the range 1 to 5.

C#:

private int GetCardChoice() {
    do {
        Console.Write("Enter a number between 1 and 5 to specify card to use:> ");
        Choice = Console.ReadLine();
        loop = !int.TryParse(Choice, out Value);

        if (Value > 0 && Value < 6) {
            inRange = true;
        }
        else {
            inRange = false;
        }
    } while (!inRange || loop)
    return Value;
}


Delphi/Pascal:


Java:

private int getCardChoice() {
    String choice;
    int value = 0;
    boolean parsed;
    do {
        Console.write("Enter a number between 1 and 5 to specify card to use:> ");
        choice = Console.readLine();
        try {
            value = Integer.parseInt(choice);
            parsed = true;
        } catch (NumberFormatException e) {
            parsed = false;
        }
    } while (!parsed || value < 1 || value > 5);
    return value;
}


Python:

This handles characters and out of range integers entered.

def __GetCardChoice(self):
    Choice = 0
    while not 0 < Choice < 6:
        try:
            Choice = int(input("Enter a number between 1 and 5 to specify card to use:> "))
        except:
            pass
    return Choice



VB.NET:

      Private Function GetCardChoice() As Integer
            Dim Choice As Integer = 0
            Dim Value As Integer
            While Choice < 1 Or Choice > 5
                Try
                    Do
                        Console.Write("Enter a number between 1 and 5 to specify card to use:> ")
                        Choice = Console.ReadLine()
                    Loop Until Integer.TryParse(Choice, Value)
                Catch ex As Exception
                End Try
            End While
            Return Value
        End Function


        Private Function GetCardChoice() As Integer
            Dim Choice As String
            Dim Value As Integer
            Do
                Console.Write("Enter a number between 1 and 5 to specify card to use:> ")
                Choice = Console.ReadLine()
            Loop Until Integer.TryParse(Choice, Value) And (Value > 0 And Value < 6)
            Return Value
End Function


Add Load Function

[edit | edit source]

Add functionality to select (load) a specific (saved) game file (currently no choice is given).

C#:

private void SetupGame()
        {
            string Choice;
            Console.Write("Enter L to load a game from a file, anything else to play a new game:> ");
            Choice = Console.ReadLine().ToUpper();
            if (Choice == "L")
            {
                //Loading
                Console.WriteLine("Please Enter the filename");
                string filename = Console.ReadLine();
                if (!LoadGame(filename + ".txt"))
                {
                    GameOver = true;
                }
                //Loading
            }
            else
            {
                CreateStandardDeck();
                Deck.Shuffle();
                for (int Count = 1; Count <= 5; Count++)
                {
                    MoveCard(Deck, Hand, Deck.GetCardNumberAt(0));
                }
                AddDifficultyCardsToDeck();
                Deck.Shuffle();
                CurrentLock = GetRandomLock();
            }
        }


Delphi/Pascal:


Java:

private void setupGame() {
    String choice;
    Console.write("Enter L to load a game from a file, anything else to play a new game:> ");
    choice = Console.readLine().toUpperCase();
    if (choice.equals("L")) {
        Console.write("Enter file to load:> ");
        String name = Console.readLine();
        if (!loadGame(name)) {
            gameOver = true;
        }
    } else {
        createStandardDeck();
        deck.shuffle();
        for (int count = 1; count <= 5; count++) {
            moveCard(deck, hand, deck.getCardNumberAt(0));
        }
        addDifficultyCardsToDeck();
        deck.shuffle();
        currentLock = getRandomLock();
    }
}


Python:

def __SetupGame(self):
    Choice = input("Enter L to load a game from a file, anything else to play a new game:> ").upper()
    if Choice == "L":
        if not self.__LoadGame( input("Enter file to load:> ")):
            self.__GameOver = True
    else:
        self.__CreateStandardDeck()
        self.__Deck.Shuffle()
        for Count in range(5):
            self.__MoveCard(self.__Deck, self.__Hand, self.__Deck.GetCardNumberAt(0))
        self.__AddDifficultyCardsToDeck()
        self.__Deck.Shuffle()
        self.__CurrentLock = self.__GetRandomLock()


VB.NET:

Private Sub SetupGame()
            Dim Choice As String
            Console.Write("Enter L to load a game from a file, anything else to play a new game:> ")
            Choice = Console.ReadLine().ToUpper()
            If Choice = "L" Then
                Dim file As String
                Console.WriteLine("Enter File to load")
                file = Console.ReadLine
                If Not LoadGame(file) Then
                    GameOver = True
                End If
            Else
                CreateStandardDeck()
                Deck.Shuffle()
                For Count = 1 To 5
                    MoveCard(Deck, Hand, Deck.GetCardNumberAt(0))
                Next
                AddDifficultyCardsToDeck()
                Deck.Shuffle()
                CurrentLock = GetRandomLock()
            End If
        End Sub


Require player to complete challenges in order

[edit | edit source]

Currently the challenges for a lock do not need to be completed in order. Change the functionality to only allow the user to complete challenges for a lock in the order they are listed.

C#:

public virtual bool CheckIfConditionMet(string sequence)
        {
            foreach (var C in Challenges)
            {
                if (!C.GetMet() && sequence == ConvertConditionToString(C.GetCondition()))
                {
                    C.SetMet(true);
                    return true;
                }
                else if (!C.GetMet() && sequence != ConvertConditionToString(C.GetCondition()))
                {
                    return false;
                }
            }
            return false;
        }


Delphi/Pascal:


Java:

public boolean checkIfConditionMet(String sequence) {
    for (Challenge c : challenges) {
        if (!c.getMet()) {
            if (sequence.equals(convertConditionToString(c.getCondition()))) {     
                c.SetMet(true);
                return true;
            }
            else {
                return false;
            }
        }
    }
    return false;
}


Python:

def CheckIfConditionMet(self, Sequence):
    for C in self._Challenges:
        if not C.GetMet():
            if Sequence == self.__ConvertConditionToString(C.GetCondition()):
                C.SetMet(True)
                return True
            else:
                return False
    return False


VB.NET:

       Public Overridable Function CheckIfConditionMet(ByVal Sequence As String) As Boolean
           For Each C In Challenges
               If Not C.GetMet() Then
                   If Sequence = ConvertConditionToString(C.GetCondition()) Then
                       C.SetMet(True)
                       Return True
                   Else
                       Return False
                   End If
               End If
           Next
           Return False
       End Function


Difficulty card functionality

[edit | edit source]

At the moment a difficulty card will give the user the option to discard 5 cards OR discard a key by selecting it using 1-5. Change the functionality to force the user to select a key to discard OR if no keys are in the players hand then discard 5 cards from the deck.

C#:

                    if (Hand.GetNumberOfCards() == 0)
                    {
                        Console.Write("5 Cards have been discarded from the deck ");
                        Discard.AddCard(CurrentCard);
                        CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, "D", cardChoice);
                    }
                    else
                    {
                        int Keys = 0, val, newKeys;
                        string Choice = "";
                        for (int CurCard = 0; CurCard < Hand.GetNumberOfCards(); CurCard++)
                        {
                            if (Hand.GetCardDescriptionAt(CurCard)[0] == 'K')
                                Keys += 1;
                        }

                        if (Keys > 0)
                        {
                            do
                            {
                                newKeys = 0;
                                do
                                {
                                    Console.Write("To deal with this you need to select a card to discard ");
                                    Console.Write("(enter 1-5 to specify position of key):> ");
                                    Choice = Console.ReadLine();
                                } while (!int.TryParse(Choice, out val));
                                Discard.AddCard(CurrentCard);
                                CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, Choice, cardChoice);
                                for (int CurCard = 0; CurCard < Hand.GetNumberOfCards(); CurCard++)
                                {
                                    if (Hand.GetCardDescriptionAt(CurCard)[0] == 'K')
                                        newKeys += 1;
                                }
                            } while (newKeys == Keys);
                        }
                        else
                        {
                            Console.Write("5 Cards have been discarded from the deck ");
                            Discard.AddCard(CurrentCard);
                            CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, "D", cardChoice);
                        }                        
                    }
                }
            }


Delphi/Pascal:


Java:

if (hand.getNumberOfCards() == 0) { // if the hand is empty, just discard 5 cards
    discard.addCard(currentCard);
    currentCard.process(deck, discard, hand, sequence, currentLock, "D", cardChoice);
} else {
    Console.write("To deal with this you need to either lose a key ");
    Console.write("(enter 1-5 to specify position of key) or (D)iscard five cards from the deck:> ");
    String choice = Console.readLine();
    Console.writeLine();
    discard.addCard(currentCard);
    currentCard.process(deck, discard, hand, sequence, currentLock, choice, cardChoice);
}


Python:

    def __GetCardFromDeck(self, CardChoice):
        if self.__Deck.GetNumberOfCards() > 0:
            if self.__Deck.GetCardDescriptionAt(0) == "Dif":
                CurrentCard = self.__Deck.RemoveCard(self.__Deck.GetCardNumberAt(0))
                print()
                print("Difficulty encountered!")
                print(self.__Hand.GetCardDisplay())
                print("To deal with this you need to lose a key ", end='')
                KeyFound = False
                for i in range(0,self.__Hand.GetNumberOfCards()):
                    if self.__Hand.GetCardDescriptionAt(i)[0] == "K":
                        KeyFound = True
                if KeyFound:
                    Choice = input("(enter 1-5 to specify position of key):> ")
                else:
                    input("so five cards must be discarded from the deck instead. Press (ENTER) to continue:> ")
                    Choice = "D"
                print()
                self.__Discard.AddCard(CurrentCard)
                CurrentCard.Process(self.__Deck, self.__Discard, self.__Hand, self.__Sequence, self.__CurrentLock, Choice, CardChoice)
        while self.__Hand.GetNumberOfCards() < 5 and self.__Deck.GetNumberOfCards() > 0:
            if self.__Deck.GetCardDescriptionAt(0) == "Dif":
                self.__MoveCard(self.__Deck, self.__Discard, self.__Deck.GetCardNumberAt(0))
                print("A difficulty card was discarded from the deck when refilling the hand.")
            else:
                self.__MoveCard(self.__Deck, self.__Hand, self.__Deck.GetCardNumberAt(0))
        if self.__Deck.GetNumberOfCards() == 0 and self.__Hand.GetNumberOfCards() < 5:
            self.__GameOver = True


VB.NET:

Private Sub GetCardFromDeck(ByVal CardChoice As Integer)
            Dim i = 0
            Dim character As String
            Dim KeyPresent As Boolean = False

            If Deck.GetNumberOfCards() > 0 Then
                If Deck.GetCardDescriptionAt(0) = "Dif" Then
                    Dim CurrentCard As Card = Deck.RemoveCard(Deck.GetCardNumberAt(0))
                    Console.WriteLine()
                    Console.WriteLine("Difficulty encountered!")
                    Console.WriteLine(Hand.GetCardDisplay())
                    i = 0
                    While i < 4
                        character = Hand.GetCardDescriptionAt(i).Chars(0)
                        If character = "K" Then
                            KeyPresent = True
                        End If
                        i += 1
                    End While
                    If KeyPresent Then
                        Dim bool As Boolean = False
                        While bool = False
                            Console.Write("To deal with this you need to lose a key ")
                            Console.Write("(enter 1-5 to specify position of key)")
                            Dim Choice As Integer = Console.ReadLine()
                            If Hand.GetCardDescriptionAt(Choice - 1).Chars(0) = "K" Then
                                Console.WriteLine()
                                Discard.AddCard(CurrentCard)
                                CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, Choice, CardChoice)
                                bool = True
                            Else
                                Console.WriteLine("please select a key")
                            End If
                        End While
                    Else
                        Console.WriteLine("no keys in your hand, discarding 5 cards from deck")
                        Dim numberOfCards = 0
                        Dim j = 0
                        If Deck.GetNumberOfCards() > 4 Then
                            While j < 5
                                Console.WriteLine($"removing card {Deck.GetCardNumberAt(0)}")
                                MoveCard(Deck, Discard, Deck.GetCardNumberAt(0))
                                j += 1
                            End While
                        End If

                    End If


                    End If
            End If
            While Hand.GetNumberOfCards() < 5 And Deck.GetNumberOfCards() > 0
                If Deck.GetCardDescriptionAt(0) = "Dif" Then
                    MoveCard(Deck, Discard, Deck.GetCardNumberAt(0))
                    Console.WriteLine("A difficulty card was discarded from the deck when refilling the hand.")
                Else
                    MoveCard(Deck, Hand, Deck.GetCardNumberAt(0))
                End If
            End While
            If Deck.GetNumberOfCards() = 0 And Hand.GetNumberOfCards() < 5 Then
                GameOver = True
            End If
        End Sub


Difficulty error

[edit | edit source]

When given a difficulty card, the program will ask for either a 1-5 input or discard 5 deck cards. When a Key is selected it will not always discard it because the list index changes itself.

C#:


Delphi/Pascal:


Java:

// Changes to DifficultyCard process method
if (parsed) {
    if (choiceAsInteger >= 1 && choiceAsInteger < 5) {
        if (hand.getCardDescriptionAt(choiceAsInteger - 1).charAt(0) == 'K') {
            Card cardToMove = hand.removeCard(hand.getCardNumberAt(choiceAsInteger - 1));
            discard.addCard(cardToMove);
            return;
        } else {
            Console.writeLine("Card selected is not a key, discarding 5 cards from the deck.");

        }
    } else {
        Console.writeLine("Invalid card position, discarding 5 cards from the deck.");
    }
}

// Changes made to Breakthrough getCardFromDeck method
Console.write("To deal with this you need to either lose a key ");
Console.write("(enter 1-4 to specify position of key) or (D)iscard five cards from the deck:> ");
String choice = Console.readLine();


Python:

#Changes to GetCardFromDeck
def __GetCardFromDeck(self, CardChoice):
    if self.__Deck.GetNumberOfCards() > 0:
        if self.__Deck.GetCardDescriptionAt(0) == "Dif":
            CurrentCard = self.__Deck.RemoveCard(self.__Deck.GetCardNumberAt(0))
            print()
            print("Difficulty encountered!")
            print(self.__Hand.GetCardDisplay())
            print("To deal with this you need to either lose a key ", end='')
            Choice = input("(enter 1-4 to specify position of key) or (D)iscard five cards from the deck:> ")
            #The line above has been changed
            print()
            self.__Discard.AddCard(CurrentCard)
            CurrentCard.Process(self.__Deck, self.__Discard, self.__Hand, self.__Sequence, self.__CurrentLock, Choice, CardChoice)
    while self.__Hand.GetNumberOfCards() < 5 and self.__Deck.GetNumberOfCards() > 0:
        if self.__Deck.GetCardDescriptionAt(0) == "Dif":
            self.__MoveCard(self.__Deck, self.__Discard, self.__Deck.GetCardNumberAt(0))
            print("A difficulty card was discarded from the deck when refilling the hand.")
        else:
            self.__MoveCard(self.__Deck, self.__Hand, self.__Deck.GetCardNumberAt(0))
    if self.__Deck.GetNumberOfCards() == 0 and self.__Hand.GetNumberOfCards() < 5:
        self.__GameOver = True


# Changes to Process in DifficultyCard
def Process(self, Deck, Discard, Hand, Sequence, CurrentLock, Choice, CardChoice):
    ChoiceAsInteger = None
    try:
        ChoiceAsInteger = int(Choice)
    except:
        pass
    if ChoiceAsInteger is not None:
        if ChoiceAsInteger >= 1 and ChoiceAsInteger <= 5:
            # Removed 2 lines here
            if ChoiceAsInteger > 0: #This line is redundant
                ChoiceAsInteger -= 1
            if Hand.GetCardDescriptionAt(ChoiceAsInteger)[0] == "K":
                CardToMove = Hand.RemoveCard(Hand.GetCardNumberAt(ChoiceAsInteger))
                Discard.AddCard(CardToMove)
                return
    Count = 0
    while Count < 5 and Deck.GetNumberOfCards() > 0:
        CardToMove = Deck.RemoveCard(Deck.GetCardNumberAt(0))
        Discard.AddCard(CardToMove)
        Count += 1


VB.NET:

' New DifficultyCard Class Process subroutine

        Public Overrides Sub Process(ByVal Deck As CardCollection, ByVal Discard As CardCollection, ByVal Hand As CardCollection, ByVal Sequence As CardCollection, ByVal CurrentLock As Lock, ByVal Choice As String, ByVal CardChoice As Integer)
            Dim ChoiceAsInteger As Integer
            If Integer.TryParse(Choice, ChoiceAsInteger) Then

                While ChoiceAsInteger < 1 Or ChoiceAsInteger > Hand.GetNumberOfCards - 1
                    Console.WriteLine("Invalid choice, try again")
                    Choice = Console.ReadLine
                    Integer.TryParse(Choice, ChoiceAsInteger)
                End While
                ChoiceAsInteger -= 1

                If Hand.GetCardDescriptionAt(ChoiceAsInteger)(0) = "K" Then
                    Dim CardToMove As Card = Hand.RemoveCard(Hand.GetCardNumberAt(ChoiceAsInteger))
                    Discard.AddCard(CardToMove)
                    Return
                End If
            End If

            Dim Count As Integer = 0
            While Count < 5 And Deck.GetNumberOfCards() > 0
                Dim CardToMove As Card = Deck.RemoveCard(Deck.GetCardNumberAt(0))
                Discard.AddCard(CardToMove)
                Count += 1
            End While
        End Sub


Retrieve card

[edit | edit source]

Create a new card child class for a Retrieve card. If a player draws a retrieve card they are able to retrieve one card from the discard pile and return it to their hand. There should be two retrieve cards in the deck. These should be added, like the difficulty cards, after the user draws their hand.

C#:


Delphi/Pascal:


Java:

class RetrieveCard extends Card {

    protected String cardType;

    public RetrieveCard() {
        super();
        cardType = "Ret";
    }

    public RetrieveCard(int cardNo) {
        cardType = "Ret";
        cardNumber = cardNo;
    }

    @Override
    public String getDescription() {
        return cardType;
    }

    @Override
    public void retrieve(CardCollection hand, CardCollection discard) {
        Console.writeLine(discard.getCardDisplay());
        int choiceAsInt = 0;
        do {
            Console.writeLine("Choose a card to return to your hand:> ");
            String choice = Console.readLine();
            try {
                choiceAsInt = Integer.parseInt(choice);
            } catch (Exception e) {
                Console.writeLine("Invalid card position");
                Console.writeLine();
            }
        } while (!(choiceAsInt > 0 && choiceAsInt <= discard.getNumberOfCards()));
        hand.addCard(discard.removeCard(discard.getCardNumberAt(choiceAsInt - 1)));
    }
}

// In Breakout class
public void addRetrieveCardsToDeck() {
    for (int i = 0; i < 2; i++) {
        deck.addCard(new RetrieveCard());
    }
}

// Changes to getCardFromDeck method
} else if (deck.getCardDescriptionAt(0).equals("Ret")) {
    Card currentCard = deck.removeCard(deck.getCardNumberAt(0));
    Console.writeLine("Retrieve card found!");
    currentCard.retrieve(hand, discard);
}

// Changes to setupGame method
addDifficultyCardsToDeck();
addRetrieveCardsToDeck();
deck.shuffle();


Python:

class RetrieveCard(Card):
    def __init__(self):
        self._CardType = 'Ret'
        super(RetrieveCard, self).__init__()
    def GetDescription(self):
        return self._CardType
    def Process(self, Deck, Discard, Hand, Sequence, CurrentLock, Choice, CardChoice):
        CardToMove = Discard.RemoveCard(Discard.GetCardNumberAt(int(Choice)-1))
        Hand.AddCard(CardToMove)

def __AddRetrieveCardsToDeck(self):
        for Count in range(2):
            self.__Deck.AddCard(RetrieveCard())

Get card from deck class:

elif self.__Deck.GetCardDescriptionAt(0) == 'Ret':
    CurrentCard = self.__Deck.RemoveCard(self.__Deck.GetCardNumberAt(0))
    print()
    print("Retrieve card encountered!")
    print(self.__Hand.GetCardDisplay())
    print()
    print(self.__Discard.GetCardDisplay())
    choice = input('Choose a card to retrieve from the Discard pile')
    print()
    CurrentCard.Process(self.__Deck, self.__Discard, self.__Hand, self.__Sequence, self.__CurrentLock, choice, CardChoice)
    self.__Discard.AddCard(CurrentCard)
Must also add a call from the __SetUpGame function


VB.NET:

In order to complete this challenge you need to create a new class called something like RetrievalCard, you need to alter the play game function, you need to alter the setupGame subroutine and you need to create a function to add retrieval cards to the deck. We will look at the Retrieval card class first, then the add retrieval cards function, then the altered setup game subroutine, then the play game function It is worth noting that only the code in the case "U" block has been changed for the playGame() subroutine.

    Class RetrieveCard
        Inherits Card
        Protected cardType As String
        Sub New()
            MyBase.New()
            cardType = "R t"
        End Sub
        Public Sub New(ByVal CardNo As Integer)
            cardType = "R t"
            CardNumber = CardNo
        End Sub


        Public Overrides Function GetDescription() As String
            Return cardType
        End Function
    End Class


 Private Sub AddRetrievalCardsToDeck()
            For Count = 1 To 2
                Deck.AddCard(New RetrieveCard())
            Next
        End Sub


Private Sub SetupGame()
            Dim Choice As String
            Console.Write("Enter L to load a game from a file, anything else to play a new game:> ")
            Choice = Console.ReadLine().ToUpper()
            If Choice = "L" Then
                If Not LoadGame("game2.txt") Then
                    GameOver = True
                End If
            Else
                CreateStandardDeck()
                Deck.Shuffle()
                For Count = 1 To 5
                    MoveCard(Deck, Hand, Deck.GetCardNumberAt(0))
                Next
                AddDifficultyCardsToDeck()
                AddRetrievalCardsToDeck()
                Deck.Shuffle()
                CurrentLock = GetRandomLock()
            End If
        End Sub


 Public Sub PlayGame()
            Dim MenuChoice As String
            If Locks.Count > 0 Then
                GameOver = False
                CurrentLock = New Lock()
                SetupGame()
                While Not GameOver
                    LockSolved = False
                    While Not LockSolved And Not GameOver
                        Console.WriteLine()
                        Console.WriteLine("Current score: " & Score)
                        Console.WriteLine(CurrentLock.GetLockDetails())
                        Console.WriteLine(Sequence.GetCardDisplay())
                        Console.WriteLine(Hand.GetCardDisplay())
                        MenuChoice = GetChoice()
                        Select Case MenuChoice
                            Case "D"
                                Console.WriteLine(Discard.GetCardDisplay())
                            Case "U"
                                Dim CardChoice As Integer = GetCardChoice()
                                Dim DiscardOrPlay As String = GetDiscardOrPlayChoice()
                                If DiscardOrPlay = "D" Then
                                    MoveCard(Hand, Discard, Hand.GetCardNumberAt(CardChoice - 1))
                                    GetCardFromDeck(CardChoice)
                                ElseIf DiscardOrPlay = "P" Then
                                    If Hand.GetCardDescriptionAt(CardChoice - 1) = "R t" Then
                                        Console.WriteLine("Here are the display cards for you to peruse at your leisure")
                                        Console.WriteLine(Discard.GetCardDisplay())
                                        Console.WriteLine("please select the card you want to take in integer form, 1st card on left etc")
                                        Dim selectedCard As Integer
                                        selectedCard = Console.ReadLine()
                                        MoveCard(Hand, Discard, Hand.GetCardNumberAt(CardChoice - 1))
                                        MoveCard(Discard, Hand, Discard.GetCardNumberAt(selectedCard - 1))

                                    Else
                                        PlayCardToSequence(CardChoice)
                                    End If
                                End If
                        End Select
                        If CurrentLock.GetLockSolved() Then
                            LockSolved = True
                            ProcessLockSolved()
                        End If
                    End While
                    GameOver = CheckIfPlayerHasLost()
                End While
            Else
                Console.WriteLine("No locks in file.")
            End If
        End Sub


Card count

[edit | edit source]

A player loses if they run out of cards in the deck without solving the locks. Therefore they may wish to see this information. Change the program so that alongside the current score the game also displays the number of cards remaining in the deck on each turn.

C#:

//This is from PlayGame
Console.WriteLine("Cards reamining: " + Deck.GetNumberOfCards());

//This a separate function
public static bool DeckEmpty(CardCollection Deck)
{
    int NumberOfCardsInDeck = Deck.GetNumberOfCards();
    if (NumberOfCardsInDeck == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//This is from PlayGame in the switch MenuChoice
case "D":
    {
        Console.WriteLine(Discard.GetCardDisplay());
        bool empty = DeckEmpty(Deck);
        if (empty == true)
        {
            GameOver = true;
        }
            break;
    }


Delphi/Pascal:


Java:

// after line Console.writeLine("Current score: " + score); in Breakthrough.playGame()
Console.writeLine(deck.getNumberOfCards()+" cards remaining in the deck");


Python:

35: print("Current score:", self.__Score)
36: print("Amount of cards in deck: " + str(self.__Deck.GetNumberOfCards())) # Display amount of cards in deck 
37: print(self.__CurrentLock.GetLockDetails())
38: print ("Amount counted.")


VB.NET:

Public Sub PlayGame()
    cardsLeftInDeck = Deck.GetNumberOfCards()
    Console.Write("Cards left in deck: " & cardsLeftInDeck)


Save game

[edit | edit source]

There is a load game feature but no ability to save the state of a game. Create one that can be called instead of View Discard or Use Card and saves the game to a file of the users choosing. Also change the Load Game functionality so that the user can enter the name of the file they want to load.

Delphi/Pascal:


Java:

Add a case S into playGame:

  case "S": {
                            Console.writeLine("Please input the filename");
                            String filename = Console.readLine();
                            saveGame(filename);
                            break;
                        }

And change getChoice:

private String getChoice() {
        Console.writeLine();
        Console.write("(D)iscard inspect, (U)se card, (S)ave Game:> ");
        String choice = Console.readLine().toUpperCase();
        return choice;
    }

New saveGame()

    private boolean saveGame(String fileName) {
        try {
            BufferedWriter myStream = new BufferedWriter(new FileWriter(fileName));
            myStream.append(score + "\n");
            int i = 0;
            int j = 0;
            for (Challenge c : currentLock.getChallenges()) {
                if (i > 0 && i < currentLock.getChallenges().size()) {
                    myStream.append(";");
                }
                for (String condition : c.getCondition()) {
                    if (c.getCondition().size() - 1 == j) {
                        myStream.append(condition);
                    } else {
                        myStream.append(condition + ",");
                    }
                    j++;
                }
                j = 0;
                i++;
            }
            myStream.append("\n");
            i = 0;
            for (Challenge c : currentLock.getChallenges()) {
                if (c.getMet()) {
                    if (currentLock.getChallenges().size() - 1 == i) {
                        myStream.append("Y");
                    } else {
                        myStream.append("Y;");
                    }
                } else {
                    if (currentLock.getChallenges().size() - 1 == i) {
                        myStream.append("N");
                    } else {
                        myStream.append("N;");
                    }
                }
                i++;
            }
            myStream.append("\n");
            i = 0;
            for (Card c : hand.getCards()) {
                if (hand.getCards().size() - 1 == i) {
                    myStream.append(c.getDescription() + " " + c.getCardNumber());
                } else {
                    myStream.append(c.getDescription() + " " + c.getCardNumber() + ",");
                }
                i++;
            }
            i = 0;
            myStream.append("\n");
            for (Card c : sequence.getCards()) {
                if (sequence.getCards().size() - 1 == i) {
                    myStream.append(c.getDescription() + " " + c.getCardNumber());
                } else {
                    myStream.append(c.getDescription() + " " + c.getCardNumber() + ",");
                }
                i++;
            }
            i = 0;
            myStream.append("\n");
            for (Card c : discard.getCards()) {
                if (discard.getCards().size() - 1 == i) {
                    myStream.append(c.getDescription() + " " + c.getCardNumber());
                } else {
                    myStream.append(c.getDescription() + " " + c.getCardNumber() + ",");
                }
                i++;
            }
            i = 0;
            myStream.append("\n");
            for (Card c : deck.getCards()) {
                if (deck.getCards().size() - 1 == i) {
                    myStream.append(c.getDescription() + " " + c.getCardNumber());
                } else {
                    myStream.append(c.getDescription() + " " + c.getCardNumber() + ",");
                }
                i++;
            }
            myStream.close();
            return true;
        } catch (Exception e) {
            Console.writeLine("File not loaded");
            return false;
        }
    }

Add a method to CardCollection:

  public List<Card> getCards()
        {
            return cards;
        }

Add a method to Lock:

   public List<Challenge> getChallenges()
        {
            return challenges;
        }


Python:

#Add to the Breakthrough Class
    def SaveGame(self,FileName):
        with open(FileName,'w') as f:
            #save score
            f.writelines(str(self.__Score) + "\n")
            #save locks
            line =""
            line = line + self.__CurrentLock.SaveLock()
            f.writelines(line+"\n")
            #save met
            line =""
            line = line + self.__CurrentLock.SaveMet()
            f.writelines(line + "\n")
            #Saves hand to the 4th line in same formatting as loadgame
            line =""
            for i in range(self.__Hand.GetNumberOfCards()):
                line = line + self.__Hand.GetCardDescriptionAt(i) + " " + str(self.__Hand.GetCardNumberAt(i)) + ","
            line = line[:-1] + "\n"
            f.writelines(line)
            #Saves sequence to 5th line
            line =""
            for i in range(self.__Sequence.GetNumberOfCards()):
                line = line + self.__Sequence.GetCardDescriptionAt(i) + " " + str(self.__Sequence.GetCardNumberAt(i)) + ","
            line = line[:-1] +"\n"
            f.writelines(line)
            #Saves Discard to 6th line
            line =""
            for i in range(self.__Discard.GetNumberOfCards()):
                line = line + self.__Discard.GetCardDescriptionAt(i) + " " + str(self.__Discard.GetCardNumberAt(i)) + ","
            line = line[:-1] +"\n"
            f.writelines(line)
            #Saves Deck to 7th line
            line =""
            for i in range(self.__Deck.GetNumberOfCards()):
                line = line + self.__Deck.GetCardDescriptionAt(i) + " " + str(self.__Deck.GetCardNumberAt(i)) + ","
            line = line[:-1]
            f.writelines(line)

#Add to the Locks Class
    def SaveLock(self):
        lockDetails =""
        for C in self._Challenges:
            lockDetails += ",".join(C.GetCondition() ) + ";"
        lockDetails = lockDetails[:-1]
        return lockDetails

    def SaveMet(self):
        metDetails =""
        for C in self._Challenges:
            if C.GetMet():
                metDetails += "Y;"
            else:
                metDetails += "N;"
        metDetails = metDetails[:-1]
        return metDetails

#Modify PlayGame in Breakthrough
                     if MenuChoice == "D":
                        print(self.__Discard.GetCardDisplay())
                    elif MenuChoice == "S":
                        fileName = input("Please enter filename for saved game")
                        if fileName.endswith(".txt"):
                            self.SaveGame(fileName)
                        else:
                            self.SaveGame(fileName + ".txt")
                    elif MenuChoice == "U":
                        CardChoice  = self.__GetCardChoice()
                        DiscardOrPlay = self.__GetDiscardOrPlayChoice()
                        if DiscardOrPlay == "D":
                            self.__MoveCard(self.__Hand, self.__Discard, self.__Hand.GetCardNumberAt(CardChoice - 1))
                            self.__GetCardFromDeck(CardChoice)
                        elif DiscardOrPlay == "P":
                            self.__PlayCardToSequence(CardChoice)
#Modify SetupGame
    def __SetupGame(self):
        Choice = input("Enter L to load a game from a file, anything else to play a new game:> ").upper()
        if Choice == "L":
            filename = input("Enter filename to load")
            if filename.endswith(".txt"):
                valid = self.__LoadGame(filename)
            else:
                valid = self.__LoadGame(filename + ".txt")
            if not valid:
                self.__GameOver = True
        else:
            self.__CreateStandardDeck()
            self.__Deck.Shuffle()
            for Count in range(5):
                self.__MoveCard(self.__Deck, self.__Hand, self.__Deck.GetCardNumberAt(0))
            self.__AddDifficultyCardsToDeck()
            self.__Deck.Shuffle()
            self.__CurrentLock = self.__GetRandomLock()


C#:

'Create a new SaveGame method in Breakthrough class and modify the switch statement in PlayGame() as well as update the SetupGame() method in Breakthrough class to allow specific files to be chosen'

                        // code below taken from SetupGame()
string Choice;
            Console.Write("Enter L to load a game from a file, anything else to play a new game:> ");
            Choice = Console.ReadLine().ToUpper();
            if (Choice == "L")
            {
            	Console.Write("Enter the name of the file you want to load: ");
            	Choice = Console.ReadLine();
            	Choice += ".txt";
            	if (!LoadGame(Choice)){
            		GameOver = true;
            	}
            }
                        // Switch statement below taken from PlayGame()
                        switch (MenuChoice)
                        {
                            case "D":
                                {
                                    Console.WriteLine(Discard.GetCardDisplay());
                                    break;
                                }
                            case "U":
                                {
                                    int CardChoice = GetCardChoice();
                                    string DiscardOrPlay = GetDiscardOrPlayChoice();
                                    if (DiscardOrPlay == "D")
                                    {
                                        MoveCard(Hand, Discard, Hand.GetCardNumberAt(CardChoice - 1));
                                        GetCardFromDeck(CardChoice);
                                    }
                                    else if (DiscardOrPlay == "P")
                                        PlayCardToSequence(CardChoice);
                                    else if (DiscardOrPlay == "S"){
                                    	Console.Write("Please enter a filename: ");
                                    	string file = Console.ReadLine();
                                    	if(saveGame(file))
                                    		Console.WriteLine("File saved successfully!");
                                    	else
                                    		Console.WriteLine("An error has occured!");
                                    }
                                    break;
                                }
                        	case "S":
                        		{
                        			Console.WriteLine("Please input a file name: ");
                        			string fileName = Console.ReadLine();
                        			saveGame(fileName);
                        			break;
                        		}
                        }

private bool saveGame(string fileName){
        	try{
        		using (StreamWriter MyStream = new StreamWriter(fileName + ".txt")){
        			// saving score
        			MyStream.WriteLine(Score.ToString());
        			// saving locks
        			MyStream.WriteLine(CurrentLock.getChallenges()); // does not matter what you call it, I just called it this
        			
        			// saving current hand
        			MyStream.WriteLine(CurrentLock.SaveMet());
        			
        			// Hand
        			string line = "";
        			for (int n = 0; n < Hand.GetNumberOfCards(); n++){
        				line += Hand.GetCardDescriptionAt(n) + " " + Convert.ToString(Hand.GetCardNumberAt(n)) + ",";
        			}
        			line = line.TrimEnd(',');
        			
        			// TrimEnd takes a char parameter and removes the final character
        			
        			MyStream.WriteLine(line);
        			
        			// Sequence
        			
        			line = "";
        			for (int n = 0; n < Sequence.GetNumberOfCards(); n++){
        				line += Sequence.GetCardDescriptionAt(n) + " " + Convert.ToString(Sequence.GetCardNumberAt(n)) + ",";
        			}
        			line = line.TrimEnd(',');
        			
        			MyStream.WriteLine(line);
        			
        			// Discard
        			
        			line = "";
        			for (int n = 0; n < Discard.GetNumberOfCards(); n++){
        				line += Discard.GetCardDescriptionAt(n) + " " + Convert.ToString(Discard.GetCardNumberAt(n)) + ",";
        			}
        			line = line.TrimEnd(',');
        			MyStream.WriteLine(line);
        			
        			MyStream.WriteLine();
        			
        			// deck
        			
        			line = "";
        			for (int n = 0; n < Deck.GetNumberOfCards(); n++){
        				line += Deck.GetCardDescriptionAt(n) + " " + Convert.ToString(Deck.GetCardNumberAt(n)) + ",";
        			}
        			
        			line = line.TrimEnd(',');
        			MyStream.WriteLine(line);
        			
        		}
        		return true;
        	} catch(Exception e){
        		return false;
        	}
        }

'Then in the Lock class do:'

public string getChallenges(){
        	string send = "";
        	foreach (Challenge C in Challenges){
        		send += String.Join(",", C.GetCondition()) + ";";
        	}
        	send = send.TrimEnd(';');
        	return send;
        }
        
        public string SaveMet(){
        	string met = "";
        	foreach (Challenge C in Challenges){
        		if (C.GetMet()){
        			met += "Y;";
        		}
        		else{
        			met += "N;";
        		}
        	}
        	met = met.TrimEnd(';');
        	return met;
        }
'Footnote: In theory, it does not really matter what you call the methods. It is simplest to name them as appropriate as possible as per the zen of coding, but if it helps not to follow the standard for this then it doesn't really matter for the exam.'


VB.NET:

'New SaveGame Subroutine:
Private Sub SaveGame()
        'Saves the score to first line
        IO.File.WriteAllText("SaveGame.txt", Score & Environment.NewLine)
        'Saves the locks in 2nd + 3rd line in the formatting of the loadgame funtion
        IO.File.AppendAllText("SaveGame.txt", CurrentLock.SaveLock() & Environment.NewLine)
        IO.File.AppendAllText("SaveGame.txt", CurrentLock.Savemet() & Environment.NewLine)
        'Saves hand to the 4th line in same formatting as loadgame
        For i = 0 To Hand.GetNumberOfCards - 1
            If i.Equals(Hand.GetNumberOfCards - 1) Then
                IO.File.AppendAllText("SaveGame.txt", Hand.GetCardDescriptionAt(i) & " " & Hand.GetCardNumberAt(i))
            Else
                IO.File.AppendAllText("SaveGame.txt", Hand.GetCardDescriptionAt(i) & " " & Hand.GetCardNumberAt(i) & ",")
            End If
        Next
        IO.File.AppendAllText("SaveGame.txt", Environment.NewLine)
        'Saves sequence to 5th line
        For i = 0 To Sequence.GetNumberOfCards - 1
            If i.Equals(Sequence.GetNumberOfCards - 1) Then
                IO.File.AppendAllText("SaveGame.txt", Sequence.GetCardDescriptionAt(i) & " " & Sequence.GetCardNumberAt(i))
            Else
                IO.File.AppendAllText("SaveGame.txt", Sequence.GetCardDescriptionAt(i) & " " & Sequence.GetCardNumberAt(i) & ",")
            End If
        Next
        IO.File.AppendAllText("SaveGame.txt", Environment.NewLine)
        'Saves Discard to 6th line
        For i = 0 To Discard.GetNumberOfCards - 1
            If i.Equals(Discard.GetNumberOfCards - 1) Then
                IO.File.AppendAllText("SaveGame.txt", Discard.GetCardDescriptionAt(i) & " " & Discard.GetCardNumberAt(i))
            Else
                IO.File.AppendAllText("SaveGame.txt", Discard.GetCardDescriptionAt(i) & " " & Discard.GetCardNumberAt(i) & ",")
            End If
        Next
        IO.File.AppendAllText("SaveGame.txt", Environment.NewLine)
        'Saves Deck to 7th line
        For i = 0 To Deck.GetNumberOfCards - 1
            If i.Equals(Deck.GetNumberOfCards - 1) Then
                IO.File.AppendAllText("SaveGame.txt", Deck.GetCardDescriptionAt(i) & " " & Deck.GetCardNumberAt(i))
            Else
                IO.File.AppendAllText("SaveGame.txt", Deck.GetCardDescriptionAt(i) & " " & Deck.GetCardNumberAt(i) & ",")
            End If
        Next
    End Sub

'New SaveLock Sub in Locks, saves with same formatting as the load locks sub needs:
Public Function SaveLock()
        Dim lockdetails As String
        'Loops through each list of conditions
        For Each C In Challenges
            'If the last challenge has been reached, don't put a ;
            If C.Equals(Challenges.Last) Then
                lockdetails &= ConvertConditionToString(C.GetCondition())
            Else
                'Saves the condition with a ,
                lockdetails &= ConvertConditionToString(C.GetCondition()) + ","
                lockdetails = lockdetails.Substring(0, lockdetails.Length - 1)
                'Removes last , and replaces with ;
                lockdetails &= ";"
            End If

        Next
        Return lockdetails
    End Function

'New SaveMet sub in Locks:
Public Function Savemet()
        Dim met As String
        For Each C In Challenges
            'If the challenge is met, set to Y;
            If C.GetMet() Then
                met &= "Y;"
            Else
                'If not, set to N;
                met &= "N;"
            End If
            'Removes the last ; because weird formatting of load game
            If C.Equals(Challenges.Last) Then
                met = met.Substring(0, met.Length - 1)
            End If
        Next
        Return met
    End Function


Speciality deck

[edit | edit source]

Currently the game provides a preset set of cards - picks, files and keys. Create a new method to create a SpecialityDeck for an alternative version of the game so the user/player can be provided with an option to play the StandardDeck *or* a SpecialityDeck. SpecialityDeck consists of three types of tool (E)xplosive, (W)elder and (A)nother.

C#:


Delphi/Pascal:


Java:


Python:


VB.NET:


Wild card

[edit | edit source]

Currently the game provides a preset deck of cards. Add functionality for a 'wild card' which can be played against *any* particular lock.

C#:


Delphi/Pascal:


Java:


Python:

Changes to code:

    def __CreateStandardDeck(self):
        for Count in range(5):
            NewCard = ToolCard("P", "a")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("P", "b")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("P", "c")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("W", "x")
            self.__Deck.AddCard(NewCard)
        for Count in range(3):
            NewCard = ToolCard("F", "a")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("F", "b")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("F", "c")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("K", "a")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("K", "b")
            self.__Deck.AddCard(NewCard)
            NewCard = ToolCard("K", "c")
            self.__Deck.AddCard(NewCard)

    def __SetScore(self):
        if self._ToolType == "W":
            self.score = 0
        if self._ToolType == "K":
            self._Score = 3
        elif self._ToolType == "F":
            self._Score = 2
        elif self._ToolType == "P":
            self._Score = 1

    def CheckIfConditionMet(self, Sequence):
        for C in self._Challenges:
            cond_string = self.__ConvertConditionToString(C.GetCondition())
            matched = True
            for card in range(len(Sequence)):
                if Sequence[card] not in {'Wx', cond_string[card]}:
                    matched = False
                    break
            if not C.GetMet() and matched:
                C.SetMet(True)
                return True
        return False


VB.NET:

'New Special Card

    Class SpecialCard
        Inherits Card

        Protected CardType As String

        Sub New()
            MyBase.New()
            CardType = "Spe"
        End Sub

        Public Sub New(ByVal CardNo As Integer)
            CardType = "Spe"
            CardNumber = CardNo
        End Sub

        Public Overrides Function GetDescription() As String
            Return CardType
        End Function

        Public Overrides Sub Process(ByVal Deck As CardCollection, ByVal Discard As CardCollection, ByVal Hand As CardCollection, ByVal Sequence As CardCollection, ByVal CurrentLock As Lock, ByVal Choice As String, ByVal CardChoice As Integer)
            Choice = -1
            CurrentLock.SetChallengeMet(Choice, True)
        End Sub
    End Class

'BreakThrough GetCardFromDeck with new additions to take into account the new card

        Private Sub GetCardFromDeck(ByVal CardChoice As Integer)
            If Deck.GetNumberOfCards() > 0 Then
                If Deck.GetCardDescriptionAt(0) = "Dif" Then
                    Dim CurrentCard As Card = Deck.RemoveCard(Deck.GetCardNumberAt(0))
                    Console.WriteLine()
                    Console.WriteLine("Difficulty encountered!")
                    Console.WriteLine(Hand.GetCardDisplay())
                    Console.Write("To deal with this you need to either lose a key ")
                    Console.Write("(enter 1-5 to specify position of key) or (D)iscard five cards from the deck:> ")
                    Dim Choice As String = Console.ReadLine()
                    Console.WriteLine()
                    Discard.AddCard(CurrentCard)
                    CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, Choice, CardChoice)

                ElseIf Deck.GetCardDescriptionAt(0) = "Spe" Then
                    Dim CurrentCard As Card = Deck.RemoveCard(Deck.GetCardNumberAt(0))
                    Console.WriteLine()
                    Console.WriteLine("Special Card Obtained!")
                    Console.WriteLine("Pick a number between 1 and " & CurrentLock.GetNumberOfChallenges)
                    Dim Choice As String = Console.ReadLine()
                    Console.WriteLine()
                    Discard.AddCard(CurrentCard)
                    CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, Choice, CardChoice)


                End If
            End If
            While Hand.GetNumberOfCards() < 5 And Deck.GetNumberOfCards() > 0
                If Deck.GetCardDescriptionAt(0) = "Dif" Then
                    MoveCard(Deck, Discard, Deck.GetCardNumberAt(0))
                    Console.WriteLine("A difficulty card was discarded from the deck when refilling the hand.")

                ElseIf Deck.GetCardDescriptionAt(0) = "Spe" Then
                    MoveCard(Deck, Discard, Deck.GetCardNumberAt(0))
                    Console.WriteLine("A special card was discarded from the deck when refilling the hand.")

                Else
                    MoveCard(Deck, Hand, Deck.GetCardNumberAt(0))
                End If
            End While
            If Deck.GetNumberOfCards() = 0 And Hand.GetNumberOfCards() < 5 Then
                GameOver = True
            End If
        End Sub

'New subroutine added to BreakThrough Class (adds 2 special cards to the Deck)

Private Sub AddSpecialCardToDeck()
            For count = 1 To 2
                Deck.AddCard(New SpecialCard())
            Next
        End Sub

'Line of code added to BreakThrough class SetupGame (add just before the line Deck.Shuffle())

AddSpecialCardToDeck()


Consecutive Tool Type Penalty

[edit | edit source]

Currently no error message is displayed if the user attempts to play two consecutive cards of the same tool type. Change the code to notify the user when their card has been disallowed due to this rule. In addition, leverage a score penalty of 1 point (reduce the user's score by one) and notify the user that this has occurred in all cases except where the user's score would then become negative in which case it should be omitted.

C#:


Delphi/Pascal:


Java:

// line 128, within Breakthrough class
    private void playCardToSequence(int cardChoice) {
        if (sequence.getNumberOfCards() > 0) {
            if (hand.getCardDescriptionAt(cardChoice - 1).charAt(0) != sequence.getCardDescriptionAt(sequence.getNumberOfCards() - 1).charAt(0)) {
                score += moveCard(hand, sequence, hand.getCardNumberAt(cardChoice - 1));
                getCardFromDeck(cardChoice);
            } else {
            	Console.writeLine("You can't play the same card type twice! (-1 point)");
            	score--;
            }
        } else {
            score += moveCard(hand, sequence, hand.getCardNumberAt(cardChoice - 1));
            getCardFromDeck(cardChoice);
        }
        if (checkIfLockChallengeMet()) {
            Console.writeLine();
            Console.writeLine("A challenge on the lock has been met.");
            Console.writeLine();
            score += 5;
        }
    }


Python:

def __PlayCardToSequence(self, CardChoice):

       if self.__Sequence.GetNumberOfCards() > 0:
           if self.__Hand.GetCardDescriptionAt(CardChoice - 1)[0] != self.__Sequence.GetCardDescriptionAt(self.__Sequence.GetNumberOfCards() - 1)[0]:
               self.__Score += self.__MoveCard(self.__Hand, self.__Sequence, self.__Hand.GetCardNumberAt(CardChoice - 1))
               self.__GetCardFromDeck(CardChoice)
           else:
               print("You are not allowed to play two consecutive moves with the same key")
               if self.__Score > 0:
                   print("There's a 1 point penalty for not adhering to the rule")
                   self.__Score = self.__Score - 1


VB.NET:

'New variable into the BreakThrough class

Private Warning As Boolean

'Added into PlayGame subroutine at the top

Warning = False

'New PlayCardToSequence subroutine with additions

Private Sub PlayCardToSequence(ByVal CardChoice As Integer)
            If Sequence.GetNumberOfCards() > 0 Then
                If Hand.GetCardDescriptionAt(CardChoice - 1)(0) <> Sequence.GetCardDescriptionAt(Sequence.GetNumberOfCards() - 1)(0) Then
                    Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(CardChoice - 1))
                    GetCardFromDeck(CardChoice)

                Else
                    Console.WriteLine()
                    If Warning = False Then
                        Console.WriteLine("You cannot play the same tool twice")
                        Console.WriteLine()
                        Console.WriteLine("If this happens again you will be deducted points")
                        Warning = True
                    Else
                        Console.WriteLine("You have been warned! Your score will now be deducted")
                        If Score > 0 Then
                            Score -= 1
                            Console.WriteLine("Your score has decreased by 1")
                        Else
                            Console.WriteLine("Your score is already zero")
                        End If
                    End If

                End If
            Else
                Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(CardChoice - 1))
                GetCardFromDeck(CardChoice)
            End If
            If CheckIfLockChallengeMet() Then
                Console.WriteLine()
                Console.WriteLine("A challenge on the lock has been met.")
                Console.WriteLine()
                Score += 5
            End If
        End Sub


See remaining Cards in the deck

[edit | edit source]

Shows the list of remaining cards within the deck (kind of ruins the game but it could get asked)

C#:

//goes in the switch statement (MenuChoice) in PlayGame()
//char doesn't have to be "C"
case "C":
{
    Console.WriteLine(Deck.GetCardDisplay());
    break;
}


Delphi/Pascal:


Java:

//in switch(menuChoice) in playGame() (line 76)
                        case "R":
                            Console.writeLine(deck.getCardDisplay());
                            break;


Python:

26    def PlayGame(self):
27        if len(self.__Locks) > 0:
28            self.__SetupGame()
29            while not self.__GameOver:
30                self.__LockSolved = False
31                while not self.__LockSolved and not self.__GameOver:
32                    print()
33                    print("Current score:", self.__Score)
34                    print(self.__CurrentLock.GetLockDetails())
35                    print(self.__Sequence.GetCardDisplay())
36                    print(self.__Hand.GetCardDisplay())
37                    print(self.__Deck.GetCardDisplay())


VB.NET:

Within PlayGame() Subroutine:
'New case R to show remaining deck
                        Case "R"
                            Console.WriteLine(Deck.GetCardDisplay())
                    End Select
-Riddlesdown Collegiate


Never reuse locks

[edit | edit source]

When a lock is completed a new lock is selected from the list of locks at random. However, it could select a lock that has already been solved by the player. Adjust the method GetRandomLock() in the breakthrough class to fix this.

C#:

   private Lock GetRandomLock()
   {
       Lock NewLock;
       do
           NewLock = Locks[RNoGen.Next(0, Locks.Count)];
       while (!NewLock.GetLockSolved());
       return NewLock;
   }


Delphi/Pascal:


Java:

    private Lock getRandomLock() {
        Lock newLock;
        
        do {
            newLock = locks.get(rNoGen.nextInt(locks.size()));
        } while (!newLock.getLockSolved());

        return newLock;
    }


Python:

def __GetRandomLock(self):
    newLock = self.__Locks[random.randint(0, len(self.__Locks) - 1)]
    while newLock.GetLockSolved():
        newLock = self.__Locks[random.randint(0, len(self.__Locks) - 1)]
    return newLock


VB.NET:


Post Inspection of Discard Pile

[edit | edit source]

When playing the game, the player can choose to inspect the discard pile by entering a "D" at their first input. The program is to be amended so that the player can choose to retrieve ONE card from the discard pile and discard ONE card from their hand. The card being retrieved cannot be a difficulty card.

Amend the method PlayGame from the Breakthrough class so that after the user chooses to inspect the discard pile: • the user is prompted to enter a card number to retrieve from the discard pile by entering an integer value for the card. Entering 0 will skip this step. The user should be given the following prompt: "Please enter a number greater than 0 for a card to retrieve. Enter 0 if you wish to skip this step" • the user is then asked to enter a number for the card that they wish to remove from their hand. The user should be given the following prompt: "Please enter a number for the card to discard from your hand" • the cards are transferred between the discard pile and the hand and the game continues

C#:


Delphi/Pascal:


Java:


Python:

#the following added within the PlayGame method
if MenuChoice == "D":
    print(self.__Discard.GetCardDisplay())
    retrieveCard = int(input("Enter the card you want to retrieve or 0 to skip this step. "))
    while retrieveCard < 0:
        retrieveCard = int(input("Enter the card you want to retrieve or 0 to skip this step. "))
    if retrieveCard != 0:
        if self.__Discard.GetCardDescriptionAt(retrieveCard - 1) != "Dif":
            print("The enter choice will be discarded")
            CardChoice  = self.__GetCardChoice()
            self.__MoveCard(self.__Hand, self.__Discard, self.__Hand.GetCardNumberAt(CardChoice - 1))
            self.__MoveCard(self.__Discard, self.__Hand, self.__Discard.GetCardNumberAt(retrieveCard - 1))
        else:
            print("The enter choice is a difficult card. ")


VB.NET:

Dim newCard, oldcard As Integer

                                Dim tempcard1 As Card

                                Dim tempcard2 As Card

                                Console.WriteLine(Discard.GetCardDisplay())

                                Console.WriteLine("Please enter a number greater than 0 for a card to retrieve. Enter 0 if you wish to skip this step")

                                newCard = Console.ReadLine()

                                If newCard <> 0 Then

                                    Console.WriteLine("Please enter a number for the card to discard from your hand")

                                    oldcard = Console.ReadLine()

                                    tempcard1 = Discard.RemoveCard(newCard)

                                    tempcard2 = Hand.RemoveCard(oldcard)

                                    Hand.AddCard(tempcard1)

                                    Discard.AddCard(tempcard2)

                                End If