本文介绍了游戏的架构和设计策略的多人卡片游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的游戏开发,所以我决定我要从头开始为体验和娱乐创造一个业余项目。具体的游戏类似于扑克称为三卡吹嘘。游戏的玩法是在电影中的两根枪管的。

I am relatively new to game development so I decided I wanted to create a hobby project from scratch for both experience and entertainment. The specific game is similar to poker known as Three Card Brag. The game is played in the movie Lock, Stock and Two Smoking Barrels.

我一直在读了一些话题对SO有关游戏开发,但大多的。这有助于改造我创建的对象的原始的方式。

I have been reading up on some of the topics on SO regarding game development, though mostly this question. This has helped revamp the original way I was creating the objects.

一个特别的问题,我有被定义游戏状态。我最初的办法是分开的一切(例如保持播放类中的筹码),但读的反应到的我pviously提到的$ P $的问题,却仿佛游戏中的所有可能的状态应该保持在一个游戏状态对象。我想出了基本上是这样的:

One particular problem I am having is defining game state. My initial approach was to separate everything (e.g. keeping chip stacks inside a Player class) but after reading the responses to the question I mentioned previously, it seems as though all possible states of the game should be maintained within a GameState object. What I came up with is essentially this:

abstract class CardGameState
{
    protected List<Player> _Players;
    protected Player _CurrentPlayer;
    protected Dictionary<Player, int> _Chips;
    protected Dictionary<Player, Hand> _CurrentHand;
    protected Dictionary<Player, PlayerStatuses> _PlayerStatus; // PlayerStatuses.InHand, PlayerStatuses.Folded, PlayerStatuses.SittingOut, etc.
    /* etc. */

,其中每个 CardGameState 是由一些行动修改:

where each CardGameState is modified by some action:

public interface IAction
{
    string Name { get; }

    CardGameState Apply(CardGameState state);
    bool IsLegal(CardGameState state);
}

现在我感觉非常强烈,这是击败面向对象编程的目的,因为数据具体涉及到播放器(在这种情况下,他的筹码,手,和当前状态)不被包封播放对象。

Now I'm feeling very strongly that this is defeating the purpose of object-oriented programming, because the data specifically related to the player (in this case, his chip stack, hand, and current status) is not encapsulated by the Player object.

在另一方面,如果一个球员要提高赌注,我会创建一个 RaiseAction 实现 IAction ,而 IAction 接口只接受当前的游戏状态,我不相信会是理想的,如果该筹码被存放在播放器类。

On the other hand, if a player were to raise the bet, I would be creating a RaiseAction that implements IAction, but the IAction interface only accepts the current game state, which I don't believe would be ideal if the chip stacks were stored within the Player class.

基本上,我的问题是:我可以有两全其美的,这样我可以有游戏状态的精确重新presentation同时保持具体涉及到对象中的游戏状态里面它提供的所有数据反对呢?

Basically, my question is: can I have the best of both worlds such that I can have an exact representation of the game state while simultaneously keeping all data related specifically to an object within the game state inside its given object?

推荐答案

在网络游戏使用命令格式(你IAction)为标准,并经过验证的方法来做到这一点。这不是面向对象的球员的感觉,但行动是面向对象的,所以从纯理论的角度查看其雄厚的设计模式,我猜。而在实践中那怎么每一个成功的网络游戏我已经看到了实现它,但请注意,动作游戏通常使用非常小的谨慎操作/数据包,直到它几乎变成各种各样的流。

In online-games using the command-pattern (your IAction) is the standard, and proven, way to do it. It's not Object Oriented in the sense of the player, but the actions are Object Oriented, so from a purely theoretical point of view its a solid design pattern, I guess. And in practice thats how every successful online game I've seen implements it, but note that action games normally use very small discreet actions/packets, until it practically becomes a stream of sorts.

编辑:

在我回答这个时间长了,我就回来了,实现了另一种解决这个问题的方法是实现游戏状态的球员,甲板等..作为衍生自即将状态置类的应用(IAction动作)的成员。这样的对象应用操作自己,而不是让应用程序应用操作的对象,这将映射动作和状态到的的,而不是命令模式。两种解决方案将工作,在那里游客有较大的开销和更多的封装,而命令是用更少的封装更容易的解决方案。

A long time after I answering this, I came back here and realized another solution to this problem is to implement GameState's Players, Decks, etc... as derived from an IState class with an Apply(IAction action) member. This way objects apply actions on themselves, instead of having the application apply actions on objects, this would map actions and state to a visitor-pattern instead of a command pattern. Either solution will work, where visitor has the larger overhead and more encapsulation, while command is the easier solution with less encapsulation.

这篇关于游戏的架构和设计策略的多人卡片游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 16:18