-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
92 lines (76 loc) · 2.07 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
##########
# CONFIG #
##########
# console
REFRESH_SPEED = 2
CLEAR_EACH_FRAME = True
CLEAR_WINDOWS = True # 'True' for Windows, 'False' for Unix-based consoles
BUFFERED_PRINT = False
# tkinter GUI
USE_GUI_TKINTER = False
# PyGame GUI
USE_GUI_PYGAME = True
# All GUIs
GUI_WIDTH = 1200
GUI_HEIGHT = 800
GUI_OFFSET_WINDOW_POSITION = -1500 # pixels, can be +-
GUI_CELL_SIZE = 10
GUI_UPDATE_INTERVAL = 1 # ms
# Grid param
GRID_WIDTH = 120
GRID_HEIGHT = 80
# Shark
ENTITY_SHARK_COUNT = 50
ENTITY_SHARK_ENERGY_GAIN = 5
ENTITY_SHARK_BASE_ENERGY = 10
ENTITY_SHARK_BIRTH_INTERVAL = 15
ENTITY_SHARK_MAX_ENERGY = 20
# Fish
ENTITY_FISH_COUNT = 70
ENTITY_FISH_BIRTH_INTERVAL = 4
ENTITY_FISH_DEATH_AGE = 40
###########
# IMPORTS #
###########
import random
import os
import time
from tkinter import Canvas, Label, StringVar, Tk
import pygame
from src.gui_pygame import GuiPygame
from src.gui_tkinter import GuiTkinter
from src.gamegrid import GameGrid as GameGrid
from src.shark import Shark
from src.fish import Fish
#######
# RUN #
#######
grid = GameGrid(GRID_WIDTH, GRID_HEIGHT)
grid.random_fill_sharks(ENTITY_SHARK_COUNT, ENTITY_SHARK_ENERGY_GAIN, ENTITY_SHARK_BASE_ENERGY, ENTITY_SHARK_BIRTH_INTERVAL, ENTITY_SHARK_MAX_ENERGY)
grid.random_fill_fishs(ENTITY_FISH_COUNT, ENTITY_FISH_BIRTH_INTERVAL, ENTITY_FISH_DEATH_AGE)
def loop():
grid.update()
gui.canvas.delete("all")
grid.draw_tkinter(gui)
gui.window.after(GUI_UPDATE_INTERVAL, loop)
if USE_GUI_TKINTER:
gui = GuiTkinter(GUI_WIDTH, GUI_HEIGHT, GUI_CELL_SIZE, GUI_OFFSET_WINDOW_POSITION)
loop()
gui.window.mainloop()
elif USE_GUI_PYGAME:
gui = GuiPygame(GUI_WIDTH, GUI_HEIGHT, GUI_CELL_SIZE)
clock = pygame.time.Clock()
while True:
grid.update()
grid.draw_pygame(gui)
pygame.event.wait()
pygame.time.delay(1000)
# clock.tick(60)
else:
while True:
if CLEAR_EACH_FRAME: os.system("cls")
print("turn = ", grid.turn)
grid.update()
if BUFFERED_PRINT: grid.draw_console_buffered()
else: grid.draw_console()
time.sleep(REFRESH_SPEED)