-
Notifications
You must be signed in to change notification settings - Fork 0
/
termGame
executable file
·94 lines (78 loc) · 3.6 KB
/
termGame
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
import sys #build with pyInstaller termGame --onefile
import os
from prompt_toolkit import prompt
from prompt_toolkit.history import FileHistory
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.completion import WordCompleter
commands = ["2048", "OsXs", "ships", "snake", "tetris", "greed", "pipes"]
out = ["2048", "OsXs", "BattleShips", "Snake", "Tetris", "Greed", "Pipes"]
commandPrompts = commands[:]
commandPrompts.append("help")
commandPrompts.append("quit")
CompleterList = WordCompleter(commandPrompts)
def readHScores():
currentPath = os.path.abspath(os.path.dirname(__file__))
with open(currentPath + '/HiScores.txt', "r") as textFile:
lines = [line.split() for line in textFile]
return lines
termArguments = sys.argv
firstCall = False
if(len(termArguments) == 1):
termArguments.append("")
if(termArguments[1].startswith("--")):
termArguments[1] = termArguments[1][2:]
while(termArguments[1] != "quit"):
if(termArguments[1] in commands):
currentPath = os.path.abspath(os.path.dirname(__file__))
index = commands.index(termArguments[1])
print("\nLaunching game : " + out[index] + " \n")
fileName = currentPath + "/terminal" + out[index] + "/game.py"
with open(fileName, "rb") as source_file:
code = compile(source_file.read(), fileName, "exec")
exec(code)
elif(termArguments[1] == "help"):
print("\nUsage: ./termGame [argument]")
print("Optional arguments:\n")
print('%12s'%"2048" + "\t:\tLaunch 2048 game")
print('%12s'%"tetris" + "\t:\tLaunch tetris game")
print('%12s'%"OsXs" + "\t:\tLaunch Os & Xs game")
print('%12s'%"ships" + "\t:\tLaunch battleships game")
print('%12s'%"snake" + "\t:\tLaunch snake game")
print('%12s'%"greed" + "\t:\tLaunch greed game")
print('%12s'%"scores" + "\t:\tShow high scores for all games")
print('%12s'%"help" + "\t:\tList termGame commands")
print('%12s'%"quit" + "\t:\tExit termGame launcher\n")
elif(termArguments[1] == "scores"):
print("\nFetching Hi Score Table...\n")
scores = readHScores()
print("\n***********************************")
print("* HI SCORES *")
print("***********************************")
print("* " + scores[0][0] + " * " + scores[0][1] + " *")
print("***********************************")
print("*" + '%12s'%"" + "\t*\t" + '%11s'%"*")
for i in range(len(scores))[1:]:
line = "*" + '%12s'%scores[i][0] + "\t*\t" + scores[i][1]
for i in range(10-len(scores[i][1])):
line += " "
line += "*"
print(line)
print("*" + '%12s'%"" + "\t*\t" + '%11s'%"*")
print("***********************************\n")
elif(termArguments[1] == "version" or termArguments[1] == "v"):
print("termGame Version 0.8.0")
termArguments[1] = "quit"
elif(termArguments[1] != ""):
print("\nCommand not recognised\n")
if(termArguments[1] != "quit"):
print("\n\nPlease enter a command")
print("Use 'quit' to exit or 'help' for a list of games\n")
width = os.get_terminal_size().columns
print("─"* width)
termArguments[1] = prompt('~~~',
history=FileHistory(os.path.abspath(os.path.dirname(__file__)) + '/.termGame_history'),
auto_suggest=AutoSuggestFromHistory(),
#completer=CompleterList,
)
print("─"* width)