Exemple #1
0
    def positionShips(self, manual=False):
        for ship in self.ships:
            row, column = [-1, -1]
            cell = 'Z11'
            direction = -1
            length = ship.length

            while not self.primaryBoard.canPositionShip(
                    cell, direction, length):
                if (self.bot) or (not manual):
                    row, column = common.randomCell()
                    cell = self.primaryBoard.encode(row, column)
                    direction = common.randomDirection()
                else:
                    while True:
                        common.clearScreen()
                        self.primaryBoard.printBoard()
                        cell = raw_input(
                            'Please Enter A Starting Cell For "%s": ' %
                            ship.name)
                        direction = raw_input(
                            'Please Enter A Direction (0-Horizontal, 1-Vertical): '
                        )
                        if (direction in [
                                '0', '1'
                        ]) and (self.primaryBoard.isValidCellAddress(cell)):
                            direction = int(direction)
                            row, column = self.primaryBoard.decode(cell)
                            break

            while length > 0:
                self.primaryBoard.cells[row][column] = ship.symbol
                row = row + direction
                column = column + (1 - direction)
                length = length - 1
Exemple #2
0
 def printRoundMessage(self, player, message):
     # Check if both of players are bots
     allBots = self.users[0].bot and self.users[1].bot
     if allBots or not player.bot:
         common.clearScreen()
         print 'Player: %s' % player.name
         print 'Primary Board:'
         player.primaryBoard.printBoard()
         print 'Tracking Board:'
         player.trackingBoard.printBoard()
         print 'DASHBOARD: %s' % message
Exemple #3
0
def elementPuzzle(gametime, debug=False):
    clearScreen()
    hint_count = 0

    with open('puzzles/elements/words.txt', 'r') as f:
        words = [line.strip() for line in f]

    # word to use for code
    word = words[random.randint(0, len(words) - 1)]
    printOut('--- ACCESS POD MAINFRAME ---')

    elements = re.findall(r'([A-Z][a-z]*)', word)

    code = ''
    for item in elements:
        code += str(element(item).atomic_number)

    if debug: print(code)

    # Enable numpad
    if not debug:
        disableKeys(False)

    attempt = '0'
    while int(attempt) != int(code):
        #print('User: '******'\nUser: '******'Password: '******'*':
            hint_count = hint(hint_count)
        try:
            int(attempt)
        except ValueError:
            attempt = '0'

    # Disable numpad
    if not debug:
        disableKeys()

    printOut('ACCESS GRANTED')
    printOut('\n\n--- POD STATUS ---')
    m, s = divmod(gametime - time.time(), 60)
    printOut(
        'ENGINE STATUS:\tOK\nHYPERDRIVE:\tOFFLINE\nLIFE SUPPORT:\tLIMITED - {:.0f} MINUTES {} SECONDS REMAINING\nHINTS USED:\t{}'
        .format(m, int(s), hint_count))

    return hint_count
Exemple #4
0
def printMenu():
    common.clearScreen()
    print 'Menu'
    print '1-New Game'
    print '2-Exit'
Exemple #5
0

def printMenu():
    common.clearScreen()
    print 'Menu'
    print '1-New Game'
    print '2-Exit'


# Main Application Flow:
if __name__ == '__main__':
    while True:
        printMenu()
        choice = raw_input()
        if choice == '2':
            common.clearScreen()
            break
        elif choice == '1':
            common.clearScreen()

            name1 = raw_input('Please Enter A Name For Player-1: ')
            bot1 = raw_input(
                'Please Select Player Type For %s (1-Bot, 2-Real User): ' %
                name1)
            easy = True
            bot = False
            if bot1 == '1':
                bot = True
                difficulty = raw_input(
                    'Please Select Player Difficulty For %s (1-Easy, 2-Hard): '
                    % name1)
