//delete a single player
        public void DeletePlayer(DTO.Player pl)
        {
            Player p = new Player();

            p.PlayerId   = pl.PlayerId;
            p.PlayerName = pl.PlayerName;

            dc.Players.DeleteOnSubmit(p);
            dc.SubmitChanges();
        }
        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;

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

            //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" + pl.Player.Count, 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()

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

            #endregion

            dc.SubmitChanges();
        }
        public bool 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;

            dc.SubmitChanges();

            return(true);
        }
        private void CheckIfMaxPlayerExceeded(DTO.Player host)
        {
            var lobby = (from p in gamelobbies where p.LobbyId.LobbyName == host.PlayerName select p).Single();

            if (lobby.Player.Count() == 4)
            {
                lobby.StartGame = true;
            }
            else
            {
                lobby.StartGame = false;
            }
        }
        public DTO.Player GetPlayerById(int id)
        {
            var pl = from p in dc.Players where p.PlayerId == id select p;

            DTO.Player player = new DTO.Player();

            foreach (var item in pl)
            {
                player = ConvertToPlayer(item);
            }

            return(player);
        }
Ejemplo n.º 6
0
        /*//OLD METHOD
         * public DTO.MonopolyEngine.GameState Brent(DTO.Player me)
         * {
         *  DTO.MonopolyEngine.GameState tmp = NewGame.publicState;
         *
         *  DTO.MonopolyEngine.StateToClient state = new DTO.MonopolyEngine.StateToClient();
         *  return null;//NewGame.publicState;
         * }*/

        //NEW METHOD TOMPEETERS 10/12/2013
        DTO.MonopolyEngine.StateToClient IService1.GetState(DTO.Player me)
        {
            DTO.MonopolyEngine.GameState tmp = NewGame.publicState;

            DTO.MonopolyEngine.StateToClient state = new DTO.MonopolyEngine.StateToClient();

            // state.ActivePlayer = tmp.ActivePlayer;
            state.ActiveTileName         = tmp.ActiveTileName;
            state.CurrentPhase           = tmp.CurrentPhase;
            state.DieCast                = tmp.DieCast;
            state.EnableBuy              = tmp.EnableBuy;
            state.lastDieRoll            = tmp.lastDieRoll;
            state.PlayerTradeRequested   = tmp.PlayerTradeRequested;
            state.PropertyTradeDirection = tmp.PropertyTradeDirection;
            state.PropertyTradeRequested = tmp.PropertyTradeRequested;
            state.TurnNumber             = tmp.TurnNumber;
            state.Log       = tmp.Notificationlog;
            state.Ownership = tmp.Ownership;
            state.IsBought  = tmp.IsBought;
            //state.PlayerList = tmp.PlayerList;

            state.ActivePlayer = new DTO.MonopolyEngine.GamePlayerToClient();


            foreach (var p in tmp.PlayerList)
            {
                if (p.MyPlayer.PlayerId == me.PlayerId)
                {
                    state.ActivePlayer.MyName            = p.MyPlayer.PlayerName;
                    state.ActivePlayer.Cash              = p.Cash;
                    state.ActivePlayer.HasEscapePrisonCh = p.HasEscapePrisonCh;
                    state.ActivePlayer.HasEscapePrisonCo = p.HasEscapePrisonCo;
                    state.ActivePlayer.IsActive          = p.IsActive;
                    state.ActivePlayer.IsPlaying         = p.IsPlaying;
                    state.ActivePlayer.IsPrison          = p.IsPrison;
                    state.ActivePlayer.Location          = p.Location;
                    state.ActivePlayer.PrisonTime        = p.PrisonTime;
                    state.OwnedProps = new List <DTO.MonopolyEngine.PropertyToClient>();
                    foreach (var item in p.PlayerProperty)
                    {
                        state.OwnedProps.Add(new DTO.MonopolyEngine.PropertyToClient()
                        {
                            HouseLevel = item.HouseLevel, ID = item.ID, Morguage = item.Morguage, SetLevel = item.SetLevel
                        });
                    }
                }
            }

            return(state);//NewGame.publicState;
        }
