File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,18 @@ def _handle_events(self) -> None:
8686 self .running = False
8787 self .agent = agents [self .agent_index ](self .grid )
8888
89+ def _draw_tiles (self ) -> None :
90+ mouse_pos = pygame .mouse .get_pos ()
91+ x , y = ((mouse_pos [0 ] // TILE_SIZE ), ((mouse_pos [1 ] - HEADER_SIZE ) // TILE_SIZE ))
92+
93+ if 0 <= y < TILES_HEIGHT and 0 <= x < TILES_WIDTH :
94+ if self .grid [y ][x ] == ' ' and self .mouse_down [0 ] == 1 :
95+ self .grid [y ][x ] = '#'
96+ if self .grid [y ][x ] == '#' and self .mouse_down [0 ] == 3 :
97+ self .grid [y ][x ] = ' '
98+
99+ self .renderer .update_walls (self .grid )
100+
89101 def run (self ) -> None :
90102 print ('Running application' )
91103
@@ -96,15 +108,7 @@ def run(self) -> None:
96108 self .agent .step ()
97109
98110 if self .mouse_down and not self .running :
99- mouse_pos = pygame .mouse .get_pos ()
100- x , y = ((mouse_pos [0 ] // TILE_SIZE ), ((mouse_pos [1 ] - HEADER_SIZE ) // TILE_SIZE ))
101-
102- if self .grid [y ][x ] == ' ' and self .mouse_down [0 ] == 1 :
103- self .grid [y ][x ] = '#'
104- if self .grid [y ][x ] == '#' and self .mouse_down [0 ] == 3 :
105- self .grid [y ][x ] = ' '
106-
107- self .renderer .update_walls (self .grid )
111+ self ._draw_tiles ()
108112
109113 self .renderer .render (self .agent )
110114
You can’t perform that action at this time.
0 commit comments