コード例 #1
0
        private void StartGame()
        {
            gameOver = false;
            newGameLabel.Hidden = true;

            game = new MineSweeperGame (NUMCOLS, NUMROWS, NUMMINES, bDoQuestioned, (MineSweeperGame g, bool forced) => {

                Point p = TileForTag (pressedTag);
                UIButton lastPressed = tiles [p.X, p.Y];

                if (!forced && g.isGameOver()) {
                    gameOver = true;
                    cheating = false;
                    newGameLabel.Hidden = false;
                    if (g.wasGameWon ()) {
                        winSound.PlaySystemSound ();
                    } else {
                        bombSound.PlaySystemSound ();
                    }
                }

                ShowScore(g);

                for (int col = 0; col < NUMCOLS; col++) {
                    for (int row = 0; row < NUMROWS; row++) {
                        UIButton tile = tiles [col, row];
                        //Console.WriteLine("Tile = {0:X} LastPressed = {1:X}", tile, lastPressed);
                        int value = g.GetTileValue(col, row);

                        MineSweeperGame.DrawType draw = g.GetDrawType(col, row);

                        switch (draw) {
                        case MineSweeperGame.DrawType.Covered:
                            if (cheating  || gameOver) {
                                if (value == 0xFFFF) {
                                    if (cheating && !gameOver) {
                                        tile.SetImage(cheatTile, UIControlState.Normal);
                                    } else {
                                        tile.SetImage(mineTile, UIControlState.Normal);
                                    }
                                } else {
                                    tile.SetImage(coveredTile, UIControlState.Normal);
                                }
                            } else {
                                tile.SetImage(coveredTile, UIControlState.Normal);
                            }
                            break;

                        case MineSweeperGame.DrawType.Flagged:
                            if (cheating && value == 0xFFFF) {
                                tile.SetImage(flaggedCheatTile, UIControlState.Normal);
                            } else if (gameOver && value == 0xFFFF) {
                                tile.SetImage(mineTile, UIControlState.Normal);
                            } else {
                                tile.SetImage(flaggedTile, UIControlState.Normal);
                            }
                            break;

                        case MineSweeperGame.DrawType.Questioned:
                            if (cheating && value == 0xFFFF) {
                                tile.SetImage(questionCheatTile, UIControlState.Normal);
                            } else {
                                tile.SetImage(questionTile, UIControlState.Normal);
                            }
                            break;

                        case MineSweeperGame.DrawType.Value:
                            tile.SetImage(numberTiles [value], UIControlState.Normal);
                            break;

                        case MineSweeperGame.DrawType.Mine:
                            if (gameOver && tile == lastPressed) {
                                tile.SetImage(redmineTile, UIControlState.Normal);
                            } else {
                                tile.SetImage(mineTile, UIControlState.Normal);
                            }
                            break;
                        }
                    }
                }

                return true;
            });
        }
コード例 #2
0
        private void ShowScore(MineSweeperGame g)
        {
            int currentScore = g.GetCurrentScore ();
            if (currentScore > highScore) {
                highScore = currentScore;
                preferences.Put(HIGHSCOREKEY, highScore.ToString());
            }

            currentScoreLabel.Text = currentScore.ToString ();
            highScoreLabel.Text = highScore.ToString ();
        }