Beispiel #1
0
        public ActionResult <BaseResult> Play(PlayData data)
        {
            var card  = new Card(data.color, data.type);
            var chain = new CheckGamePhase(GamePhase.Playing)
                        .Then(new CheckIfPlayerExists(data.id))
                        .Then(new CheckIfPlayerTurn(data.id))
                        .Then(new CheckCustomPredicate(g => g.GetPlayerByUUID(data.id).hand.Contains(card), "You don't have that card"))
                        .Then(new CheckCustomPredicate(g => g.CanCardBePlayed(card), "You can't play that card"))
                        .Then(new CheckCustomPredicate(
                                  g => !((card.type == CardType.Wild || card.type == CardType.Draw4) && card.color == CardColor.Black), "You have to choose a color"))
                        .Then(new ConcludeAndExecute(
                                  g =>
            {
                mementoList.Add(new GameMemento(g));
                g.PlayerPlaysCard(card);
                if (card.type == CardType.Skip)
                {
                    g.mediator.Notify("skip");
                }
                else
                {
                    g.mediator.Notify("card");
                }

                return(new BaseResult());
            }
                                  ));

            var game = Game.GetInstance();

            return(chain.ProcessChain(game));
        }
Beispiel #2
0
        public ActionResult <BaseResult> Join(JoinData data)
        {
            var chain = new CheckGamePhase(GamePhase.WaitingForPlayers)
                        .Then(new CheckCustomPredicate(g => g.GetActivePlayerCount() < 10, "Game player capacity exceeded"))
                        .Then(new ConcludeAndExecute(
                                  g => new JoinResult(g.AddPlayer(data.name))
                                  ));

            var game = Game.GetInstance();

            return(chain.ProcessChain(game));
        }
Beispiel #3
0
        public ActionResult <BaseResult> Start(StartData data)
        {
            var chain = new CheckGamePhase(GamePhase.WaitingForPlayers)
                        .Then(new CheckCustomPredicate(g => g.GetActivePlayerCount() >= 2, "Game needs at least 2 players"))
                        .Then(new CheckIfPlayerExists(data.id))
                        .Then(new ConcludeAndExecute(
                                  g => { g.StartGame(data.finiteDeck, data.onlyNumbers, data.slowGame); return(new BaseResult()); }
                                  ));

            var game = Game.GetInstance();

            return(chain.ProcessChain(game));
        }
Beispiel #4
0
        public ActionResult <BaseResult> Draw(PlayerData data)
        {
            var chain = new CheckGamePhase(GamePhase.Playing)
                        .Then(new CheckIfPlayerExists(data.id))
                        .Then(new CheckIfPlayerTurn(data.id))
                        .Then(new CheckCustomPredicate(g => !g.CanPlayerPlayAnyOn(g.GetPlayerByUUID(data.id)), "You can't draw a card right now"))
                        .Then(new ConcludeAndExecute(
                                  g => { mementoList.Add(new GameMemento(g)); g.PlayerDrawsCard(); g.mediator.Notify("move"); return(new BaseResult()); }
                                  ));

            var game = Game.GetInstance();

            return(chain.ProcessChain(game));
        }
Beispiel #5
0
        public ActionResult <BaseResult> Uno(PlayerData data)
        {
            var chain = new CheckGamePhase(GamePhase.Playing)
                        .Then(new CheckIfPlayerExists(data.id))
                        .Then(new CheckIfPlayerTurn(data.id))
                        // TODO: add a few more here?
                        .Then(new ConcludeAndExecute(
                                  g =>
            {
                mementoList.Add(new GameMemento(g));
                g.PlayerSaysUNO();
                g.mediator.Notify("move");
                return(new BaseResult());
            }
                                  ));

            var game = Game.GetInstance();

            return(chain.ProcessChain(game));
        }