Esempio n. 1
0
import socket
import re
import movement

Obstacle = False

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.1.2', 31415))
s.sendall('r'.encode())

while 1:
    reply = s.recv(4096).decode()
    if not reply == '':
        if reply[0] == 'w':
            nums = re.findall('-?\d+.?\d+', reply)
            heading = nums[0]
            dist = nums[1]
            print("New waypoint: Heading of " + str(heading) +
                  ", Distance of " + str(dist))
            movement.go(heading, dist)
            if Obstacle:
                s.sendall("o".encode())
            else:
                s.sendall("s".encode())

        elif reply[0] == 'i':
            nav.stop()

        elif reply[0] == 'h':
            s.sendall("h" + str(nav.get_heading()).encode())
Esempio n. 2
0
def currLoc():
    """
    Prints current player location for debugging.
    """
    print "Current location: %d,%d" % (movement.x, movement.y)

currLoc()

### The actual game setup and loop starts here:
while True:
    # Get user input (ui).
    ui = []  # reset ui
    ui = raw_input('> ')
    ui = ui.split(' ')
    ui.append("")  # Prevent traceback.

    if ui[0] == "go":
        movement.go(ui[1])
        currLoc()
        locations.checkLoc([movement.x, movement.y])
    elif ui[0] == "look":
        locations.checkLoc([movement.x, movement.y])
    elif ui[0] == "quit":
        exit("Bye!")
    else:
        if ui[0] != "":
            print "I don't understand that."
        else:
            print
Esempio n. 3
0
import socket
import re
import movement


Obstacle = False

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.1.2', 31415))
s.sendall('r'.encode())

while 1:
    reply = s.recv(4096).decode()
    if not reply == '':
        if reply[0] == 'w':
            nums = re.findall('-?\d+.?\d+', reply)
            heading = nums[0]
            dist = nums[1]
            print("New waypoint: Heading of " + str(heading) + ", Distance of " + str(dist))
            movement.go(heading, dist)
            if Obstacle:
                s.sendall("o".encode())
            else:
                s.sendall("s".encode())

        elif reply[0] == 'i':
            nav.stop()

        elif reply[0] == 'h':
            s.sendall("h" + str(nav.get_heading()).encode())