Exemple #6
0
def main(debug=False, gametime=10.0):
    if not debug:
        disableButton()
        os.system("./utils/numlock.sh")

    clearScreen()
    hint_count = 0

    # user settles down and presses numpad 'enter' to start
    print('--- WARNING ---\nPLEASE READ BEFORE LAUNCHING\n\n')
    print(
        'ESCAPE POD USERS MUST RESPECT THE FOLLOWING RULES:\n- NO FOOD OR DRINKS INSIDE THE POD\n- BE GENTLE WITH POD FEATURES\n- ESCAPE POD FITS ONE PERSON ONLY'
    )
    print('\nIN CASE OF EMERGENCY PUSH POD DOOR OPEN')
    input('\n\n--- PRESS ENTER TO LAUNCH ---')
    if not debug:
        disableKeys()
    time.sleep(1)

    # close door electromagnets
    openDoor(False)
    printOut('PLEASE PULL DOOR CLOSED NOW')
    time.sleep(2)

    clearScreen()
    printOut('--- WELCOME ON BOARD ---')
    printOut(
        "\nIF YOU REQUIRE A HINT DURING ANY OF THE PUZZLES, PRESS '*' FOLLOWED BY ENTER\n"
    )
    printOut('POD NOW LAUNCHING...')
    time.sleep(5)
    clearScreen()
    lights('dim')

    if not debug:
        # open video of launch and crash (blocking)
        os.system("omxplayer --no-keys --no-osd -o local " + start +
                  " --win '0 0 1080 960' > /dev/null &")
        time.sleep(28)
        lights('flash')
        lights('dim')
        time.sleep(5)

    lights('fade')

    # open video of static space (in parallel)
    os.system("omxplayer --no-keys --no-osd -o local " + static +
              " --win '0 0 1080 960' > /dev/null &")

    printOut('SYSTEMS DAMAGED DUE TO ASTEROID COLLISION')
    time.sleep(2)
    printOut('\nSYSTEMS REBOOTING')
    for i in range(0, 5):
        print('.', end='', flush=True)
        time.sleep(1)

    # start countdown
    timeout = time.time() + (gametime * 60)
    m, s = divmod(timeout - time.time(), 60)
    printOut(
        '\n\n--- WARNING ---\nLIFE SUPPORT DAMAGED: {:.0f} MINUTES {} SECONDS REMAINING'
        .format(m, int(s)))
    printOut('PLEASE FOLLOW INSTRUCTIONS TO ENSURE SURVIVAL')
    time.sleep(2)

    # open video of traversing space (in parallel)
    os.system("killall -s SIGINT omxplayer.bin")
    os.system("omxplayer --no-keys --no-osd -o local " + journey +
              " --win '0 0 1080 960' > /dev/null &")

    # 1st PUZZLE: login (elements.py)
    hint_count += elementPuzzle(timeout, debug)
    time.sleep(2)

    # open video of asteroids approaching (in parallel)
    os.system("killall -s SIGINT omxplayer.bin")
    os.system("omxplayer --no-keys --no-osd -o local " + asteroids +
              " --win '0 0 1080 960' > /dev/null &")
    lights('dim')

    # 2nd PUZZLE: asteroid avoiding minigame (asteroids.py)
    deaths = asteroidPuzzle(timeout, debug)
    lights('fade')

    # open video of static space (in parallel)
    os.system("omxplayer --no-keys --no-osd -o local " + static +
              " --win '0 0 1080 960' > /dev/null &")

    # discount time depending on no. of deaths
    if deaths >= 1:
        timeout -= 10
        if deaths >= 2:
            timeout -= deaths * 5
        printOut(
            '\n\n --- WARNING ---\nLIFE SUPPORT DAMAGED BY ASTEROID COLLISION')
        m, s = divmod(timeout - time.time(), 60)
        printOut('{:.0f} MINUTE{} {} SECONDS REMAINING'.format(
            m, 'S' if m >= 2.0 else '', int(s)))
    time.sleep(2)

    # 3rd PUZZLE: repair codes (resistors.py)
    hint_count += resistorPuzzle(timeout, debug)
    os.system("killall -s SIGINT omxplayer.bin")
    os.system("omxplayer --no-keys --no-osd -o local " + journey +
              " --win '0 0 1080 960' > /dev/null &")
    printOut('\n\nALL SYSTEMS GREEN FOR LANDING')
    time.sleep(2)
    clearScreen()
    printOut('--- WARNING ---\nPOD LANDING SEQUENCE ENGAGING...')
    time.sleep(3)

    lights('dim')
    # open video of landing (in parallel)
    os.system("killall -s SIGINT omxplayer.bin")
    os.system("omxplayer --no-keys --no-osd -o local " + landing +
              " --win '0 0 1080 960' > /dev/null &")

    # stop countdown
    final_time = timeout - time.time()

    # tell user they passed!
    clearScreen()
    time.sleep(30)
    lights('fade')
    printOut('POD SAFELY LANDED')

    # user presses numpad 'enter' to open bay door
    if not debug:
        disableKeys(False)
    printOut('\n\n--- THANKS FOR PLAYING! ---\n\n')
    m, s = divmod(final_time, 60)
    printOut('{}YOU FINISHED WITH {:.0f} MINUTE{} {} SECONDS {}.'.format(
        'CONGRATULATIONS! ' if final_time >= 0 else '', m,
        'S' if m >= 2.0 else '', int(s),
        'REMAINING' if final_time >= 0 else 'OVERTIME'))
    printOut('\nTOTAL HINTS USED:\t{}\nASTEROID COLLISIONS:\t{}'.format(
        hint_count, deaths))
    printOut('\n\n--- PRESS ENTER TO OPEN POD DOOR ---')
    input('')

    # open door electromagnets
    openDoor(True)

    # Wait for user to leave
    time.sleep(10)
