Esempio n. 1
0
 public bool removePlayer(Player player)
 {
     player.inQueue = false;
     return queue.Remove(player);
 }
Esempio n. 2
0
        public void Request_UseCard(Player player)
        {
            int slot = player.gameContext.data.Payload.slotId; //  This is the slot which is the cards destination
            int card = player.gameContext.data.Payload.cid; // This is the card which the player has on hand

            GamePlayer requestPlayer = player.gPlayer;

            // If opposite players turn
            if (!requestPlayer.IsPlayerTurn())
            {
                // Screen warning
                requestPlayer.playerContext.SendTo(new Response(GameService.GameResponseType.GAME_NOT_YOUR_TURN,
                new Dictionary<string, object>
                        {
                            {"card",card},
                            {"error","Not your turn!"}
                        }));

                // Fire releaseCard (to recall the card to origin pos)
                this.Request_OpponentReleaseCard(player);
                Console.WriteLine(">[GAME] Not your turn!");
                return;
            }

            // If cardslot is not empty
            else if (requestPlayer.boardCards.ContainsKey(slot))
            {
                JObject retObj = new JObject(
                    new JProperty("cid", card)
                    );

                //requestPlayer.playerContext.SendTo(new Response(GameService.GameResponseType.GAME_USECARD_OCCUPIED, retObj));
                this.Request_OpponentReleaseCard(player);

                requestPlayer.playerContext.SendTo(
                    new Response(GameService.GameResponseType.GAME_USECARD_OCCUPIED, new JObject(
                        new JProperty("slot", slot),
                        new JProperty("message", "Slot is already occupied!")
                )));

                Console.WriteLine(">[GAME] Slot occupied!");
                return;
            }

            // Not enough mana to use card
            else if (!requestPlayer.HasEnoughMana(card))
            {
                requestPlayer.playerContext.SendTo(new Response(GameService.GameResponseType.GAME_USECARD_OOM, "Not enough mana!"));
                Console.WriteLine(">[GAME] Not enough mana!");
                return;
            }

            else
            {
                // Move a card to the board
                Card c;
                requestPlayer.handCards.TryGetValue(card, out c);
                requestPlayer.handCards.Remove(card);
                requestPlayer.boardCards.Add(slot, c);

                // Set the slotId to the card
                c.slotId = slot;

                //Next turn
                requestPlayer.gameRoom.NextTurn();

                // Send Reply
                Response response = new Response(GameService.GameResponseType.GAME_USECARD_PLAYER_OK, new Dictionary<string, int>
                        {
                            {"cid",card},
                            {"slotId",slot}
                        });

                requestPlayer.playerContext.SendTo(response);
                response.Type = GameService.GameResponseType.GAME_USECARD_OPPONENT_OK;
                requestPlayer.GetOpponent().playerContext.SendTo(response);
                Console.WriteLine(">[GAME] Sent!");
            }
        }
Esempio n. 3
0
 public void AddPlayer(Player player)
 {
     player.inQueue = true;
     this.queue.AddLast(player);
 }
Esempio n. 4
0
        public void Request_QueuePlayer(Player player)
        {
            // Check if the player already have a game player
            if (player.gPlayer == null)
            {

                if (!player.inQueue)
                {
                    GameQueue.GetInstance().AddPlayer(player);
                    Console.WriteLine("\t\t\t\t\t\t\t" + player.name + " queued!");
                    player.gameContext.SendTo(new Response(GameService.GameResponseType.QUEUE_OK, "You are now in queue!"));
                }
                else
                {
                    Console.WriteLine("\t\t\t\t\t\t\t" + player.name + " tried to queue twice!");
                    player.gameContext.SendTo(new Response(GameService.GameResponseType.QUEUE_ALREADY_IN, "You are already in queue!")); //todo better response type
                }

            }
            else
            {
                Console.WriteLine("> [GAME] Player was already in game, giving gameUpdate (Create)");

                // Send the gamestate to the player (As create since its the first state of this override player)
                Pair<Response> response = player.gPlayer.gameRoom.GenerateGameUpdate(true);
                if (player.gPlayer.isPlayerOne)
                {
                    response.First.Type = GameService.GameResponseType.GAME_RECOVER;
                    player.gPlayer.playerContext.SendTo(response.First);
                }
                else
                {
                    response.Second.Type = GameService.GameResponseType.GAME_RECOVER;
                    player.gPlayer.playerContext.SendTo(response.Second);
                }

            }
        }
Esempio n. 5
0
        public void Request_OpponentReleaseCard(Player player)
        {
            GamePlayer requestPlayer = player.gPlayer;

            JObject retData = new JObject(
             new JProperty("cid", player.gameContext.data.Payload.cid));

            Response response = new Response(
                GameService.GameResponseType.GAME_PLAYER_RELEASE,
                retData
                );

            requestPlayer.playerContext.SendTo(response);

            response.Type = GameService.GameResponseType.GAME_OPPONENT_RELEASE;
            requestPlayer.GetOpponent().playerContext.SendTo(response);
        }
Esempio n. 6
0
        public void Request_NextRound(Player player)
        {
            GamePlayer requestPlayer = player.gPlayer;

            // Validate player turn
            if (!requestPlayer.IsPlayerTurn()) return;

            // Run next round
            requestPlayer.gameRoom.NextRound();

            // Send back game state (update)

            Pair<Response> response = requestPlayer.gameRoom.GenerateGameUpdate();
            requestPlayer.GetOpponent().playerContext.SendTo(response.First);
            requestPlayer.playerContext.SendTo(response.Second);
        }
Esempio n. 7
0
        public void Request_MoveCard(Player player)
        {
            GamePlayer requestPlayer = player.gPlayer;

            JObject retData = new JObject(
                new JProperty("cid", player.gameContext.data.Payload.cid),
                new JProperty("x", player.gameContext.data.Payload.x),
                new JProperty("y", player.gameContext.data.Payload.y)
                );

            Response response = new Response(
                GameService.GameResponseType.GAME_OPPONENT_MOVE,
                retData
                );

            requestPlayer.GetOpponent().playerContext.SendTo(response);
        }
Esempio n. 8
0
        public void Request_CardAttack(Player player)
        {
            int attacker = player.gameContext.data.attacker;
            int defender = player.gameContext.data.defender;

            bool cardAttackPlayer = player.gameContext.data.cardAttackPlayer; //NB MIGHT BE NULL IF NOT USED
            bool playerAttackCard = player.gameContext.data.playerAttackCard; //NB MIGHT BE NULL IF NOT USED

            GamePlayer requestPlayer = player.gPlayer;

            if (!requestPlayer.IsPlayerTurn())
            {
                return;
            }

            GamePlayer opponent = requestPlayer.GetOpponent();
            if (opponent != null)
            {
                // Attack Card and shaise, must authenticate the Move
                Card atkCard = requestPlayer.handCards[attacker];
                Card defCard = opponent.handCards[defender];

                if (cardAttackPlayer)
                {
                    atkCard.Attack(ref opponent); // Card on Player attack
                }
                else if (playerAttackCard)
                {
                    requestPlayer.Attack(defCard); // Player on Card attack
                }
                else
                {
                    atkCard.Attack(ref defCard); // Card on Card
                }

                // Send back game update
                Pair<Response> response = requestPlayer.gameRoom.GenerateGameUpdate();
                opponent.playerContext.SendTo(response.First);
                requestPlayer.playerContext.SendTo(response.Second);

            }
            else
            {
                player.gameContext.SendTo(new Response(GameService.GameResponseType.GAME_OPPONENT_NOEXIST, "Opponent does not exist!"));
            }
        }