Beispiel #1
0
        public static Opponent[] GetOpponents()
        {
            List<Opponent> opponents = new List<Opponent>();

            // Read In XML
            XmlTextReader reader = new XmlTextReader(@"resources/Opponents.xml");
            XmlDocument opponentInfo = new XmlDocument();
            opponentInfo.Load(reader);
            reader.Close();

            // Create Opponents List
            foreach (XmlNode opponentTag in opponentInfo.GetElementsByTagName("Opponent"))
            {
                try
                {
                    Opponent opponent = new Opponent();
                    opponent.Name = opponentTag.Attributes["name"].Value;
                    opponent.ImgLoc = opponentTag.Attributes["img"].Value;

                    switch (opponentTag.Attributes["difficulty"].Value.ToUpper())
                    {
                        case "NORMAL":
                            opponent.Difficulty = AIDifficulty.NORMAL;
                            break;
                        case "HARD":
                            opponent.Difficulty = AIDifficulty.HARD;
                            break;
                        default:
                            opponent.Difficulty = AIDifficulty.EASY;
                            break;
                    }

                    opponents.Add(opponent);
                }
                catch (Exception) { }
            }
            return opponents.ToArray();
        }
        private ListBoxItem GetOpponentItem(Opponent opp)
        {
            Image img = new Image();
            img.Source = new BitmapImage(new Uri(PLAYER_IMG_PATH + "\\" + opp.ImgLoc, UriKind.Relative));
            img.Stretch = Stretch.Uniform;

            Label lbl = new Label();
            lbl.VerticalAlignment = VerticalAlignment.Center;
            lbl.FontSize = 18;
            lbl.FontWeight = FontWeights.Bold;
            lbl.Content = opp.Name;

            DockPanel dock = new DockPanel();
            dock.Height = 50;
            dock.Margin = new Thickness(0,2,0,2);
            dock.Children.Add(img);
            dock.Children.Add(lbl);

            ListBoxItem imgItem = new ListBoxItem();
            imgItem.Background = new SolidColorBrush(GetOpponentColor(opp.Difficulty));
            imgItem.Content = dock;
            return imgItem;
        }