Question

Question 2: Virus Wars A popular subgenre of strategy game is the so-called Virus War format, where the player is shown a fieIn [ ]: #Semi-Hidden Test for Position updates correctly (1 point) # youll know if you got it right, but have to reread the

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Position class:

import math

class Position:

    def __init__(self, x, y, speed):

        self.x = x

        self.y = y

        self.dx = 0.0

        self.dy = 0.0

        if speed < 0:

            raise ValueError('Speed cannot be negative')

        else:

            self.speed = speed

   

    def moveTo(self):

        self.x = self.dx

        self.y = self.dy

   

    def tick(self):

        if self.dx != self.x

            if pow((self.dx - self.x), 2) > pow(self.speed, 2):

                if self.dx > self.x

                    self.x = self.x + self.speed

                else:

                    self.x = self.x - self.speed

                   

        if self.dy != self.y

            if pow((self.dy - self.y), 2) > pow(self.speed, 2):

                if self.dy > self.y

                    self.y = self.y + self.speed

                else:

                    self.y = self.y - self.speed

                   

    def distance(self, other):

        return math.sqrt(math.pow((self.x - other.x), 2) + math.pow((self.y - other.y), 2))

import math Fclass Position: definit__(self, x, y, speed): self.x = x self.y = y self. dx = 0.0 self.dy = 0.0 if speed < 0: r

Function Tests:

In [1]: import math class Position: definit__(self, x, y, speed): self.x = x self.y = y self.dx = 0.0 self.dy = 0.0 if speed

Add a comment
Know the answer?
Add Answer to:
Question 2: Virus Wars A popular subgenre of strategy game is the so-called Virus War format,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 2 : Virus Wars A popular subgenre of strategy game is the so-called Virus War...

    Question 2 : Virus Wars A popular subgenre of strategy game is the so-called Virus War format, where the player is shown a field of cells, each with a virus count, and may attack other cells within a certain range. We are going to write some classes in Python to implement a simple Virus Wars game. 2a) The position class (9 points) Everything within this game is going to require a position, so it makes sense to define it up...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT