Esempio n. 1
0
 private void SendRoundInformation()
 {
     foreach (Player player in this.Players)
     {
         player.NetworkManager.Send(ProtocolManager.RoundInformation(this.discardPile.Cards[0], this.playerWhoIsOnTurn, this.Players));
     }
 }
Esempio n. 2
0
 private void SendPlayerCards()
 {
     foreach (Player player in this.Players)
     {
         player.NetworkManager.Send(ProtocolManager.PlayerCards(player));
     }
 }
Esempio n. 3
0
        private void SendIsAlive()
        {
            while (this.isReading == true)
            {
                this.Send(ProtocolManager.IsAlive());

                Thread.Sleep(2000);
            }
        }
Esempio n. 4
0
        private void StartGame(Game game)
        {
            game.PrepareGameStart();

            foreach (Player player in game.Players)
            {
                player.NetworkManager.Send(ProtocolManager.GameStart(game.GameID.ToString(), player.PlayerID.ToString()));
            }

            Console.WriteLine("A game started (GameID: {0}, Players: {1}/{2})!", game.GameID, game.JoinedPlayers, game.PlayersNeeded);
        }
Esempio n. 5
0
        private void GameOver()
        {
            try
            {
                if (this.Players.Count > 0)
                {
                    foreach (Player player in this.Players)
                    {
                        player.NetworkManager.Send(ProtocolManager.GameOver(this.playerWhoIsOnTurn.PlayerID.ToString()));
                    }
                }
            }
            catch (Exception)
            { }

            this.FireOnGameEnded();
        }
Esempio n. 6
0
        private void CreateNewGame(int amountOfPlayers, NetworkManager networkManager)
        {
            Game game = new Game(this.nextGameID, amountOfPlayers);

            this.nextGameID++;
            game.Players = new List <Player>();
            game.Players.Add(new Player(1, networkManager));
            this.games.Add(game);
            game.GameEnded += this.GameEnded;

            if (amountOfPlayers < 2 || amountOfPlayers > 4)
            {
                networkManager.Send(ProtocolManager.Invalid());
            }
            else
            {
                networkManager.Send(ProtocolManager.OK());

                Console.WriteLine("{0} created a new game (GameID: {1}, Players: {2}/{3})!", ((IPEndPoint)networkManager.PlayerClient.Client.RemoteEndPoint).Address.ToString(), game.GameID, game.JoinedPlayers, game.PlayersNeeded);
            }
        }
Esempio n. 7
0
        private void JoinGame(int gameID, NetworkManager networkManager)
        {
            bool gameFound = false;

            foreach (Game game in games)
            {
                if (game.GameID == gameID)
                {
                    if (game.JoinedPlayers < game.PlayersNeeded)
                    {
                        game.Players.Add(new Player(game.JoinedPlayers + 1, networkManager));
                        game.JoinedPlayers++;
                        gameFound = true;
                        networkManager.Send(ProtocolManager.OK());

                        Console.WriteLine("{0} joined a game (GameID: {1}, PlayerID: {2}, Players: {3}/{4})!", ((IPEndPoint)networkManager.PlayerClient.Client.RemoteEndPoint).Address.ToString(), game.GameID, game.JoinedPlayers, game.JoinedPlayers, game.PlayersNeeded);

                        if (game.JoinedPlayers == game.PlayersNeeded)
                        {
                            this.StartGame(game);
                        }
                    }
                    else
                    {
                        networkManager.Send(ProtocolManager.Invalid());
                    }

                    break;
                }
            }

            if (gameFound == false)
            {
                networkManager.Send(ProtocolManager.Invalid());
            }
        }
Esempio n. 8
0
        public void NewCardSet(string[] setCardArray)
        {
            if (setCardArray.Length == 5)
            {
                foreach (Player player in this.Players)
                {
                    if (player.PlayerID.ToString() == setCardArray[1])
                    {
                        Card  card = null;
                        Color color;

                        if (Enum.IsDefined(typeof(Color), (int)(setCardArray[2].ToCharArray()[0])) == true)
                        {
                            color = (Color)(setCardArray[2].ToCharArray()[0]);

                            if (int.TryParse(setCardArray[3], out int number) == false)
                            {
                                if (Enum.IsDefined(typeof(ActionCardType), (int)(setCardArray[3].ToCharArray()[0])) == true)
                                {
                                    ActionCardType type = (ActionCardType)(setCardArray[3].ToCharArray()[0]);
                                    card = new ActionCard(color, type);
                                }
                            }
                            else
                            {
                                card = new NumericCard(color, number);
                            }

                            if (int.TryParse(setCardArray[4], out int uno) == true)
                            {
                                if (uno == 0 || uno == 1)
                                {
                                    if (this.CheckIfValidCard(card, player) == true)
                                    {
                                        this.RemoveCardAfterSet(card, player);

                                        player.NetworkManager.Send(ProtocolManager.OK());

                                        if (this.CheckIfGameOver() == true)
                                        {
                                            this.GameOver();
                                            break;
                                        }
                                        else
                                        {
                                            this.CheckIfUno(setCardArray[4]);
                                            this.ExecuteCardEffect(card, this.GetNextPlayer(), false);
                                            ChangePlayerTurn();
                                        }
                                    }
                                    else
                                    {
                                        player.NetworkManager.Send(ProtocolManager.Invalid());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 private void SendRoomList(NetworkManager networkManager)
 {
     networkManager.Send(ProtocolManager.RoomList(games));
 }