Exemple #7
0
def asteroidPuzzle(gametime, debug=False):
    # Disable buttons while printing
    if not debug:
        disableButton()

    pygame.mixer.init()
    pygame.init()  #turn all of pygame on.
    hit_sound = pygame.mixer.Sound('puzzles/asteroids/hit.wav')

    clearScreen()

    printOut(
        '--- WARNING! ---\nESCAPE POD NOW ENTERING HIGHLY DENSE ASTEROID FIELD'
    )
    printOut(
        'MAIN MONITOR WILL BE DISABLED TO CONSERVE POWER FOR EVASIVE MANEUVERS\nMANUAL NAVIGATION REQUIRED\nMANUAL CONTROLS LOCATED TO YOUR LEFT'
    )
    printOut('ENTERING FIELD IN')
    for i in [3, 2, 1]:
        print(i)
        time.sleep(1)

    os.system("killall -s SIGINT omxplayer.bin")

    clearScreen()
    pygame.mixer.music.load('puzzles/asteroids/moon.wav')
    pygame.mixer.music.play(-1)

    timeout = time.time() + TIMEOUT
    speed = SPEED
    curses.initscr()
    win = curses.newwin(HEIGHT, WIDTH, 0, 0)
    win.keypad(1)
    curses.noecho()
    curses.curs_set(0)
    win.border(0)
    win.nodelay(1)

    player = Player()
    win.addch(player.y, player.x, player.getIcon())

    key = None

    asteroids = []

    interval = time.time()
    curr_time = time.time()

    # Enable buttons
    if not debug:
        disableButton(False)

    while True:
        if time.time() > timeout:
            break
        if time.time() > curr_time + 5:
            speed *= RATE
            curr_time = time.time()
        win.border(0)
        win.addstr(0, 0, 'Time Left : {:.2f} '.format(timeout - time.time()))
        win.addstr(HEIGHT - 1, 1, 'Deaths : {} '.format(player.deaths()))
        if debug:
            win.addstr(HEIGHT - 1, WIDTH - 13, 'Speed : {:.2f}'.format(speed))

        event = win.getch()
        key = None if event == -1 else event

        if key == ord('a'):
            player.left()
            win.addch(player.y, player.x, player.getIcon())
            win.addch(player.y, player.x + 1, ' ')
        if key == ord('d'):
            player.right()
            win.addch(player.y, player.x, player.getIcon())
            win.addch(player.y, player.x - 1, ' ')

        if time.time() > player.last_death + 1:
            player.setIcon()

        if time.time() > interval + speed:
            win.addch(player.y, player.x, player.getIcon())
            for i in range(0, NUM_ASTEROIDS):
                first = Asteroid()
                asteroids.append(first)
            for asteroid in asteroids:
                asteroid.fall()
                if asteroid.exist:
                    if hit(player, asteroid, hit_sound):
                        player.setIcon('*')
                        win.addch(player.y, player.x, player.getIcon())
                        win.addch(asteroid.y - 1, asteroid.x, ' ')
                    else:
                        win.addch(asteroid.y, asteroid.x, '@')
                        win.addch(asteroid.y - 1, asteroid.x, ' ')
            interval = time.time()

    curses.endwin()
    pygame.mixer.music.fadeout(2000)

    # Disable buttons
    if not debug:
        disableButton()

    clearScreen()
    printOut('NAVIGATION THROUGH ASTEROID FIELD COMPLETE...')
    printOut('POD WAS HIT {} TIME{}'.format(
        player.deaths(), '' if player.deaths() == 1 else 'S'))
    printOut('\n\n--- POD STATUS ---')
    m, s = divmod(gametime - time.time(), 60)
    printOut(
        'ENGINE STATUS:\tOK\nHYPERDRIVE:\tOFFLINE\nLIFE SUPPORT:\tLIMITED - {:.0f} MINUTE{} {} SECONDS REMAINING'
        .format(m, 'S' if m >= 2.0 else '', int(s)))

    return player.deaths()
