private void button2_Click_1(object sender, EventArgs e)
        {
            ColorDialog cd = new ColorDialog();

            if (cd.ShowDialog() == DialogResult.OK)
            {
                ColorDialog cdDop = new ColorDialog();
                if (cdDop.ShowDialog() == DialogResult.OK)
                {
                    var fish  = new TigerShark(10, 10, 300, cd.Color, cdDop.Color);
                    int place = ocean.PutFishInOcean(fish);
                    Draw();
                    MessageBox.Show("Ваше место: " + place);
                }
            }
        }
Exemplo n.º 2
0
 public bool LoadData(string filename)
 {
     if (!File.Exists(filename))
     {
         return(false);
     }
     using (FileStream fs = new FileStream(filename, FileMode.Open))
     {
         string s = "";
         using (BufferedStream bs = new BufferedStream(fs))
         {
             byte[]       b    = new byte[fs.Length];
             UTF8Encoding temp = new UTF8Encoding(true);
             while (bs.Read(b, 0, b.Length) > 0)
             {
                 s += temp.GetString(b);
             }
         }
         s = s.Replace("\r", "");
         var strs = s.Split('\n');
         if (strs[0].Contains("CountLevels"))
         {
             int count = Convert.ToInt32(strs[0].Split(':')[1]);
             if (oceanLevels != null)
             {
                 oceanLevels.Clear();
             }
             oceanLevels = new List <ClassArray <IAnimal> >(count);
         }
         else
         {
             throw new FileFormatException();
         }
         int counter = -1;
         for (int i = 1; i < strs.Length; ++i)
         {
             if (strs[i] == "Level")
             {
                 counter++;
                 oceanLevels.Add(new ClassArray <IAnimal>(countPlaces, null));
             }
             else if (strs[i].Split(':')[0] == "Shark")
             {
                 IAnimal shark  = new Shark(strs[i].Split(':')[1]);
                 int     number = oceanLevels[counter] + shark;
                 if (number == -1)
                 {
                     throw new FileFormatException();
                 }
             }
             else if (strs[i].Split(':')[0] == "TigerShark")
             {
                 IAnimal shark  = new TigerShark(strs[i].Split(':')[1]);
                 int     number = oceanLevels[counter] + shark;
                 if (number == -1)
                 {
                     throw new FileFormatException();
                 }
             }
         }
     }
     return(true);
 }