Me and my friend are working on a school project where we need to make a "BattleBot" out of our maqueen. I am using this opportunity to teach my friend OOP (he has less experience in programming), so I am trying to make the bot as a class.
We tested the maqueens to make sure you can use classes (which you can), and that our function works (which it does).
Here is a minimal reproducible example to our code -
class Battlebot:
def __init__(self):
pass
# Bob and Weave
def bob_weave(self):
rand_itterations = randint(2,7)
for i in range(rand_itterations):
# Generate Random Values
turn_speed = randint(20,100)
turn_time = randint(50,500)
move_speed = randint(50,100)
move_time = randint(50,500)
# Turn
maqueen.motor_run(maqueen.Motors.M1, maqueen.Dir.CW, turn_speed)
maqueen.motor_run(maqueen.Motors.M2, maqueen.Dir.CCW, turn_speed)
basic.pause(turn_time)
maqueen.motor_stop(maqueen.Motors.ALL)
# Move
maqueen.motor_run(maqueen.Motors.M1, maqueen.Dir.CW, move_speed)
maqueen.motor_run(maqueen.Motors.M2, maqueen.Dir.CW, move_speed)
basic.pause(move_time)
maqueen.motor_stop(maqueen.Motors.ALL)
fwire_immigrant = Battlebot()
def on_forever():
fwire_immigrant.bob_weave()
basic.forever(on_forever)
We are using the MakeCode website.