Exemple #8
0
def resistorPuzzle(gametime, debug=False):
    clearScreen()
    hint_count = 0

    if not debug:
        disableKeys()

    global ser

    if not tryConnect('/dev/ttyUSB1', b'RESISTORS\r\n'):
        if not tryConnect('/dev/ttyUSB0', b'RESISTORS\r\n'):
            try:
                if not tryConnect('/dev/ttyACM1', b'RESISTORS\r\n'):
                    return
            except:
                if not tryConnect('/dev/ttyACM0', b'RESISTORS\r\n'):
                    return

    # pick 2 random resistors
    resistor1 = random.randint(0, NUM_RESISTORS - 1)
    resistor2 = random.randint(0, NUM_RESISTORS - 1)
    while resistor2 == resistor1:
        # ensure resistor 2 is not same as resistor 1
        resistor2 = random.randint(0, NUM_RESISTORS - 1)

    if debug:
        print('Resistor 1: {}\nResistor 2: {}'.format(resistor1, resistor2))

    code1 = resistors[resistor1]
    code2 = resistors[resistor2]

    if debug:
        print('Code 1: {}'.format(code1))
        print('Code 2: {}'.format(code2))

    ser.write((str(resistor1) + '\n').encode())
    ser.write((str(resistor2) + '\n').encode())

    if debug:
        print('Values sent')

    while True:
        read_ser = ser.readline()
        if read_ser == b'ready\r\n':
            if debug:
                print('Arduino ready, LEDs lit')
            break

    printOut('--- WARNING ---')
    printOut('ENGINE DAMAGED DUE TO ASTEROID COLLISION')
    printOut('ATTEMPTING AUTOMATIC REPAIR')
    for i in range(5):
        print('.', end='', flush=True)
        time.sleep(0.5)
    printOut(' AUTOMATIC REPAIR FAILED!')
    printOut('MANUAL OVERRIDE REQUIRED\n\n')

    # Enable numpad
    if not debug:
        disableKeys(False)

    attempt = '0'
    while int(attempt) != int(code1) and int(attempt) != int(code2):
        attempt = input('ENTER ENGINE REPAIR CODE 1 OF 2: ')
        if attempt == '*':
            hint_count = hint(hint_count)
        try:
            int(attempt)
        except ValueError:
            attempt = '0'
    remaining = code2 if int(attempt) == int(code1) else code1
    if int(attempt) == int(code1):
        ser.write((str(resistor1) + 'ok\n').encode())
    else:
        ser.write((str(resistor2) + 'ok\n').encode())

    printOut('\n')

    attempt = '0'
    while int(attempt) != int(remaining):
        attempt = input('ENTER ENGINE REPAIR CODE 2 OF 2: ')
        if attempt == '*':
            hint_count = hint(hint_count)
        try:
            int(attempt)
        except ValueError:
            attempt = '0'
    if int(attempt) == int(code1):
        ser.write((str(resistor1) + 'ok\n').encode())
    else:
        ser.write((str(resistor2) + 'ok\n').encode())

    # Disable numpad
    if not debug:
        disableKeys()
    clearScreen()

    printOut('REPAIR CODES ACCEPTED, ENGINE NOW REPAIRING')
    for i in range(5):
        print('.', end='', flush=True)
        time.sleep(0.5)
    printOut(' COMPLETE!')

    printOut('\n\n--- POD STATUS ---')
    m, s = divmod(gametime - time.time(), 60)
    printOut(
        'ENGINE STATUS:\tOK\nHYPERDRIVE:\tONLINE\nLIFE SUPPORT:\tLIMITED - {:.0f} MINUTE{} {} SECONDS REMAINING\nHINTS USED:\t{}'
        .format(m, 'S' if m >= 2.0 else '', int(s), hint_count))

    ser.close()

    return hint_count