예제 #1
0
def task():
    #Commands to control the "world"
    #Open a particular world file
    world.readWorld("beeperWorld.kwld")
    #Set the size of the visible world
    world.setSize(10, 10)
    #Set the speed of the robot
    world.setDelay(30)

    sb15 = UrRobot(5, 6, North, 1, fill='green', outline='blue')

    def turn(a):
        for i in range(a):
            sb15.turnLeft()

    def pickAndTurn(a):
        for i in range(a):
            sb15.pickBeeper()
            sb15.turnLeft()
            sb15.move()
            turn(3)
            sb15.move()

    #Write the code to make your robot pick up all the beepers.
    sb15.turnLeft()
    sb15.move()
    pickAndTurn(4)
    sb15.pickBeeper()
    time.sleep(3)
예제 #2
0
def task():
        def turnSB15(a):
                for i in range(a):
                        sb15.turnLeft()
        def turnKarel(a):
                for i in range(a):
                        karel.turnLeft()
#       Commands to control the "world"
        world.readWorld("stepsWorld.kwld")    # open a particular world file
        world.setSize(10,10)               # set the size of the visible world
        #^^ should be 10
        world.setDelay(90)                # set simulation speed. 0-fastest, 100-slowest

        karel = UrRobot(2,3,East, 1,fill="blue")
        sb15 = UrRobot(1,6,North, 10, fill="green")
        sb15.move()
        karel.turnLeft()
        turnSB15(1)
        sb15.move()
        turnSB15(3)
        sb15.move()
        turnSB15(1)
        sb15.move()
        turnSB15(1)
        turnKarel(1)
        karel.move()
        turnKarel(1)
        karel.move()
        turnKarel(2)
        turnSB15(2)
예제 #3
0
class RemoteControl:
    def __init__(self,
                 name,
                 street,
                 avenue,
                 direction,
                 beepers,
                 fill=None,
                 outline=None):
        self.karel = UrRobot(street, avenue, direction, beepers, fill, outline)
        #        self.window = window()
        world.setDelay(0)
        self.fill = fill
        self.name = name
        global offset
        offset += 20
        window = gtk.Dialog()
        window.set_has_separator(False)
        try:
            color = gtk.gdk.color_parse(fill)
            window.modify_bg(gtk.STATE_NORMAL, color)
        except:
            pass

        window.connect("destroy", self.destroy)
        window.set_title(name)
        window.set_size_request(100, 150)

        moveButton = gtk.Button("Move")
        moveButton.connect("clicked", self.move)
        moveButton.show()
        window.vbox.pack_start(moveButton, True, False, 0)

        turnButton = gtk.Button("TurnLeft")
        turnButton.connect("clicked", self.turnLeft)
        turnButton.show()
        window.vbox.pack_start(turnButton, True, False, 0)

        pickButton = gtk.Button("PickBeeper")
        pickButton.connect("clicked", self.pickBeeper)
        pickButton.show()
        window.vbox.pack_start(pickButton, True, False, 0)

        putButton = gtk.Button("PutBeeper")
        putButton.connect("clicked", self.putBeeper)
        putButton.show()
        window.vbox.pack_start(putButton, True, False, 0)

        turnOffButton = gtk.Button("TurnOff")
        turnOffButton.connect("clicked", self.turnOff)
        turnOffButton.show()
        window.vbox.pack_start(turnOffButton, True, False, 0)
        window.show()
        window.move(500 + offset, 20 + offset)

    def move(self, widget):
        if not self.karel.isRunning():
            print(self.name + " tried to move when it wasn't running.")
            return
        try:
            self.karel.move()
            print(self.name + ".move()")
        except:
            print(self.name + " tried to walk through a wall.")

    def turnLeft(self, widget):
        try:
            self.karel.turnLeft()
            print(self.name + ".turnLeft()")
        except:
            print(self.name + " tried to turnLeft when it wasn't running.")

    def pickBeeper(self, widget):
        if not self.karel.isRunning():
            print(self.name + " tried to pickBeeper when it wasn't running.")
            return
        try:
            self.karel.pickBeeper()
            print(self.name + ".pickBeeper()")
        except:
            print(self.name + " tried to pickBeeper when none are present.")

    def putBeeper(self, widget):
        if not self.karel.isRunning():
            print(self.name + " tried to putBeeper when it wasn't running.")
            return
        try:
            self.karel.putBeeper()
            print(self.name + ".putBeeper()")
        except:
            print(self.name + " tried to putBeeper when none available.")

    def turnOff(self, widget):
        self.karel.turnOff()
        print(self.name + ".turnOff()")

    def destroy(self, widget):
        gtk.main_quit()