Exemplo n.º 1
0
 public Game(IEnumerable<Connection> connections, Server server, Lobby lobby, GameSpecificationInfo gameSpecification)
 {
     this.connections.AddRange(connections);
     this.server = server;
     this.lobby = lobby;
     this.gameSpecification = gameSpecification;
 }
Exemplo n.º 2
0
        public void ServerProposeGame(GameSpecificationInfo gameSpecification)
        {
            this.ShowRequestGameButton = false;
            this.ShowAcceptGameButton = true;
            this.ShowDeclineGameButton = true;
            this.ShowCancelGameButton = false;
            this.IsProcessingGameInvite = true;

            string statusText = gameSpecification.InitiatingPlayer + " proposed a game with ";
            foreach (string player in gameSpecification.Players)
            {
                statusText += player + " ";
            }
            statusText += "\n";

            foreach (string card in gameSpecification.Cards)
            {
                statusText += card + " ";
            }
            this.GameInviteStatusText = statusText;
        }
Exemplo n.º 3
0
        public void RequestGame(IEnumerable<string> selectedPlayers)
        {
            GameSpecificationInfo gameSpecification = new GameSpecificationInfo();
            gameSpecification.InitiatingPlayer = this.Connection.Username;
            gameSpecification.Players.AddRange(selectedPlayers);
            gameSpecification.Players.Add(this.connection.Username);

            if(this.gameParameters != null)
            {
                string[] cards = this.gameParameters.Split(',');
                foreach (string entry in cards)
                {
                    string card = entry.Trim();
                    bool bane = false;
                    bool prohibit = false;
                    string cardPart = null;
                    if (card.StartsWith("bane:", StringComparison.OrdinalIgnoreCase))
                    {
                        bane = true;
                        cardPart = card.Substring(5).Trim();
                    }
                    else if (card.StartsWith("!"))
                    {
                        prohibit = true;
                        cardPart = cardPart.Substring(1).Trim();
                    }
                    else
                    {
                        cardPart = card;
                    }
                    if (string.Equals(cardPart, "colony", StringComparison.OrdinalIgnoreCase))
                    {
                        gameSpecification.UseColonies = prohibit ? CardUseType.DoNotUse : CardUseType.Use;
                    }
                    if (string.Equals(cardPart, "shelters", StringComparison.OrdinalIgnoreCase))
                    {
                        gameSpecification.UseShelters = prohibit ? CardUseType.DoNotUse : CardUseType.Use;
                    }
                    if (string.Equals(cardPart, "hand25", StringComparison.OrdinalIgnoreCase))
                    {
                        gameSpecification.StartingHandType = StartingHandType.FiveTwoSplit;
                    }
                    else if (string.Equals(cardPart, "hand34", StringComparison.OrdinalIgnoreCase))
                    {
                        gameSpecification.StartingHandType = StartingHandType.FourThreeSplit;
                    }
                    else if (string.Equals(cardPart, "handsame", StringComparison.OrdinalIgnoreCase))
                    {
                        gameSpecification.StartingHandType = StartingHandType.RandomSameStartingHands;
                    }

                    CardModel c = CardModelFactory.GetCardModel(card);
                    if (c != null && c.IsKingdomCard)
                    {
                        if (bane)
                        {
                            gameSpecification.Bane = c.ID;
                        }
                        else if (prohibit)
                        {
                            gameSpecification.ProhibitedCards.Add(c.ID);
                        }
                        else if (gameSpecification.Cards.Count < 10)
                        {
                            gameSpecification.Cards.Add(c.ID);
                        }
                    }
                }
            }

            NetworkMessage message = new NetworkMessage();
            message.MessageCategory = SystemMessages.SystemPrefix;
            message.MessageType = SystemMessages.RequestGame;
            message.MessageContent = NetworkSerializer.Serialize(gameSpecification);
            this.connection.SendSystemMessage(message);
        }
Exemplo n.º 4
0
        public void ProposeGameWithUsers(Connection source, List<string> players, GameSpecificationInfo gameSpecification, Lobby lobby)
        {
            List<Connection> gameConnections = new List<Connection>();
            lock (this.serverLock)
            {
                foreach (string target in players)
                {
                    User user = lobby.Users.FirstOrDefault(u => u.Name == target);
                    if (user == null)
                    {
                        NetworkMessage message = new NetworkMessage();
                        message.MessageCategory = SystemMessages.SystemPrefix;
                        message.MessageType = SystemMessages.DeclineGame;
                        source.SendMessage(message);
                        return;
                    }
                    else
                    {
                        gameConnections.Add(user.Connection);
                    }
                }

                for (int i = 0; i < gameConnections.Count; i++)
                {
                    bool ok = gameConnections[i].TryProposeGame();
                    if (!ok)
                    {
                        for (int j = 0; j < i; j++)
                        {
                            gameConnections[j].CancelGame();
                        }
                        return;
                    }
                }
            }
            Game game = new Game(gameConnections, this, lobby, gameSpecification);
            Thread thread = new Thread(new ThreadStart(game.NegotiateGame));
            thread.Start();
        }