private void Impossible_Click(object sender, EventArgs e) { FieldData.FullyOpened = false; FieldData.Closed = true; FieldUtils.GenerateEmptyField(EnumData.EDifficulty.Impossible); MainGlControl.Show(); RedrawField(false); }
private async Task ShowGameResult(EnumData.EGameResult result) { await Task.Factory.StartNew(() => { if (result == EnumData.EGameResult.None) { return; } BeginInvoke(new Action(() => { ResultRichTextBox.Font = new Font("Segoe UI", (int)(FieldData.CellsCountHeight * 4)); })); switch (result) { case EnumData.EGameResult.Win: BeginInvoke(new Action(() => { ResultRichTextBox.ForeColor = Color.DarkGreen; ResultRichTextBox.Text = "Вы\nпобедили!"; })); break; case EnumData.EGameResult.Lose: BeginInvoke(new Action(() => { ResultRichTextBox.ForeColor = Color.DarkRed; ResultRichTextBox.Text = "Вы\nпроиграли!"; })); break; } FieldUtils.OpenAllCells(); BeginInvoke(new Action(() => { ResultRichTextBox.Show(); })); do { Thread.Sleep(100); } while (ResultRichTextBox.Visible); }); }
private void MainGlControl_MouseClick(object sender, MouseEventArgs e) { int x = e.X; int y = MainGlControl.Height - e.Y; switch (e.Button) { case MouseButtons.Left: if (FieldData.Closed) { FieldUtils.FillField(x / 32, y / 32); FieldData.Closed = false; } FieldUtils.OpenCell(x / 32, y / 32); RedrawField(false); break; case MouseButtons.Right: FieldUtils.MarkCell(x / 32, y / 32); RedrawField(false); break; } }
private async void RedrawField(bool fromControl) { if (!MainGlControl.Created) { return; } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); //GL.MatrixMode(MatrixMode.Modelview); //GL.LoadIdentity(); if (!fromControl) { if (FieldData.FullyOpened) { MainGlControl.Hide(); return; } } if (!fromControl) { await ShowGameResult(FieldUtils.CheckGameResult()); } int x = 2; int y = 2; int cellSize = 30; for (int cellX = 0; cellX < FieldData.CellsCountWight; cellX++) { int tempY = y; for (int cellY = 0; cellY < FieldData.CellsCountHeight; cellY++) { Color color = Color.DarkGray; int textureId = 0; if (FieldData.FieldArray[cellX, cellY].Marked) { textureId = (int)EnumData.ETexturesTypes.Mark; color = Color.Gold; } if (FieldData.FieldArray[cellX, cellY].Opened) { color = Color.White; if (FieldData.FieldArray[cellX, cellY].Mined) { textureId = (int)EnumData.ETexturesTypes.Mine; //color = FieldData.Completed ? Color.Green : Color.Red; color = FieldData.FieldArray[cellX, cellY].Mined && FieldData.FieldArray[cellX, cellY].Marked ? Color.Green : Color.Red; } if (FieldData.FieldArray[cellX, cellY].MinesNear > 0) { textureId = FieldData.FieldArray[cellX, cellY].MinesNear; } } DrawField(new PointF(x, y), new Size(cellSize, cellSize), textureId, color); y = y + cellSize + 2; } x = x + cellSize + 2; y = tempY; } MainGlControl.SwapBuffers(); }