Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v1.1/clicker/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions v1.1/clicker/keypress_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions v1.1/clicker/main_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

52 changes: 52 additions & 0 deletions v1.1/launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import time, os, random
from mrmine.main_script import mrmine_start_game
from colorama import Fore as color
os.system('clear')
print("""
Enter the ID for the game you would like to play.
1. Mr. Mine [WIP]""")
game=input(" > ")
try:
game=int(game)
except Exception:
print("Invalid ID.")
exit()
if game==1:
print("Starting Mr. Mine...")
time.sleep(0.5)
print("Loading Game...")
time.sleep(random.uniform(0.5, 1.5))
os.system('clear')
i=0
d1=random.randint(-3, 3)
d2=random.randint(-3, 3)
d3=random.randint(-3, 3)
while i<100:
os.system('clear')
print("="*102)
print("|"+color.GREEN+("█"*i)+color.WHITE+("█"*(100-i))+"|")
print("|"+color.GREEN+("█"*i)+color.WHITE+("█"*(100-i))+"| ("+str(i)+"%)")
print("="*102)
if i<=15+d1:
print(color.WHITE+"Loading Launcher...")
elif i<=50+d2:
print(color.WHITE+"Initializing Game...")
elif i<=80+d3:
print(color.WHITE+"Loading GUI...")
elif i<100:
print("Loading Scripts...")
elif i==100:
break
i+=1
time.sleep(random.uniform(0.05, 0.2))
os.system('clear')
print("="*102)
print("|"+color.GREEN+("█"*100)+color.WHITE+"|")
print("|"+color.GREEN+("█"*100)+color.WHITE+"| (100%)")
print("="*102)
print(color.WHITE+"Loading Complete!")
time.sleep(1)
print(color.WHITE+"Welcome to Mr. Mine!")
time.sleep(0.5)
os.system('clear')
mrmine_start_game()
Binary file added v1.1/mrmine/__pycache__/gui.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
283 changes: 283 additions & 0 deletions v1.1/mrmine/gui.py

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions v1.1/mrmine/keypress_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys
import termios
import tty
import select
from contextlib import contextmanager

@contextmanager
def raw_mode(file):
old_attrs = termios.tcgetattr(file.fileno())
try:
tty.setraw(file.fileno())
yield
finally:
termios.tcsetattr(file.fileno(), termios.TCSADRAIN, old_attrs)

SPECIAL_KEYS = {
'\x1b[A': 'UP',
'\x1b[B': 'DOWN',
'\x1b[C': 'RIGHT',
'\x1b[D': 'LEFT'
}

def detect_keypress_nonblocking():
with raw_mode(sys.stdin):
rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
if rlist:
chars = []
char = sys.stdin.read(1)
if char == '\x1b': # Escape character
chars.append(char)
char = sys.stdin.read(1)
if char:
chars.append(char)
if char == '[':
char = sys.stdin.read(1)
if char:
chars.append(char)
result = ''.join(chars)
return SPECIAL_KEYS.get(result, result)
return None
183 changes: 183 additions & 0 deletions v1.1/mrmine/main_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
from threading import Thread
import threading
from mrmine.keypress_detector import detect_keypress_nonblocking
from mrmine.gui import update_GUI, scroll, update_GUI_func, GUI_send, get_save
import os, time, random, math
global save_data
# Make the relay of keys more accessible
key_pressed = None

def keypress_listener():
global key_pressed
while True:
key = detect_keypress_nonblocking()
if key:
key_pressed = key.lower()
if key_pressed == '\x03': # Ctrl+C for interrupt
raise KeyboardInterrupt

def tick():
global key_pressed
while True:
if key_pressed:
key = key_pressed
key_pressed = False
print(f"Key registered: {key}")
if key == 'up' or key == 'down':
scroll(key)
update_GUI()
elif key in ["k", "q", "c", "s", "h", "u", " ", "p", "r"]:
update_GUI_func(key)
else:
time.sleep(0.1)
update_GUI()

