Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for Python. Also, I have posted a picture (bottom pic) of the code for DiceShaker for part a and b of the question.

image text in transcribed

image text in transcribedThis is for Python. Also, I have posted a picture (bottom pic) of the code for DiceShaker for part a and b of the question. Make sure you use this as a reference for part a and b. Also, make sure the output looks like the top pic. Both codes are in the same file.

3. (40 points) Write a simple game named MatchGame that uses a DiceShaker with two dice. For every roll, if the face of the die are the same you get a point. MatchGame supports four methods: a. init__() takes no parameters. You will initialize and use an instance of DiceShaker that has two dice with 6 sides. b. roll() - shakes the DiceShaker and checks to see if you have rolled a match or not or not. It keeps track of the total rolls and the score. c. getRolls() - returns how many rolls have been done during the game so far. d.getScore() - returns the score of the game. >>> m=MatchGame () >>> m.roll() No match. No points. Die Values 1 6 >>> m.roll() No match. No points. Die Values 5 2 >>> m.roll() No match. No points. Die Values 5 4 >>> m.roll() No match. No points. Die Values 1 4 >>> m.roll() No match. No points. Die Values 4 3 >>> m. roll() No match. No points. Die Values 6 4 >>> m.roll() No match. No points. Die Values 6 3 >>> m.roll() Match! 1 point! Die Values: 6 6 >>> m.getScore () 1 >>> m.roll() No match. No points. Die Values 4 1 >>> m.roll() No match. No points. Die Values 5 1 >>> m.getRolls() 10 class DiceShaker(object): DiceShaker class' def init__(self, dieCount=1, dieSides=6): 'initialize a dice shaker self.dieCount = dieCount self.dieSides = dieSides self.shake() def shake (self): shake all the dice in the shaker self.li = [random.randint(1, self.dieSides + 1) for i in range(self.dieCount)] def getTotalRoll(self): 'get the total face value of all the dice' return sum(self.li) def getIndividualRolls(self): 'get a lsit of integers of all the individual die rolls' return self.li def -_str__(self): get a string with all the die rolls seperated by a space' try: ans = str(self.li[0]). for i in self.li[1:]: ans += 1 + str(i) except IndexError: return return ans

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions