Skip to content

Commit 9260ccc

Browse files
Merge pull request #6 from XtheGxmerz0/main
merge v1.1
2 parents 108d0b1 + 2a362a2 commit 9260ccc

File tree

12 files changed

+609
-0
lines changed

12 files changed

+609
-0
lines changed

v1.1/clicker/gui.py

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

v1.1/clicker/keypress_detector.py

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

v1.1/clicker/main_script.py

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

v1.1/launcher.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import time, os, random
2+
from mrmine.main_script import mrmine_start_game
3+
from colorama import Fore as color
4+
os.system('clear')
5+
print("""
6+
Enter the ID for the game you would like to play.
7+
1. Mr. Mine [WIP]""")
8+
game=input(" > ")
9+
try:
10+
game=int(game)
11+
except Exception:
12+
print("Invalid ID.")
13+
exit()
14+
if game==1:
15+
print("Starting Mr. Mine...")
16+
time.sleep(0.5)
17+
print("Loading Game...")
18+
time.sleep(random.uniform(0.5, 1.5))
19+
os.system('clear')
20+
i=0
21+
d1=random.randint(-3, 3)
22+
d2=random.randint(-3, 3)
23+
d3=random.randint(-3, 3)
24+
while i<100:
25+
os.system('clear')
26+
print("="*102)
27+
print("|"+color.GREEN+("█"*i)+color.WHITE+("█"*(100-i))+"|")
28+
print("|"+color.GREEN+("█"*i)+color.WHITE+("█"*(100-i))+"| ("+str(i)+"%)")
29+
print("="*102)
30+
if i<=15+d1:
31+
print(color.WHITE+"Loading Launcher...")
32+
elif i<=50+d2:
33+
print(color.WHITE+"Initializing Game...")
34+
elif i<=80+d3:
35+
print(color.WHITE+"Loading GUI...")
36+
elif i<100:
37+
print("Loading Scripts...")
38+
elif i==100:
39+
break
40+
i+=1
41+
time.sleep(random.uniform(0.05, 0.2))
42+
os.system('clear')
43+
print("="*102)
44+
print("|"+color.GREEN+("█"*100)+color.WHITE+"|")
45+
print("|"+color.GREEN+("█"*100)+color.WHITE+"| (100%)")
46+
print("="*102)
47+
print(color.WHITE+"Loading Complete!")
48+
time.sleep(1)
49+
print(color.WHITE+"Welcome to Mr. Mine!")
50+
time.sleep(0.5)
51+
os.system('clear')
52+
mrmine_start_game()
25.2 KB
Binary file not shown.
2.1 KB
Binary file not shown.
8.32 KB
Binary file not shown.

v1.1/mrmine/gui.py

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

v1.1/mrmine/keypress_detector.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sys
2+
import termios
3+
import tty
4+
import select
5+
from contextlib import contextmanager
6+
7+
@contextmanager
8+
def raw_mode(file):
9+
old_attrs = termios.tcgetattr(file.fileno())
10+
try:
11+
tty.setraw(file.fileno())
12+
yield
13+
finally:
14+
termios.tcsetattr(file.fileno(), termios.TCSADRAIN, old_attrs)
15+
16+
SPECIAL_KEYS = {
17+
'\x1b[A': 'UP',
18+
'\x1b[B': 'DOWN',
19+
'\x1b[C': 'RIGHT',
20+
'\x1b[D': 'LEFT'
21+
}
22+
23+
def detect_keypress_nonblocking():
24+
with raw_mode(sys.stdin):
25+
rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
26+
if rlist:
27+
chars = []
28+
char = sys.stdin.read(1)
29+
if char == '\x1b': # Escape character
30+
chars.append(char)
31+
char = sys.stdin.read(1)
32+
if char:
33+
chars.append(char)
34+
if char == '[':
35+
char = sys.stdin.read(1)
36+
if char:
37+
chars.append(char)
38+
result = ''.join(chars)
39+
return SPECIAL_KEYS.get(result, result)
40+
return None