def drill_percent():
global save_data
while True:
drill_data=save_data['DRILL_DATA']
time_to_new_depth=drill_data[0]/save_data['LAYER_HARDNESS']
start_new_depth=time.time()
end_new_depth=start_new_depth+time_to_new_depth
while time.time()<=end_new_depth:
percent=round(((time.time()-start_new_depth)/time_to_new_depth)*100, 2)
GUI_send(percent, "percent_to_new_layer")
time.sleep(0.5)
save_data['DEPTH']+=1
save_data['LAYER_HARDNESS']=float((1.57**(1+(save_data['DEPTH']/50)))-0.57)
GUI_send('new_depth', 'signal')
def miner_monitor():
global save_data
while True:
i=1
resource_input={
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
12: 0,
13: 0,
14: 0,
15: 0
}
while i<=save_data['DEPTH']:
x100depth=math.ceil(i/100)
#1-100km: 0.2 coal / sec, 0.07 copper / sec, 0.003 iron / sec
#101-200km: 0.2 copper / sec, 0.07 iron / sec, 0.003 silver / sec
#etc.
if x100depth*100<=save_data['DEPTH']:
resource_input[x100depth]+=(0.2)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
resource_input[x100depth+1]+=(0.07)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
resource_input[x100depth+2]+=(0.003)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*100
else:
resource_input[x100depth]+=(0.2)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
resource_input[x100depth+1]+=(0.07)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
resource_input[x100depth+2]+=(0.003)*save_data['MINER_SPEED']*save_data['MINER_EFFICIENCY']*(save_data['DEPTH']-((x100depth-1)*100))
i+=100
for mineral in resource_input:
save_data['MINERALS'][mineral-1]+=resource_input[mineral]
save_data['MINERALS'][mineral-1]=int(round(save_data['MINERALS'][mineral-1], 0))
time.sleep(0.1)
drill_thread=threading.Thread(target=drill_percent)
miner_thread=threading.Thread(target=miner_monitor)
def read_save():
save_data = {
'SAVE_NUMBER': 1,
'END_TIME': 0,
'STORAGE': 0,
'UPGRADES': [],
'MINERALS': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
'FLUIDS': [0, 0, 0],
'SCIENTIST_DATA': [],
'CAVE_DATA': [],
'CHEST_DATA': [],
'MONEY': 0,
'TP_DATA': [],
'MANAGER': (0.00, 0),
'ATTACK': (0, 0),
'MINER_SPEED': 1,
'MINER_EFFICIENCY': 1,
'DEPTH': 10,
'DRILL_DATA': [],
'RIG_DATA': [],
'LAYER_HARDNESS': 1,
'FORGE_STATUS': 'none',
'BROADCAST': '',
'BROADCAST_TYPE': 'none',
'DATAID': 0,
'PLANET': 1
}
with open('/workspaces/coolmathgames/v1.0/mrmine/mrmine_save.txt', 'r') as file:
for line in file:
line = line.strip()
if '=' in line: # Ensuring there's a key-value split
key, value = line.split('=', 1) # Split on first '=' to handle complex values
try:
# Attempt to evaluate the value for correct data types
save_data[key] = eval(value)
except Exception:
print("Error reading save file key")
# If eval fails, it's likely a string or ambiguous format
save_data[key] = value
return save_data
def send_data_to_GUI():
while True:
get_save(save_data)
time.sleep(0.02)
send_thread=threading.Thread(target=send_data_to_GUI)
def write_save(save_data):
success=False
i=1
while i<=5 and not success:
try:
with open('/workspaces/coolmathgames/v1.0/mrmine/mrmine_save.txt', 'w') as file:
print("opened save file")
strv=''''''
for item in save_data:
print("writing item",item)
strv += item + '=' + str(save_data[item]) + '\n'
file.writelines(strv)
print("success")
success=True
break
except Exception:
print(f"Error while saving the game. (Attempt {i}/5)")
i+=1

def mrmine_start_game():
global save_data
os.system('clear')
try:
save_data=read_save()
save_data['DATAID']=str(random.randint(1, 1000000000))
write_save(save_data)
save_data=read_save()
except Exception:
print("Error while loading / writing save file.")
save_data=None
print("Exiting the game...")
exit()
if save_data['BROADCAST_TYPE'] == "message":
print("Message from devs: "+str(save_data['BROADCAST']))
time.sleep(1)
os.system('clear')
try:
listener_thread = Thread(target=keypress_listener)
listener_thread.daemon = True
listener_thread.start()
drill_thread.start()
miner_thread.start()
send_thread.start()
update_GUI()
while True:
tick()
except KeyboardInterrupt:
print("Game interrupted, exiting...")
exit()
24 changes: 24 additions & 0 deletions v1.1/mrmine/mrmine_save.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SAVE_NUMBER=1
END_TIME=0
STORAGE=0
UPGRADES=[]
MINERALS=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
FLUIDS=[0, 0, 0]
SCIENTIST_DATA=[]
CAVE_DATA=[]
CHEST_DATA=[]
MONEY=0
TP_DATA=[]
MANAGER=(0.0, 0)
ATTACK=(0, 0)
MINER_SPEED=1
MINER_EFFICIENCY=1
DEPTH=10
DRILL_DATA=[1, 1]
RIG_DATA=[]
LAYER_HARDNESS=1
FORGE_STATUS= none
BROADCAST=
BROADCAST_TYPE= none
DATAID=15573166
PLANET=1
24 changes: 24 additions & 0 deletions v1.1/mrmine/save_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SAVE_NUMBER=1
END_TIME=0
STORAGE=0
UPGRADES=[]
MINERALS=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
FLUIDS=[0, 0, 0]
SCIENTIST_DATA=[]
CAVE_DATA=[]
CHEST_DATA=[]
MONEY=0
TP_DATA=[]
MANAGER=0.00, 0
ATTACK=0, 0
MINER_SPEED=1
MINER_EFFICIENCY=1
DEPTH=10
DRILL_DATA=[]
RIG_DATA=[]
LAYER_HARDNESS=1
FORGE_STATUS=none
BROADCAST=none
BROADCAST_TYPE=none
DATAID=15B65C6F3
PLANET=1