Ejemplo n.º 7
0
 //get the playerlocation
 public int GetPlayerLocation(DTO.Player Host, DTO.Player Player)
 {
     foreach (var item in NewGame.publicState.PlayerList)
     {
         if (NewGame.publicState.ActivePlayer.PlayerId == Player.PlayerId)
         {
             if (item.Location != 0)
             {
                 location = item.Location;
             }
         }
     }
     return(location.Value);
 }
Ejemplo n.º 8
0
        //send a game update => only the dices who has been rolled
        public List <int> GetGameUpdate(DTO.Player host)
        {
            List <int> Dice = new List <int>();

            //let the client dice
            NewGame.Dice();
            var dice = from p in NewGame.publicState.lastDieRoll select p;

            foreach (var item in dice)
            {
                //get the dices
                Dice.Add(Convert.ToInt32(item));
            }
            return(Dice);
        }
        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();
        }
Ejemplo n.º 10
0
        //Method to see if the max players of an gamelobby are exceeded
        private void CheckIfMaxPlayerExceeded(DTO.Player host)
        {
            //get first lobby whose lobbyname exceeds the host playername and select the lobby
            var lobby = (from p in gamelobbies where p.LobbyId.LobbyName == host.PlayerName select p).First();

            //check if playercount is 4
            if (lobby.Player.Count() == 4)
            {
                lobby.StartGame = true;
            }
            else
            {
                lobby.StartGame = false;
            }
        }
Ejemplo n.º 11
0
        public int OrderNum(DTO.Player me)
        {
            DTO.MonopolyEngine.GameState tmp = NewGame.publicState;
            int ordernum = 0;

            foreach (var item in tmp.PlayerList)
            {
                if (item.MyPlayer.PlayerId == me.PlayerId)
                {
                    ordernum = item.OrderNumber;
                }
            }

            return(ordernum);
        }