v1.1/mrmine/main_script.py

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
key_pressed = None
9+
10+
def keypress_listener():
11+
global key_pressed
12+
while True:
13+
key = detect_keypress_nonblocking()
14+
if key:
15+
key_pressed = key.lower()
16+
if key_pressed == '\x03': # Ctrl+C for interrupt
17+
raise KeyboardInterrupt
18+
19+
def tick():
20+
global key_pressed
21+
while True:
22+
if key_pressed:
23+
key = key_pressed
24+
key_pressed = False
25+
print(f"Key registered: {key}")
26+
if key == 'up' or key == 'down':
27+
scroll(key)
28+
update_GUI()
29+
elif key in ["k", "q", "c", "s", "h", "u", " ", "p", "r"]:
30+
update_GUI_func(key)
31+
else:
32+
time.sleep(0.1)
33+
update_GUI()
34+
35+
def drill_percent():
36+
global save_data
37+
while True:
38+
drill_data=save_data['DRILL_DATA']
39+
time_to_new_depth=drill_data[0]/save_data['LAYER_HARDNESS']
40+
start_new_depth=time.time()
41+
end_new_depth=start_new_depth+time_to_new_depth
42+
while time.time()<=end_new_depth:
43+
percent=round(((time.time()-start_new_depth)/time_to_new_depth)*100, 2)
44+
GUI_send(percent, "percent_to_new_layer")
45+
time.sleep(0.5)
46+
save_data['DEPTH']+=1
47+
save_data['LAYER_HARDNESS']=float((1.57**(1+(save_data['DEPTH']/50)))-0.57)
48+
GUI_send('new_depth', 'signal')
49+
def miner_monitor():
50+
global save_data
51+
while True:
52+
i=1
53+
resource_input={
54+
1: 0,
55+
2: 0,
56+
3: 0,
57+
4: 0,
58+
5: 0,
59+
6: 0,
60+
7: 0,
61+
8: 0,
62+
9: 0,
63+
10: 0,
64+
11: 0,
65+
12: 0,
66+
13: 0,
67+
14: 0,
68+
15: 0
69+
}
70+
while i<=save_data['DEPTH']:
71+
x100depth=math.ceil(i/100)
72+
#1-100km: 0.2 coal / sec, 0.07 copper / sec, 0.003 iron / sec
73+
#101-200km: 0.2 copper / sec, 0.07 iron / sec, 0.003 silver / sec
74+
#etc.
75+
if x100depth*100<=save_data['DEPTH']:
76+
resource_input[x100depth]+=(0.2)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
77+
resource_input[x100depth+1]+=(0.07)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
78+
resource_input[x100depth+2]+=(0.003)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
79+
else:
80+
resource_input[x100depth]+=(0.2)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
81+
resource_input[x100depth+1]+=(0.07)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
82+
resource_input[x100depth+2]+=(0.003)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
83+
i+=100
84+
for mineral in resource_input:
85+
save_data['MINERALS'][mineral-1]+=resource_input[mineral]
86+
save_data['MINERALS'][mineral-1]=int(round(save_data['MINERALS'][mineral-1], 0))
87+
time.sleep(0.1)
88+
drill_thread=threading.Thread(target=drill_percent)
89+
miner_thread=threading.Thread(target=miner_monitor)
90+
def read_save():
91+
save_data = {
92+
'SAVE_NUMBER': 1,
93+
'END_TIME': 0,
94+
'STORAGE': 0,
95+
'UPGRADES': [],
96+
'MINERALS': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
97+
'FLUIDS': [0, 0, 0],
98+
'SCIENTIST_DATA': [],
99+
'CAVE_DATA': [],
100+
'CHEST_DATA': [],
101+
'MONEY': 0,
102+
'TP_DATA': [],
103+
'MANAGER': (0.00, 0),
104+
'ATTACK': (0, 0),
105+
'MINER_SPEED': 1,
106+
'MINER_EFFICIENCY': 1,
107+
'DEPTH': 10,
108+
'DRILL_DATA': [],
109+
'RIG_DATA': [],
110+
'LAYER_HARDNESS': 1,
111+
'FORGE_STATUS': 'none',
112+
'BROADCAST': '',
113+
'BROADCAST_TYPE': 'none',
114+
'DATAID': 0,
115+
'PLANET': 1
116+
}
117+
with open('/workspaces/coolmathgames/v1.0/mrmine/mrmine_save.txt', 'r') as file:
118+
for line in file:
119+
line = line.strip()
120+
if '=' in line: # Ensuring there's a key-value split
121+
key, value = line.split('=', 1) # Split on first '=' to handle complex values
122+
try:
123+
# Attempt to evaluate the value for correct data types
124+
save_data[key] = eval(value)
125+
except Exception:
126+
print("Error reading save file key")
127+
# If eval fails, it's likely a string or ambiguous format
128+
save_data[key] = value
129+
return save_data
130+
def send_data_to_GUI():
131+
while True:
132+
get_save(save_data)
133+
time.sleep(0.02)
134+
send_thread=threading.Thread(target=send_data_to_GUI)
135+
def write_save(save_data):
136+
success=False
137+
i=1
138+
while i<=5 and not success:
139+
try:
140+
with open('/workspaces/coolmathgames/v1.0/mrmine/mrmine_save.txt', 'w') as file:
141+
print("opened save file")
142+
strv=''''''
143+
for item in save_data:
144+
print("writing item",item)
145+
strv += item + '=' + str(save_data[item]) + '\n'
146+
file.writelines(strv)
147+
print("success")
148+
success=True
149+
break
150+
except Exception:
151+
print(f"Error while saving the game. (Attempt {i}/5)")
152+
i+=1
153+
154+
def mrmine_start_game():
155+
global save_data
156+
os.system('clear')
157+
try:
158+
save_data=read_save()
159+
save_data['DATAID']=str(random.randint(1, 1000000000))
160+
write_save(save_data)
161+
save_data=read_save()
162+
except Exception:
163+
print("Error while loading / writing save file.")
164+
save_data=None
165+
print("Exiting the game...")
166+
exit()
167+
if save_data['BROADCAST_TYPE'] == "message":
168+
print("Message from devs: "+str(save_data['BROADCAST']))
169+
time.sleep(1)
170+
os.system('clear')
171+
try:
172+
listener_thread = Thread(target=keypress_listener)
173+
listener_thread.daemon = True
174+
listener_thread.start()
175+
drill_thread.start()
176+
miner_thread.start()
177+
send_thread.start()
178+
update_GUI()
179+
while True:
180+
tick()
181+
except KeyboardInterrupt:
182+
print("Game interrupted, exiting...")
183+
exit()

0 commit comments

Comments
 (0)