Exemplo n.º 1
0
        public Minesweeper(int rowCount = 10, int colCount = 8, double percent = 0.10)
        {
            RowCount = rowCount;
            ColCount = colCount;
            Percent  = percent;

            Model = new MinesweeperModel(rowCount, colCount, percent);
            OverriddenInitializeComponent();
        }
Exemplo n.º 2
0
        private void Minesweeper_Load(object sender, EventArgs e)
        {
            _dataAccess = new MinesweeperFileDataAccess();

            _model             = new MinesweeperModel(_dataAccess);
            _model.PlayerLost += new EventHandler <MinesweeperEventArgs>(OnPlayerLost);
            _model.Draw       += new EventHandler(OnDraw);

            _windowSize = 360;
            _model.NewGame(6);
            GenerateTable();
        }
Exemplo n.º 3
0
        public static void Main(String[] args)
        {
            Console.WriteLine("Welcome to Minesweeper! how many bombs would you like to play with? (20 by 20 board)");

            int bombCount;

            while (!int.TryParse(Console.ReadLine(), out bombCount) || bombCount < 1 || bombCount > 399)
            {
                Console.WriteLine("That was not a valid number. Try again.");
            }

            MinesweeperModel model = new MinesweeperModel(bombCount);

            int row, col;

            do
            {
                Console.WriteLine(model.ToString());

                Console.WriteLine("Which row?");

                while (!int.TryParse(Console.ReadLine(), out row) || row < 0 || row >= 20)
                {
                    Console.WriteLine("Invalid row. please enter a number from 0 to 19");
                }

                Console.WriteLine("Which column?");

                while (!int.TryParse(Console.ReadLine(), out col) || col < 0 || col >= 20)
                {
                    Console.WriteLine("Invalid column. please enter a number from 0 to 19");
                }
            } while (model.Inspect(row, col) != null && !model.IsWinner());

            if (model.IsWinner())
            {
                Console.WriteLine("Congratulations! You win!");
            }

            else
            {
                Console.WriteLine("Sorry, you lose.");
            }

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        private void InitNewGame(MinesweeperModel.DifficultyLevels difficulty)
        {
            splitContainer1.Panel2.Controls.Clear();

            model = new MinesweeperModel(difficulty);

            comboBox1.Text = difficulty.ToString();

            buttons = new Button[model.Rows, model.Cols];
            AddButtons(model.Rows, model.Cols);

            Size = new Size(model.Cols * 37, model.Rows * 45);

            IsFirstButton = true;

            Counter          = 0;
            FlagsUnused.Text = $"{FLAG_EMOJI} = {model.NumOfFlags}";
        }
Exemplo n.º 5
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            IMinesweeperDataAccess dataAccess;

            dataAccess = new MinesweeperDbDataAccess("name=MinesweeperModel");

            _model = new MinesweeperModel(dataAccess);
            _model.NewGame(6);

            _viewModel = new MinesweeperViewModel(_model);
            _viewModel.LoadGameOpen  += new EventHandler(ViewModel_LoadGameOpen);
            _viewModel.LoadGameClose += new EventHandler <String>(ViewModel_LoadGameCloseAsync);
            _viewModel.SaveGameOpen  += new EventHandler(ViewModel_SaveGameOpen);
            _viewModel.SaveGameClose += new EventHandler <String>(ViewModel_SaveGameClose);

            _view             = new MainWindow();
            _view.DataContext = _viewModel;
            _view.Show();
        }