mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-12 07:40:50 -08:00
print_with_tab / print_with_whitespace is trivial with Python string formatting and was mostly used in only 2 lines.
86 lines
2.1 KiB
Python
Executable File
86 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Play the Acey-Ducey game
|
|
https://www.atariarchives.org/basicgames/showpage.php?page=2
|
|
"""
|
|
|
|
import random
|
|
|
|
cards = {
|
|
1: "1",
|
|
2: "2",
|
|
3: "3",
|
|
4: "4",
|
|
5: "5",
|
|
6: "6",
|
|
7: "7",
|
|
8: "8",
|
|
9: "9",
|
|
10: "Jack",
|
|
11: "Queen",
|
|
12: "King",
|
|
13: "Ace",
|
|
}
|
|
|
|
|
|
def play_game() -> None:
|
|
cash = 100
|
|
while cash > 0:
|
|
print(f"You now have {cash} dollars\n")
|
|
print("Here are you next two cards")
|
|
round_cards = list(cards.keys())
|
|
random.shuffle(round_cards)
|
|
card_a, card_b, card_c = round_cards.pop(), round_cards.pop(), round_cards.pop()
|
|
if card_a > card_b:
|
|
card_a, card_b = card_b, card_a
|
|
print(f" {cards[card_a]}")
|
|
print(f" {cards[card_b]}\n")
|
|
while True:
|
|
try:
|
|
bet = int(input("What is your bet? "))
|
|
if bet < 0:
|
|
raise ValueError("Bet must be more than zero")
|
|
if bet == 0:
|
|
print("CHICKEN!!\n")
|
|
if bet > cash:
|
|
print("Sorry, my friend but you bet too much")
|
|
print(f"You only have {cash} dollars to bet")
|
|
continue
|
|
cash -= bet
|
|
break
|
|
|
|
except ValueError:
|
|
print("Please enter a positive number")
|
|
print(f" {cards[card_c]}")
|
|
if bet > 0:
|
|
if card_a < card_c < card_b:
|
|
print("You win!!!")
|
|
cash += bet * 2
|
|
else:
|
|
print("Sorry, you lose")
|
|
|
|
print("Sorry, friend, but you blew your wad")
|
|
|
|
|
|
def main() -> None:
|
|
print(
|
|
"""
|
|
Acey-Ducey is played in the following manner
|
|
The dealer (computer) deals two cards face up
|
|
You have an option to bet or not bet depending
|
|
on whether or not you feel the card will have
|
|
a value between the first two.
|
|
If you do not want to bet, input a 0
|
|
"""
|
|
)
|
|
keep_playing = True
|
|
|
|
while keep_playing:
|
|
play_game()
|
|
keep_playing = input("Try again? (yes or no) ").lower().startswith("y")
|
|
print("Ok hope you had fun")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|