コード例 #1
0
ファイル: ValidationUtils.cs プロジェクト: julijak/Tetrakom
 public static bool checkField(Form form, Panel gridPanel)
 {
     int redCount = 0;
     int greenCount = 0;
     int yellowCount = 0;
     int blueCount = 0;
     int bonusCount = 0;
     List<CellDTO> cells = new List<CellDTO>(gridPanel.Controls.Count);
     foreach (Control control in gridPanel.Controls) {
         Cell cell = control as Cell;
         CellDTO dto = new CellDTO(cell.BackColor.ToArgb());
         cells.Add(dto);
         switch (cell.BackColor.Name) {
             case "Red": redCount++;
                 break;
             case "Green": greenCount++;
                 break;
             case "Yellow": yellowCount++;
                 break;
             case "Blue": blueCount++;
                 break;
             default:
                 if (cell.BackgroundImage != null && cell.BackgroundImage == Properties.Resources.bonusImg) {
                     bonusCount++;
                 }
                 break;
         }
     }
     if (redCount != 12 || yellowCount != 12 || greenCount != 12 || blueCount != 12 || bonusCount != 1) {
         MessageBox.Show(form, "Неправильно заданы фигуры", "Ошибка", MessageBoxButtons.OK);
         return false;
     }
     return true;
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: julijak/Tetrakom
 private void saveFileDialog_FileOk(object sender, CancelEventArgs e)
 {
     var path = saveFileDialog.FileName;
     List<CellDTO> cells = new List<CellDTO>(gridPanel.Controls.Count);
     foreach (Control control in gridPanel.Controls) {
         Cell cell = control as Cell;
         CellDTO dto = new CellDTO(cell.BackColor.ToArgb());
         cells.Add(dto);
     }
     FileUtils.saveToFile(path, cells);
 }