Example #1
0
        public async Task <ActionResult <MineSweeper> > PostMineSweeper(MineSweeper mineSweeper)
        {
            _context.MineSweeperItems.Add(mineSweeper);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetMineSweeper), new { id = mineSweeper.id }, mineSweeper));
        }
Example #2
0
        public virtual void CheckForVictory()
        {
            bool IsClear = true;
            Tile t;

            for (int x = 0; x < fieldSize.X; x++)
            {
                for (int y = 0; y < fieldSize.Y; y++)
                {
                    t = tiles[x][y][0];
                    if (!t.IsOpened && !t.IsFlagged && t.CurrentState > -1)
                    {
                        IsClear = false;
                        break;
                    }
                }
                if (!IsClear)
                {
                    break;
                }
            }
            if (IsClear)
            {
                MineSweeper.InvokeLevelWon();
            }
        }
        // Difficulty button event
        public void Difficulty_Click(object sender, EventArgs e)
        {
            // Get the name of the sender object
            String name = ((Button)sender).Name;

            // Make progress bar visible
            progressBar.Visible = true;

            // Setup the game
            switch (name)
            {
            case "btnEasy":
                game = new MineSweeper(1, progressBar);
                break;

            case "btnMedium":
                game = new MineSweeper(2, progressBar);
                break;

            case "btnHard":
                game = new MineSweeper(3, progressBar);
                break;

            case "btnNightmare":
                game = new MineSweeper(4, progressBar);
                break;
            }

            PlayGame();
        }
Example #4
0
        public void GetMarkedMineFieldReturnsCorrectResult()
        {
            var sut = new MineSweeper();
            var mineField = new[]
            {
                "...*.*",
                "*....*",
                "..*.*.",
                "*....*",
                "...*..",
                "......"
            };

            var expected = new[]
            {
                "111*3*",
                "*2234*",
                "23*2*3",
                "*2233*",
                "111*21",
                "001110"
            };

            var actual = sut.GetMarkedMineField(mineField);

            Assert.Equal(expected, actual);
        }
Example #5
0
        public async Task <IActionResult> PutMineSweeper(long id, MineSweeper mineSweeper)
        {
            if (id != mineSweeper.id)
            {
                return(BadRequest());
            }

            _context.Entry(mineSweeper).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MineSweeperExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #6
0
 public override void StartGame(MineSweeper mineSweeper)
 {
     mineSweeper.Width  = 515;
     mineSweeper.Height = 562;
     board = new Board(mineSweeper, 10, 10, 50);
     board.InitializeBoard();
 }
Example #7
0
 public override void StartGame(MineSweeper mineSweeper)
 {
     mineSweeper.Width  = 615;
     mineSweeper.Height = 663;
     board = new Board(mineSweeper, 12, 12, 80);
     board.InitializeBoard();
 }
Example #8
0
    // Start is called before the first frame update
    void Start()
    {
        playerObject    = FindObjectOfType <MineSweeper>();
        objectiveObject = FindObjectOfType <BattleShip>();

        Port.PlayerSavedAShipEvent += OnPlayerSavesShip;
    }
Example #9
0
 public override void StartGame(MineSweeper mineSweeper)
 {
     mineSweeper.Height = 463;
     mineSweeper.Width  = 416;
     board = new Board(mineSweeper, 8, 8, 10);
     board.InitializeBoard();
 }
Example #10
0
        public void IsMine_Asterix_ReturnsTrue()
        {
            var sweeper = new MineSweeper();
            var result  = sweeper.IsMine('*');

            Assert.IsTrue(result);
        }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        if (goal == null)
        {
            goal = FindObjectOfType <Port>();
        }

        shipsSavedDisplay.text = " " + ships;

        if (playerObject == null)
        {
            playerObject = FindObjectOfType <MineSweeper>();
        }

        if (playerObject != null)
        {
            mineSweeperHPLabel.text = playerObject.hitPoints.ToString();
        }


        if (objectiveObject == null)
        {
            objectiveObject = FindObjectOfType <BattleShip>();
        }

        if (objectiveObject != null)
        {
            battleShipHPLabel.text = objectiveObject.hitPoints.ToString();
        }
    }
Example #12
0
        public void IsMine_NotAsterix_ReturnsFalse()
        {
            var sweeper = new MineSweeper();
            var result  = sweeper.IsMine('.');

            Assert.IsFalse(result);
        }
Example #13
0
        public MineSweeperUI()
        {
            game      = new MineSweeper();
            buttonsUI = new Button[MAX_BOUNDS, MAX_BOUNDS];
            game.setMines(2);

            InitializeComponent();
        }
