public void setGrid(gameType type, Difficulty level) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { dataGridView1.Rows[i].Cells[j].Value = ""; } } if (modoDeJuego != null || type == gameType.Standard) { if (modoDeJuego == null) { modoDeJuego = new ModoDeJuego(level); sudoku = modoDeJuego; } for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (modoDeJuego.mask[i, j] != 0) { dataGridView1.Rows[i].Cells[j].Value = modoDeJuego.mask[i, j]; } ColorMap[i, j] = Color.White; } } //this.Text += " - Standard " + (standard.diff == Difficulty.Easy ? "(easy) " : (standard.diff == Difficulty.Medium ? "(medium)" : "(hard)")); } LockCellMap(); }
private void startGame() { this.Text += " " + dificultadElegida; modoDeJuego = null; sudoku = null; gameType type; setStandardTableView(); type = gameType.Standard; Difficulty level = dificultadElegida; dataGridView1.Focus(); dataGridView1.ClearSelection(); clearHighlight(); setGrid(type, level); ticks = sudoku.ticks; timer1.Start(); }
private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (modoDeJuego == null) { System.Media.SystemSounds.Asterisk.Play(); return; } if (dataGridView1.SelectedCells.Count > 0) { var selected = dataGridView1.SelectedCells[0]; int sel_i = selected.RowIndex; int sel_j = selected.ColumnIndex; if (CellMap[sel_i, sel_j] == LOCKED) { if (!(e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)) { System.Media.SystemSounds.Asterisk.Play(); } return; } if (!(e.KeyValue >= 49 && e.KeyValue <= 57 || e.KeyValue >= 97 && e.KeyValue <= 105)) { if (e.KeyValue == 27 || e.KeyValue == 8 || e.KeyValue == 46) // Same as e.KeyCode == Keys.Enter etc. { selected.Value = ""; if (modoDeJuego != null) { modoDeJuego.grillaUsuario[selected.RowIndex, selected.ColumnIndex] = 0; } } else if (!(e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)) { System.Media.SystemSounds.Asterisk.Play(); } } else { int value = -1; if (e.KeyValue >= 49 && e.KeyValue <= 57) { selected.Value = e.KeyValue - 48; value = e.KeyValue - 48; } else { selected.Value = e.KeyValue - 96; value = e.KeyValue - 96; } if (modoDeJuego != null) { modoDeJuego.grillaUsuario[sel_i, sel_j] = value; } highlightSelectedNumber(); } } if ((modoDeJuego != null && Sudoku.estaResuelto(modoDeJuego.grillaUsuario, ModoDeJuego.esquema))) { timer1.Stop(); ColorearAVerde(); MessageBox.Show("FELICITACIONES ! NIVEL : " + dificultadElegida + " SUPERADO"); modoDeJuego = null; sudoku = null; } }