示例#1
0
        private void Save(object sender, RoutedEventArgs e)
        {
            switch (CurrentMode)
            {
            case "Description":
                NewDungeon.SetDescription(MainData.Text);
                break;

            case "Answer":
                NewDungeon.SetAnswer(MainData.Text);
                break;

            case "Enter":
                NewDungeon.SetToenter(MainData.Text);
                break;

            case "EncounterDescription":
                NewDungeon.GetEncounters[EncounterList.SelectedIndex].SetDis(MainData.Text);
                break;

            case "EncounterName":
                //need to rewrite(maybe)
                NewDungeon.GetEncounters[EncounterList.SelectedIndex].SetName(MainData.Text);
                EncounterList.Items.Clear();
                foreach (Encounter enc in NewDungeon.GetEncounters)
                {
                    EncounterList.Items.Add(enc.Name);
                }
                break;

            case "ActionDis":
                NewDungeon.GetEncounters[EncounterList.SelectedIndex].GetActions[ActionList.SelectedIndex].SetDis(MainData.Text);
                break;

            case "ActionCons":
                NewDungeon.GetEncounters[EncounterList.SelectedIndex].GetActions[ActionList.SelectedIndex].SetCons(MainData.Text);
                break;
            }
        }
示例#2
0
        public Dungeon Loader(string filePath)
        {
            Dungeon      Dungeon = new Dungeon();
            FileStream   fs      = new FileStream(filePath, FileMode.Open);
            StreamReader sr      = new StreamReader(fs, Encoding.UTF8);
            string       data    = "";

            while (data != "<End>")
            {
                data = sr.ReadLine();
                switch (data)
                {
                case "<Map-BitMap>":
                    int w = Convert.ToInt32(sr.ReadLine());
                    int h = Convert.ToInt32(sr.ReadLine());
                    Dungeon.image = new byte[w, h, 3];
                    File.Create(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\DungeonCreator\\test111");

                    Bitmap bm = new Bitmap(w, h);
                    for (int i = 0; i != h; i++)
                    {
                        for (int j = 0; j != w; j++)
                        {
                            int r = 0;
                            int a = sr.Read() - 48;
                            if (a < 0)
                            {
                                a = sr.Read();
                                a = sr.Read() - 48;
                            }
                            switch (a)
                            {
                            case 3:
                            {
                                int t = 0;
                                t += (sr.Read() - 48) * 100;
                                t += (sr.Read() - 48) * 10;
                                t += (sr.Read() - 48);
                                r  = t;
                                break;
                            }

                            case 2:
                            {
                                int t = 0;
                                t += (sr.Read() - 48) * 10;
                                t += (sr.Read() - 48);
                                r  = t;
                                break;
                            }

                            case 1:
                            {
                                int t = 0;
                                t += (sr.Read() - 48);
                                r  = t;
                                break;
                            }

                            default:
                                break;
                            }
                            int g = 0;
                            a = sr.Read() - 48;
                            switch (a)
                            {
                            case 3:
                            {
                                int t = 0;
                                t += (sr.Read() - 48) * 100;
                                t += (sr.Read() - 48) * 10;
                                t += (sr.Read() - 48);
                                g  = t;
                                break;
                            }

                            case 2:
                            {
                                int t = 0;
                                t += (sr.Read() - 48) * 10;
                                t += (sr.Read() - 48);
                                g  = t;
                                break;
                            }

                            case 1:
                            {
                                int t = 0;
                                t += (sr.Read() - 48);
                                g  = t;
                                break;
                            }
                            }
                            int b = 0;
                            a = sr.Read() - 48;
                            switch (a)
                            {
                            case 3:
                            {
                                int t = 0;
                                t += (sr.Read() - 48) * 100;
                                t += (sr.Read() - 48) * 10;
                                t += (sr.Read() - 48);
                                b  = t;
                                break;
                            }

                            case 2:
                            {
                                int t = 0;
                                t += (sr.Read() - 48) * 10;
                                t += (sr.Read() - 48);
                                b  = t;
                                break;
                            }

                            case 1:
                            {
                                int t = 0;
                                t += (sr.Read() - 48);
                                b  = t;
                                break;
                            }

                            default:
                                break;
                            }
                            Color c = Color.FromArgb(255, r, g, b);
                            Dungeon.image[j, i, 0] = (byte)r;
                            Dungeon.image[j, i, 1] = (byte)g;
                            Dungeon.image[j, i, 2] = (byte)b;
                            r = 0;
                            g = 0;
                            b = 0;
                            bm.SetPixel(j, i, c);
                        }
                    }
                    Dungeon.map = bm;
                    // bm.Save(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\DungeonCreator\\test111.png");
                    break;

                case "<Name>":
                    Dungeon.SetName(sr.ReadLine());
                    break;

                case "<Discription>":
                    Dungeon.SetDescription(sr.ReadLine());
                    break;

                case "<ToEnter>":
                    Dungeon.SetToenter(sr.ReadLine());
                    break;

                case "<Answer>":
                    Dungeon.SetAnswer(sr.ReadLine());
                    break;

                case "<Encounters>":
                {
                    string a = "";

                    while (a != "<EndEncounter>")
                    {
                        a = sr.ReadLine();
                        switch (a)
                        {
                        case "<EncounterName>":
                            Dungeon.AddNewEncounter("load");
                            Dungeon.GetEncounters[Dungeon.encountersLength - 1].SetName(sr.ReadLine());
                            break;

                        case "<Discription>":
                            Dungeon.GetEncounters[Dungeon.encountersLength - 1].SetDis(sr.ReadLine());
                            break;

                        case "<Actions>":
                            for (int i = 0; i != 4; i++)
                            {
                                sr.ReadLine();
                                Dungeon.GetEncounters[Dungeon.encountersLength - 1].GetActions[i].SetDis(sr.ReadLine());
                                sr.ReadLine();
                                Dungeon.GetEncounters[Dungeon.encountersLength - 1].GetActions[i].SetCons(sr.ReadLine());
                            }
                            break;
                        }
                    }

                    break;
                }

                default:
                    break;
                }
            }
            return(Dungeon);
        }