Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Blackjack with dices: Blackjack with dice can be played with any number of players and one dice.The goal for each player is to get 21

Blackjack with dices: Blackjack with dice can be played with any number of players and one dice.The goal for each player is to get 21 points, or as close as 21 as possible. If you get more than 21 you loose. At the start each player throws the dice three times and sums the value. These are the scores the player starts with. For each round the player gets to know his score and can choose to quit or throw the dice. If the player throws the dice the players score will increase with the number on the dice. If the player gets more than 21 points the player has lost and is out of the game. The player with the most points, no more than 21, have won.

a) Import the class Player and class Dice. (shown at the end of this)

b) Create a Class that represents the game. The game must have at least one dice and a list of players.

c) Create a function that creates a player based on user input. The function should read the navn from the user, throw the dice three times and sets the score equal to the sum of those three dices. The function should return a reference to the player object that was made.

d) Create a method in the class for the game that plays a game(lap) for one player. The method should take the player object to the player as a parameter. The method should:

- Show who their turn is by printing a message that includes the name of the player

- Print the score of the player

- Ask if the player wants to throw the dice again

- If the player wants to throw the dice again: throw the dice and add the value to the score

- Declare if the player has more than 21 points and thereby lost the game

e) Create a script that tests that the classes and methods made so far works as they should

f) Create a function that asks how many players and reads it from the user. Then, the function should create the specified number of players and put them in a list of players. The constructor to the class of the game must take this list of players as a parameter.

g) Create a method in the class for the game that plays a game for all the players. That is, each player who has not lost or chosen to finish will play another game. You should find out how the method should distinguish between players who are still involved and non-participating players.

h) Create a method in the class for the game that checks who, if any, has won.

i) Create a script that runs the game and plays until someone wins.

Dice:

import random

Class Dice:

def __init__(self, number_sides=6):

self.__value = 1

self.__sides = number_sides

def throw(self):

self.__value = random.randint(1, self.__sides)

def get_verdi(self):

return self.__value

Player:

class Player: def __init__(self, id, name): self.__id = id self.__name = name self.__score = 0 def get_id(self): return self.__id def get_name(self): return self.__name def get_score(self): return self.__score def set_name(self, new_name): if new_name == "": raise ValueError("Name can not be empty!") self.__name = new_name def set_score(self, new_score): if new_score >= 0: self.__score = new_score else: raise ValueError("Score can not be negative!")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions