Manage multiple maps in one game

This commit is contained in:
Yohann D'ANELLO 2020-12-26 00:45:17 +01:00
parent 330d78702a
commit ad5ae22e5f
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 23 additions and 2 deletions

View File

@ -3,7 +3,7 @@
from json import JSONDecodeError
from random import randint
from typing import Any, Optional
from typing import Any, Optional, List
import curses
import json
import os
@ -22,7 +22,8 @@ class Game:
"""
The game object controls all actions in the game.
"""
map: Map
maps: List[Map]
map_index: int
player: Player
screen: Any
# display_actions is a display interface set by the bootstrapper
@ -52,6 +53,8 @@ class Game:
Create a new game on the screen.
"""
# TODO generate a new map procedurally
self.maps = []
self.map_index = 0
self.map = Map.load(ResourceManager.get_asset_path("example_map_2.txt"))
self.map.logs = self.logs
self.logs.clear()
@ -61,6 +64,24 @@ class Game:
self.map.spawn_random_entities(randint(3, 10))
self.inventory_menu.update_player(self.player)
@property
def map(self) -> Map:
"""
Return the current map where the user is.
"""
return self.maps[self.map_index]
@map.setter
def map(self, m: Map) -> None:
"""
Redefine the current map.
"""
if len(self.maps) == self.map_index:
# Insert new map
self.maps.append(m)
# Redefine the current map
self.maps[self.map_index] = m
def run(self, screen: Any) -> None: # pragma no cover
"""
Main infinite loop.