コード例 #1
0
        private void SetLiner_Click(object sender, EventArgs e)
        {
            ColorDialog dialog = new ColorDialog();

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ColorDialog dialogDop = new ColorDialog();
                if (dialogDop.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var car = new CruiseLiner(10, 100, 1000, dialog.Color, true, true, true, dialogDop.Color, true, true);

                    int place = prichal.PutShipInPrichal(car);
                    Draw();
                    log.Info("Ваше место: " + place);
                }
            }
        }
コード例 #2
0
        public bool LoadData(string filename)
        {
            try {
                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');
                    try {
                        strs[0].Contains("CountLeveles:");
                        //считываем количество уровней
                        int count = Convert.ToInt32(strs[0].Split(':')[1]);
                        if (prichalStages != null)
                        {
                            prichalStages.Clear();
                        }

                        prichalStages = new List <ClassArray <ITransport> >(count);
                    }
                    catch (Exception) {
                        //если нет такой записи, то это не те данные
                        throw new DataErrorException();
                    }
                    int counter = -1;
                    for (int i = 1; i < strs.Length; ++i)
                    {
                        if (strs[i] == "Level")
                        {
                            counter++;
                            prichalStages.Add(new ClassArray <ITransport>(countPlaces, null));
                        }
                        else if (strs[i].Split(':')[0] == "Ship")
                        {
                            ITransport ship   = new Ship(strs[i].Split(':')[1]);
                            int        number = prichalStages[counter] + ship;
                            if (number == -1)
                            {
                                MessageBox.Show("Корабль -1", "", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false);
                            }
                        }
                        else if (strs[i].Split(':')[0] == "CruiseLiner")
                        {
                            ITransport ship   = new CruiseLiner(strs[i].Split(':')[1]);
                            int        number = prichalStages[counter] + ship;
                            if (number == -1)
                            {
                                MessageBox.Show("Лайнер -1", "", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false);
                            }
                        }
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                throw new FileNotFoundException(ex.Message + "Файл не существует");
            }
            catch (DirectoryNotFoundException ex)
            {
                throw new DirectoryNotFoundException(ex.Message + "Директории не существует");
            }
            catch (DriveNotFoundException ex)
            {
                throw new DriveNotFoundException(ex.Message + "Попытка доступа к недоступному диску или данным совместного использования");
            }
            catch (EndOfStreamException ex)
            {
                throw new EndOfStreamException(ex.Message + "Попытка чтения за концом потока.");
            }
            catch (InternalBufferOverflowException ex)
            {
                throw new InternalBufferOverflowException(ex.Message + "Буфер переполнен!");
            }
            catch (InvalidDataException ex)
            {
                throw new InvalidDataException(ex.Message + "Недопустимый формат данных");
            }
            return(false);
        }