Implemented walker class and methods random_turn, next_pos, move_in_bounds
This commit is contained in:
		| @@ -1,9 +1,46 @@ | |||||||
|  | from enum import Enum | ||||||
| from random import choice, random, randint | from random import choice, random, randint | ||||||
| from dungeonbattle.interfaces import Map, Tile | from dungeonbattle.interfaces import Map, Tile | ||||||
|  |  | ||||||
|  class Generator: |  | ||||||
|  |  | ||||||
|     def __init__(self, params): |  | ||||||
|  |  | ||||||
|  | class Directions(Enum): | ||||||
|  |     up = auto() | ||||||
|  |     down = auto() | ||||||
|  |     left = auto() | ||||||
|  |     right = auto() | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Walker: | ||||||
|  |  | ||||||
|  |     def __init__(self, x, y): | ||||||
|  |         self.x = x | ||||||
|  |         self.y = y | ||||||
|  |         self.dir = choice(list(Directions)) | ||||||
|  |  | ||||||
|  |     def random_turn(self): | ||||||
|  |         self.dir = choice(list(Directions)) | ||||||
|  |  | ||||||
|  |     def next_pos(self): | ||||||
|  |         if self.dir == Directions.up: | ||||||
|  |             return self.x, self.y + 1 | ||||||
|  |         elif self.dir == Directions.down: | ||||||
|  |             return self.x, self.y - 1 | ||||||
|  |         elif self.dir == Directions.right: | ||||||
|  |             return self.x + 1, self.y | ||||||
|  |         elif self.dir == Directions.left: | ||||||
|  |             return self.x - 1, self.y | ||||||
|  |  | ||||||
|  |     def move_in_bounds(self, width, height): | ||||||
|  |         nx, ny = self.next_pos() | ||||||
|  |         if 0 < nx < width and 0 < ny < height: | ||||||
|  |             self.x, self.y = nx, ny | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Generator: | ||||||
|  |  | ||||||
|  |     def __init__(self, params = DEFAULT_PARAMS): | ||||||
|         self.params = params |         self.params = params | ||||||
|  |  | ||||||
|     def run(self): |     def run(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user