示例#1
0
        public void btnEasyModeClicked(object sender, RoutedEventArgs e)
        {
            this.drawCells(easySize);
            Minesweeper.getInstance().initGame(easySize, easyBombs);

            Console.WriteLine(Minesweeper.getInstance());
        }
示例#2
0
        public void No_rows()
        {
            var minefield = Array.Empty <string>();
            var expected  = Array.Empty <string>();

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#3
0
 public void Timer1_Elapsed(object sender, EventArgs e)
 {
     if (!Minesweeper.firstClick)
     {
         Minesweeper.DecreaseTime(-1);
     }
 }
示例#4
0
 public static void Main(string[] args)
 {
     using (var game = new Minesweeper())
     {
         game.Run();
     }
 }
示例#5
0
        public GameObject()
        {
            Game        = Minesweeper.Instance;
            SpriteBatch = Game.SpriteBatch;

            Children   = new List <GameObject>();
            Coroutines = new List <IEnumerator>();
        }
示例#6
0
 public static Minesweeper getInstance()
 {
     if (self == null)
     {
         self = new Minesweeper();
     }
     return(self);
 }
示例#7
0
 public MinesweeperBoard(int size)
 {
     InitializeComponent();
     this.m      = new Minesweeper.Minesweeper();
     this.m.size = size;
     this.m.generateMines();
     this.printBoard();
     this.refreshStats();
 }
示例#8
0
        private void Mouse_Right_Click(object sender, MouseButtonEventArgs e)
        {
            Button b   = (Button)sender;
            int    col = Grid.GetColumn(b);
            int    row = Grid.GetRow(b);

            Minesweeper.RightClick(col, row);
            Render();
        }
示例#9
0
        private void Mouse_Left_Click(object sender, RoutedEventArgs e)
        {
            Button b   = (Button)sender;
            int    col = Grid.GetColumn(b);
            int    row = Grid.GetRow(b);

            Minesweeper.LeftClick(col, row);
            Render();
        }
 public MinesweeperBoard(int size)
 {
     InitializeComponent();
     this.m = new Minesweeper.Minesweeper();
     this.m.size = size;
     this.m.generateMines();
     this.printBoard();
     this.refreshStats();
 }
示例#11
0
 static void Main(string[] args)
 {
     while (true)
     {
         Minesweeper ms = new Minesweeper(40, 20, 100);
         ms.Start();
         Console.ReadKey(true);
         Console.Clear();
     }
 }
 public MinesweeperController(Minesweeper gui, Board board)
 {
     this.board     = board;
     this.gui       = gui;
     BombsRemaining = board.AmountOfBombs;
     SquareList     = board.GetSquaresList();
     bombImage      = new Bitmap(new Bitmap(@"..\..\bomb-icon.png"), gui.buttonArray[0, 0].Width - 5, gui.buttonArray[0, 0].Height - 5);
     flagImage      = new Bitmap(new Bitmap(@"..\..\flag-icon.png"), gui.buttonArray[0, 0].Width - 5, gui.buttonArray[0, 0].Height - 5);
     SetUpButtonHandlers();
     gui.setLabelText("Bombs Remaining: " + BombsRemaining);
 }
示例#13
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Board board = new Board(25, 25, 100);

            board.start();
            Minesweeper           gui        = new Minesweeper(board);
            MinesweeperController controller = new MinesweeperController(gui, board);

            Application.Run(gui);
        }
