跳转至内容

A-level 计算机/AQA/试卷 1/骨架程序/2022

来自 Wikibooks,开放世界中的开放书籍

这是针对 AQA A Level 计算机科学规范。

这里可以提出关于一些问题可能是什么以及我们如何解决它们的建议。

请尊重他人,不要破坏页面,因为这会影响学生备考!
请不要在此页面上讨论问题。请使用讨论页面

C 部分预测

[编辑 | 编辑源代码]

2022 年试卷 1 将包含 5 道题,共 17 分。只要你熟悉程序,这将是小菜一碟。

06. 这个问题与 Breakthrough 类有关。

06.1 说明 Breakthrough 类中一个布尔属性的名称。[1 分]

06.2 说明 Breakthrough 类中使用异常处理的方法的名称。[1 分]

06.3 参考 CreateStandardDeckAddDifficultyCardsToDeck 方法以及“game1.txt”文件 - 牌堆中总共有多少张牌?[1 分]

06.4 参考“game1.txt”保存的游戏文件,说明保存的游戏文件中的每一行代表什么。[2 分]


07. 这个问题与 Breakthrough 类中的 __Loadlocks 方法有关。

07.1 说明 __Locks 使用的数据类型。[1 分]

07.2 说明可以添加到“locks.txt”文件中以表示需要 Acute PickBasic FileCrude Key 打开的 3 挑战锁的格式正确的单行。[1 分]


08. 这个问题与 Breakthrough 类中的 CreateStandardDeckAddDifficultyCardsToDeck 方法有关。

08.1 说明使用的迭代类型。[1 分]

08.2 说明游戏运行时生成多少张难度卡

08.3 说明游戏运行时生成多少张其他卡片。

08.4 如果我们希望使游戏难度降低(将难度卡的数量从五张减少到三张),请描述需要进行的必要代码更改,假设我们希望保持卡片的总数量相同

  • 关于类的题目?
  • 关于第二个类的题目?
  • 关于第三个类的题目?
  • 关于类图的题目?
  • 关于游戏功能的题目,例如如何判断游戏是否结束?
  • 关于为什么使用文本文件而不是其他文件类型来存储数据的题目?

这些预测是根据去年的高级附属试卷做出的

D 部分预测

[编辑 | 编辑源代码]

骨架程序上的编程问题

  • 2022 年试卷 1 包含 4 道题:5 分题、9 分题、10 分题和 13 分题 - 这些分数包括屏幕截图,因此编码的可能分数将降低 1-2 分。
  • 2021 年试卷 1 包含……
  • 2020 年试卷 1 包含 4 道题:6 分题、8 分题、11 分题和 12 分题 - 这些分数包括屏幕截图,因此编码的可能分数将降低 1-2 分。
  • 2019 年试卷 1 包含 4 道题:5 分题、8 分题、9 分题和 13 分题 - 这些分数包括屏幕截图,因此编码的分数将降低 1-2 分。
  • 2018 年试卷 1 包含一道 2 分题、一道 5 分题、两道 9 分题和一道 12 分题 - 这些分数包括屏幕截图。
  • 2017 年试卷 1 包含一道 5 分题、三道 6 分题和一道 12 分题。

当前问题是本页面贡献者推测的。

修复密钥 1-5。

[编辑 | 编辑源代码]

修复输入的卡片编号不在 1 到 5 范围内引起的“IndexOutOfRange”异常。

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

这处理了输入的字符和超出范围的整数。

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


添加加载功能

[编辑 | 编辑源代码]

添加选择(加载)特定(保存的)游戏文件的功能(目前没有提供选择)。

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


要求玩家按顺序完成挑战

[编辑 | 编辑源代码]

目前,锁的挑战不需要按顺序完成。更改功能,仅允许用户按列出的顺序完成锁的挑战。

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


难度卡功能

[编辑 | 编辑源代码]

目前,难度卡将允许用户选择弃牌 5 张或通过选择 1-5 弃牌。更改功能,强制用户选择一张要弃牌的牌,或者如果玩家手中没有牌,则从牌堆中弃牌 5 张。

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


难度错误

[编辑 | 编辑源代码]

当给定难度卡时,程序将要求输入 1-5 或弃牌 5 张。当选择一张牌时,它并不总是会弃牌,因为列表索引会自行更改。

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

' 新的 DifficultyCard 类 Process 子程序

        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


检索卡片

[编辑 | 编辑源代码]

为检索卡创建一个新的卡片子类。如果玩家抽到检索卡,他们可以从弃牌堆中检索一张牌并将其放回手中。牌堆中应该有两张检索卡。这些应该像难度卡一样,在用户抽取手牌后添加。

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())

