예제 #1
0
        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();
            }
        }
예제 #2
0
 private void PrepareText(EpizodeXML epizode)
 {
     //var EpizodeContents = new FlowDocumentScrollViewer();
     var Flowdoc = new FlowDocument();
     Paragraph para = new Paragraph();
     para.Inlines.Add(epizode.ID + "\n" + Crypto.Decrypt(epizode.Text, "pass"));
     Flowdoc.Blocks.Add(para);
     //this.txtEpizodeContents = new FlowDocumentScrollViewer();
     this.txtEpizodeContents.Document = Flowdoc;
     //this.txtEpizodeContents
 }
예제 #3
0
 private void AddRemoveItems(EpizodeXML epizode)
 {
     var invs = epizode.Inventories;
     foreach (var inv in invs)
     {
         var name = inv.Name;
         int qty = inv.Quantity;
         if (inv.Action == true)
         {
             AddInventoryItem(name, qty);
         }
         else
         {
             RemoveInventoryItem(name, qty);
         }
     }
 }
예제 #4
0
        private void PrepareInventory(EpizodeXML epizode)
        {
            var InventoryConditions = epizode.Choices.InventoryConditions;
            foreach (var invent in InventoryConditions)
            {
                var name = invent.Name;
                bool aval = invent.IsAvailable;

                if (aval == true)
                {
                    int qty = invent.Quantity;

                    var inv = this.Game.lstInventory.Find(i => i.Name == name);
                    if (inv != null)
                    {
                        if (inv.Quantity >= qty)
                        {
                            this.CreateButton(invent);
                        }
                    }
                }
                else
                {
                    var inv = this.Game.lstInventory.Find(i => i.Name == name);
                    if (inv == null || inv.Quantity == 0)
                    {
                        this.CreateButton(invent);
                    }
                }
            }
        }
예제 #5
0
        private void PrepareRollBacks(EpizodeXML epizode)
        {
            var conditions = epizode.Choices.ChanceRollBacks;
            foreach (var cond in conditions)
            {
                var predicates = cond.Predicates;
                var pass = true;
                foreach (var pred in predicates)
                {
                    var type = pred.Type;
                    if (type == PredicateTypes.eInventory)
                    {
                        var name = pred.Name;

                        bool aval = pred.IsAvailable;

                        switch (pred.Type)
                        {
                            case PredicateTypes.eInventory:
                                {
                                    var inv = this.Game.lstInventory.Find(i => i.Name == name);

                                    if (aval == true)
                                    {
                                        int qty = pred.Quantity;

                                        if (inv == null || inv.Quantity < qty)
                                        {
                                            pass = false;
                                        }
                                    }
                                    else
                                    {
                                        if (inv != null && inv.Quantity != 0)
                                        {
                                            pass = false;
                                        }
                                    }
                                    break;
                                }
                            case PredicateTypes.eStat:
                                {
                                    var inv = this.Game.lstStats.Find(i => i.Name == name);
                                    int qty = pred.Quantity;
                                    if (aval == true)
                                    {
                                        if (inv == null || inv.Value < qty)
                                        {
                                            pass = false;
                                        }
                                    }
                                    else
                                    {
                                        if (inv != null && inv.Value > qty)
                                        {
                                            pass = false;
                                        }
                                    }
                                    break;
                                }
                        }

                    }
                }
                if (pass)
                {
                    this.CreateButton(cond);
                    break;
                }
            }
        }
예제 #6
0
 private void PrepareDecisions(EpizodeXML epizode)
 {
     if (epizode.Choices != null)
     {
         var choices = epizode.Choices.Decisions;
         foreach (var choice in choices)
         {
             this.CreateButton(choice);
         }
     }
 }
예제 #7
0
        private void PrepareChoices(EpizodeXML epizode)
        {
            this.spButtons.Children.Clear();

            this.PrepareDecisions(epizode);
            this.PrepareChances(epizode);
            this.PrepareBattle(epizode);
            this.PrepareInventory(epizode);
            this.PrepareConditions(epizode);
        }
예제 #8
0
        private void PrepareChances(EpizodeXML epizode)
        {
            if (epizode.Choices != null)
            {
                Random rand = new Random(DateTime.Now.Second);
                var r = rand.NextDouble();
                var chances = epizode.Choices.Chances;

                var cnt = chances.Count();
                double tillNow = 0;

                foreach (var chance in chances)
                {
                    tillNow += chance.Probability;
                    if (r < tillNow)
                    {
                        this.CreateButton(chance);
                        break;
                    }
                }
            }
        }
예제 #9
0
 private void PrepareBattle(EpizodeXML epizode)
 {
     var choices = epizode.Choices.Battles;
     foreach (var choice in choices)
     {
         this.CreateBattleButton(choice);
     }
 }
예제 #10
0
        private void AddRemoveStats(EpizodeXML epizode)
        {
            var stats = epizode.Stats;
            foreach (var stat in stats)
            {
                var name = stat.Name;
                int qty = stat.Quantity;

                if (stat.Reset == true)
                {
                    int resetqty = Game.lstStats.Find(s => s.Name == "Initial" + stat.Name).Value;

                    this.ResetStat(stat.Name, resetqty);
                }
                else
                {
                    if (stat.Action == true)
                    {
                        this.AddStat(name, qty);
                    }
                    else
                    {
                        this.RemoveStat(name, qty);
                    }
                }
            }
        }