2 changed files with 98 additions and 5 deletions
@ -1,2 +1,3 @@
|
||||
gamelog.typescript |
||||
commands.history |
||||
login.py |
||||
|
@ -1,5 +1,97 @@
|
||||
c = '' |
||||
while c != 'quit': |
||||
c = input('$ ') |
||||
with open('commands.history', 'a') as f: |
||||
f.write(c + '\n') |
||||
import re |
||||
import subprocess |
||||
from time import sleep |
||||
|
||||
from login import username, password # DIY |
||||
|
||||
|
||||
class status(): |
||||
def __init__(self): |
||||
self.prompt = "" |
||||
self.sector = "" |
||||
|
||||
def update(self): |
||||
self.gamelog = re.sub('\x1b.*?m','', subprocess.check_output(['tail', '-n', '1', 'gamelog.typescript']).decode('latin_1')) |
||||
|
||||
c = re.match(r"Command \[TL.*\]:\[(\d{1,6})\] \(\?=Help\)\? :", self.gamelog) |
||||
if c != None: |
||||
self.prompt = "command" |
||||
self.sector = c.group(1) |
||||
|
||||
elif re.match(r"^Computer command \[TL", self.gamelog): |
||||
self.prompt = "computer" |
||||
|
||||
elif re.match(r"^Engage the Autopilot", self.gamelog): |
||||
self.prompt = "engage" |
||||
|
||||
elif re.match(r"Planet command \(\?=help\) \[D\]", self.gamelog): |
||||
self.prompt = "planet" |
||||
|
||||
else: |
||||
self.prompt = "" |
||||
|
||||
|
||||
def reset_mode(): |
||||
|
||||
while game_status.prompt != "command": |
||||
if game_status.prompt == "computer": |
||||
execute('q') |
||||
else: |
||||
print("Failed to return to command mode. ") |
||||
|
||||
sleep(3) |
||||
|
||||
game_status.update() |
||||
|
||||
|
||||
def goto(): |
||||
|
||||
game_status.update() |
||||
|
||||
sector = input("enter target sector:") |
||||
|
||||
reset_mode() |
||||
|
||||
while game_status.sector != sector: |
||||
|
||||
if game_status.prompt == "command": |
||||
execute(sector + "\n") |
||||
|
||||
sleep(2) |
||||
game_status.update() |
||||
|
||||
if game_status.prompt == "engage": |
||||
execute('e') |
||||
|
||||
|
||||
def execute(cmd): |
||||
|
||||
if cmd == None: |
||||
return |
||||
|
||||
commands = { |
||||
'goto': goto, |
||||
'login' : f"{username}\n\na\n\nt\n\ny\ny\n\n\n{password}\n\n", |
||||
'logout': "qy\n\nx\n\n\nq\n", |
||||
} |
||||
|
||||
if cmd in commands.keys(): |
||||
t = commands[cmd] |
||||
try: |
||||
if type(t) == str: |
||||
execute(t) |
||||
else: # type <function> |
||||
execute(t()) |
||||
|
||||
except KeyboardInterrupt: |
||||
input("Command terminated. \n\nPress enter key. ") |
||||
|
||||
else: |
||||
with open('commands.history', 'a') as f: |
||||
f.write(cmd + '\n') |
||||
|
||||
|
||||
game_status = status() |
||||
|
||||
while True: |
||||
execute(input('$ ')) |
||||
|
Loading…
Reference in new issue