Browse Source

Change to argparse

master
Noëlle 4 years ago
parent
commit
1fdd9247bc
1 changed files with 13 additions and 18 deletions
  1. 13
    18
      koboldgen.py

+ 13
- 18
koboldgen.py View File

@@ -1,5 +1,5 @@
import random as r
import sys
import sys, argparse

beg = ["a","e","i","o","u","ba","be","bi","bo","bu","by","y","da","de","di","do","du","dy","fa","fi","fo","fe","fu","ga","ge","gi","go","gu","ka","ke","ki","ko","ku","ky","ma","me","mi","mo","mu","na","ne","ni","no","nu","pa","pe","pi","po","pu","ra","re","ri","ro","ru","ry","sa","se","si","so","su","ta","te","ti","to","tu","ty","wa","we","wi","wo","wy","za","ze","zi","zo","zu","zy"]
mid = beg + ["l","x","n","r"]
@@ -101,8 +101,13 @@ class Character:
print(f"Body: {self.stats[3]}")

if __name__ == "__main__":
args = sys.argv[1:]
if "--campaign" in args or "-c" in args:
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("-n", "--num", help="print this many kobolds", type=int, default=1)
group.add_argument("-s", "--ship", help="print only the ship name and description", action="store_true")
group.add_argument("-c", "--campaign", help="print a full campaign block with 6 kobolds", action="store_true")
args = parser.parse_args()
if args.campaign:
cs = []
for _ in range(6):
c = Character()
@@ -121,21 +126,11 @@ if __name__ == "__main__":
print("The kobolds:")
for k in cs:
k.print()

elif args.ship:
ship = gen_transpo()
print(f"The {ship[0]} {ship[1]} {ship[2]}, but {ship[3]}.")
else:
if len(args) == 0:
for _ in range(args.num):
c = Character()
c.generate()
c.print()
else:
try:
num = int(args[0])
for _ in range(num):
c = Character()
c.generate()
c.print()
except:
print(f"Invalid arguments: {', '.join(args)}")
c = Character()
c.generate()
c.print()
c.print()

Loading…
Cancel
Save