Example #1
0
        public static bool Create(AActionParams actionParams, out AAction?action)
        {
            action = actionParams switch {
                BuyAction.Params p => ActionRequest.HasRequiredProps(actionParams.Request, "PieceType") && AreNotNull(actionParams.Game)
                                ? new BuyAction(p)
                                : null,
                PlantAction.Params p => ActionRequest.HasRequiredProps(actionParams.Request, "Origin", "Target") && AreNotNull(actionParams.Game, actionParams.Board)
                                  ? new PlantAction(p)
                                  : null,
                GrowAction.Params p => ActionRequest.HasRequiredProps(actionParams.Request, "Origin") && AreNotNull(actionParams.Game, actionParams.Board)
                                 ? new GrowAction(p)
                                 : null,
                CollectAction.Params p => ActionRequest.HasRequiredProps(actionParams.Request, "Origin") && AreNotNull(actionParams.Game, actionParams.Board)
                                    ? new CollectAction(p)
                                    : null,
                EndTurnAction.Params p => AreNotNull(actionParams.Game)
                                    ? new EndTurnAction(p)
                                    : null,
                StartGameAction.Params p => AreNotNull(actionParams.Session, actionParams.Game)
                                      ? new StartGameAction(p)
                                      : null,
                PlaceStartingTreeAction.Params p => ActionRequest.HasRequiredProps(actionParams.Request, "Origin") && AreNotNull(actionParams.Game, actionParams.Board)
                                              ? new PlaceStartingTreeAction(p)
                                              : null,
                _ => throw new ArgumentOutOfRangeException()
            };

            return(action != null);
        }
Example #2
0
 protected ATurnAction(AActionParams actionParams) : base(actionParams)
 {
     AddValidators(
         new AActionValidator[] {
         new OnPlayersTurn(actionParams.PlayerId, actionParams.Game)
     }
         );
 }
Example #3
0
 protected ATurnActionWithOrigin(AActionParams actionParams)  : base(actionParams)
 {
     Board  = actionParams.Board;
     Origin = (Hex)actionParams.Request.Origin;
     AddValidators(new AActionValidator[] {
         new ValidTile(Origin),
         new TileHasNotBeenActiveThisTurn(Origin, Game),
         new TileBelongsToPlayerOrIsEmpty(Origin, PlayerId, Game, Board),
     });
 }
Example #4
0
 protected ATurnActionOnOwnPiece(AActionParams actionParams) : base(actionParams)
 {
     AddValidators(new [] {
         new TileBelongsToPlayer(Origin, PlayerId, Game, Board),
     });
 }
Example #5
0
 protected AAction(AActionParams actionParams)
 {
     Game     = actionParams.Game !;
     PlayerId = actionParams.PlayerId !;
 }
Example #6
0
 protected AHostAction(AActionParams actionParams) : base(actionParams)
 {
     Session = actionParams.Session !;
     AddValidators(new AActionValidator[] { new PlayerIsHost(Session, PlayerId) });
 }