-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (70 loc) · 3.17 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
# +–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––+
# | SnakeAI |
# | Snake game with artificial neural network and genetic algorithm |
# +–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––+
# | |
# | creator: Konrad Weiß email: [email protected] |
# | start of dev: 4.8.2020 url: logilutions.de/snakeAI |
# | version: see about.md github: github.com/konrad2002/snakeAI |
# | |
# | (C) 2020 - Konrad Weiß and logilutions.de |
# | |
# +–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––+
# import local classes
from settings import Settings
from gui.app.menu import MenuApp
from gui.app.game import GameApp
# import used kivy parts
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle,Canvas,Ellipse,Color,Line
from kivy.vector import Vector
from kivy.clock import Clock
from kivy.core.window import Window
# random, numpy, time, sys, json, socket and sqlite3
from random import randrange
import numpy as np
import time
import sys
import json
import socket
class MainController (object):
def __init__ (self):
self.settings = Settings()
def run (self):
if self.settings.configurated:
#sth
print("configuration set")
self.showGame()
else:
self.showMenu()
def showMenu (self):
self.menuApp = MenuApp()
self.menuApp.setMainController(self)
self.menuApp.run()
def showGame(self):
self.gameApp = GameApp()
self.gameApp.setMainController(self)
self.gameApp.run()
# if conf is done write data into settings
def setConfiguration(self):
print("[menu] set configuration")
self.settings.playerMode = self.menuApp.playerMode
self.settings.playerTypes = self.menuApp.playerTypes
self.settings.configurated = True
self.menuApp.stop()
self.run()
def stopGame(self):
self.gameApp.stop()
self.run()
def stop(self):
if self.settings.gameStarted:
self.gameApp.stop()
else:
self.menuApp.stop()
main = MainController()
main.run()