Question

In: Computer Science

Can you program Exploding kittens card game in c++ using linked lists and classes! The game...

Can you program Exploding kittens card game in c++ using linked lists and classes!

The game is played with between 2 and 4 players. You'll have a deck of cards containing some Exploding Kittens. You play the game by putting the deck face down and taking turns drawing cards until someone draws an Exploding Kitten. When that happens, that person explodes. They are now dead and out of the game. This process continues until there's only one player left, who wins the game.

Rules: https://explodingkittens.com/downloads/rules/EK_Party_Pack-Rules_wSlap.pdf

Solutions

Expert Solution

PURPOSE:

In order to get comfortable with Python classes and object-oriented programming, I've decided to simulate the Exploding Kittens card game. To make it easier to program

import random

class Card:
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name
    
    def __repr__(self):
        return str(self.name)

class Deck:
    def __init__(self, kittens = 4, regulars = 48):
        self.kittens = kittens
        self.regulars = regulars
        self.types = ['Exploding Kitten']*self.kittens + ['Regular']*self.regulars
        self.actual_cards = [Card(i) for i in self.types]
    
    def shuffle(self):
        random.shuffle(self.actual_cards)
    
    def get_top_card(self):
        card_to_be_returned = self.actual_cards.pop(0)
        return card_to_be_returned
    
    def get_four_cards(self): #for dealing the initial hand to each player
        four_cards = []
        for i in range(4):
            card_name_list = []
            for j in range(len(self.actual_cards)):
                card_name_list.append(self.actual_cards[j].name)
            regular_card_index = card_name_list.index('Regular')
            regular_card = self.actual_cards.pop(regular_card_index)
            four_cards.append(regular_card)
        return four_cards
        
class Player: 
    def __init__(self, ID, hand):
        self.player_ID = ID
        self.hand = hand
        self.alive = True
        
    def __str__(self):
        return self.player_ID
    
    def __repr__(self):
        return str(self.player_ID)

class ExplodingKittens():
    def __init__(self,num_players):
        self.num_players = num_players
        self.player_list = []
    
    def start_game(self): #set up game for first round of card draws
        self.deck_of_cards = Deck(self.num_players - 1, 53 - self.num_players)
        for player_ID in range(1, self.num_players + 1): #start w Player 1
            cards_for_player = self.deck_of_cards.get_four_cards() #Deal card to player
            player_ID = "Player " + str(player_ID)
            new_player = Player(player_ID, cards_for_player) #Save player ID and card
            self.player_list.append(new_player)
        self.deck_of_cards.shuffle()
        
    def play_round(self):
        for i in range(len(self.player_list)):
            top_card = self.deck_of_cards.get_top_card()
            print('{} drew {}'.format(self.player_list[i], top_card))
            if str(top_card) == 'Exploding Kitten':
                print('{} is dead!'.format(self.player_list[i]))
                self.player_list[i].alive = False
            alive = [self.player_list[j].alive for j in range(len(self.player_list))]
            if sum(alive) == 1:
                winner_index = alive.index(True)
                return '{} won the game!'.format(self.player_list[winner_index])
        
        player_list = [] #update player_list with only living players
        for i in range(len(self.player_list)): 
            if self.player_list[i].alive:
                player_list.append(self.player_list[i])
        self.player_list = player_list
    
    def decide_winner(self):
        while len(self.player_list) > 1:
            outcome = self.play_round()
            if outcome is not None:
                print(outcome)
                break

if __name__=="__main__":
    """run this code when executing module as a program 
    and not when importing its classes"""
    game = ExplodingKittens(5)
    game.start_game()
    print(game.player_list)
    game.decide_winner()

Related Solutions

Using C++, you will create a program, where you will create two doubly linked lists. These...
Using C++, you will create a program, where you will create two doubly linked lists. These doubly linked lists will contain integers within them. Using the numbers in both of these linked lists, you add the numbers together, and insert the addition of the two numbers into a singly linked list. the input can be from the user or you just write the input. for example, if one number in the doubly linked list is 817 and in the other...
I'm having trouble programming connect four board game using linked lists, sets and maps in c++....
I'm having trouble programming connect four board game using linked lists, sets and maps in c++. Can you code connect four game using these concepts.
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of...
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of songs/artist pairs. Allow your user to add song / artist pairs to the list, remove songs (and associated artist) from the list and be sure to also write a function to print the list! Have fun! Make sure you show your implementation of the use of vectors in this lab (You can use them too ) You MUST modularize your code ( meaning, there...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this uml as a reference.
In C++ Use vectors instead of linked lists Create a Hash table program using H(key) =...
In C++ Use vectors instead of linked lists Create a Hash table program using H(key) = key%tablesize with Chaining and Linear probing for a text file that has a list of 50 numbers Ask the user to enter the file name, what the table size is, and which of the two options they want to use between chaining and linear probing
Please include comments on what you are doing.   Using linked lists, write a Python program that...
Please include comments on what you are doing.   Using linked lists, write a Python program that performs the following tasks: store the records for each college found in the input file - colleges.csv - into a linked list. (File includes name and state data fields) allow the user to search the linked list for a college’s name; display a message indicating whether or not the college’s name was in the database allow the user to enter a state's name and...
Discover classes for generating a student report card that lists all classes, grades, and the grade...
Discover classes for generating a student report card that lists all classes, grades, and the grade point average for a semester. Create a UML diagram with constructors and methods. Implement the code including Javadoc comments.
IN C++ Write a program to play the Card Guessing Game. Your program must give the...
IN C++ Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. -Guess only the suit of the card. -Guess both the face value and suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
C++ language or Python. Linked Lists You are given a linked list that contains N integers....
C++ language or Python. Linked Lists You are given a linked list that contains N integers. You are to perform the following reverse operation on the list: Select all the subparts of the list that contain only even integers. For example, if the list is {1,2,8,9,12,16}, then the selected subparts will be {2,8}, {12,16}. Reverse the selected subpart such as {8,2} and {16,12}. The list should now be {1,8,2,9,16,12}. Your node definition should consist of 2 elements: the integer value...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT