Go Fish/PureBasic: Difference between revisions

m
Fixed syntax highlighting.
mNo edit summary
m (Fixed syntax highlighting.)
 
(One intermediate revision by one other user not shown)
Line 1:
{{collection|Go Fish}}
If 'computer' is entered for the player's name, it will play itself.
<langsyntaxhighlight PureBasiclang="purebasic">#MaxCards = 52 ;Max #of cards possible in a card collection
#ShortCardRanks$ = "2;3;4;5;6;7;8;9;10;J;Q;K;A"
#LongCardRanks$ = "deuce;three;four;five;six;seven;eight;nine;ten;jack;queen;king;ace"
Line 12:
Structure _membersCardCollectionClass
*vtable.i
Sizesize.i ;# of cards present
card.i[#MaxCards] ;collection content, stores rank# for each card, suits aren't used
EndStructure
Line 89:
Protected i
If isDeck
*this\Sizesize = #MaxCards - 1
For i = 0 To #MaxCards - 1
*this\card[i] = (i % #NumCardRanks) + 1
Next
Else
*this\Sizesize = -1
EndIf
EndProcedure
 
Procedure CC_countCards(*this._membersCardCollectionClass)
ProcedureReturn *this\Sizesize + 1
EndProcedure
 
Procedure CC_countMatchingCards (*this._membersCardCollectionClass, rank)
Protected i, count
For i = 0 To *this\Sizesize
If *this\card[i] = rank
count + 1
Line 120:
 
Procedure CC_pushCard(*this._membersCardCollectionClass, rank)
If *this\Sizesize < #MaxCards And (rank > 0 And rank <= #NumCardRanks)
*this\Sizesize + 1
*this\card[*this\Sizesize] = rank
EndIf
EndProcedure
Line 128:
Procedure CC_popCard(*this._membersCardCollectionClass)
Protected rank
If *this\Sizesize >= 0
rank = *this\card[*this\Sizesize]
*this\Sizesize - 1
EndIf
ProcedureReturn rank ;returns #Null if no cards are in collection
Line 139:
Protected i
For i = *this\Sizesize To 0 Step -1
If *this\card[i] = rank
If *this\Sizesize < (#MaxCards - 1) And i <> *this\Sizesize
MoveMemory(@*this\card[i + 1], @*this\card[i], SizeOf(Integer) * *this\Sizesize - i)
EndIf
*this\Sizesize - 1
EndIf
Next
Line 153:
Protected i, cardsTransfered, *src._membersCardCollectionClass = *source, blankcard
If *source <> #Null
For i = *src\Sizesize To 0 Step -1
If *src\card[i] = rank
*this\Sizesize + 1
*this\card[*this\Sizesize] = *src\card[i]
If *src\Sizesize < (#MaxCards - 1) And i <> *src\Sizesize
MoveMemory(@*src\card[i + 1], @*src\card[i], SizeOf(Integer) * (*src\Sizesize - i))
EndIf
*src\Sizesize - 1
cardsTransfered + 1
EndIf
Line 171:
Procedure CC_shuffle(*this._membersCardCollectionClass)
Protected w, i
If *this\Sizesize >= 0
Dim shuffled(*this\Sizesize)
For i = *this\Sizesize To 0 Step -1
w = Random(i)
shuffled(i) = *this\card[w]
Line 182:
Next
For i = 0 To *this\Sizesize
*this\card[i] = shuffled(i)
Next
Line 191:
Protected i, output$
For i = 0 To *this\Sizesize
output$ + StringField(#ShortCardRanks$, *this\card[i],";")
If i <> *this\Sizesize: output$ + ", ": EndIf
Next
ProcedureReturn output$
Line 200:
Procedure CC_sortCards(*this._membersCardCollectionClass)
Protected low, high
Protected firstIndex, lastIndex = *this\Sizesize
If lastIndex > firstIndex + 1
Line 704:
 
PrintN(#CRLF$ + "Press Enter to exit.")
Input()</langsyntaxhighlight>
9,485

edits