Beispiel #1
0
        public void Let2ndPlayerJoin(Game game, string name2)
        {
            DobbyDBHelper.DobbyDBHelper dobby = new DobbyDBHelper.DobbyDBHelper();
            List <Grid> grid = dobby.GetGrid();

            dobby.FreeDobby();

            Builder.Player player2 = AddPlayer(AddAndOrLoadUser(name2), false, game);
            SetupGrid(game.Players.ToList()[0], player2, game.Rows, game.Columns);
        }
Beispiel #2
0
        public Game CreateGame(string name1, int rows, int columns, GameBoard gameBoard)
        {
            this.CleanUp();
            Game game = CreateGameMethod(rows, columns);

            Builder.Player player1 = AddPlayer(AddAndOrLoadUser(name1), true, game);
            gameBoard.ActivePlayer = player1;
            game.Players.Add(player1);

            return(game);
        }
Beispiel #3
0
 public Builder.Player AddPlayer(UserPerson user, bool isHost, Game game)
 {
     Builder.Player player = new Builder.Player
     {
         UserPerson = user,
         IsHost     = isHost,
         Game       = game
     };
     Session.Save(player);
     return(player);
 }
Beispiel #4
0
        internal bool IsGameOver(Builder.Player player)
        {
            List <Ship> ships = Session.Query <Ship>().Where(p => p.Player == player).ToList();

            foreach (Ship ship in ships)
            {
                if (!ship.IsSunk)
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #5
0
 private void SetThisGridUp(int rows, int columns, Builder.Player player)
 {
     for (int i = 0; i < rows; i++)
     {
         for (int j = 0; j < columns; j++)
         {
             Grid grid = new Grid
             {
                 Coordinate = $"{((char)(i + 65))}{j + 1}",
                 IsHit      = false,
                 Player     = player
             };
             Session.Save(grid);
             Session.Flush();
         }
     }
 }
Beispiel #6
0
 public Grid GetGrid(string coordinate, Builder.Player player)
 {
     return(Session.Query <Grid>().Where(c => (c.Coordinate.ToLower() == coordinate.ToLower()) && (c.Player == player)).Single());
 }
Beispiel #7
0
 internal Builder.Player SwitchPlayer(Game game, Builder.Player activePlayer)
 {
     return(Session.Query <Builder.Player>().Where(p => p.Game == game && p.PlayerId != activePlayer.PlayerId).Single());
 }
Beispiel #8
0
 public void SetupGrid(Builder.Player player1, Builder.Player player2, int rows, int columns)
 {
     SetThisGridUp(rows, columns, player1);
     SetThisGridUp(rows, columns, player2);
 }