2021-03-11 00:47:14 +01:00
|
|
|
import pygame
|
2021-03-12 11:45:27 +01:00
|
|
|
import os
|
2021-04-14 23:45:34 +02:00
|
|
|
from enum import Enum
|
2021-03-11 00:47:14 +01:00
|
|
|
|
2021-05-11 20:30:01 +02:00
|
|
|
from ui.button import Button
|
|
|
|
from ui.input_box import InputBox
|
|
|
|
|
2021-03-11 00:47:14 +01:00
|
|
|
# VARIABLE STARTS WITH ... IF IT'S
|
|
|
|
# V a value like a string or an int
|
2021-03-12 20:48:16 +01:00
|
|
|
# STRUCT a list or other structure of values
|
2021-05-11 20:30:01 +02:00
|
|
|
# FUNC a function
|
|
|
|
# OBJ a classes instance
|
2021-05-23 05:50:49 +02:00
|
|
|
# ASSET a png file (or other graphic format) (moved to asset_constants)
|
2021-03-12 21:25:33 +01:00
|
|
|
# MAP a JSON map file
|
2021-03-11 00:47:14 +01:00
|
|
|
|
|
|
|
|
2021-03-11 18:51:43 +01:00
|
|
|
# ================= #
|
|
|
|
# === VARIABLES === #
|
|
|
|
# ================= #
|
|
|
|
|
2021-03-11 00:47:14 +01:00
|
|
|
V_NAME_OF_WINDOW = "MineFusion TM"
|
2021-03-16 06:41:40 +01:00
|
|
|
V_FPS = 60
|
2021-03-11 00:47:14 +01:00
|
|
|
|
2021-05-23 20:20:02 +02:00
|
|
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
DIR_ASSETS = os.path.join(ROOT_DIR, "resources", "assets")
|
2021-05-23 05:50:49 +02:00
|
|
|
|
2021-05-21 14:00:26 +02:00
|
|
|
TURN_INTERVAL = 0.3 # interval between two turns in seconds
|
2021-04-17 19:56:34 +02:00
|
|
|
|
2021-03-11 00:47:14 +01:00
|
|
|
V_TILE_SIZE = 60
|
2021-05-07 22:26:58 +02:00
|
|
|
V_GRID_VER_TILES = 10 # vertical (number of rows)
|
|
|
|
V_GRID_HOR_TILES = 10 # horizontal (number of columns)
|
2021-03-11 00:47:14 +01:00
|
|
|
V_SCREEN_PADDING = 10
|
2021-05-02 21:04:41 +02:00
|
|
|
V_NUMBER_PADDING = 50
|
|
|
|
V_TILE_AREA_HEIGHT = V_TILE_SIZE * V_GRID_VER_TILES
|
|
|
|
V_TILE_AREA_WIDTH = V_TILE_SIZE * V_GRID_HOR_TILES
|
2021-03-11 00:47:14 +01:00
|
|
|
|
2021-05-11 20:30:01 +02:00
|
|
|
# side menu values
|
|
|
|
V_SIDE_MENU_WIDTH = 80
|
|
|
|
V_INPUT_BOX_HEIGHT = 55
|
|
|
|
V_BUTTON_HEIGHT = 40
|
|
|
|
|
2021-06-06 15:51:08 +02:00
|
|
|
SCREEN_WIDTH = V_TILE_AREA_WIDTH + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING + V_SIDE_MENU_WIDTH + 10
|
|
|
|
SCREEN_HEIGHT = V_TILE_AREA_HEIGHT + 2 * V_SCREEN_PADDING + V_NUMBER_PADDING
|
|
|
|
SCREEN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
2021-03-11 00:47:14 +01:00
|
|
|
|
2021-04-14 23:45:34 +02:00
|
|
|
|
|
|
|
# =============== #
|
|
|
|
# ==== ENUMS ==== #
|
|
|
|
# =============== #
|
|
|
|
|
|
|
|
class Direction(Enum):
|
2021-04-17 16:45:20 +02:00
|
|
|
UP = 0
|
|
|
|
RIGHT = 1
|
|
|
|
DOWN = 2
|
|
|
|
LEFT = 3
|
2021-04-17 23:22:27 +02:00
|
|
|
|
2021-04-17 18:03:16 +02:00
|
|
|
def next(self):
|
2021-04-17 23:22:27 +02:00
|
|
|
v = (self.value + 1) % 4
|
2021-04-17 18:03:16 +02:00
|
|
|
return Direction(v)
|
2021-04-17 23:22:27 +02:00
|
|
|
|
2021-05-02 21:04:41 +02:00
|
|
|
def previous(self):
|
2021-04-17 18:03:16 +02:00
|
|
|
v = (self.value - 1) % 4
|
|
|
|
return Direction(v)
|
2021-04-14 23:45:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Action(Enum):
|
2021-04-17 16:45:20 +02:00
|
|
|
ROTATE_LEFT = 0
|
|
|
|
ROTATE_RIGHT = 1
|
|
|
|
GO = 2
|
2021-04-14 23:45:34 +02:00
|
|
|
|
|
|
|
|
2021-05-03 20:03:32 +02:00
|
|
|
class Digit(Enum):
|
|
|
|
ONES = 0
|
|
|
|
TENS = 1
|
|
|
|
|
|
|
|
|
|
|
|
class Coords(Enum):
|
|
|
|
X = 0
|
|
|
|
Y = 1
|
|
|
|
|
|
|
|
|
2021-05-07 19:02:09 +02:00
|
|
|
class Terrain(Enum):
|
2021-05-09 17:55:42 +02:00
|
|
|
CONCRETE = 2
|
2021-05-09 19:39:00 +02:00
|
|
|
GRASS = 5
|
|
|
|
MUD = 8
|
2021-05-20 15:01:09 +02:00
|
|
|
MINE = 500
|
2021-05-07 22:26:58 +02:00
|
|
|
|
2021-05-07 19:02:09 +02:00
|
|
|
|
2021-03-12 20:48:16 +01:00
|
|
|
# =============== #
|
|
|
|
# === STRUCTS === #
|
|
|
|
# =============== #
|
|
|
|
|
2021-03-27 18:22:04 +01:00
|
|
|
# # NORMAL STRUCTS
|
|
|
|
|
|
|
|
# # USED BY JSON GENERATOR
|
2021-03-27 18:30:46 +01:00
|
|
|
|
2021-03-27 18:22:04 +01:00
|
|
|
# used to generate random tile colors
|
2021-05-07 22:26:58 +02:00
|
|
|
STRUCT_TILE_TERRAINS = ["CONCRETE", "GRASS", "MUD"]
|
|
|
|
|
2021-03-27 18:22:04 +01:00
|
|
|
# used to generate random mines and create not random mines
|
|
|
|
STRUCT_MINE_TYPES = ["standard", "chained", "time"]
|
2021-03-27 18:30:46 +01:00
|
|
|
|
2021-03-27 18:22:04 +01:00
|
|
|
# values that are predefined for certain mine types and can't be changed by changing any parameters
|
|
|
|
# put here all dict keys that have hardcoded values and are not supposed to be editable
|
2021-04-17 23:22:27 +02:00
|
|
|
HARDCODED_VALUES = ["mine_type"]
|
2021-03-27 18:30:46 +01:00
|
|
|
|
2021-03-27 18:22:04 +01:00
|
|
|
# default values and key-value pairs for JsonGenerator class
|
|
|
|
# when defining a new mine it's dict template must be put here
|
|
|
|
STRUCT_MINE_ATTRIBUTES = {
|
|
|
|
"standard": {
|
|
|
|
"mine_type": "standard"
|
|
|
|
},
|
|
|
|
"chained": {
|
|
|
|
"mine_type": "chained",
|
|
|
|
"predecessor": None
|
|
|
|
},
|
|
|
|
"time": {
|
|
|
|
"mine_type": "time",
|
|
|
|
"timer": None
|
|
|
|
}
|
|
|
|
}
|
2021-03-27 18:30:46 +01:00
|
|
|
|
2021-03-27 18:22:04 +01:00
|
|
|
# types of attributes the mines have
|
|
|
|
# used for random mine generation
|
|
|
|
# int - integral number
|
|
|
|
STRUCT_MINE_ATTRIBUTE_TYPES = {
|
|
|
|
"standard": [],
|
2021-04-03 23:10:13 +02:00
|
|
|
"chained": [],
|
2021-03-27 18:22:04 +01:00
|
|
|
"time": [int]
|
|
|
|
}
|
2021-03-12 20:48:16 +01:00
|
|
|
|
2021-05-11 20:30:01 +02:00
|
|
|
|
|
|
|
# ============== #
|
|
|
|
# ==== FUNC ==== #
|
|
|
|
# ============== #
|
|
|
|
|
|
|
|
def get_tile_coordinates(position):
|
|
|
|
row, column = position
|
|
|
|
padding = V_SCREEN_PADDING + V_NUMBER_PADDING
|
|
|
|
|
|
|
|
return tuple((padding + column * V_TILE_SIZE, padding + row * V_TILE_SIZE))
|
|
|
|
|
|
|
|
|
|
|
|
# ============= #
|
|
|
|
# ==== OBJ ==== #
|
|
|
|
# ============= #
|
|
|
|
|
|
|
|
# initializing pygame modules so all instances can be constructed properly
|
|
|
|
pygame.init()
|
|
|
|
|
2021-05-23 06:14:12 +02:00
|
|
|
# creating old ui components used in menu
|
2021-05-11 20:30:01 +02:00
|
|
|
HIGHLIGHT = pygame.transform.scale(
|
|
|
|
pygame.image.load(os.path.join(DIR_ASSETS, "old_tiles/tile_white.png")),
|
|
|
|
(V_TILE_SIZE, V_TILE_SIZE)
|
|
|
|
)
|
|
|
|
HIGHLIGHT.set_alpha(100)
|
|
|
|
|
|
|
|
|
2021-03-12 21:25:33 +01:00
|
|
|
# ============== #
|
|
|
|
# ==== MAPS ==== #
|
|
|
|
# ============== #
|
2021-04-14 12:01:20 +02:00
|
|
|
|
2021-05-07 19:02:09 +02:00
|
|
|
MAP_RANDOM_10x10 = os.path.join("resources", "minefields", "fourthmap.json")
|
2021-03-12 21:25:33 +01:00
|
|
|
|
2021-05-03 20:03:32 +02:00
|
|
|
|