private void UpdateGrid()
        {
            DobbyDBHelper dobby = new DobbyDBHelper();

            dobby.UpdateGridToDB(Grid.Values.ToList());
            dobby.FreeDobby();
        }
        public void SwitchActivePlayer()
        {
            DobbyDBHelper dobby = new DobbyDBHelper();

            this.ActivePlayer = dobby.SwitchPlayer(this.Game, this.ActivePlayer);

            dobby.FreeDobby();
        }
        public List <Game> GetActiveGames()
        {
            DobbyDBHelper dobby    = new DobbyDBHelper();
            List <Game>   gameList = dobby.GetActiveGames();

            dobby.FreeDobby();
            return(gameList);
        }
Beispiel #4
0
        public IHttpActionResult InitiateGame(string player1, int rows, int columns)
        {
            GameBoard     gameBoard = GameBoard.StartGame(player1, rows, columns);
            DobbyDBHelper dobby     = new DobbyDBHelper();

            gameBoard.Grid = dobby.GetGridDictionary();
            dobby.FreeDobby();
            return(Ok(gameBoard));
        }
        private Ship IsShipSunk(Grid thisGrid, DobbyDBHelper dobby)
        {
            List <Grid> shipGrid = dobby.GetShipCoords(thisGrid);

            foreach (Grid grid in shipGrid)
            {
                if (grid.IsHit == false)
                {
                    return(null);
                }
            }
            return(shipGrid[0].Ship);
        }
        public Message DropBomb(string coordinate)
        {
            if (Grid[coordinate.ToUpper()].IsHit)
            {
                return(null);
            }
            else
            {
                Grid          thisGrid = Grid[coordinate.ToUpper()];
                DobbyDBHelper dobby    = new DobbyDBHelper();
                Message       message  = dobby.DropBomb(thisGrid);
                message.SunkenShip = IsShipSunk(thisGrid, dobby);
                message.GameOver   = dobby.IsGameOver(thisGrid.Player);

                dobby.FreeDobby();

                return(message);
            }
        }