Ejemplo n.º 1
0
        public async Task HiddenAttack()
        {
            var         socketId     = Context.ConnectionId;
            string      enemySockeId = duelsController.GetOpponentSocketId(socketId);
            List <Ship> ships        = strategyController.GetEnemyShips(strategyController.GetOpponentSocketId(socketId));
            List <Cell> cells        = strategyController.GetEnemyCells(strategyController.GetOpponentArenaId(socketId));

            AttackChangerVisitor atackChangerVisitor = new AttackChangerVisitor(cells, ships);
            Strategy             activeStrategy      = StrategyHolder.GetPlayerStrategy(socketId);
            List <CellOutcome>   outcomes            = activeStrategy.Accept(atackChangerVisitor);

            foreach (CellOutcome outcome in outcomes)
            {
                switch (outcome.attackOutcome)
                {
                case AttackOutcome.Hit:
                    await Clients.Client(enemySockeId).SendAsync("pingAttack", outcome.posX, outcome.posY, "Hit", false);

                    await Clients.Caller.SendAsync("pingAttack", outcome.posX, outcome.posY, "Hit", true);

                    break;

                case AttackOutcome.Armor:
                    duelsController.ChangeTurns(socketId);
                    await Clients.Client(enemySockeId).SendAsync("pingAttack", outcome.posX, outcome.posY, "Armor", false);

                    await Clients.Caller.SendAsync("pingAttack", outcome.posX, outcome.posY, "Armor", true);

                    break;

                //For now, both [Missed and Invalid] trigger default switch
                default:
                    duelsController.ChangeTurns(socketId);
                    await Clients.Client(enemySockeId).SendAsync("pingAttack", outcome.posX, outcome.posY, "Missed", false);

                    await Clients.Caller.SendAsync("pingAttack", outcome.posX, outcome.posY, "Missed", true);

                    //turn change using the proxy class
                    TurnOutcome turn = proxyPlayerTurn.ChangeTurn();
                    await Clients.Client(turn.InactiveId).SendAsync("changedTurn", turn.CallerTurn);

                    await Clients.Client(turn.ActiveId).SendAsync("changedTurn", turn.OpponetTurn);

                    break;
                }
            }
        }