私は、Pythonで基本的なテキストベースのゲームのためのマップのために10x10のグリッドを作ろうとしています。 私はMapTile
クラスと約(x, y)
グリッドを移動することができるプレーヤークラスを作成することができました。しかし、個々のMapTilesを持つクラスのインスタンスを作成する方法はわかりません。私はそれがすべての100 MapTile
のためにmaptile1、maptile2 ...等を作成することは任意であると読んだが、私は別の方法を考えることができない..テキストベースのグリッドのクラスの動的インスタンスを作成するにはどうすればよいですか?
私は何を持っている!
# This class contains the x and y values for a grid
class MapTile:
def __init__(self, x, y):
self.x = x
self.y = y
# basic char class containing position
class Character:
def __init__(self, name, hp, x, y):
self.name = name
self.hp = hp
self.x = x
self.y = y
# movement func
def Move(self, Direction):
if Direction.upper() == "UP":
if self.y > 1:
self.y -= 1
elif Direction.upper() == "LEFT":
if self.x > 1:
self.x -= 1
elif Direction.upper() == "RIGHT":
if self.x < 10:
self.x += 1
elif Direction.upper() == "DOWN":
if self.y < 10:
self.y += 1
def __str__(self):
return "{}\n========\nHP = {}\nX = {}\nY = {}".format(self.name,
self.hp,
self.x,
self.y)
私にはわかりません。
'[x] [y]'で索引付けされた 'list'-of-listsに10x10グリッドの' MapTile'インスタンスを置くか、またはキーの 'タプル' 、y) 'それぞれの位置。 – martineau
私は1つのインスタンスしか持たず、(x、y)座標はリストのリストにする必要がありますか? –