Example #14
0
        public void it_should_contain_elements()
        {
            var field = new MineField(3, 4, new List <string> {
                "*...", "*.*.", "...."
            });
            var sweeper = new MineSweeper(field);

            Assert.AreEqual(true, sweeper.GenerateSolution().Any());
        }
Example #15
0
        /// <summary>
        /// This method will keep looping until a bug is found, or if the player closes the program.
        /// </summary>
        private static void Update()
        {
            #region Game-Diff-Selection
            // Write instructions + information to Console.
            TextManager.WriteLine("Select a game: ");
            foreach (var index in IndexToGameMode)
            {
                TextManager.WriteLine($"{index.Key}. {index.Value}");
            }
            TextManager.WriteLine();
            TextManager.WriteLine("Enter a number to select game: \n", ConsoleColor.Green);

            // Get gamemode from user input
            var gameIndex = GetIndexFromUserInput(IndexToGameMode.Count);
            var gameName  = IndexToGameMode[gameIndex];

            // Write instrutions + information to Console.
            TextManager.Clear();
            TextManager.WriteLine($"Game Selected: {gameName}");
            foreach (var index in IndexToDifficulty)
            {
                TextManager.WriteLine($"{index.Key}. {index.Value}");
            }
            TextManager.WriteLine();
            TextManager.WriteLine("Enter a number to select difficulty: \n", ConsoleColor.Green);

            // Get game difficulty from user input
            var difficultyIndex = GetIndexFromUserInput(IndexToDifficulty.Count);
            var difficulty      = IndexToDifficulty[difficultyIndex];

            // Write instructions + information to Console.
            TextManager.Clear();
            TextManager.WriteLine($"Game Selected: {gameName}");
            TextManager.WriteLine($"Difficulty Selected: {difficulty}");
            TextManager.WriteLineBreak();
            TextManager.WriteLine();
            #endregion

            // Start game depending on what the user had input.
            switch (gameIndex)
            {
            case 1:
                CurrentGame = new MineSweeper(difficulty);
                break;

            case 2:
                CurrentGame = new PuyoPuyo(difficulty);
                break;

            default:
                throw new Exception("Invalid game mode has been declared.");
            }

            // Start the game once the user has selected a game and difficulty.
            CurrentGame.StartGame();
        }
Example #16
0
        public void CountNeighbourMines_EmptyGrid_ReturnsZero()
        {
            var sweeper = new MineSweeper();
            var grid    = new char[][] { };

            var expected = 0;
            var result   = sweeper.CountNeighbourMines(grid, 2, 2);

            Assert.AreEqual(expected, result);
        }
Example #17
0
 static void InputEngine_onButtonDown(InputEngine.MouseArgs e)
 {
     if (MineSweeper.IsGUI())
     {
         currentScreen.OnButtonDown(e);
     }
     if (MineSweeper.IsField())
     {
         s_hud.OnButtonDown(e);
     }
 }
Example #18
0
 public static void Draw()
 {
     if (MineSweeper.IsGUI())
     {
         currentScreen.Draw();
     }
     if (MineSweeper.IsField())
     {
         s_hud.Draw();
     }
 }
Example #19
0
 public static void Update()
 {
     if (MineSweeper.IsGUI())
     {
         currentScreen.Update();
     }
     if (MineSweeper.IsField())
     {
         s_hud.Update();
     }
 }
Example #20
0
 static void InputEngine_onKeyDown(InputEngine.KeyboardArgs e)
 {
     if (MineSweeper.IsGUI())
     {
         currentScreen.OnKeyDown(e);
     }
     if (MineSweeper.IsField())
     {
         s_hud.OnKeyDown(e);
     }
 }
Example #21
0
 public static void Draw()
 {
     MineSweeper.spriteBatch.Begin();
     if (MineSweeper.IsField())
     {
         MineSweeper.gameField.Draw();
         Entity.EntityManager.Draw();
     }
     GUI.GUIEngine.Draw();
     MineSweeper.spriteBatch.End();
 }
Example #22
0
        public void it_should_count_correct_mine_count_for_a_neighbourhood()
        {
            var field = new MineField(3, 4, new List <string> {
                "*...", "*.*.", "...."
            });
            var sweeper = new MineSweeper(field);

            Assert.AreEqual("1", sweeper.GetMineCount(0, 2));
            Assert.AreEqual(MineField.MINE.ToString(), sweeper.GetMineCount(0, 0));
            Assert.AreEqual("3", sweeper.GetMineCount(1, 1));
        }
Example #23
0
 public override void OnOpenedWOAnimation()
 {
     IsOpened = true;
     if (CurrentState == -1)
     {
         MineSweeper.InvokeLevelLost();
     }
     else
     {
         MineSweeper.gameField.CheckForVictory();
     }
 }
