I was curious how fast I could get Acey Ducey up and running. 40 minutes around 50 LOC. But when I went to save it, turns out I had tried this exercise once already:
And it had several nice features to save LOC, ie a Deck and shuffling is not need for 3 cards, neither are any subs or functions...
so another 43 minutes rewrite and down to 17 lines, still very readable:
Code: (Select All)
_Title "Acey Ducey" 'b+ 2021-03-03 see how long it takes to write game from scratch 12:15
' 1 hr to get it going + 2/3 to make it pretty,
' thing is there is no end to making pretty, I could add comma's to player's total for next beautification.
Randomize Timer
Cards$ = "23456789XJQKA" ' I guess Ace is highest
player& = 100 ' player
round& = 0 ' round
Do
round& = round& + 1
CPR 2, "Acey Ducey Round #" + ts$(round&)
card1& = Int(Rnd * 13) + 1 ' not exactly playing from a full deck here, could draw 5 aces in a row
card2& = Int(Rnd * 13) + 1 ' ok it's like 13 cards shuffled before each draw
cardWinLose& = Int(Rnd * 13) + 1
CPR 5, "First Card: " + Mid$(Cards$, card1&, 1)
CPR 6, " 2nd Card: " + Mid$(Cards$, card2&, 1)
CPR 8, "Player you have: $" + ts$(player&)
CPR 10, " Of that amount, please enter how much you would like to bet"
Locate 11, 11
Input " that the next card is = or between those two cards"; bet&
If bet& > player& Then bet& = player&
CPR 13, " Win | Lose Card: " + Mid$(Cards$, cardWinLose&, 1)
If cardWinLose& > card1& And cardWinLose& > card2& Or cardWinLose& < card1& And cardWinLose& < card2& Then
CPR 15, "Player Lost $" + ts$(bet&)
player& = player& - bet&
Else
CPR 15, "Player Won $" + ts$(bet&)
player& = player& + bet&
End If
CPR 20, "Zzz... press any"
Sleep
_KeyClear
Cls
Loop Until player& <= 0
CPR 23, " Player you are bankrupt, good day!"
Sub CPR (Row, S$) 'Center Print Row
Locate Row, (_Width - Len(S$)) / 2: Print S$
End Sub
Function ts$ (N As Long)
ts$ = _Trim$(Str$(N))
End Function
And it had several nice features to save LOC, ie a Deck and shuffling is not need for 3 cards, neither are any subs or functions...
so another 43 minutes rewrite and down to 17 lines, still very readable:
Code: (Select All)
_Title "Acey Ducey 2024-07-21 version" ' b+ 2024-07-21
Randomize Timer
ranking$ = "23456789TJQKA" ' one letter or digit to designate card value
bank = 100
While bank
r1 = Int(Rnd * 13) + 1: r2 = Int(Rnd * 13) + 1: r3 = Int(Rnd * 13) + 1
If r1 < r2 Then low = r1: high = r2 Else low = r2: high = r1
Print Mid$(ranking$, r1, 1); " "; Mid$(ranking$, r2, 1)
Print "You have"; bank; "to bet."
Input "Enter your bet "; bet
If bet > bank Then bet = bank
If bet = 0 Then bet = 1
Print "Betting"; bet; Chr$(10); Mid$(ranking$, r3, 1)
If r3 >= low And r3 <= high Then bank = bank + bet: Print "You won"; bet: Print
If r3 < low Or r3 > high Then bank = bank - bet: Print "You lost"; bet: Print
Wend
Print "Game Over, no money left to bet."
b = b + ...