forked from ufosc/TERMINALMONOPOLY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.py
139 lines (113 loc) · 4.68 KB
/
modules.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import screenspace as ss
import style as s
class PlayerModules():
# Color literals for printing board
COLORS = {"BROWN": "\033[38;5;94m",
"LIGHTBLUE": "\033[38;5;117m",
"ROUGE": "\033[38;5;162m",
"ORANGE": "\033[38;5;202m",
"RED": "\033[38;5;9m",
"YELLOW": "\033[38;5;226m",
"GREEN": "\033[38;5;2m",
"BLUE": "\033[38;5;12m",
"WHITE": "\033[38;5;15m",
"CYAN": "\033[38;5;14m",
"LIGHTGRAY": "\033[38;5;7m"}
def calculator() -> str:
"""A simple calculator module that can perform basic arithmetic operations."""
#Uses recursion to calculate.
def calculate(equation: str) -> float:
for i in range(0, len(equation)-1):
if(equation[i] == '+'):
eqLeft = equation[:i]
eqRight = equation[(i+1):]
return calculate(eqLeft) + calculate(eqRight)
for i in range(0, len(equation)-1):
if(equation[i] == '-'):
#Checks for unary operator '-'
if(i == 0):
eqLeft = "0"
else:
eqLeft = equation[:i]
eqRight = equation[(i+1):]
return calculate(eqLeft) - calculate(eqRight)
for i in range(0, len(equation)-1):
if(equation[i] == '*'):
eqLeft = equation[:i]
eqRight = equation[(i+1):]
return calculate(eqLeft) * calculate(eqRight)
for i in range(0, len(equation)-1):
if(equation[i] == '/'):
eqLeft = equation[:i]
eqRight = equation[(i+1):]
return calculate(eqLeft)/calculate(eqRight)
for i in range(0, len(equation)-1):
if(equation[i] == '%'):
eqLeft = equation[:i]
eqRight = equation[(i+1):]
return calculate(eqLeft)%calculate(eqRight)
for i in range(0, len(equation)-1):
if(equation[i] == '^'):
eqLeft = equation[:i]
eqRight = equation[(i+1):]
return calculate(eqLeft) ** calculate(eqRight)
return float(equation)
response = '\nCALCULATOR TERMINAL\n'
digit_result = 0
print("\r", end='')
equation = input(s.COLORS.GREEN)
if(equation == "e"):
return equation
#Trims unnecessary spaces and pads operators with spaces
equation = equation.replace(" ", "")
for op in ['+', '-', '*', '/', '%', '^']:
equation = equation.replace(op, " " + op + " ")
#Removes spaces from negative number
if(len(equation) > 1 and equation[1] == '-'):
equation = "-" + equation[3:]
try:
digit_result = calculate(equation)
except:
return "error"
responseEQ = f'{equation} = {digit_result}'
#There are 75 columns for each terminal, making any string longer than 75 characters overflow.
numOverflowingChar = len(responseEQ) - 75
lineNumber = 0
wrappedResponse = ""
while(numOverflowingChar > 0):
wrappedResponse += responseEQ[(75*lineNumber):(75*(lineNumber + 1))] + '\n'
lineNumber = lineNumber + 1
numOverflowingChar = numOverflowingChar - 75
wrappedResponse += responseEQ[(75*lineNumber):(75*(lineNumber + 1)) + numOverflowingChar] + '\n'
#response += wrappedResponse
print(s.COLORS.RESET, end='')
return wrappedResponse
def trade():
pass
def mortgage():
pass
def roll():
pass
def gamble():
pass
def attack():
pass
def stocks():
pass
def kill() -> str:
return s.get_graphics()['skull']
def disable() -> str:
result = ('X ' * round(ss.cols/2+0.5) + '\n' +
(' X' * round(ss.cols/2+0.5)) + '\n'
) * (ss.rows//2)
return result
def make_board(board_pieces) -> list[str]:
board = [''] * 35
# Hard coded for board printing specifically
for i in range(35):
for j in range(80):
if board_pieces[i*80+j] != '\n':
board[i] += (board_pieces[i*80+j])
return board
class BankerModules():
pass