Pages in this set

Page 1

Preview of page 1
'Skeleton Program code for the AQA COMP1 Summer 2014 examination

'this code should be used in conjunction with the Preliminary Material

'written by the AQA COMP1 Programmer Team

'developed in the Visual Studio 2008 (Console Mode) programming environment (VB.NET)



Module CardPredict



Const NoOfRecentScores As Integer = 3



Structure TCard

Dim…

Page 2

Preview of page 2
DisplayMenu()

Choice = GetMenuChoice()

Select Case Choice

Case "1"

LoadDeck(Deck)

ShuffleDeck(Deck)

PlayGame(Deck, RecentScores)

Case "2"

LoadDeck(Deck)

PlayGame(Deck, RecentScores)

Case "3"

DisplayRecentScores(RecentScores)

Case "4"

ResetRecentScores(RecentScores)

End Select

Loop Until Choice = "q"

End Sub



Function GetRank(ByVal RankNo As Integer) As String

Dim Rank As String = ""

Select Case RankNo

Case…

Page 3

Preview of page 3
Case 5 : Rank = "Five"

Case 6 : Rank = "Six"

Case 7 : Rank = "Seven"

Case 8 : Rank = "Eight"

Case 9 : Rank = "Nine"

Case 10 : Rank = "Ten"

Case 11 : Rank = "Jack"

Case 12 : Rank = "Queen"

Case 13…

Page 4

Preview of page 4
Console.WriteLine()

Console.WriteLine("MAIN MENU")

Console.WriteLine()

Console.WriteLine("1. Play game (with shuffle)")

Console.WriteLine("2. Play game (without shuffle)")

Console.WriteLine("3. Display recent scores")

Console.WriteLine("4. Reset recent scores")

Console.WriteLine()

Console.Write("Select an option from the menu (or enter q to quit): ")

End Sub



Function GetMenuChoice() As Char

Dim Choice As Char

Choice = Console.ReadLine

Console.WriteLine()

Return…

Page 5

Preview of page 5
Count = Count + 1

End While

FileClose(1)

End Sub



Sub ShuffleDeck(ByRef Deck() As TCard)

Dim NoOfSwaps As Integer

Dim Position1 As Integer

Dim Position2 As Integer

Dim SwapSpace As TCard

Dim NoOfSwapsMadeSoFar As Integer

NoOfSwaps = 1000

For NoOfSwapsMadeSoFar = 1 To NoOfSwaps

Position1 = Int(Rnd() * 52) +…

Page 6

Preview of page 6
Console.WriteLine()

End Sub



Sub GetCard(ByRef ThisCard As TCard, ByRef Deck() As TCard, ByVal
NoOfCardsTurnedOver As Integer)

Dim Count As Integer

ThisCard = Deck(1)

For Count = 1 To (51 NoOfCardsTurnedOver)

Deck(Count) = Deck(Count + 1)

Next

Deck(52 NoOfCardsTurnedOver).Suit = 0

Deck(52 NoOfCardsTurnedOver).Rank = 0

End Sub



Function IsNextCardHigher(ByVal LastCard As…

Page 7

Preview of page 7
Console.WriteLine()

Console.Write("Please enter your name: ")

PlayerName = Console.ReadLine

Console.WriteLine()

Return PlayerName

End Function



Function GetChoiceFromUser() As Char

Dim Choice As Char

Console.Write("Do you think the next card will be higher than the last card (enter y or n)? ")

Choice = Console.ReadLine

Return Choice

End Function



Sub DisplayEndOfGameMessage(ByVal Score…

Page 8

Preview of page 8
Console.WriteLine()

Console.WriteLine("Well done! You guessed correctly.")

Console.WriteLine("Your score is now " & Score & ".")

Console.WriteLine()

End Sub



Sub ResetRecentScores(ByRef RecentScores() As TRecentScore)

Dim Count As Integer

For Count = 1 To NoOfRecentScores

RecentScores(Count).Name = ""

RecentScores(Count).Score = 0

Next

End Sub



Sub DisplayRecentScores(ByVal RecentScores() As TRecentScore)

Dim Count As…

Page 9

Preview of page 9
Console.WriteLine()

Console.ReadLine()

End Sub



Sub UpdateRecentScores(ByRef RecentScores() As TRecentScore, ByVal Score As Integer)

Dim PlayerName As String

Dim Count As Integer

Dim FoundSpace As Boolean

PlayerName = GetPlayerName()

FoundSpace = False

Count = 1

While Not FoundSpace And Count <= NoOfRecentScores

If RecentScores(Count).Name = "" Then

FoundSpace = True

Else…

Page 10

Preview of page 10
RecentScores(Count).Score = Score

End Sub



Sub PlayGame(ByVal Deck() As TCard, ByRef RecentScores() As TRecentScore)

Dim NoOfCardsTurnedOver As Integer

Dim GameOver As Boolean

Dim NextCard As TCard

Dim LastCard As TCard

Dim Higher As Boolean

Dim Choice As Char

GameOver = False

GetCard(LastCard, Deck, 0)

DisplayCard(LastCard)

NoOfCardsTurnedOver = 1

While NoOfCardsTurnedOver…

Comments

No comments have yet been made

Similar Computing resources:

See all Computing resources »See all resources »