My first project
What is it? My program uses python to run a basic card game that I like to play. The game is called Tongits and this is how it is played -> Rules The game can be played with 2-3 players. Each player will be dealt twelve cards. For each player's turn, a player must either pick up a card from the deck or from the top of the discard pile. They will then look at their hand to see if they can either…
This is the author's first project, a basic card game program written in Python. The game is called Tongits and can be played with 2-3 players. Each player starts with twelve cards. During their turn, a player can either pick a card from the deck or the top of the discard pile. The player then examines their hand to see if they can form a "house," which consists of three or more cards of the same suit in consecutive order or the same number in different suits. The game proceeds until a player has no cards remaining in their hand.
To create the game, the author first developed a class to generate and shuffle a deck of cards, which is then dealt to the specified number of players. The player's names are collected using user input, and each player's hand is represented as a dictionary, with the player's name serving as the key and the hand as the value. A deck class was created to enable the creation of a new, game-specific deck, which is then utilized in two additional functions.
The first function, startGame(), initializes a fresh game by creating a tailored deck based on the provided number of cards to deal and add. The second function, playTongits(), calls the startGame() function to generate a new game and deck, then proceeds with the game's logic by employing a for loop that continues until a player's hand is empty. The game's rules are enforced through a series of user inputs, for loops, and nested functions. The author invites feedback on how to enhance the program.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.