Skip to content

Commit

Permalink
Final.
Browse files Browse the repository at this point in the history
Tweaks and docstrings.
  • Loading branch information
violet-black committed May 5, 2016
1 parent 48b34ba commit 4a22da9
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 142 deletions.
148 changes: 76 additions & 72 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/python3
"""
This is a classic console interface for textelite.
You may enter game commands in the command line.
"""
from cmd import Cmd

from telite import TradingGame
Expand All @@ -10,38 +14,6 @@ class TradingGameCmd(Cmd):
"""Command interface to a TradingGame"""
prompt = "> "

@staticmethod
def _check_value(value):
try:
value = float(value)
except ValueError:
print("Value must be a number")
return None
if value <= 0:
print("Nice try pilot.")
return None
else:
return value

def _check_good(self, line):
"""
:param str line:
:return iterable:
"""
line = line.strip().lower()

try:
good, number = line.split(' ')
except ValueError:
good = line
amt = 9999
else:
amt = self._check_value(number)
if not amt:
return False
amt = int(amt)
return good, amt

def __init__(self, debug=False):
self.debug = debug
Cmd.__init__(self)
Expand All @@ -51,6 +23,48 @@ def __init__(self, debug=False):
def set_prompt(self):
self.prompt = 'Cash : %0.2f>' % self.game.ship.cash

@staticmethod
def do_intro(line):
print(
'''
Welcome to pyElite {version}
Available commands:
/// CONTROLS ///
info (or i) [planet name] - planet information
buy (or b) [trade good] [amount] - buy from a local store
sell (or s) [trade good] [amount] - sell to a local store
fuel (or f) [amount] - buy amount LY of fuel
jump (or j) [planet name] - hyperjump
use (or u) [equipment name] - use installed equipment
dump [trade good] [amount] - dump cargo into space
upgrade [upgrade name] - buy and install upgrade
local (or l) - list of planets within the ship hyperjump range
mkt (or m) - show local market
cargo (or c) - show cargo bay
com - commander status
galhyp - jump to the next galaxy
/// OTHER /////
intro (or h) - display this text
quit (or q) - quit the game
run [filepath] - run a script (one command per line)
'''.format(version=__VERSION__)
)

@staticmethod
def do_quit(line):
print("Goodbye, commander!")
return True

@staticmethod
def do_q(line):
return TradingGameCmd.do_quit(line)

@staticmethod
def do_EOF(line):
return True

def do_jump(self, planetname):
status, msg = self.game.jump(planetname.strip())
print(msg)
Expand Down Expand Up @@ -196,50 +210,40 @@ def do_run(self, fname):
return

@staticmethod
def do_quit(line):
print("Goodbye, commander!")
return True

@staticmethod
def do_q(line):
return TradingGameCmd.do_quit(line)

@staticmethod
def do_EOF(line):
return True
def do_h(line):
return TradingGameCmd.do_intro(line)

@staticmethod
def do_intro(line):
print(
'''
Welcome to pyElite {version}
Available commands:
/// CONTROLS ///
info (or i) [planet name] - planet information
buy (or b) [trade good] [amount] - buy from a local store
sell (or s) [trade good] [amount] - sell to a local store
fuel (or f) [amount] - buy amount LY of fuel
jump (or j) [planet name] - hyperjump
use (or u) [equipment name] - use installed equipment
dump [trade good] [amount] - dump cargo into space
upgrade [upgrade name] - buy and install upgrade
local (or l) - list of planets within the ship hyperjump range
mkt (or m) - show local market
cargo (or c) - show cargo bay
com - commander status
galhyp - jump to the next galaxy
def _check_value(value):
try:
value = float(value)
except ValueError:
print("Value must be a number")
return None
if value <= 0:
print("Nice try pilot.")
return None
else:
return value

/// OTHER /////
intro (or h) - display this text
quit (or q) - quit the game
run [filepath] - run a script (one command per line)
'''.format(version=__VERSION__)
)
def _check_good(self, line):
"""
:param str line:
:return iterable:
"""
line = line.strip().lower()

@staticmethod
def do_h(line):
return TradingGameCmd.do_intro(line)
try:
good, number = line.split(' ')
except ValueError:
good = line
amt = 9999
else:
amt = self._check_value(number)
if not amt:
return False
amt = int(amt)
return good, amt


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 4a22da9

Please sign in to comment.