-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
197 lines (156 loc) · 5.84 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import random
import time
from tkinter import *
from tkinter import ttk
import Program as prg
#not used at the moment
#generates a random string of 0's and 1's from length 200 to 1000
#used for flavor but doesn't seem to work as well on textboxes
def randBinary():
binLength = random.randint(200, 1000)
for x in range(binLength):
string = '01'
print(random.choice(string), end = "")
x+=1
print('')
def ICEcheck():
one = random.randint(1, 6)
two = random.randint(1, 6)
three = random.randint(1, 6)
if one+two+three >= 15:
return True
else:
return False
#file IO stuff
file = "starterDeck.txt"
f = open(file, "r")
#sets the file input to a string
initial = str(f.read())
#splits the string into individual skills with skill levels and initializes stuff for later
programs = initial.split(':')
deck = {}
progList = []
#creates a dictionary with the skill name as keys and the skill levels as values
for x in range(len(programs)):
program = programs[x].split()[0]
progList.append(program)
skill = int(programs[x].split()[1])
deck[program] = skill
#sets up gui window
root = Tk()
root["bg"] = "black"
root.title("GURPS Hacker")
root.minsize(800, 500)
#grabs image to be used for background. Image size needs changing
bgImage = PhotoImage(file = "background.png")
w = bgImage.width()
h = bgImage.height()
root.geometry("%dx%d+50+30" % (w, h))
cv = Canvas(width = w, height = h)
cv.create_image(0, 0, image = bgImage, anchor = 'nw')
#adds the top and bottom frame to the root window
topFrame = Frame(cv)
topFrame['bg'] = ''
bottomFrame = Frame(cv)
bottomFrame['bg'] = ''
sideFrame = Frame(cv)
sideFrame['bg'] = ''
#radio buttons
v = IntVar()
systemButt = Radiobutton(sideFrame, text = "System", bg = 'black', fg = 'red', variable = v, value = 0)
irlButt = Radiobutton(sideFrame, text = "IRL", bg = 'black', fg = 'red', variable = v, value = 1)
#sets the combobox values to the list of programs read in from the file
comboBox1 = ttk.Combobox(topFrame, values = progList)
#somethings wierd here
#it sets the colors but not for the whole combobox
style = ttk.Style()
style.map('TCombobox', fieldbackground=[('readonly','black')])
style.map('TCombobox', selectbackground=[('readonly', 'black')])
style.map('TCombobox', selectforeground=[('readonly', 'red')])
comboBox1['state'] = 'readonly'
#checks what program is being executed and runs the method associated with it
#VERY INCOMPLETE. Only breach program is implemented
def execute(event = None):
textBox.delete('1.0', END)
ice = ICEcheck()
if ice:
textBox.insert(END, "You've been detected. \nTry to break the ice: breach \nBack out: exit")
if inpBox.get() == "breach":
breach()
elif inpBox.get == "back":
textBox.delete('1.0', END)
inpBox.delete('1.0', END)
else:
textBox.delete('1.0', END)
textBox.insert(END, "You probably don't have time to be sitting around cowboy...")
else:
if comboBox1.get() == "breach":
breach()
elif comboBox1.get() == "alter":
alter()
elif comboBox1.get() == "":
textBox.insert(END, "You actually going to do something?")
else:
textBox.insert(END, "You can't do that yet.")
#creates the execure button and textbox where all the relevent info will be displayed
executeButt = Button(topFrame, text = "Execute Program", bg = "black", fg = "red", command = execute)
textBox = Text(bottomFrame, height = 10, bg = "black", fg = "red")
#input box
inpBox = Text(bottomFrame, height = 1, bg = 'black', fg = '#03f6fe')
inpBox.pack(side = BOTTOM)
executeButt.bind('<Return>', execute)
textBox.insert(END, "Enter your ID below...")
def login():
if inpBox.get('1.0', END) == 'password\n':
clrButton.configure(text = "Clear Text", command = clear)
textBox.delete("1.0", END)
inpBox.delete("1.0", END)
textBox.insert(END, "Welcome user\nChoose an option above to begin...")
else:
textBox.delete("1.0", END)
textBox.insert(END, "Wrong ID chummer")
inpBox.delete("1.0", END)
#simple method to clear the textbox
def clear():
textBox.delete("1.0", END)
inpBox.delete("1.0", END)
clrButton = Button(bottomFrame, text = "LOGIN", bg = "black", fg = "red", command = login)
#runs a skill check against the users breach program skill
#not much functionality and doesn't account for other system complications
def breach():
breach = prg.Breach(deck["breach"])
breach.setSkillLvl(deck["breach"])
stmt, chk = breach.skillCheck()
textBox.insert(END, stmt)
if chk:
textBox.insert(END, "You're in.")
else:
textBox.insert(END, "No dice.")
def alter():
subject = inpBox.get('1.0', END)
if subject == '\n':
textBox.insert(END, "What are you altering?")
else:
subject = subject[:-1]
alter = prg.Alter(deck["alter"])
stmt, chk = alter.skillCheck()
textBox.insert(END, stmt)
if chk:
textBox.insert(END, subject + " successfully changed, backing out.")
else:
textBox.insert(END, "No dice.")
#inserts all relevent objects into the gui and sets the main loop to display window
cv.pack(side = 'bottom', fill = 'both', expand = 'yes')
topFrame.pack(padx = 20)
sideFrame.pack(padx = 20, pady = 20)
clrButton.pack()
bottomFrame.pack(padx = 20, pady = 200)
executeButt.pack(padx = 20, pady = 20)
systemButt.pack(side = LEFT)
irlButt.pack(side = LEFT)
comboBox1.pack()
textBox.pack()
root.mainloop()
if v == 1:
inpBox.insert(END, "What was the roll?: ")
chk = inpBox.get(1.0, END).split()[-1]