Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

game design improvement

Tags:

c#

I was having a discussion with my developer mate on following game design.

I have a collection of Move in the Game class. my developer mate is asking me to remove the collection and only have the current move information there.

what is your suggestions?

public class Game
{
    public String Id { get; set; }
    public String CreatorId { get; set; }

    public List<Player> Players { get; set; }
    public List<Move> Moves { get; set; }
}

public class Player
{
    public String Id { get; set; }
    public String Name { get; set; }
}

public class Move
{
    public String Id { get; set; }
    public String PlayerId { get; set; }
    public String PlayerName { get; set; }
    public String NextMoveId { get; set; }
    public String NextPlayerId { get; set; }
    public String Position { get; set; }
}

Edit:
my developer mate suggests me to only have a single Move object in the Game class.

like image 917
Zain Shaikh Avatar asked Dec 17 '22 19:12

Zain Shaikh


2 Answers

There's no really correct approach that any of us can provide for your design. It isn't a cut-and-dry situation; there's no "right" or "wrong" answer. And it's especially difficult for us to make suggestions given that we don't know all of the details behind your game's design. For example, as I asked in a comment and several of the other answers have hinted towards, if you have an "Undo" or "Replay" feature, you will need to store a history of all the moves. If not, and you have no desire to implement such a feature, there is no need to store information about all of the moves.

This is the kind of design decision that you need to learn how to make as a programmer. Consider all of the possible benefits of one approach and the benefits of the other approach, then decide which one best suits your application. Make a "T" chart if you find it helpful. Something like:

       Keeping List of All Moves           |         Storing Only Last Move
    ---------------------------------------|------------------------------------
     - Allows you to implement Undo        |   - Simplifies your game's design 
        or Replay feature                  | 
     - Consumes more memory                |   - Saves memory by only storing the
                                           |      minimum amount of data
                                           | 
                                           |
    ...etc.

In the end, you (and your colleague) are the ones in the best position to make this decision. Making sure that you've armed yourself with a careful comparison of the advantages and disadvantages is the best way to ensure that you've made the right one.

like image 98
Cody Gray Avatar answered Jan 13 '23 22:01

Cody Gray


A game often consists of a set of moves performed by one or more players. Between each move, the game is in a certain state.

If you have the current state, and no need to playback or undo any moves, you would never access the previous moves. Future moves are not known yet, so with just the information you provided, I'd say Game should not have any Move, just a State and a ProcessMove(Move move) method to change the Game's State. The Move is generated by one of the Players.

like image 31
C.Evenhuis Avatar answered Jan 13 '23 22:01

C.Evenhuis