Пример #1
0
        public void Execute(ApplicationCommand command)
        {
            GameCommand game_command = (GameCommand)command;

            switch (game_command.type)
            {
            case "Message":
            {
                gui.ShowStringMessage(command.body);
                break;
            }

            case "Booster":
            {
                string[]    ids = game_command.body.Split(',');
                List <Card> tmp = new List <Card>();
                foreach (string id in ids)
                {
                    Card card = allcards.Find(crd => crd.Id.ToString() == id);
                    if (card == null)
                    {
                        throw new Exception("CARD NOT FOUND: " + id.ToString());
                    }
                    tmp.Add(card);
                }
                gui.ShowBooster(tmp);
                break;
            }

            case "PlayCard":
            {
                if (current_playmode != null)
                {
                    // !!!
                    // тоже костыль, надо сразу научить игру просить то, что надо
                    GameCommand response = new GameCommand("PlayMode", current_playmode);
                    Send(response);
                }
                else
                {
                    throw new Exception("Empty card play mode");
                }
                break;
            }

            case "CurrentGold":
            {
                gui.DisplayGold(command.body);
                break;
            }

            case "Board":
            {
                string[]    ids = game_command.body.Split(',');
                List <Card> tmp = new List <Card>();
                foreach (string id in ids)
                {
                    tmp.Add(allcards.Find(card => card.Id.ToString() == id));
                }
                gui.DisplayBoard(tmp);
                break;
            }

            case "Wonder":
            {
                Wonder wonder = allwonders.Find(wnd => wnd.Id == Convert.ToInt32(command.body));
                gui.DisplayWonder(wonder);
                break;
            }

            case "NewTier":
            {
                gui.DisplayNewTier();
                break;
            }

            case "GameState":
            {
                int gold = (int)game_command.Data["Gold"];
                gui.DisplayGameState(gold);
                break;
            }
            }
        }
Пример #2
0
        // костыль
        // второй параметр false - парсит все чудеса, иначе только рандомную сторону
        public static IEnumerable <Wonder> ParseForWonders(string xml_folder, bool random)
        {
            // !!!
            // говнокод
            foreach (string dir in Directory.GetDirectories(xml_folder))
            {
                List <string> tmp = new List <string>();
                if (random)
                {
                    tmp.Add((Guid.NewGuid().GetHashCode() % 2 == 0) ? Directory.GetDirectories(dir).First() : Directory.GetDirectories(dir).Last());
                }
                else
                {
                    tmp.Add(Directory.GetDirectories(dir).First());
                    tmp.Add(Directory.GetDirectories(dir).Last());
                }
                foreach (string wonder_path in tmp)
                {
                    string        filename = Directory.GetFiles(wonder_path, "*.xml").First();
                    StringBuilder sb       = new StringBuilder();
                    using (StreamReader sr = new StreamReader(filename))
                    {
                        String line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            sb.AppendLine(line);
                        }
                    }
                    Wonder      wonder    = new Wonder();
                    string      xmlstring = sb.ToString();
                    XmlDocument xml       = new XmlDocument();
                    xml.LoadXml(xmlstring);
                    var wondernode = xml.FirstChild;
                    wonder.Id   = Convert.ToInt32(wondernode.Attributes["Id"].Value);
                    wonder.Name = wondernode.Attributes["Name"].Value;
                    foreach (XmlNode child in wondernode.ChildNodes)
                    {
                        Card card = new Card();
                        foreach (XmlNode card_node in child.ChildNodes)
                        {
                            switch (card_node.Name)
                            {
                            case "military":
                                card.Military = Convert.ToInt32(card_node.InnerText);
                                break;

                            case "tech":
                                card.Tech = (Tech)Enum.Parse(typeof(Tech), card_node.InnerText);
                                break;

                            case "etb":
                            {
                                Card.Calculator.PerMode mode    = Card.Calculator.PerMode.Single;
                                Card.Calculator.Targets targets = Card.Calculator.Targets.Self;
                                int value = Convert.ToInt32(card_node.InnerText);
                                foreach (XmlAttribute attr in card_node.Attributes)
                                {
                                    switch (attr.Name)
                                    {
                                    case "PerMode":
                                    {
                                        mode = (Card.Calculator.PerMode)Enum.Parse(typeof(Card.Calculator.PerMode), attr.Value);
                                        break;
                                    }

                                    case "Targets":
                                    {
                                        targets = (Card.Calculator.Targets)Enum.Parse(typeof(Card.Calculator.Targets), attr.Value);
                                        break;
                                    }
                                    }
                                }
                                card.ETB = new Card.Calculator()
                                {
                                    mode = mode, targets = targets, value = value
                                };
                                break;
                            }

                            case "fame":
                            {
                                Card.Calculator.PerMode mode    = Card.Calculator.PerMode.Single;
                                Card.Calculator.Targets targets = Card.Calculator.Targets.Self;
                                int value = Convert.ToInt32(card_node.InnerText);
                                foreach (XmlAttribute attr in card_node.Attributes)
                                {
                                    switch (attr.Name)
                                    {
                                    case "PerMode":
                                    {
                                        mode = (Card.Calculator.PerMode)Enum.Parse(typeof(Card.Calculator.PerMode), attr.Value);
                                        break;
                                    }

                                    case "Targets":
                                    {
                                        targets = (Card.Calculator.Targets)Enum.Parse(typeof(Card.Calculator.Targets), attr.Value);
                                        break;
                                    }
                                    }
                                }
                                card.Fame = new Card.Calculator()
                                {
                                    mode = mode, targets = targets, value = value
                                };
                                break;
                            }

                            case "cost":
                                card.Cost = card_node.InnerText;
                                break;
                            }
                        }
                        wonder.Tiers.Add(card);
                    }
                    yield return(wonder);
                }
            }
        }