private void btnGenerateGame_Click_1(object sender, RoutedEventArgs e)
        {
            Game Game = new Game();
            Game.lstStats = Globals.GameElements.StartupStats;
            Game.lstEpizodes = new List<EpizodeXML>();
            foreach (RadDiagramShape sh in this.diagram.Shapes)
            {
                if (sh.Tag != null)
                {
                    EpizodeXML Ep = new EpizodeXML();
                    Epizode Source = sh.Tag as Epizode;

                    Ep.ID = Source.EpizodeNumber;
                    Ep.Inventories = Source.lstInventories;
                    Ep.Skills = Source.lstSkills;
                    Ep.Stats = Source.lstStats;
                    Ep.Text = Crypto.Encrypt(Source.EpizodeText, "pass");
                    Ep.image = Source.LargeIconSerialized;
                    Ep.Choices = new Choices();

                    Game.lstEpizodes.Add(Ep);
                }
            }

            foreach (RadDiagramConnection con in this.diagram.Connections)
            {
                var source = con.Source as RadDiagramShape;
                Epizode Epizode;
                try
                {
                    Epizode = source.Tag as Epizode;
                }
                catch
                {
                    this.diagram.SelectedItem = con;
                    MessageBox.Show("Hanging connection");
                    return;

                }
                var EpizodeXML = Game.lstEpizodes.FirstOrDefault(ep => ep.ID == Epizode.EpizodeNumber);
                var Choice = con.Content as ConnectionXML;
                if (EpizodeXML.Choices == null)
                {
                    EpizodeXML.Choices = new Choices();
                }
                try {
                    switch (Choice.Type)
                    {
                        case ConnectionTypes.eDecision:
                            Choice.Decision.GoTo = ((Epizode)((RadDiagramShape)con.Target).Tag).EpizodeNumber;
                            EpizodeXML.Choices.Decisions.Add(Choice.Decision);
                            break;
                        case ConnectionTypes.eChance:
                            Choice.Chance.GoTo = ((Epizode)((RadDiagramShape)con.Target).Tag).EpizodeNumber;
                            EpizodeXML.Choices.Chances.Add(Choice.Chance);
                            break;
                        case ConnectionTypes.eBattle:
                            Choice.Battle.GoTo = ((Epizode)((RadDiagramShape)con.Target).Tag).EpizodeNumber;
                            EpizodeXML.Choices.Battles.Add(Choice.Battle);
                            break;
                        case ConnectionTypes.eCondition:
                            Choice.Condition.GoTo = ((Epizode)((RadDiagramShape)con.Target).Tag).EpizodeNumber;
                            EpizodeXML.Choices.Conditions.Add(Choice.Condition);
                            break;
                        case ConnectionTypes.eChanceRollback:
                            Choice.Condition.GoTo = ((Epizode)((RadDiagramShape)con.Target).Tag).EpizodeNumber;
                            EpizodeXML.Choices.Conditions.Add(Choice.Condition);
                            break;
                        case ConnectionTypes.eInventoryCondition:
                            EpizodeXML.Choices.InventoryConditions.Add(Choice.InventoryCondition);
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                catch
                {
                    this.diagram.SelectedItem = con;
                    MessageBox.Show("Hanging destination connection");
                    return;
                }
            }

            var dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == true)
            {
                var nam = dialog.FileName;
                XmlSerializer serializer = new XmlSerializer(typeof(Game));
                TextWriter writ = new StreamWriter(nam);

                serializer.Serialize(writ, Game);
                writ.Close();
            }
        }
Exemple #2
0
 public void CreateAnInstanceOfGame()
 {
     GameClasses.Game game = new GameClasses.Game();
     Assert.IsType <GameClasses.Game>(game);
 }
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            //this.GameSource = XElement.Load("game.xml");
            XmlSerializer serializer = new XmlSerializer(typeof(Game));

            FileStream fs = new FileStream("game.xml", FileMode.Open);
            this.GameSource = (Game)serializer.Deserialize(fs);
            fs.Close();

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");

            this.Game = new SaveGameData();
            this.isLoadedGame = this.LoadGame("Autosave.xml");
            if (isLoadedGame == false)
            {
                this.InitializeGame();
            }

            this.ExecuteEpizode(this.Game.CurrentEpizode);
        }