Django/GAE 中基于浏览器的策略游戏。型号建议?

发布于 2024-09-30 03:40:34 字数 698 浏览 3 评论 0原文

我正在使用 app-engine-patch 在 Google App Engine 上的 Django 中创建一个基于回合和文本的策略游戏。简化的概念是每个玩家可以建造几个不同的单位和建筑物来改善他们的基地并与其他玩家争夺积分。

我的问题涉及 Django 模型的设计,在我看来,具有不同攻击力、生命等的建筑物和单位应该是它们自己的模型,如下

class Unit(db.Model):
    name = db.StringProperty()
    type = db.ReferenceProperty(UnitType)
    targets = KeyListProperty(UnitType)
    attack = db.IntegerProperty()
    life = db.IntegerProperty()
    price = db.IntegerProperty()

所示:我的问题是如何最容易地设置特定单位/建筑物的玩家数量。举例来说,玩家应该能够购买 15 架飞机。

然后,我可以在玩家模型中将“飞机”设置为 IntegerProperty,并在获取飞机的攻击力和生命时使用单位名称作为标识符。然而,这不是一个非常动态的设计,因为玩家模型不知道单位“飞机”是否确实存在。我希望玩家模型能够以某种方式反映现有的单位/建筑模型。

这是我第一次尝试基于网络的游戏,所以我可能完全偏离轨道,有人对此有意见吗?有更好的方法吗?

I'm creating a turn and text-based strategy game in Django on Google App Engine with app-engine-patch. The simplified concept is that each player build can several different units and buildings to improve their base and fight other players for points.

My question involves the designing of the Django models, it seems to me that the buildings and units, which will have different attack power, life and such, should be their own models like so:

class Unit(db.Model):
    name = db.StringProperty()
    type = db.ReferenceProperty(UnitType)
    targets = KeyListProperty(UnitType)
    attack = db.IntegerProperty()
    life = db.IntegerProperty()
    price = db.IntegerProperty()

My problem then comes to how to easiest be able to set the players amount of a specific unit/building. As an example a player should be able to purchase, say 15 airplanes.

I then could just set "airplane" as an IntegerProperty in the player model and use the unit name as an identifier when getting the attack power and life of the airplane. That would however not be a very dynamic design, since the player model does not know if the unit "airplane" is actually present yet. I would like the player model to mirror the existing Unit/Building-models in someway.

This is my first try on a web-based game so I might be totally off track, does anyone have input on this? Is there a better way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-10-07 03:40:34

Unit 类派生怎么样?

class Airplane(Unit):
    owner = db.ReferenceProperty(User)

这样,您的 User 类就会根据 文档

编辑

或者,您可以像这样实现 Airplane 类:

class Airplane(db.Model):
    unit = ReferenceProperty(Unit)
    amount = IntegerProperty()
    user = db.ReferenceProperty(User)

How about deriving from the Unit class?

class Airplane(Unit):
    owner = db.ReferenceProperty(User)

That way your User class would automatically get an airplane_set collection (well, a query really) according to the documentation

Edit

Alternatively you could implement an the Airplane class like this:

class Airplane(db.Model):
    unit = ReferenceProperty(Unit)
    amount = IntegerProperty()
    user = db.ReferenceProperty(User)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文