示例#1
0
 private void PrepareText(EpizodeXML epizode, LinearLayout lay)
 {
     TextView ivue = new TextView(this);
     ivue.Text = Crypto.Decrypt(epizode.Text, "pass");
     ivue.SetPadding(10, 0, 10, 0);
     ivue.SetTextSize(Android.Util.ComplexUnitType.Dip, 14);
     lay.AddView(ivue);
 }
示例#2
0
 private void PrepareDecisions(EpizodeXML epizode, LinearLayout lay)
 {
     if (epizode.Choices != null)
     {
         var choices = epizode.Choices.Decisions;
         foreach (var choice in choices)
         {
             this.CreateButton(choice, lay);
         }
     }
 }
示例#3
0
        private void PrepareImage(EpizodeXML epizode, LinearLayout lay)
        {
            if (epizode.image == null)
            {
                return;
            }
            var bmp = this.bytesToUIImage(epizode.image);

            ImageView ivue = new ImageView(this);
            ivue.SetImageBitmap(bmp);
            lay.AddView(ivue);
        }
示例#4
0
 private void PrepareChoices(EpizodeXML epizode, LinearLayout lay)
 {
     this.PrepareDecisions(epizode, lay);
     this.PrepareChances(epizode, lay);
     this.PrepareBattle(epizode, lay);
     this.PrepareConditions(epizode, lay);
 }
示例#5
0
        private void PrepareConditions(EpizodeXML epizode, LinearLayout lay)
        {
            var conditions = epizode.Choices.Conditions;
            foreach (var cond in conditions)
            {
                var predicates = cond.Predicates;
                var pass = true;
                foreach (var pred in predicates)
                {
                    var type = pred.Type;
                    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, lay);
                    break;
                }
            }
        }
示例#6
0
        private void PrepareChances(EpizodeXML epizode, LinearLayout lay)
        {
            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;//double.Parse(chance.Attribute(Probability).Value, System.Globalization.NumberStyles.AllowDecimalPoint);
                    if (r < tillNow)
                    {
                        Button btn = new Button(this);
                        btn.Click += this.Click;
                        btn.Text = chance.Text;
                        btn.Tag = chance.GoTo;
                        btn.SetTextSize(Android.Util.ComplexUnitType.Dip, 14);
                        lay.AddView(btn);
                        break;
                    }
                }
            }
        }
示例#7
0
 private void PrepareBattle(EpizodeXML epizode, LinearLayout lay)
 {
     var choices = epizode.Choices.Battles;
     foreach (var choice in choices)
     {
         this.CreateBattleButton(choice, lay);
     }
 }
示例#8
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);
                    }
                }
            }
        }
示例#9
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);
         }
     }
 }
示例#10
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();
            }
        }