public void StartGame(DTO.Player Host)
        {
            int lst = (from l in dc.PlayerLobbies where l.HostPlayer == Host.PlayerId select l.LobbyId).First();
            //       var play = from p in gamelobbies where p.LobbyId.LobbyId == lst select p;
            var lobName = (from p in dc.Lobbies where p.LobbyId == lst select p.LobbyName).First();

            var update = (from l in dc.PlayerLobbies where l.HostPlayer == Host.PlayerId select l).ToList();

            //static
            DTO.PlayerLobby pl = new DTO.PlayerLobby(Host)
            {
                LobbyId = new DTO.Lobby()
                {
                    LobbyId = lst, LobbyName = lobName.ToString()
                }, IsAwaitingForPlayers = true, StartGame = false
            };

            foreach (var item in update)
            {
                item.IsWaitingForPlayers = false;

                item.StartGame = true;
                //static
                if (pl.Player.Count != 4)
                {
                    AddPlayer("hello");
                    pl.Player.Add(new DTO.Player()
                    {
                        PlayerName = "Hello", AlreadExist = false, PlayerId = GenerateID()
                    });
                }
            }

            //static
            gamelobbies.Add(pl);

            var lobby = from d in gamelobbies where d.LobbyId.LobbyId == lst select d;

            foreach (var item in lobby)
            {
                item.IsAwaitingForPlayers = false;
                item.StartGame            = true;
            }

            #region Game init()

            var gamelob = (from p in gamelobbies where p.HostPlayer.PlayerId == Host.PlayerId select p).Single();

            DTO.PlayerLobby plLobby = ConvertToDTOPlayerLobby(Host, lobby);
            NewGame = new DTO.MonopolyEngine.SingleGame(plLobby);
            NewGame.StartGame();

            #endregion

            dc.SubmitChanges();
        }
Esempio n. 2
0
        //Start game
        #region GameStart()

        //Start the game
        public void StartGame(DTO.Player Host)
        {
            //select the lobbyid from the playerlobby which hostplayer is Host
            int lst = (from l in dc.PlayerLobbies where l.HostPlayer == Host.PlayerId select l.LobbyId).First();
            //select the lobbyname of the lobby with the same name as lst
            var lobName = (from p in dc.Lobbies where p.LobbyId == lst select p.LobbyName).First();
            //select all playerlobbies from the database whose hostplayer id is the same as the Host's playerID
            var update = (from l in dc.PlayerLobbies where l.HostPlayer == Host.PlayerId select l).ToList();

            //Make a static playerlobby to test it all
            DTO.PlayerLobby pl = new DTO.PlayerLobby(Host)
            {
                LobbyId = new DTO.Lobby()
                {
                    LobbyId = lst, LobbyName = lobName.ToString()
                }, IsAwaitingForPlayers = true, StartGame = false
            };

            foreach (var item in update)
            {
                //the lobby isn't awaiting for players anymore
                item.IsWaitingForPlayers = false;
                //the game is started
                item.StartGame = true;


                //static to see if the count is fout
                while (pl.Player.Count != 4)
                {
                    //add static players until player count is four
                    AddPlayer("hello");
                    pl.Player.Add(new DTO.Player()
                    {
                        PlayerName = "Hello", AlreadExist = false, PlayerId = GenerateID()
                    });
                }
            }

            //static add the playerlobby pl
            gamelobbies.Add(pl);
            //select the lobbyid from the gamelobby
            var lobby = from d in gamelobbies where d.LobbyId.LobbyId == lst select d;

            foreach (var item in lobby)
            {
                //set the bools right
                item.IsAwaitingForPlayers = false;
                item.StartGame            = true;
            }

            //intitiates the game
            #region Game init()
            //get the gamelobby
            //var gamelob = (from p in gamelobbies where p.HostPlayer.PlayerId == Host.PlayerId select p).First();
            //make a playerlobby of the host and the lobby
            DTO.PlayerLobby plLobby = ConvertToDTOPlayerLobby(Host, lobby);
            NewGame = new DTO.MonopolyEngine.SingleGame();
            //Update the players of the game
            NewGame.UpdatePlayers(plLobby);
            //stat the game
            NewGame.StartGame();

            #endregion

            dc.SubmitChanges();
        }