Go Fish: Difference between revisions

92 bytes added ,  1 month ago
m (Resave to try to get FutureBasic solution to show in menu)
Line 245:
 
=={{header|FutureBasic}}==
May 5, 2024 Rich Love
Fixed intermittent hang
Also, now using && and || to be compatible with later versions of FutureBasic.
( replaces AND and OR )
<syntaxhighlight lang="futurebasic">
 
/*
 
Line 251 ⟶ 256:
-- Rich Love --
 
FutureBasic app forFor Macintosh
Get the latest FutureBasic here
http://www.brilorsoftware.com/fb/pages/home.html
Line 271 ⟶ 276:
cards = "A234567890JQK"
short play(13), Computer(13), deck(13), guess(13), poss(13), asked(13)
str255 YourName, Someone,RequestedCard
//bool gNeedToClearScreen
short Points(2) : Points(0) = 0 : Points(1) = 0
short i, k, j, CardNumber
Line 283 ⟶ 288:
str255 WantsCard
WantsCard = str$(TheCard)
WantsCard = Mid$(cards,k,1)
if TheCard = 0 then WantsCard = "10"
if TheCard = 11 then WantsCard = "jack"
Line 294 ⟶ 299:
void local fn PrintViewScrollToBottom( printView as ViewRef )
BeginCCode
NSScrollView *scrollView = [printView enclosingScrollView];
NSClipView *clipView = [scrollView contentView];
[clipView scrollToPoint:NSMakePoint(0,printView.frame.size.height-scrollView.contentSize.height + 20)];
[scrollView reflectScrolledClipView:clipView];
EndC
end fn
 
Line 306 ⟶ 311:
RemainingCards -= 1
short sc
sc = rnd(RemainingCards) + 1 // 5/2/24 Rich added + 1
For k = 1 To 13
Line 329 ⟶ 334:
End fn
 
 
void local fn cpuGoFishing
Line 334 ⟶ 340:
fn DealCards
Print " a card from the deck."
if k > 13 then k = 13
deck(k) -= 1
Computer(k) += 1
Line 350 ⟶ 357:
WantsCard = Mid$(cards,i,1)
if WantsCard = "j" or|| WantsCard = "J" then WantsCard = "Jack"
if WantsCard = "q" or|| WantsCard = "Q" then WantsCard = "Queen"
if WantsCard = "k" or|| WantsCard = "K" then WantsCard = "King"
if WantsCard = "a" or|| WantsCard = "A" then WantsCard = "Ace"
if WantsCard = "0" then WantsCard = "10"
Line 376 ⟶ 383:
WantsCard = Mid$(cards,i,1)
if WantsCard = "j" or|| WantsCard = "J" then WantsCard = "Jack"
if WantsCard = "q" or|| WantsCard = "Q" then WantsCard = "Queen"
if WantsCard = "k" or|| WantsCard = "K" then WantsCard = "King"
if WantsCard = "a" or|| WantsCard = "A" then WantsCard = "Ace"
if WantsCard = "0" then WantsCard = "10"
Line 400 ⟶ 407:
i = 0:k = 0:j = 0:CardNumber = 0
forFor i = 0 to 1
Points(i) = 0
next i
FORFor i = 1 TO 13 '// Reset each element to 0
play(i) = 0
Computer(i) = 0
Line 428 ⟶ 435:
fn CheckForCompletedBook // Rich added 5/1/24
fn CheckForCompletedBookCheckCPUForCompletedBook // Rich added 5/15/24
end fn
 
Line 461 ⟶ 468:
Next i
If RemainingCards = <0 Or|| np = 0 Or|| nc = 0
text ,,fn colorRed
Line 497 ⟶ 504:
Print " __ _ _ "
Print " __ _ ___ / _(_)___| |__ "
Print " / ` |/ _ \ | |_| / __| '//_ \ "
Print "| (_) | (_) | | _| \__ \ | | | "
Print " \__, |\___/ |_| |_|___/_| |_| "
Line 513 ⟶ 520:
print " The remaining cards are placed face down in the center of the table"
print " to form the draw pile (the fish pond)."
print " On your turn, you ask the CPU forFor a card."
print " You must already have at least one card of a given rank to ask forFor more."
print " (A rank is one or|| more of any card.)"
print " If the CPU has any cards of the named rank, it must hand over all such cards,"
print " and you can then ask again."
Line 524 ⟶ 531:
print " If at any time, your hand is empty, a new card will be drawn from the pile."
print " The game ends when every book is complete,"
print " or|| there are no more cards left in the pile."
print " The player with the most books wins."
Line 533 ⟶ 540:
if ( UserInput == NULL ) then "InputYourName" // Rich added this 5/1/24
fn CFStringGetPascalString (UserInput, @YourName, 256, _kCFStringEncodingMacRoman)
gNeedToClearScreen = _True
cls
if YourName = "X" or|| YourName = "x" or|| YourName = chr$(127) then fn QuitOrResumeAlert(@"EXIT")
End fn
Line 562 ⟶ 568:
end fn
 
'//--- Start ---
 
fn BuildWindow
Line 580 ⟶ 586:
 
ShowHand = _false
 
short loopcounter = 0
str255 RequestedCard
 
While ShowHand = _false
Line 596 ⟶ 603:
Print Chr$(10) + " " + str$(RemainingCards) + " remaining cards"
text ,,fn colorWhite
/*
// Uncomment this to see the CPU'sCPUs cards forFor testing
Print Chr$(10) + "CPU Cards: ";
For i = 1 To 13
Line 636 ⟶ 644:
if fn CheckForEndGame = _True then cls:fn InitCards:goto "Loop"
loopcounter ++
Someone = YourName
if gNeedToClearScreen = _False then fn PrintViewScrollToBottom( fn WindowPrintView(1) ):gNeedToClearScreen = _False
CFStringRef UserInput = 0
Line 652 ⟶ 657:
WantsCard = RequestedCard
if WantsCard = "j" or|| WantsCard = "J" then WantsCard = "Jack"
if WantsCard = "q" or|| WantsCard = "Q" then WantsCard = "Queen"
if WantsCard = "k" or|| WantsCard = "K" then WantsCard = "King"
if WantsCard = "a" or|| WantsCard = "A" then WantsCard = "Ace"
if WantsCard = "0" then WantsCard = "10"
Line 663 ⟶ 668:
AorAn = "a"
if WantsCard = "Ace" then AorAn = "an"
print YourName + " asked forFor " + AorAn + " " + WantsCard
print
text ,,fn ColorWhite
Line 669 ⟶ 674:
fn PrintViewScrollToBottom( fn WindowPrintView(1))
if RequestedCard = "X" or|| RequestedCard = "x" then fn QuitOrResumeAlert(@"EXIT")
If RequestedCard <> "" Then CardNumber = Instr$(1,cards, Ucase$(RequestedCard)): RequestCard = _true
Line 678 ⟶ 683:
print
fn PrintViewScrollToBottom( fn WindowPrintView(1))
Else if play(CardNumber) = 0 Then text ,,fn colorRed: Print "You don'//t have that card!": text ,,fn colorRed: RequestCard = _false
fn PrintViewScrollToBottom( fn WindowPrintView(1))
text,,fn ColorWhite
End If
// loopcounter should never reach 100 but just in case, prevent hangs
if loopcounter > 100 then loopcounter = 0:exit while
Wend
Line 708 ⟶ 712:
ShowHand = _false
End If
// loopcounter should never reach 100 but just in case, prevent hangs
if loopcounter > 100 then loopcounter = 0:exit while
Wend
 
Line 726 ⟶ 729:
po = 0
For i = 1 To 13
If (Computer(i) > 0) And&& (guess(i) > 0) Then poss(i) = 1: po += 1
Next i
short whilecounter
WhileCounter = 0
If po = 0
// this k is the card the CPU gets after go fish card.
while computer(k) = 0 Or asked(k)
k = rnd(12) +1
while computerComputer(k) = 0 Or|| asked(k)
whilecounter ++
k = rnd(12) +1
if WhileCounter > 100 then k = 0: exit while //5/5/24 Rich added this to prevent hangs
wend
Else
// this k is the card you get after go fish
k = rnd(12) + 1
while poss(k) = 0
k = rnd(12) + 1
if WhileCounter > 100 then k = 0: exit while //5/5/24 Rich added this to prevent hangs
wend
Line 746 ⟶ 760:
if k = 0 then "Loop" //5/5/24 Rich added this to prevent hangs
WantsCard = fn CheckForFaceCard(k)
if WantsCard = "j" or|| WantsCard = "J" then WantsCard = "Jack"
if WantsCard = "q" or|| WantsCard = "Q" then WantsCard = "Queen"
if WantsCard = "k" or|| WantsCard = "K" then WantsCard = "King"
if WantsCard = "a" or|| WantsCard = "A" then WantsCard = "Ace"
if WantsCard = "0" then WantsCard = "10"
Line 759 ⟶ 773:
print "-------------------------------------"
Print:Print Someone + " wants your " + wantsCard + "'s."
Line 766 ⟶ 782:
asked(k) = 1
If play(k) = 0
Line 771 ⟶ 788:
text ,,fn colorRed: Print "go fish!"
text ,,fn colorWhite:Print Someone + " got";: fn cpuGoFishing
fn CheckCPUForCompletedBook
CPUsTurn = _true
Line 792 ⟶ 810:
 
handleevents
 
</syntaxhighlight>
 
44

edits