Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python coding!! In this assignment you have been given a very simple framework that pits an army of Clones against an army of Robots. It

Python coding!!

In this assignment you have been given a very simple framework that pits an army of Clones against an army of Robots. It is your job to create Clone and Robot classes that are compatible with the framework. In this lab, you will be working with the attached file clone wars.py. (screenshots below)

The army of Robots will attack first. Each Robot will shoot randomly at Clones (up to 5 times) until it hits one for damage. Once all Robots have attempted to attack, it will be the Clones turn.

The army of Clones will attack second. Each Clone will shoot randomly at Robots (up to 5 times) until it hits one for damage. After a Clone hits a Robot, there is a 0.3% chance it will issue Order 66. This will cause all Clones to shoot themselves instead of their randomly chosen targets when they pull the trigger on their blasters. Once all Clones have attempted to attack, it will again be the Robots turn. Once either all Clones are dead or all Robots are dead, the simulation will end.

Robot is the simpler of the two classes you must implement, so we will discuss it first: Robots should have the following private attributes: hitpoints the life of the robot solder. When this reaches zero, the robot dies. damage the damage dealt by the robot when it shoots and enemy dead boolean that tracks if the robot is dead Robots should have the following public methods: takeDamage This method should accept an integer representing an amount of damage inflicted upon the Robot. This amount of damage should be subtracted from the Robots hitpoints. If this results in the Robots hitpoints being non-positive, then the Robots dead attribute should be set. shoot This method should accept a target, which could be either a Robot or Clone object. If the Robot is not dead, the target should take damage. (In other words, dead robots cant shoot) dead This is a simple accessor method for returning the value of the Robots private dead attribute. hitpoints This method accepts no parameters and returns a string. If the Robot is not dead, the string should contain the Robots current hitpoints formatted to 4 digits. If the Robot is dead, the returned string should simply contain DEAD.

Clones are a bit more complicated because any single Clone instance could randomly issue Order 66, causing ALL Clone instances to start targeting themselves: Clones should have the same private attributes as Robots: hitpoints the life of the clone solder. When this reaches zero, the clone dies. damage the damage dealt by the clone when it shoots dead boolean that tracks if the clone is dead Additionally, Clones should have a private boolean class variable order66. When True, Order 66 will be in effect. Clones should have the following public methods: takeDamage This method should work just like the Robot classs takeDamage method. shoot This method should accept a target, which could be either a Robot or Clone object. If the Clone is not dead, the private method shoot should be called (See Below). Next, if Order 66 is not in effect, the Clone should call the private static method issueOrder66 (See Below). dead This is a simple accessor method for returning the value of the Clones private dead attribute. Same as with the Robot class. hitpoints This method accepts no parameters and returns a string. If the Clone is not dead, the string should contain the Clones current hitpoints formatted to 4 digits. If the Clone is dead, the returned string should simply contain DEAD. Same as with the Robot class. Clones should have the following private methods: issueOrder66 This is a static method that accepts no parameters. It should instate Order 66 with a 0.3% probability. shoot This method accepts a target, which could be either a Clone object or a Robot object. If Order 66 is in effect, the Clone will shoot itself. If Order 66 is not in effect, the Clone will shoot target. In both cases, the damage dealt is specified by the private attribute damage.

Once you implement these two classes correctly, the Robot vs Clone battle simulation should run! Run a few times and check that the Robots and Clones are fighting correctly. Be sure to show that Order 66 works correctly when issued.

image text in transcribed

image text in transcribed

import os import time from random import random as R from random import choice as getRandom # CODE GOES HERE def printBattleStatus (cloneArmy, robotArmy): ACCEPTS: - a list of Clone objects cloneArmy robotArmy - a list of Robot objects RETURNS: Nothing Clears the screen and prints the hitpoints of all the clone soldiers on the left and all the robot soldiers on the right Example output: clone3 Robots DEAD I DEAD ] I25 1 20 1 20 1 DEAD 50 DEAD 35 1 20 1 DEAD I DEAD ] 151 20] os.system 'clear') if Clone. order66 is True: print '[ ORDER 66!1' Robots print 'Clones print ' for clone, robot in zip (cloneArmy, robotArmy): print ' [ %s ] [ %s ]' % (clone . hitpoints(), robot . hitpoints()) time.sleep (1) def allDead (army): ACCEPTS: army a list of either Robot or Clone objects RETURNS: True

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

Students also viewed these Databases questions