示例#1
0
        //Show the playerslobbies
        #region ShowPlayLobbies()

        //get all the lobbies whose bool IsAwaitingForPlayers is false
        public List <DTO.PlayerLobby> GatAvailablePlayLobbies()
        {
            //get the hostplayer and the lobbyID
            var rooms = from p in dc.PlayerLobbies
                        where p.PlayerId == p.HostPlayer
                        select new { p.LobbyId, p.HostPlayer };

            //make a list of DTO playerlobbies
            List <DTO.PlayerLobby> lobbies = new List <DTO.PlayerLobby>();

            foreach (var item in rooms)
            {
                //add all lobbies in rooms to the list of DTO playerlobbies
                DTO.PlayerLobby l = new DTO.PlayerLobby(new DTO.Player()
                {
                    PlayerId = (int)item.HostPlayer, PlayerName = GetPlayerName((int)item.HostPlayer)
                })
                {
                    LobbyId = new DTO.Lobby()
                    {
                        LobbyId = item.LobbyId
                    }
                };
                lobbies.Add(l);
            }

            return(lobbies);
        }
        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();
        }
        public void DeletePlayerLobby(DTO.PlayerLobby pl)
        {
            PlayerLobby playlobby = new PlayerLobby();

            playlobby.LobbyId    = pl.LobbyId.LobbyId;
            playlobby.HostPlayer = pl.HostPlayer.PlayerId;

            dc.PlayerLobbies.DeleteOnSubmit(playlobby);
            dc.SubmitChanges();
        }
        public void StartGame(DTO.Player Host)
        {
            var lst = from l in gamelobbies where l.HostPlayer == Host select new { l.LobbyId.LobbyId };

            var update = (from l in dc.PlayerLobbies where l.LobbyId == lst.Single().LobbyId select l).Single();

            update.IsWaitingForPlayers = false;

            var lobby = from d in gamelobbies where d.HostPlayer == Host select d;

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

            dc.SubmitChanges();
        }
 private static DTO.PlayerLobby ConvertToDTOPlayerLobby(DTO.Player Host, IEnumerable <DTO.PlayerLobby> lobby)
 {
     DTO.PlayerLobby plLobby = new DTO.PlayerLobby();
     foreach (var item in lobby)
     {
         if (item.HostPlayer == Host)
         {
             plLobby.HostPlayer           = item.HostPlayer;
             plLobby.IsAwaitingForPlayers = item.IsAwaitingForPlayers;
             plLobby.LobbyId   = item.LobbyId;
             plLobby.Player    = item.Player;
             plLobby.StartGame = item.StartGame;
         }
     }
     return(plLobby);
 }
示例#6
0
        //delete a single playerlobby
        public void DeletePlayerLobby(DTO.PlayerLobby pl)
        {
            //get the wanted playerlobby out of the game lobby list
            var play = (from p in gamelobbies where p.HostPlayer.PlayerId == pl.HostPlayer.PlayerId select p).First();

            //delete this lobby
            gamelobbies.Remove(play);

            //get the playerlobby to delete
            PlayerLobby playlobby = new PlayerLobby();

            playlobby.LobbyId    = pl.LobbyId.LobbyId;
            playlobby.HostPlayer = pl.HostPlayer.PlayerId;

            dc.PlayerLobbies.DeleteOnSubmit(playlobby);
            dc.SubmitChanges();
        }
        public List <DTO.PlayerLobby> GatAvailablePlayLobbies()
        {
            /* var rooms = from r in dc.Players
             *           join pl in dc.PlayerLobbies
             *           on r.PlayerId equals pl.HostPlayer
             *           where pl.IsWaitingForPlayers == true
             *           select new { pl.LobbyId, pl.HostPlayer};*/
            var rooms = from p in dc.PlayerLobbies
                        where p.PlayerId == p.HostPlayer
                        select new { p.LobbyId, p.HostPlayer };

            /*var rooms = from r in dc.PlayerLobbies
             *            where r.IsWaitingForPlayers == true
             *            select r;*/


            List <DTO.PlayerLobby> lobbies = new List <DTO.PlayerLobby>();

            foreach (var item in rooms)
            {
                DTO.PlayerLobby l = new DTO.PlayerLobby(new DTO.Player()
                {
                    PlayerId = (int)item.HostPlayer, PlayerName = GetPlayerName((int)item.HostPlayer)
                })
                {
                    LobbyId = new DTO.Lobby()
                    {
                        LobbyId = item.LobbyId
                    }
                };

                /* DTO.PlayerLobby l = new DTO.PlayerLobby();
                 * l.HostPlayer = new DTO.Player() { PlayerId = (int)item.HostPlayer};
                 * l.LobbyId = new DTO.Lobby() { LobbyId = (int)item.LobbyId };
                 * l.IsAwaitingForPlayers = (bool)item.IsWaitingForPlayers;*/
                lobbies.Add(l);
            }

            return(lobbies);
        }
示例#8
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();
        }