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 create a house, or add to a house. A house is essentially a collection of three or more cards of either the same suit in consectutive order or the same number in different suits. The game continues until a player has no more cards left in their hand
How does it work?
In my program, I first created a class that would create and shuffle a deck, and then deal a specifieid number of cards to a specified number of players. That is done by creating a list of cards and shuffling them (using the random module). It then uses user input to create strings of each players name, and then uses each name as a key while dealing the called amount of cards to the players hand as a list (so essentially, the player's hand is a dictionary key:item pair). The reason I created a class deck is so I could use it to instantiate a new deck specific to the game, and keep it. Using this class, I then created two more functions. The first function was the startGame() function, which would instantiate a new game creating a deck specific to the game. This function takes two parameters being the number of cards you want to deal, and the number of cards you want to add. The second function is the playTongits() function, which uses the first function to create a new game and deck. It uses the same parameters because this function calls the first function. It then runs through the game logic or "rules" by using a for loop with a set condition (that condition being that if the length of a player's hand is = 0, the game is finished). I then use a series of inputs for the user to answer, and for loops and nested functions to satisfy the game logic. It will continue for each player on repeat until the condition is met.
github repository
let me know if I can work on anything to make the program better :)
Top comments (0)