add calendar and region

This commit is contained in:
bridge
2025-08-20 22:51:42 +08:00
parent 7851cbba0d
commit 658f2aefdb
5 changed files with 226 additions and 20 deletions

View File

@@ -3,15 +3,25 @@ from dataclasses import dataclass
class Month(Enum):
JANUARY = "January"
FEBRUARY = "February"
MARCH = "March"
APRIL = "April"
MAY = "May"
JUNE = "June"
JULY = "July"
AUGUST = "August"
SEPTEMBER = "September"
JANUARY = 1
FEBRUARY = 2
MARCH = 3
APRIL = 4
MAY = 5
JUNE = 6
JULY = 7
AUGUST = 8
SEPTEMBER = 9
OCTOBER = 10
NOVEMBER = 11
DECEMBER = 12
class Year(int):
pass
def __add__(self, other: int) -> 'Year':
return Year(int(self) + other)
def next_month(month: Month, year: Year) -> tuple[Month, Year]:
if month == Month.DECEMBER:
return Month.JANUARY, year + 1
else:
return Month(month.value + 1), year

View File

@@ -1,5 +1,6 @@
from enum import Enum
from dataclasses import dataclass
from dataclasses import dataclass, field
import itertools
class TileType(Enum):
PLAIN = "plain" # 平原
@@ -13,6 +14,9 @@ class TileType(Enum):
GLACIER = "glacier" # 冰川/冰原
SNOW_MOUNTAIN = "snow_mountain" # 雪山
region_id_counter = itertools.count(1)
@dataclass
class Region():
"""
@@ -26,6 +30,18 @@ class Region():
name: str
description: str
qi: int # 灵气从0~255
id: int = field(init=False)
def __post_init__(self):
self.id = next(region_id_counter)
def __hash__(self) -> int:
return hash(self.id)
def __eq__(self, other) -> bool:
if not isinstance(other, Region):
return False
return self.id == other.id
# 物产
# 灵气
# 其他
@@ -36,12 +52,11 @@ class Tile():
type: TileType
x: int
y: int
# region: Region
region: Region | None = None # 可以是一个region的一部分也可以不属于任何region
class Map():
"""
通过dict记录position 到 tile。
TODO: 记录region到position的映射。
TODO: 有特色的地貌,比如西部大漠,东部平原,最东海洋和岛国。南边热带雨林,北边雪山和冰原。
"""
def __init__(self, width: int, height: int):
@@ -59,4 +74,19 @@ class Map():
self.tiles[(x, y)] = Tile(tile_type, x, y)
def get_tile(self, x: int, y: int) -> Tile:
return self.tiles[(x, y)]
return self.tiles[(x, y)]
def create_region(self, name: str, description: str, qi: int, locs: list[tuple[int, int]]):
"""
创建一个region。
"""
region = Region(name=name, description=description, qi=qi)
for loc in locs:
self.tiles[loc].region = region
return region
def get_region(self, x: int, y: int) -> Region | None:
"""
获取一个region。
"""
return self.tiles[(x, y)].region