-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameClient.py
More file actions
115 lines (93 loc) · 3.64 KB
/
GameClient.py
File metadata and controls
115 lines (93 loc) · 3.64 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
__author__ = 'dark-wizard'
import sys
import game_display # noqa: F401 — must load before pygame so SDL scale hint applies
import pygame
from GameMechanics import GameCoreManager
from GameMechanics import *
from GameMechanics.GameInfo import GameInfo as GI
import GameUI
lore = """
With the death of the King comes
the infighting among his sons.
He failed to specify an heir and now
you must defeat your brother and
claim the kingdom. Take over all
of your brother's territory and
force his surrender or just kill
him and be done with it!
"""
class GameClient():
screen = None
unitGrid = None
worldGrid = None
background = None
game_core = None
test_AI = None
clock = pygame.time.Clock()
def __init__(self, size, conf, fullscreen=False, ai_difficulty="easy"):
pygame.init()
self.screen = game_display.set_mode(fullscreen=fullscreen)
self.loadSprites(size, conf, ai_difficulty)
self.run_forever()
def loadSprites(self, size, conf, ai_difficulty="easy"):
self.unitGrid = GameUI.UnitGridRenderer.UnitGridRenderer([])
self.worldGrid = GameUI.WorldRenderer.WorldRenderer(size)
#add call for generating "new game" objects
self.background = pygame.image.load("images/bg.jpg").convert()
self.game_core = GameCoreManager.GameCoreManager(2, (size, size + 6))
start = 1
if conf == "PvP":
start = -1
self.test_AI = AI.AIManager(start, ai_difficulty if conf == "PvAI" else "easy")
self.create_links_to_static()
GI.game_core.new_game()
GI.game_core.create_backup()
GI.worldGrid.draw_active_data(GI.all_active_data)
GI.window_manager.show(lore, header = "The King is dead!\n")
#GI.selected_unit = GI.worldGrid.get_block(4, 0)
def redraw(self):
try:
self.screen.blit(self.background, (0, 0))
if GI.window_manager.tl_active and not GI.ai.working or (GI.ai.working and GI.ai.need_to_redraw):
self.game_core.move_obj()
if GI.ai.need_to_switch:
GI.ai.load_next_unit()
self.worldGrid.redraw()
# self.worldGrid.draw_active_data(GI.all_active_data)
self.worldGrid.update_position()
# self.screen.blit(self.worldGrid.image, self.worldGrid.world_position)
self.screen.blit(self.unitGrid.image, self.unitGrid.cornerPosition)
GI.window_manager.redraw()
self.screen.blit(GI.window_manager.image, (0, 0))
finally:
# Must present every frame: early return above used to skip flip() and left a black buffer.
pygame.display.update()
pygame.display.flip()
def create_links_to_static(self):
GI.worldGrid = self.worldGrid
GI.game_core = self.game_core
GI.unitGrid = self.unitGrid
GI.ai = self.test_AI
#print GI.ai
windows = ButtonWindowManager.ButtonWindowManager()
GI.window_manager = windows
GI.set_defaults()
def processEvents(self, event):
res = GI.window_manager.process_event(event)
if res:
self.worldGrid.process_event(event)
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_q:
pygame.quit()
sys.exit()
def run_forever(self):
while 1:
GI.time_passed = self.clock.tick(20000)
#print GI.time_passed
for event in pygame.event.get():
self.processEvents(event)
self.redraw()
if __name__ == "__main__":
gl = GameClient()