Exemplo n.º 1
0
        public void OnPostMove(int id, int x, int y)
        {
            var gameBoard = GameBoardEngine.GetGameBoardFromDb(id);

            if (!GameBoardEngine.GameBoardPanels.Any(e => e.IsRevealed))
            {
                GameBoardEngine.FirstMove(x, y, new Random(), gameBoard);
            }

            GameBoardEngine.RevealPanel(x, y, gameBoard);
            GameBoardEngine.UpdateGameBoard(gameBoard);
        }
Exemplo n.º 2
0
        static void MainGame(GameBoardEngine gameEngine, GameBoard game,
                             AppDbContext ctx, int userYint, int userXint, bool userCanceled, bool saveGame, bool plantFlag, string type)
        {
            do
            {
                Console.Clear();
                ConsoleUI.PrintBoard(gameEngine, game);

                (userYint, userCanceled, plantFlag, saveGame) = GetUserIntInput("Enter Y coordinate", 1, game.Height, 0, "F", "S");
                if (userCanceled)
                {
                    ClearConsoleIfUserCanceled(userCanceled);
                    break;
                }
                if (plantFlag)
                {
                    PlantFlag(gameEngine, game, plantFlag);
                }
                else if (saveGame)
                {
                    SaveGameIfUserSaved(gameEngine, game, saveGame, ctx, type);
                }
                else
                {
                    (userXint, userCanceled, _, _) = GetUserIntInput("Enter X coordinate", 1, game.Width, 0, null);
                    ClearConsoleIfUserCanceled(userCanceled);
                    if (!gameEngine.GameBoardPanels.Any(e => e.IsRevealed))
                    {
                        gameEngine.FirstMove(userXint, userYint, new Random(), game);
                    }
                    gameEngine.RevealPanel(userXint, userYint, game);
                }
            } while (game.Status == GameStatus.InProgress);

            switch (game.Status)
            {
            case GameStatus.Completed:
                Console.WriteLine("GAME WON");
                break;

            case GameStatus.Failed:
                ConsoleUI.PrintBoard(gameEngine, game);
                Console.WriteLine("GAME LOST!");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 3
0
        private static string NewGame()
        {
            var dbOption = new DbContextOptionsBuilder <AppDbContext>()
                           .UseSqlite("Data Source=/Users/maria/csharp2019fall/Proge/minesweeper/WebApp/app.db").Options;

            var ctx        = new AppDbContext(dbOption);
            var gameEngine = new GameBoardEngine(ctx);

            var userHeight       = 0;
            var userWidth        = 0;
            var userCanceledGame = false;

            (userHeight, userCanceledGame, _, _) = GetUserIntInput("Enter board height", 8, 64, 0);
            ClearConsoleIfUserCanceled(userCanceledGame);

            (userWidth, userCanceledGame, _, _) = GetUserIntInput("Enter board width", 8, 64, 0);
            ClearConsoleIfUserCanceled(userCanceledGame);


            var game = new GameBoard
            {
                Height    = userHeight,
                MineCount = 10,
                Width     = userWidth
            };

            gameEngine.CreateNewGameBoard(userHeight, userWidth, 10);

            ConsoleUI.PrintBoard(gameEngine, game);

            var userXint     = 0;
            var userYint     = 0;
            var userCanceled = false;
            var plantFlag    = false;
            var saveGame     = false;

            (userYint, userCanceled, _, _) = GetUserIntInput("Enter Y coordinate", 1, game.Height, 0);
            ClearConsoleIfUserCanceled(userCanceled);

            (userXint, userCanceled, _, _) = GetUserIntInput("Enter X coordinate", 1, game.Width, 0);
            ClearConsoleIfUserCanceled(userCanceled);

            gameEngine.FirstMove(userXint, userYint, new Random(), game);
            gameEngine.RevealPanel(userXint, userYint, game);

            MainGame(gameEngine, game, ctx, userYint, userXint, userCanceled, saveGame, plantFlag, "newGame");
            return("");
        }