从牌堆类中获取卡片

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)
还必须从 __SetUpGame 函数中添加一个调用


VB.NET

为了完成此挑战,您需要创建一个名为 RetrievalCard 之类的新类,您需要更改 play game 函数,您需要更改 setupGame 子程序,并且您需要创建一个函数来将检索卡添加到牌堆中。我们将首先查看 Retrieval 卡类,然后是添加检索卡函数,然后是更改后的 setup game 子程序,然后是 play game 函数。值得注意的是,对于 playGame() 子程序,只有 case “U” 块中的代码已更改。

    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


卡片数量

[编辑 | 编辑源代码]

如果玩家在没有解决锁的情况下用完了牌堆中的牌,则算输。因此,他们可能希望查看此信息。更改程序,以便在每次回合中除了当前分数之外,还显示牌堆中剩余的卡片数量。

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)


保存游戏

[编辑 | 编辑源代码]

有一个加载游戏的功能,但无法保存游戏的状态。创建一个可以在查看弃牌或使用牌代替的功能,并将游戏保存到用户选择的文件中。此外,更改加载游戏功能,以便用户可以输入他们想要加载的文件的名称。

Delphi/Pascal


Java

在 playGame 中添加一个 case S

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

并更改 getChoice

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

新增 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;
        }
    }

在 CardCollection 类中添加一个方法

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

在 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#

“在 Breakthrough 类中创建一个新的 SaveGame 方法,并修改 PlayGame() 中的 switch 语句,以及更新 Breakthrough 类中的 SetupGame() 方法,以允许选择特定的文件”

                        // 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;
        	}
        }

“然后在 Lock 类中执行以下操作:”

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;
        }
“脚注:理论上,你如何命名方法并不重要。根据编码的禅意,尽可能地以合适的方式命名它们是最简单的,但如果这对考试来说不遵循标准会有帮助,那么它实际上并不重要。”


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


专业牌组

[编辑 | 编辑源代码]

目前游戏提供了一组预设的卡片——撬棍、文件和钥匙。创建一个新方法来为游戏的替代版本创建 SpecialityDeck,以便为用户/玩家提供选择玩 StandardDeck *或* SpecialityDeck 的选项。SpecialityDeck 包含三种类型的工具:(E)xplosive(爆炸物)、(W)elder(焊接器)和 (A)nother(其他)。

C#


Delphi/Pascal


Java


Python


VB.NET


万能牌

[编辑 | 编辑源代码]

目前游戏提供了一套预设的牌组。添加“万能牌”的功能,该牌可以对*任何*特定锁使用。

C#


Delphi/Pascal


Java


Python

代码更改

    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()


连续工具类型惩罚

[编辑 | 编辑源代码]

如果用户尝试连续使用两种相同类型的工具卡,目前不会显示任何错误消息。更改代码,以便在用户的卡片因此规则而被拒绝时通知用户。此外,扣除 1 分的得分惩罚(将用户的得分减少 1 分),并在所有情况下通知用户已发生此情况,*除了*用户得分随后会变为负数的情况,在这种情况下应省略。

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


查看牌堆中剩余的卡片

[编辑 | 编辑源代码]

显示牌堆中剩余卡片的列表(有点破坏游戏体验,但可能会被问到)

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 学院


永不重复使用锁

[编辑 | 编辑源代码]

当锁被打开时,会从锁列表中随机选择一个新的锁。但是,它可能会选择玩家已经解开的锁。调整 Breakthrough 类中的 GetRandomLock() 方法以解决此问题。

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


弃牌堆检查后

[编辑 | 编辑源代码]

在玩游戏时,玩家可以通过在第一次输入时输入“D”来选择检查弃牌堆。程序需要进行修改,以便玩家可以选择从弃牌堆中取回一张牌,并从手中丢弃一张牌。取回的牌不能是难度牌。

修改 Breakthrough 类中的 PlayGame 方法,以便在用户选择检查弃牌堆后:• 提示用户输入要从弃牌堆中取回的牌的编号,方法是输入牌的整数数值。输入 0 将跳过此步骤。应向用户显示以下提示:“请输入大于 0 的数字以取回卡片。如果您希望跳过此步骤,请输入 0”• 然后要求用户输入他们希望从手中移除的牌的编号。应向用户显示以下提示:“请输入要从手中丢弃的牌的编号”• 卡片在弃牌堆和手中之间转移,游戏继续

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
华夏公益教科书