示例#14
0
        public void Horizontal_line()
        {
            var minefield = new[]
            {
                " * * "
            };
            var expected = new[]
            {
                "1*2*1"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#15
0
        public void No_columns()
        {
            var minefield = new[]
            {
                ""
            };
            var expected = new[]
            {
                ""
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#16
0
        public void Horizontal_line_mines_at_edges()
        {
            var minefield = new[]
            {
                "*   *"
            };
            var expected = new[]
            {
                "*1 1*"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#17
0
        static void Main()
        {
            Minesweeper _minesweeper;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            _minesweeper = new Minesweeper();
            _minesweeper.FormBorderStyle = FormBorderStyle.FixedDialog;
            _minesweeper.MaximizeBox     = false;
            _minesweeper.MinimizeBox     = false;
            _minesweeper.Size            = new System.Drawing.Size(360 - 35, 30 + 360);
            _minesweeper.StartPosition   = FormStartPosition.CenterScreen;
            Application.Run(_minesweeper);
        }
示例#18
0
        public void Minefield_with_only_mines()
        {
            var minefield = new[]
            {
                "***",
                "***",
                "***"
            };
            var expected = new[]
            {
                "***",
                "***",
                "***"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#19
0
        public void Space_surrounded_by_mines()
        {
            var minefield = new[]
            {
                "***",
                "* *",
                "***"
            };
            var expected = new[]
            {
                "***",
                "*8*",
                "***"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#20
0
        public void Mine_surrounded_by_spaces()
        {
            var minefield = new[]
            {
                "   ",
                " * ",
                "   "
            };
            var expected = new[]
            {
                "111",
                "1*1",
                "111"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#21
0
        private void StartGame_Click(object sender, EventArgs e)
        {
            string selectedOption   = DifficultySelector.GetItemText(DifficultySelector.SelectedItem);
            bool   noOptionSelected = false;

            switch (selectedOption)
            {
            case "Easy 8*8 (10 mines)":
                GameInfo.BoardX         = 8;
                GameInfo.BoardY         = 8;
                GameInfo.TotalMineCount = 10;
                break;

            case "Normal 16*16 (40 mines)":
                GameInfo.BoardX         = 16;
                GameInfo.BoardY         = 16;
                GameInfo.TotalMineCount = 40;
                break;

            case "Hard 30*16 (99 mines)":
                GameInfo.BoardX         = 30;
                GameInfo.BoardY         = 16;
                GameInfo.TotalMineCount = 99;
                break;

            case "Custom":
                GameInfo.BoardX         = (int)XCustomizer.Value;
                GameInfo.BoardY         = (int)YCustomizer.Value;
                GameInfo.TotalMineCount = (int)MinesCustomizer.Value;
                break;

            default:    //no item is selected
                noOptionSelected = true;
                break;
            }
            if (noOptionSelected == false)
            {
                Hide();//hide startup menu
                MinesweeperInstance = new Minesweeper();
                MinesweeperInstance.Show();
                GameInfo.GameStarted = true;
            }
        }
示例#22
0
        public Minesweeper(Minesweeper A)//copy ctor
        {
            Size     = A.Size;
            Mines    = A.mines;
            gameOver = A.gameOver;

            board     = new sbyte[Size, Size];
            gameBoard = new char[Size, Size];
            visited   = new bool[Size, Size];

            for (sbyte i = 0; i < Size; i++)
            {
                for (sbyte j = 0; j < Size; j++)
                {
                    board[i, j]     = A.board[i, j];
                    gameBoard[i, j] = A.gameBoard[i, j];
                    visited[i, j]   = A.visited[i, j];
                }
            }
        }
示例#23
0
        public void Cross()
        {
            var minefield = new[]
            {
                "  *  ",
                "  *  ",
                "*****",
                "  *  ",
                "  *  "
            };
            var expected = new[]
            {
                " 2*2 ",
                "25*52",
                "*****",
                "25*52",
                " 2*2 "
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#24
0
        private void play_Click(object sender, EventArgs e)
        {
            if (sizeButtons.SelectedValue == null)
            {
                return;
            }
            int bombs = Int32.Parse(Math.Round(numberBombs.Value).ToString());
            int rows  = Int32.Parse(Math.Round(numberRows.Value).ToString());
            int cols  = Int32.Parse(Math.Round(numberCols.Value).ToString());

            Enum.TryParse <ButtonSize>(sizeButtons.SelectedValue.ToString(), out ButtonSize buttonSize);
            int size = (int)buttonSize;

            Hide();

            Minesweeper form1 = new Minesweeper(rows, cols, bombs, size);

            form1.Closed += (s, args) => Close();
            form1.Show();
            form1.NewGame();
        }
示例#25
0
        public void Vertical_line_mines_at_edges()
        {
            var minefield = new[]
            {
                "*",
                " ",
                " ",
                " ",
                "*"
            };
            var expected = new[]
            {
                "*",
                "1",
                " ",
                "1",
                "*"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#26
0
        static async Task MainAsync(/*IntPtr handle*/)
        {
            var ms = new Minesweeper();

            while (true)
            {
                InfoMessage("[Token] Введите токен бота, пожалуйста: ");
                if (!await ms.ConnectAsync(Console.ReadLine()))
                {
                    ErrorMessage("[Token] [Error] Некорректный токен!");
                }
                else
                {
                    break;
                }
            }

            //ShowWindow(handle, 0);
            while (run)
            {
            }
        }
示例#27
0
        public Grid(int _cols, int _rows, int _mineCount, int windowWidth, int _x, int _y, Minesweeper _parent)
        {
            cols           = _cols;
            rows           = _rows;
            mineCount      = _mineCount;
            RemainingFlags = _mineCount;

            x = _x;
            y = _y;

            parent = _parent;

            gameOver = false;

            cells = new Cell[cols, rows];

            InitCells(cells, windowWidth / _cols);

            GenerateMines();

            AddCells();
        }
示例#28
0
        public void Large_minefield()
        {
            var minefield = new[]
            {
                " *  * ",
                "  *   ",
                "    * ",
                "   * *",
                " *  * ",
                "      "
            };
            var expected = new[]
            {
                "1*22*1",
                "12*322",
                " 123*2",
                "112*4*",
                "1*22*2",
                "111111"
            };

            Assert.Equal(expected, Minesweeper.Annotate(minefield));
        }
示例#29
0
        public static string Resolve(string input)
        {
            var           rows           = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            Minesweeper   current        = null;
            StringBuilder sb             = new StringBuilder();
            int           minesweepCount = 0;

            for (int i = 0; i < rows.Length; i++)
            {
                if (current == null)
                {
                    minesweepCount++;
                    var rowcol = rows[i].Split(' ');
                    if (rows[i] == "0 0")
                    {
                        break;
                    }
                    current = new Minesweeper(int.Parse(rowcol[1]), int.Parse(rowcol[0]));
                }
                else
                {
                    current.AddRow(rows[i]);
                    if (current.IsComplete)
                    {
                        if (minesweepCount > 1)
                        {
                            sb.Append(Environment.NewLine);
                        }

                        sb.AppendFormat("Field #{0}:{1}", minesweepCount, Environment.NewLine);
                        sb.Append(current.SolveField());
                        current = null;
                    }
                }
            }
            return(sb.ToString());
        }
示例#30
0
        public static Grid newGrid(string difficulty, Minesweeper _parent)
        {
            Grid g;

            if (difficulty.Equals("easy"))
            {
                g = new Grid(10, 8, 10, EasyWidth, _parent.Width / 2 - EasyWidth / 2, 100, _parent);
            }
            else if (difficulty.Equals("medium"))
            {
                g = new Grid(18, 14, 40, MedWidth, _parent.Width / 2 - MedWidth / 2, 100, _parent);
            }
            else if (difficulty.Equals("hard"))
            {
                g = new Grid(24, 20, 99, HardWidth, _parent.Width / 2 - HardWidth / 2, 100, _parent);
            }
            else
            {
                throw new InvalidOperationException();
            }

            _parent.UpdateFlagCounter(g.GetMineCount());
            return(g);
        }
示例#31
0
        static void Main(string[] args)
        {
            CommandLineApplication cli =
                new CommandLineApplication(throwOnUnexpectedArg: true);

            cli.Description = "Randomly places mines and solves an ever expanding area";

            Func <bool> coords;
            {
                var opt = cli.Option(
                    "-c",
                    "Show a coordinate system. @ marks the origin.",
                    CommandOptionType.NoValue
                    );
                coords = () => opt.HasValue();
            }
            Func <int?> seed;
            {
                var opt = cli.Option(
                    "-s <seed>",
                    "The seed that determines where mines are",
                    CommandOptionType.SingleValue
                    );
                seed = () => ParseMaybeIntOption(defaultValue: null, option: opt);
            }
            Func <double> probability;

            {
                var opt = cli.Option(
                    "-p <probability>",
                    "The probability that a given spot is a mine. Default is: 60.0 / (16 * 16)",
                    CommandOptionType.SingleValue
                    );
                probability = () => ParseDoubleOption(defaultValue: 60.0 / (16 * 16), option: opt);
            }
            cli.Command("run",
                        (target) =>
            {
                target.Description = "Randomly places mines and solves an ever expanding area";
                target.HelpOption("-? | -h | --help");
                target.ShowInHelpText = true;
                target.OnExecute((Func <int>)(() =>
                {
                    var minesweeper = new Minesweeper(probability(), seed: seed());
                    var board       = new Board(minesweeper);
                    var solver      = new Solver(board);
                    board.Print(coords());
                    while (true)
                    {
                        Console.ReadKey();
                        Console.WriteLine("Step {0} --------- Press key to continue ---------", solver.Step);
                        solver.SolveStep();
                        board.Print(coords());
                    }
                }));
            });
            cli.Command("screensaver",
                        (target) =>
            {
                target.Description = "Like run but solves 40 steps consecutively and restarts";
                target.HelpOption("-? | -h | --help");
                target.ShowInHelpText = true;
                target.OnExecute((Func <int>)(() =>
                {
                    while (true)
                    {
                        var minesweeper = new Minesweeper(probability(), seed: seed());
                        var board       = new Board(minesweeper);
                        var solver      = new Solver(board);
                        board.Print(coords());
                        for (int i = 0; i < 40; i++)
                        {
                            Console.WriteLine("Step {0} --------- Press key to continue ---------", solver.Step);
                            solver.SolveStep();
                            board.Print(coords());
                        }
                    }
                }));
            });
            cli.Command("with-initial",
                        (target) =>
            {
                target.Description = "Like run but has an initial configuration that specifies some mine spots and some non mine spots";
                target.HelpOption("-? | -h | --help");
                target.ShowInHelpText       = true;
                CommandArgument initialFile = target.Argument(
                    "file",
                    "A file with an initial configuration. '*' is a known mine ' ' known free spot and everything else might be a mine depending on chance",
                    multipleValues: false
                    );
                target.OnExecute((Func <int>)(() =>
                {
                    var isMineDict  = ParseInitField(File.ReadAllText(initialFile.Value));
                    var minesweeper = new Minesweeper(probability(), isMineDict, seed());
                    var board       = new Board(minesweeper, isMineDict);
                    var solver      = new Solver(board, isMineDict.Where(e => !e.Value).Select(e => board[e.Key]).ToList());
                    board.Print(coords());
                    while (true)
                    {
                        Console.ReadKey();
                        Console.WriteLine("Step {0} --------- Press key to continue ---------", solver.Step);
                        solver.SolveStep();
                        board.Print(coords());
                    }
                }));
            });
            cli.Command("solve",
                        (target) =>
            {
                target.Description = "Solve a given minesweeper and show what you can uncover next";
                target.HelpOption("-? | -h | --help");
                target.ShowInHelpText       = true;
                CommandArgument initialFile = target.Argument(
                    "file",
                    "A file with an initial configuration. '*' is a known mine a digit is a known free spot with that number of adjacent mines",
                    multipleValues: false
                    );
                target.OnExecute((Func <int>)(() =>
                {
                    KnownMinesweeper minesweeper;
                    Dictionary <Coord, bool> isMineDict;
                    SolveGivenMinesweeper(File.ReadAllText(initialFile.Value), out minesweeper, out isMineDict);
                    var board  = new Board(minesweeper, isMineDict);
                    var solver = new Solver(board, isMineDict.Where(e => !e.Value).Select(e => board[e.Key]).ToList());
                    board.Print(coords());
                    solver.SolveStep();
                    Console.WriteLine("\n\nAfter solve step:\n\n");
                    board.Print(coords());
                    Console.WriteLine("\nThese tiles can be uncoved next:");
                    Console.WriteLine(string.Join("\n", minesweeper.SoverTriedToUncover.Select(c => c.ToString()).ToArray()));
                    return(0);
                }));
            });
            cli.HelpOption("-? | -h | --help");

            cli.OnExecute((Func <int>)(() =>
            {
                cli.ShowHint();
                return(0);
            }));

            //try
            //{
            cli.Execute(args);
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}
        }
示例#32
0
        static void Main(string[] args)
        {
            Console.WriteLine("Zadejte velikost mřížky.");
            Console.WriteLine("Volte čísla v rozsahu {0} - {1}", Minesweeper.Minesweeper.minGridSize, Minesweeper.Minesweeper.maxGridSize);
            Console.WriteLine("Pro hodnotu 9 bude velikost mřížky 9x9");
            int size = 0;
            do // Uživatel se musí trefit do povoleného rozsahu velikostí
            {
                try
                {
                    Console.Write("Velikost [{0}]: ", Minesweeper.Minesweeper.defaultGridSize);
                    size = Convert.ToInt32(Console.ReadLine());
                }
                catch
                {
                    size = Minesweeper.Minesweeper.defaultGridSize;
                }
            } while ((size < Minesweeper.Minesweeper.minGridSize) || (size > Minesweeper.Minesweeper.maxGridSize));
            Console.WriteLine();

            // Vytvoříme a vygenerujeme herní desku
            Minesweeper.Minesweeper m = new Minesweeper.Minesweeper();
            m.size = size;
            m.generateMines();

            char action = ' ';
            do // Uživatel prozkoumává herní desku a označuje miny, dokud neřekne, že má hotovo
            {
                // Nejdříve se vyčistí obrazovka
                Console.Clear();

                // Vypíšeme statistiky
                TUI.printStats(m.stats);

                TUI.printGrid(m.size, m.cells);
                Console.WriteLine();
                Console.WriteLine("Na kterou hodnotu chcete kliknout?");
                Console.WriteLine("Zadejte operaci následovanou dvěma čísly oddělenýmy mezerou.");
                Console.WriteLine("Operace jsou:\n s (stoupnout), m (označit minu), u (zrušit označení), q (vyhodnotit).");
                Console.WriteLine("První číselná hodnota reprezentuje osu X, druhá osu Y");
                Console.Write("\nVstup: ");

                // Parsujeme vstup [1/2]
                int x = 0, y = 0;
                try
                {
                    string[] input = Console.ReadLine().Split();
                    action = char.Parse(input[0]);

                    // Pokud uživatel řekl, že už má hotovo
                    if (action == 'q')
                        break;

                    // Parsujeme vstup [2/2]
                    x = int.Parse(input[1]);
                    y = int.Parse(input[2]);
                }
                catch { };

                // Pokud uživatel zadal neexistující souřadnice
                if (m.cells.get(x, y) == null)
                {
                    TUI.pressAnyKeyToContinue(
                        "\nNeplatné souřadnice.\n"
                        + "Pokračujte stiskem libovolné klávesy ..."
                    );
                    continue;
                }

                // Pokud by chtěl uživatel provést na prozkoumaných souřadnicích
                if (m.cells.get(x, y).value >= 0)
                {
                    TUI.pressAnyKeyToContinue(
                        "\nNelze provést operaci na daných souřadnicích. Jsou již prozkoumané.\n"
                        + "Pokračujte stiskem libovolné klávesy ..."
                    );
                    continue;
                }

                // Provedeme požadovanou akci s požadovanými souřadnicemi
                m.action(action, x, y);

                // Pokud uživatel stoupl na minu
                if ((action == 's') && (m.toBeOrNotToBe(x, y)))
                    break;

            } while (true); // Cyklus je ukončen zevnitř

            TUI.printHorizontalBorder();

            // Pokud uživatel stoupl na minu
            if (action == 's')
            {
                Console.WriteLine("Stoupl jste na minu a umřete za 3... 2... 1...");
                Console.WriteLine("Smůla. Jste mrtvý. Zkuste to znovu :-)");
            }
            else
            {
                // Pokud uživatel označil miny na správných místech
                if (m.foundAllAndOnlyMines())
                    Console.WriteLine("Jste rozený profík! Našel jste všechny miny.");
                else
                    Console.WriteLine("Bohužel jste neoznačil všechny miny správně. Doufejme, že na ně nikdo nešlápne.");
            }
            TUI.pressAnyKeyToContinue("\nStisknutím libovolné klávesy ukončíte program");
        }
示例#33
0
 public void setParent(Minesweeper.Board newParent)
 {
     parent = newParent;
 }