Example #24
0
 static void InputEngine_onButtonDown(InputEngine.MouseArgs e)
 {
     leftPressed  |= (e.button == 0);
     rightPressed |= (e.button == 1);
     if (MineSweeper.IsField())
     {
         if (e.button == 0 && e.curState.RightButton == ButtonState.Released)
         {
             allowDnD = true;
             DnDstart = new Vector2(e.curState.X, e.curState.Y);
         }
     }
 }
Example #25
0
 public override void OnOpened()
 {
     IsOpened = true;
     Entity.EntityManager.AddSquareFadeOut(Position, Size);
     if (CurrentState == -1)
     {
         MineSweeper.InvokeLevelLost();
     }
     else
     {
         MineSweeper.gameField.CheckForVictory();
     }
 }
Example #26
0
    // Update is called once per frame
    void Update()
    {
        if (minesweep == null)
        {
            isMineSweeperActive = false;
            minesweep           = FindObjectOfType <MineSweeper>();
        }
        if (minesweep != null)
        {
            isMineSweeperActive = true;
        }

        ClickOnCell();
    }
        public void ReturnEmptyField()
        {
            var          mineSweeper = new MineSweeper();
            const string fields      = "~~~\n" +
                                       "00\n" +
                                       "~~~";
            var          actual   = mineSweeper.Sweep(fields);
            const string expected = "~~~\n" +
                                    "Field #1:\n" +
                                    "~~~\n" +
                                    "\n";

            Assert.AreEqual(expected, actual);
        }
Example #28
0
        public void CountNeighbourMines_1MineAndGivenCoordinateAtBottomCorner_ReturnsOne()
        {
            var sweeper = new MineSweeper();
            var grid    = new[]
            {
                new[] { '*', '.', '.' },
                new[] { '*', '.', '.' },
                new[] { '.', '.', '.' }
            };

            var expected = 0;
            var result   = sweeper.CountNeighbourMines(grid, 2, 2);

            Assert.AreEqual(expected, result);
        }
Example #29
0
        public void CountNeighbourMines_TwoMine_ReturnsTwo()
        {
            var sweeper = new MineSweeper();
            var grid    = new[]
            {
                new[] { '*', '.', '.' },
                new[] { '*', '.', '.' },
                new[] { '.', '.', '.' }
            };

            var expected = 2;
            var result   = sweeper.CountNeighbourMines(grid, 0, 1);

            Assert.AreEqual(expected, result);
        }
Example #30
0
        public void it_should_generate_the_correct_the_solution()
        {
            var field = new MineField(4, 4, new List <string> {
                "*...", "*.*.", "....", "...*"
            });
            var sweeper = new MineSweeper(field);

            var solution = sweeper.GenerateSolution();

            Assert.AreEqual(4, solution.Count);
            Assert.AreEqual("*311", solution[0]);
            Assert.AreEqual("*3*1", solution[1]);
            Assert.AreEqual("1222", solution[2]);
            Assert.AreEqual("001*", solution[3]);
        }
Example #31
0
 static void InputEngine_onButtonUp(InputEngine.MouseArgs e)
 {
     if (MineSweeper.IsField() && !InputEngine.eventHandled && !ignoreNextClick)
     {
         MineSweeper.gameField.HitTest(new Vector3(e.curState.X, e.curState.Y, 0), e.button);
     }
     ignoreNextClick = leftPressed && rightPressed;
     if (e.button == 0)
     {
         leftPressed = false;
     }
     if (e.button == 1)
     {
         rightPressed = false;
     }
 }
Example #32
0
        public void FullMineFieldReturnsMine()
        {
            var sut = new MineSweeper();
            var mineField = new[]
            {
                "*"
            };

            var expected = new[]
            {
                "*"
            };

            var actual = sut.GetMarkedMineField(mineField);

            Assert.Equal(expected, actual);
        }
Example #33
0
        public void EmptyMineFieldReturnsZero()
        {
            var sut = new MineSweeper();
            var mineField = new[]
            {
                "."
            };

            var expected = new[]
            {
                "0"
            };

            var actual = sut.GetMarkedMineField(mineField);

            Assert.Equal(expected, actual);
        }
Example #34
0
        public void MineFieldHandlesDiagonalMines(string[] mineField, string[] expected)
        {
            var sut = new MineSweeper();

            var actual = sut.GetMarkedMineField(mineField);

            Assert.Equal(expected, actual);
        }
Example #35
0
        public void OneRowMineFieldReturnsCorrectResult(string source, string result)
        {
            var sut = new MineSweeper();
            var mineField = new[]
            {
                source
            };

            var expected = new[]
            {
                result
            };

            var actual = sut.GetMarkedMineField(mineField);

            Assert.Equal(expected, actual);
        }