We will finally give our tanks the ability to fire their cannons. Adding a fire
method means that we will need to raise exceptions related to cannon fire, in addition to exceptions that come from movement. To handle this situation, we will define custom error classes. Create a file called exceptions.py in the combatsim directory and enter the following code:
class CombatsimError(Exception): """Base class for exceptions generated by combatsim""" def __init__(self, value): """Create a CombatsimError exception. Arguments: value String describing the error """ Exception.__init__(self, value) class MoveError(CombatsimError): def __init__(self, value): CombatsimError.__init__(self,value) class ShootError(CombatsimError): def __init__(self, value): CombatsimError.__init__(self,value)
Enter the following code in vehicle.py in the combatsim directory:
import...