Skip to content

Commit 9c208c1

Browse files
v1.4-alpha upload
1 parent 41b2f96 commit 9c208c1

File tree

10 files changed

+925
-0
lines changed

10 files changed

+925
-0
lines changed

v1.4-alpha/clicker/gui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

v1.4-alpha/clicker/main_script.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def clicker_start_game():
3+
pass

v1.4-alpha/launcher.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import time, os, random
2+
from mrmine.main_script import mrmine_start_game, m_ms_initialize
3+
from mrmine.keypress_detector import m_kd_initialize
4+
from mrmine.gui import m_g_initialize
5+
from clicker.main_script import clicker_start_game
6+
from colorama import Fore as color
7+
os.system('clear')
8+
version='v1.4-alpha'
9+
print(f'''
10+
You are on version {version}.
11+
To see all versions go to:
12+
https://github.com/XtheGxmerz0/coolmathgames''')
13+
time.sleep(0.75)
14+
print('''
15+
Enter the ID for the game you would like to play.
16+
1. Mr. Mine | [v1.4-alpha, Work-In-Progress]
17+
2: Clicker Game | [v1.0, Work-In-Progress]''')
18+
game=input(" > ")
19+
try:
20+
game=int(game)
21+
except Exception:
22+
print("Invalid ID.")
23+
exit()
24+
if game==1:
25+
print("Starting Mr. Mine...")
26+
time.sleep(0.5)
27+
print("Loading Game...")
28+
time.sleep(random.uniform(0.5, 1.5))
29+
os.system('clear')
30+
#i=0
31+
#d1=random.randint(-3, 3)
32+
#d2=random.randint(-3, 3)
33+
#d3=random.randint(-3, 3)
34+
#while i<100:
35+
#os.system('clear')
36+
# print("="*102)
37+
# print("|"+color.GREEN+("█"*i)+color.RESET+("█"*(100-i))+"|")
38+
# print("|"+color.GREEN+("█"*i)+color.RESET+("█"*(100-i))+"| ("+str(i)+"%)")
39+
# print("="*102)
40+
# if i<=15+d1:
41+
# print(color.RESET+"Loading Launcher...")
42+
# elif i<=50+d2:
43+
# print(color.RESET+"Initializing Game...")
44+
# elif i<100:
45+
# print("Loading Scripts...")
46+
# elif i==100:
47+
# break
48+
# i+=1
49+
# time.sleep(random.uniform(0.05, 0.2))
50+
#os.system('clear')
51+
#print("="*102)
52+
#print("|"+color.GREEN+("█"*100)+color.RESET+"|")
53+
#print("|"+color.GREEN+("█"*100)+color.RESET+"| (100%)")
54+
#print("="*102)
55+
print(color.RESET+'Initializing main script...')
56+
m_ms_initialize()
57+
print(color.RESET+'Initializing GUI...')
58+
m_g_initialize()
59+
print(color.RESET+'Initializing keypress detector...')
60+
m_kd_initialize()
61+
print(color.RESET+"Loading Complete!")
62+
time.sleep(1)
63+
print(color.RESET+"Welcome to Mr. Mine!")
64+
time.sleep(0.5)
65+
os.system('clear')
66+
mrmine_start_game()

v1.4-alpha/mrmine/gui.py

Lines changed: 341 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
import termios
3+
import tty
4+
import select
5+
import time
6+
from contextlib import contextmanager
7+
log_loc= '/workspaces/coolmathgames/v1.4-alpha/mrmine/log.txt'
8+
def write_log(message):
9+
with open(log_loc, "a") as log_file:
10+
message1=('Timestamp '+ str(time.time())+': '+ str(message) + "\n")
11+
log_file.write(message1)
12+
def m_kd_initialize():
13+
write_log('From function \'initialize\': Initializing script...')
14+
@contextmanager
15+
def raw_mode(file):
16+
old_attrs = termios.tcgetattr(file.fileno())
17+
try:
18+
tty.setraw(file.fileno())
19+
yield
20+
finally:
21+
termios.tcsetattr(file.fileno(), termios.TCSADRAIN, old_attrs)
22+
23+
SPECIAL_KEYS = {
24+
'\x1b[A': 'UP',
25+
'\x1b[B': 'DOWN',
26+
'\x1b[C': 'RIGHT',
27+
'\x1b[D': 'LEFT'
28+
}
29+
30+
def detect_keypress_nonblocking():
31+
with raw_mode(sys.stdin):
32+
rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
33+
if rlist:
34+
chars = []
35+
char = sys.stdin.read(1)
36+
if char == '\x1b': # Escape character
37+
chars.append(char)
38+
char = sys.stdin.read(1)
39+
if char:
40+
chars.append(char)
41+
if char == '[':
42+
char = sys.stdin.read(1)
43+
if char:
44+
chars.append(char)
45+
result = ''.join(chars)
46+
return SPECIAL_KEYS.get(result, result)
47+
return None

