A-level 計算機/AQA/試卷 1/骨架程式/2022
這是針對 AQA A Level 計算機科學規範。
這裡可以提出關於一些問題可能是什麼以及我們如何解決它們的建議。
請尊重他人,不要破壞頁面,因為這會影響學生備考!
請不要在此頁面上討論問題。請使用討論頁面。
2022 年試卷 1 將包含 5 道題,共 17 分。只要你熟悉程式,這將是小菜一碟。
06. 這個問題與 Breakthrough 類有關。
06.1 說明 Breakthrough 類中一個布林屬性的名稱。[1 分]
06.2 說明 Breakthrough 類中使用異常處理的方法的名稱。[1 分]
06.3 參考 CreateStandardDeck 和 AddDifficultyCardsToDeck 方法以及“game1.txt”檔案 - 牌堆中總共有多少張牌?[1 分]
06.4 參考“game1.txt”儲存的遊戲檔案,說明儲存的遊戲檔案中的每一行代表什麼。[2 分]
07. 這個問題與 Breakthrough 類中的 __Loadlocks 方法有關。
07.1 說明 __Locks 使用的資料型別。[1 分]
07.2 說明可以新增到“locks.txt”檔案中以表示需要 Acute Pick、Basic File 和 Crude Key 開啟的 3 挑戰鎖的格式正確的單行。[1 分]
08. 這個問題與 Breakthrough 類中的 CreateStandardDeck 和 AddDifficultyCardsToDeck 方法有關。
08.1 說明使用的迭代型別。[1 分]
08.2 說明遊戲執行時生成多少張難度卡。
08.3 說明遊戲執行時生成多少張其他卡片。
08.4 如果我們希望使遊戲難度降低(將難度卡的數量從五張減少到三張),請描述需要進行的必要程式碼更改,假設我們希望保持卡片的總數量相同。
- 關於類的題目?
- 關於第二個類的題目?
- 關於第三個類的題目?
- 關於類圖的題目?
- 關於遊戲功能的題目,例如如何判斷遊戲是否結束?
- 關於為什麼使用文字檔案而不是其他檔案型別來儲存資料的題目?
這些預測是根據去年的高階附屬試卷做出的
骨架程式上的程式設計問題
- 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 範圍內引起的“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)
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
當鎖被開啟時,會從鎖列表中隨機選擇一個新的鎖。但是,它可能會選擇玩家已經解開的鎖。調整 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