Browse Source

Update client.

master
William Davis 1 month ago
parent
commit
c4c5bd397a
  1. 92
      client.py

92
client.py

@ -21,12 +21,21 @@ class status():
elif re.match(r"^Computer command \[TL", self.gamelog):
self.prompt = "computer"
elif re.match(r"How many holds of", self.gamelog):
self.prompt = "commerce"
elif re.match(r"^Engage the Autopilot", self.gamelog):
self.prompt = "engage"
elif re.match(r"Planet command \(\?=help\) \[D\]", self.gamelog):
elif re.match(r"Planet command ", self.gamelog):
self.prompt = "planet"
elif re.match(r"Citadel command \(\?=help\)", self.gamelog):
self.prompt = "citadel"
elif re.match(r"Corporate command ", self.gamelog):
self.prompt = "corporate"
else:
self.prompt = ""
@ -35,53 +44,85 @@ def reset_mode():
while game_status.prompt != "command":
if game_status.prompt == "computer":
execute('q')
execute('q', env)
else:
print("Failed to return to command mode. ")
execute('qn\n', env)
sleep(3)
sleep(1)
game_status.update()
def goto():
def trade():
reset_mode()
execute("pt", env)
sleep(1)
game_status.update()
sector = input("enter target sector:")
while game_status.prompt != "command":
execute("\n", env)
sleep(1)
game_status.update()
def goto(sector):
reset_mode()
while game_status.sector != sector:
if game_status.prompt == "command":
execute(sector + "\n")
execute(sector + "\n", env)
sleep(2)
sleep(1)
game_status.update()
if game_status.prompt == "engage":
execute('e')
execute('e', env)
def colonize(planet):
try:
reset_mode()
goto("1")
execute("l\n\n", env)
goto(planet)
execute("ls\n\n", env)
sleep(1)
execute("1\n", env)
while game_status.prompt != "planet":
sleep(1)
game_status.update()
execute("q", env)
except KeyboardInterrupt:
input("Command terminated. \n\nPress enter key. ")
def execute(cmd):
def execute(cmd, env):
game_status.update()
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",
}
clist = cmd.split()
if clist == []:
clist = ['']
if cmd in commands.keys():
t = commands[cmd]
print(clist)
if clist[0] in env.keys():
try:
if type(t) == str:
execute(t)
if type(env[clist[0]]) == str:
execute(env[clist[0]], env)
else: # type <function>
execute(t())
try:
execute(env[clist[0]](*clist[1:]), env)
except TypeError as e:
print(e)
input("Wrong number of arguments. Press enter.")
except KeyboardInterrupt:
input("Command terminated. \n\nPress enter key. ")
@ -91,7 +132,16 @@ def execute(cmd):
f.write(cmd + '\n')
env = {
'goto': goto,
'colonize': colonize,
'test': test,
'trade': trade,
'login' : f"{username}\n\na\n\nt\n\ny\ny\n\n\n{password}\n\n",
'logout': "qy\n\nx\n\nq",
}
game_status = status()
while True:
execute(input('$ '))
execute(input('$ '), env)

Loading…
Cancel
Save