v1.4-alpha/mrmine/log.txt

Lines changed: 172 additions & 0 deletions
Large diffs are not rendered by default.

v1.4-alpha/mrmine/main_script.py

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
from threading import Thread
2+
import threading
3+
from mrmine.keypress_detector import detect_keypress_nonblocking
4+
from mrmine.gui import update_GUI, scroll, update_GUI_func, GUI_send, get_save
5+
import os, time, random, math
6+
global save_data
7+
# Make the relay of keys more accessible
8+
version='v1.4-alpha'
9+
key_pressed = None
10+
save_loc='/workspaces/coolmathgames/v1.4-alpha/mrmine/mrmine_save.txt'
11+
log_loc= '/workspaces/coolmathgames/v1.4-alpha/mrmine/log.txt'
12+
def write_log(message):
13+
with open(log_loc, "a") as log_file:
14+
message1=('Timestamp '+ str(time.time())+': '+ str(message) + "\n")
15+
log_file.write(message1)
16+
def m_ms_initialize():
17+
write_log('From function \'initialize\': Initializing script...')
18+
def keypress_listener():
19+
global key_pressed
20+
while True:
21+
key = detect_keypress_nonblocking()
22+
if key:
23+
key_pressed = key.lower()
24+
if key_pressed == '\x03': # Ctrl+C for interrupt
25+
raise KeyboardInterrupt
26+
def tick():
27+
global key_pressed
28+
while True:
29+
if key_pressed:
30+
key = key_pressed
31+
key_pressed = False
32+
print(f"Key registered: {key}")
33+
if key == 'up' or key == 'down':
34+
scroll(key)
35+
update_GUI()
36+
elif key in ["k", "q", "c", "s", "h", "u", " ", "p", "r", "e"]:
37+
update_GUI_func(key)
38+
else:
39+
time.sleep(0.1)
40+
update_GUI()
41+
def drill_percent():
42+
global save_data
43+
while True:
44+
drill_data=save_data['DRILL_DATA']
45+
time_to_new_depth=save_data['LAYER_HARDNESS']/drill_data[0]
46+
start_new_depth=time.time()
47+
end_new_depth=start_new_depth+time_to_new_depth
48+
while time.time()<=end_new_depth:
49+
percent=round(((time.time()-start_new_depth)/time_to_new_depth)*100, 2)
50+
GUI_send(percent, "percent_to_new_layer")
51+
time.sleep(0.1)
52+
save_data['DEPTH']+=1
53+
save_data['LAYER_HARDNESS']=float((1.57**(1+(save_data['DEPTH']/50)))+23.43)
54+
write_log(f'From function \'drill_percent\': new layer; new hardness is {save_data['LAYER_HARDNESS']}.')
55+
def miner_monitor():
56+
global save_data
57+
while True:
58+
i=1
59+
resource_input={
60+
1: 0,
61+
2: 0,
62+
3: 0,
63+
4: 0,
64+
5: 0,
65+
6: 0,
66+
7: 0,
67+
8: 0,
68+
9: 0,
69+
10: 0,
70+
11: 0,
71+
12: 0,
72+
13: 0,
73+
14: 0,
74+
15: 0
75+
}
76+
while i<=save_data['DEPTH']:
77+
x100depth=math.ceil(i/100)
78+
#1-100km: 0.2 coal / sec, 0.07 copper / sec, 0.003 iron / sec (starting values)
79+
#101-200km: 0.2 copper / sec, 0.07 iron / sec, 0.003 silver / sec (starting values)
80+
#etc.
81+
#richness for resource 1 decreases (0.2 --> 0.003)
82+
#richness for resource 2 increases slightly (0.07 --> 0.125)
83+
#richness for resource 3 increases (0.003 --> 0.2)
84+
if x100depth*100<=save_data['DEPTH']:
85+
resource_input[x100depth]+=(0.2-(0.00197*i))*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
86+
resource_input[x100depth+1]+=(0.07+(0.00055*i))*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
87+
resource_input[x100depth+2]+=(0.003+(0.00197*i))*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
88+
else:
89+
resource_input[x100depth]+=(0.2-(0.00197*i))*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
90+
resource_input[x100depth+1]+=(0.07+(0.00055*i))*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
91+
resource_input[x100depth+2]+=(0.003+(0.00197*i))*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
92+
i+=100
93+
for mineral in resource_input:
94+
save_data['MINERALS'][mineral-1]+=resource_input[mineral]
95+
save_data['MINERALS'][mineral-1]=int(round(save_data['MINERALS'][mineral-1], 0))
96+
time.sleep(0.1)
97+
drill_thread=threading.Thread(target=drill_percent)
98+
miner_thread=threading.Thread(target=miner_monitor)
99+
def read_save():
100+
save_data = {
101+
'SAVE_NUMBER': 1,
102+
'END_TIME': 0,
103+
'STORAGE': 0,
104+
'UPGRADES': [],
105+
'MINERALS': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
106+
'FLUIDS': [0, 0, 0],
107+
'SCIENTIST_DATA': [],
108+
'CAVE_DATA': [],
109+
'CHEST_DATA': [],
110+
'MONEY': 0,
111+
'TP_DATA': [],
112+
'MANAGER': (0.00, 0),
113+
'ATTACK': (0, 0),
114+
'MINER_SPEED': 1,
115+
'MINER_EFFICIENCY': 1,
116+
'DEPTH': 4,
117+
'DRILL_DATA': [1, 1],
118+
'RIG_DATA': [],
119+
'LAYER_HARDNESS': 1,
120+
'FORGE_STATUS': 'none',
121+
'BROADCAST': '',
122+
'BROADCAST_TYPE': 'none',
123+
'DATAID': 0,
124+
'PLANET': 1
125+
}
126+
with open(save_loc, 'r') as file:
127+
for line in file:
128+
line = line.strip()
129+
if '=' in line: # Ensuring there's a key-value split
130+
key, value = line.split('=', 1) # Split on first '=' to handle complex values
131+
write_log(f'From function \'read_save\': grabbed set {key, value} from save')
132+
try:
133+
# Attempt to evaluate the value for correct data types
134+
save_data[key] = eval(value)
135+
write_log(f'From function \'read_save\': writing save data key {key} to data dictionary')
136+
except Exception as e:
137+
# If eval fails, it's likely a string or ambiguous format
138+
write_log(f'From function \'read_save\': eval failed; writing directly to data dictionary')
139+
write_log(e)
140+
save_data[key] = value
141+
return save_data
142+
def send_data_to_GUI():
143+
while True:
144+
get_save(save_data)
145+
time.sleep(0.02)
146+
send_thread=threading.Thread(target=send_data_to_GUI)
147+
def write_save(save_data):
148+
success=False
149+
i=1
150+
while i<=5 and not success:
151+
write_log(f'From function \'write_save\': attempting to write to save file (attempt {i})')
152+
try:
153+
with open(save_loc, 'w') as file:
154+
write_log('From function \'write_save\': opened save file')
155+
strv=''''''
156+
for item in save_data:
157+
write_log('From function \'write_save\': writing item '+str(item))
158+
strv += item + '=' + str(save_data[item]) + '\n'
159+
file.writelines(strv)
160+
write_log('From function \'write_save\': success')
161+
success=True
162+
break
163+
except Exception as e:
164+
write_log('From function \'write_save\': failed to write to save file')
165+
write_log(e)
166+
i+=1
167+
if i>5:
168+
write_log('From function \'write_save\': aborting write to save file')
169+
def clear_log():
170+
with open(log_loc, "w"):
171+
write_log('From function \'clear_log\': clearing log file')
172+
def mrmine_start_game():
173+
clear_log()
174+
global save_data
175+
os.system('clear')
176+
try:
177+
save_data=read_save()
178+
save_data['DATAID']=str(random.randint(1, 1000000000))
179+
write_save(save_data)
180+
except Exception as e:
181+
write_log(e)
182+
print("Error while loading / writing save file.")
183+
#save_data=None
184+
#print("Exiting the game...")
185+
#exit()
186+
print("Using template data...")
187+
save_data = {
188+
'SAVE_NUMBER': 1,
189+
'END_TIME': 0,
190+
'STORAGE': 0,
191+
'UPGRADES': [],
192+
'MINERALS': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
193+
'FLUIDS': [0, 0, 0],
194+
'SCIENTIST_DATA': [],
195+
'CAVE_DATA': [],
196+
'CHEST_DATA': [],
197+
'MONEY': 0,
198+
'TP_DATA': [],
199+
'MANAGER': (0.00, 0),
200+
'ATTACK': (0, 0),
201+
'MINER_SPEED': 1,
202+
'MINER_EFFICIENCY': 1,
203+
'DEPTH': 4,
204+
'DRILL_DATA': [1, 1],
205+
'RIG_DATA': [],
206+
'LAYER_HARDNESS': 1,
207+
'FORGE_STATUS': 'none',
208+
'BROADCAST': '',
209+
'BROADCAST_TYPE': 'none',
210+
'DATAID': 0,
211+
'PLANET': 1
212+
}
213+
write_log('From function \'mrmine_start_game\': Verifying save file integrity...')
214+
if save_data['VERSION']!=version:
215+
print('Your save file is on the wrong version. Compatibility issues may arise. Please download the newest version of the game or find a compatible save file.')
216+
write_log('From function \'mrmine_start_game\': Invalid save file version.')
217+
cont=input('Would you like the game to continue running? [You may corrupt your save or cause fatal errors.] > ')
218+
yes=['yes', 'y']
219+
if cont.lower() in yes:
220+
print('Continuing with game...')
221+
write_log('From function \'mrmine_start_game\': Continuing game from use input.')
222+
time.sleep(0.5)
223+
else:
224+
print('Exiting game...')
225+
write_log('From function \'mrmine_start_game\': Exiting game from use input.')
226+
else:
227+
write_log('From function \'mrmine_save_game\': Save file integrity verified.')
228+
if save_data['BROADCAST_TYPE'] == "message":
229+
print("Message from devs: "+str(save_data['BROADCAST']))
230+
time.sleep(1)
231+
os.system('clear')
232+
try:
233+
listener_thread = Thread(target=keypress_listener)
234+
listener_thread.daemon = True
235+
listener_thread.start()
236+
drill_thread.start()
237+
miner_thread.start()
238+
send_thread.start()
239+
update_GUI()
240+
while True:
241+
tick()
242+
except KeyboardInterrupt:
243+
print("Game interrupted, exiting...")
244+
exit()

v1.4-alpha/mrmine/mrmine_save.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SAVE_NUMBER=1
2+
END_TIME=0
3+
STORAGE=0
4+
UPGRADES=[]
5+
MINERALS=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
6+
FLUIDS=[0, 0, 0]
7+
SCIENTIST_DATA=[]
8+
CAVE_DATA=[]
9+
CHEST_DATA=[]
10+
MONEY=0
11+
TP_DATA=[]
12+
MANAGER=(0.0, 0)
13+
ATTACK=(0, 0)
14+
MINER_SPEED=1
15+
MINER_EFFICIENCY=1
16+
DEPTH=4
17+
DRILL_DATA=[1, 1]
18+
RIG_DATA=[]
19+
LAYER_HARDNESS=1
20+
FORGE_STATUS=[]
21+
BROADCAST='nothing'
22+
BROADCAST_TYPE='nothing'
23+
DATAID=950380454
24+
PLANET=1
25+
VERSION='v1.3-alpha'

0 commit comments

Comments
 (0)