// Kliknutí na políčko herní desky protected void cell_Click(object sender, MouseEventArgs e) { AxisButton b = sender as AxisButton; // Pravé myšítko (od)označí minu if (e.RightButton == MouseButtonState.Pressed) { this.m.toggleMark(b.Axis.x, b.Axis.y); } // Levé myšítko otevře políčko else if (e.LeftButton == MouseButtonState.Pressed) { this.m.stepOn(b.Axis.x, b.Axis.y); // Pokud uživatel stoupl na minu if (this.m.toBeOrNotToBe(b.Axis.x, b.Axis.y)) { this.lockControls(); MessageBox.Show( "Stoupl jste na minu a umřete za 3... 2... 1...\n" + "Smůla. Jste mrtvý. Zkuste to znovu :-)" ); } } this.refreshValues(); this.refreshStats(); }
// Na herní desku vypíše jednotlivé buňky protected void printBoard() { for (int i = 0; i < this.m.size; i++) { // Vytvoříme panel, který bude odpovídat řádku tabulky StackPanel row = new StackPanel(); row.Orientation = Orientation.Horizontal; for (int j = 0; j < this.m.size; j++) { // Vytvoříme nové políčko Cell c = this.m.cells.get(j, i); AxisButton b = new AxisButton() { Height = 25, Width = 25, Content = "", Axis = c.axis, }; // Po kliknutí na políčko bude zavolána metoda cell_Click(...) b.PreviewMouseDown += new MouseButtonEventHandler(cell_Click); // A přidáme ho do řádku row.Children.Add(b); } // Přidáme řádek do herní desky this.board.Children.Add(row); } }