Ejemplo n.º 12
0
        //get the player by its id
        public DTO.Player GetPlayerById(int id)
        {
            //get all players which its id is the same as the id that is given
            var pl = from p in dc.Players where p.PlayerId == id select p;

            //make an dto player
            DTO.Player player = new DTO.Player();

            foreach (var item in pl)
            {
                //convert the database player to an DTO player
                player = ConvertToPlayer(item);
            }

            return(player);
        }
 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);
 }
        public int GetPlayerLocation(DTO.Player Host, DTO.Player Player)
        {
            // var lst = (from p in gamelobbies where p.HostPlayer.PlayerId == Host.PlayerId select p).First();

            foreach (var item in NewGame.publicState.PlayerList)
            {
                if (NewGame.publicState.ActivePlayer.PlayerId == Player.PlayerId)
                {
                    if (item.Location != 0)
                    {
                        location = item.Location;
                    }
                }
            }
            return(location.Value);
        }
        public List <int> GetGameUpdate(DTO.Player host)
        {
            var lst = (from l in gamelobbies where l.HostPlayer.PlayerId == host.PlayerId select l).First();

            List <int> Dice = new List <int>();

            if (lst.StartGame)
            {
                var dice = from p in newGame.publicState.lastDieRoll select p;
                foreach (var item in dice)
                {
                    Dice.Add(Convert.ToInt32(item));
                }
            }

            return(Dice);
        }
        /*//OLD METHOD
         * public DTO.MonopolyEngine.GameState Brent(DTO.Player me)
         * {
         *  DTO.MonopolyEngine.GameState tmp = NewGame.publicState;
         *
         *  DTO.MonopolyEngine.StateToClient state = new DTO.MonopolyEngine.StateToClient();
         *  return null;//NewGame.publicState;
         * }*/

        //NEW METHOD TOMPEETERS 10/12/2013
        DTO.MonopolyEngine.StateToClient IService1.GetState(DTO.Player me)
        {
            DTO.MonopolyEngine.GameState tmp = NewGame.publicState;

            DTO.MonopolyEngine.StateToClient state = new DTO.MonopolyEngine.StateToClient();

            // state.ActivePlayer = tmp.ActivePlayer;
            state.ActiveTileName         = tmp.ActiveTileName;
            state.CurrentPhase           = tmp.CurrentPhase;
            state.DieCast                = tmp.DieCast;
            state.EnableBuy              = tmp.EnableBuy;
            state.lastDieRoll            = tmp.lastDieRoll;
            state.PlayerTradeRequested   = tmp.PlayerTradeRequested;
            state.PropertyTradeDirection = tmp.PropertyTradeDirection;
            state.PropertyTradeRequested = tmp.PropertyTradeRequested;
            state.TurnNumber             = tmp.TurnNumber;
            state.Log = tmp.Notificationlog;
        public void JoinLobbyRoom(DTO.Player pl, DTO.Player Host)
        {
            // var plName = (from p in dc.Players where p.PlayerId == hostID select p.PlayerName).FirstOrDefault();
            int lobbyId = (from l in dc.Lobbies where l.LobbyName == Host.PlayerName select l.LobbyId).Single();

            CheckIfMaxPlayerExceeded(Host);

            PlayerLobby plobby = new PlayerLobby();

            plobby.HostPlayer = Host.PlayerId;
            plobby.LobbyId    = lobbyId;
            plobby.PlayerId   = (int)pl.PlayerId;

            EnterLobby(pl, Host.PlayerName);

            dc.PlayerLobbies.InsertOnSubmit(plobby);
            dc.SubmitChanges();
        }
        public void JoinLobbyRoom(DTO.Player pl, int hostID)
        {
            var plName  = from p in dc.Players where p.PlayerId == hostID select p;
            int lobbyId = (from l in dc.Lobbies where l.LobbyName == pl.PlayerName select l.LobbyId).FirstOrDefault();

            try
            {
                PlayerLobby plobby = new PlayerLobby();
                plobby.HostPlayer = hostID;
                plobby.LobbyId    = lobbyId;
                plobby.PlayerId   = (int)pl.PlayerId;

                dc.PlayerLobbies.InsertOnSubmit(plobby);
                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 19
0
 //get an update from the gamestate
 public DTO.MonopolyEngine.GameState GetStateUpdate(DTO.Player player)
 {
     //if the playerid is the same id as that from the activeplayer => send an update
     if (NewGame.Started)
     {
         if (NewGame.publicState.ActivePlayer.PlayerId == player.PlayerId)
         {
             return(NewGame.publicState);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 20
0
        //Joining lobbies
        #region Join()

        //join method
        public void JoinLobbyRoom(DTO.Player pl, DTO.Player Host)
        {
            //select the lobbyid from de lobbies in the database where the lobbyname is the same as the hosts playername
            int lobbyId = (from l in dc.Lobbies where l.LobbyName == Host.PlayerName select l.LobbyId).First();
            //  CheckIfMaxPlayerExceeded(Host);

            PlayerLobby plobby = new PlayerLobby();

            plobby.HostPlayer          = Host.PlayerId;
            plobby.LobbyId             = lobbyId;
            plobby.PlayerId            = (int)pl.PlayerId;
            plobby.IsWaitingForPlayers = true;
            plobby.StartGame           = false;
            //let the player pl join the lobby
            EnterLobby(pl, Host.PlayerName);

            dc.PlayerLobbies.InsertOnSubmit(plobby);
            dc.SubmitChanges();
        }
Ejemplo n.º 21
0
        public List <DTO.Player> ShowDiceRoll()
        {
            var p = from pl in dc.Players
                    where pl.PlayerId == 1
                    select pl;

            List <DTO.Player> players = new List <DTO.Player>();

            foreach (var item in p)
            {
                DTO.Player pl = new DTO.Player()
                {
                    PlayerId = (int)item.PlayerId, PlayerName = item.PlayerName, AlreadExist = (bool)item.AlreadExist, DiceEyes = (int)item.DiceEyes, DiceOnceDouble = (bool)item.OnceDouble, DiceOne = (int)item.DiceOne, DiceTwiceDouble = (bool)item.TwiceDouble, DiceTwo = (int)item.DiceTwo, IsDiceRolling = (bool)item.IsDiceRolling, Jail = (bool)item.Jail
                };

                players.Add(pl);
            }

            return(players);
        }
        private void EnterLobby(DTO.Player pl, string lobbyName)
        {
            var l = (from d in dc.Lobbies where d.LobbyName == lobbyName select d.LobbyId).Single();

            if (lobbyName != null)
            {
                var lob = (from p in gamelobbies where p.LobbyId.LobbyId == (int)l select p).Single();

                if (lob != null)
                {
                    if (lob.StartGame != true)
                    {
                        lob.Player.Add(new DTO.Player()
                        {
                            PlayerId = pl.PlayerId, PlayerName = pl.PlayerName, AlreadExist = pl.AlreadExist
                        });
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public void CreateLobby(DTO.Player host, int lobby)
        {
            try
            {
                PlayerLobby pl = new PlayerLobby();
                pl.HostPlayer          = (int)host.PlayerId;
                pl.LobbyId             = lobby;
                pl.PlayerId            = (int)host.PlayerId;
                pl.IsWaitingForPlayers = true;

                Lobby alobby = new Lobby();
                alobby.LobbyName = host.PlayerName;
                alobby.LobbyId   = lobby;


                dc.Lobbies.InsertOnSubmit(alobby);
                dc.PlayerLobbies.InsertOnSubmit(pl);
                dc.SubmitChanges();
            }
            catch (Exception)
            {
            }
        }
        public void AddPlayer(DTO.Player pl)
        {
            Player p = new Player();

            p.PlayerId    = (int)pl.PlayerId;
            p.PlayerName  = pl.PlayerName;
            p.AlreadExist = false;

            bool b = false;

            b = CheckIfPlayerAlreadyExists(p);

            if (b)
            {
                dc.Players.DeleteOnSubmit(p);
                dc.SubmitChanges();
            }
            if (!b)
            {
                dc.Players.InsertOnSubmit(p);
                dc.SubmitChanges();
            }
        }
Ejemplo n.º 25
0
        //Joinlobby method
        private void EnterLobby(DTO.Player pl, string lobbyName)
        {
            //get first lobby whose lobbyname exceeds the string lobbyname and select the lobbyID
            var l = (from d in dc.Lobbies where d.LobbyName == lobbyName select d.LobbyId).First();

            if (lobbyName != null)
            {
                //get the gamelobby where the id is the value of l
                var lob = (from p in gamelobbies where p.LobbyId.LobbyId == (int)l select p).First();

                if (lob != null)
                {
                    if (lob.StartGame != true)
                    {
                        //add the player to the lobby
                        lob.Player.Add(new DTO.Player()
                        {
                            PlayerId = pl.PlayerId, PlayerName = pl.PlayerName, AlreadExist = pl.AlreadExist
                        });
                    }
                }
            }
        }
Ejemplo n.º 26
0
        //Lobby methods
        #region Create Lobby()

        //Lobby Creation
        public void CreateLobby(DTO.Player host)
        {
            try
            {
                //make a playerlobby and set the hostplayer member to th playerid of the host, ist lobbyid is been generated
                //its playerid is set to the playerid of the host, isawatingforplayers is true and startgame false
                PlayerLobby pl = new PlayerLobby();
                pl.HostPlayer          = (int)host.PlayerId;
                pl.LobbyId             = getLobbyId();
                pl.PlayerId            = (int)host.PlayerId;
                pl.IsWaitingForPlayers = true;  //to determine which playerlobby is still awaiting for players
                pl.StartGame           = false; //to indicate if the game is started or not

                //make a new lobby with its name is the name of the host and its id is the same as the playerlobby's id
                Lobby alobby = new Lobby();
                alobby.LobbyName = host.PlayerName;
                alobby.LobbyId   = pl.LobbyId;

                //add the lobby to the static playerlobby list
                gamelobbies.Add(new DTO.PlayerLobby(host)
                {
                    LobbyId = new DTO.Lobby()
                    {
                        LobbyId = alobby.LobbyId, LobbyName = alobby.LobbyName
                    }, IsAwaitingForPlayers = true, StartGame = false
                });

                //save all changes
                dc.Lobbies.InsertOnSubmit(alobby);
                dc.PlayerLobbies.InsertOnSubmit(pl);
                dc.SubmitChanges();
            }
            catch (Exception)
            {
            }
        }
        public int GetUpdate(DTO.Player host)
        {
            var lst = (from p in gamelobbies where p.HostPlayer.PlayerId == host.PlayerId select p).Single();

            return(newGame.publicState.RevisionNumber);
        }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
        //get the active player's id
        public int GetUpdate(DTO.Player host)
        {
            var lst = (from p in gamelobbies where p.HostPlayer.PlayerId == host.PlayerId select p).First();

            return(NewGame.publicState.ActivePlayer.PlayerId);
        }