コード例 #1
0
        private void updatePointWinner(string player, char p)
        {
            using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext())
            {
                var UserWin = (from u in ctx.Users
                               where u.UserName == player
                               select u).FirstOrDefault();
                var WinGamePoint = (from g in ctx.SingleGames
                                    where g.Player1_UserName == player & g.Status == true
                                    select g).FirstOrDefault();

                if (checkInCol(p))
                {
                    UserWin.Points += 1100;
                    poin            = 1100;
                }
                else
                {
                    UserWin.Points += 1000;
                    poin            = 1000;
                }
                UserWin.NumOfGames    += 1;
                UserWin.NumOfWins     += 1;
                WinGamePoint.Winner    = player;
                WinGamePoint.GamePoint = poin;
                WinGamePoint.Status    = false;
                ctx.SaveChanges();
            }
        }
コード例 #2
0
        public void Register(string name, string pass)
        {
            using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext())
            {
                var IsExists = (from u in ctx.Users
                                where u.UserName == name
                                select u).FirstOrDefault();
                if (IsExists != null)
                {
                    ConnectedFault userNameTaken = new ConnectedFault
                    {
                        Details = name + " is taken, please pick another."
                    };
                    throw new FaultException <ConnectedFault>(userNameTaken);
                }
                User newUser = new User
                {
                    UserName       = name,
                    HashedPassword = pass,
                    NumOfGames     = 0,
                    NumOfLosses    = 0,
                    NumOfWins      = 0,
                    Points         = 0
                };
                ctx.Users.Add(newUser);
                ctx.SaveChanges();

                ICallback regCallback = OperationContext.Current.GetCallbackChannel <ICallback>();
                updateAllClinetToUpdateList(name);
                avilableClinets.Add(name, regCallback);
            }
        }
コード例 #3
0
        public void Disconnect(string player)
        {
            //remove from avilable clinet
            avilableClinets.Remove(player);
            //if is exit from game remove the game
            if (this.games.ContainsKey(player))
            {
                this.games.Remove(player);
            }
            //notify all other client that is disconnected
            foreach (var callBack in avilableClinets.Values)
            {
                Thread updateOtherPlayerThread = new Thread(() =>
                {
                    callBack.OtherPlayerDisconnected(player);
                }
                                                            );
                updateOtherPlayerThread.Start();
            }

            using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext())
            {
                List <string> PlayerGames = new List <string>();
                var           UpdatStatus = (from g in ctx.SingleGames
                                             where g.Player1_UserName == player || g.Player2_UserName == player & g.Status == true
                                             select g).ToList();
                if (PlayerGames.Count == 0)
                {
                    return;
                }
                foreach (var ga in UpdatStatus)
                {
                    ga.Status = false;
                    ctx.SaveChanges();
                }
                ctx.SaveChanges();
            }
        }
コード例 #4
0
        private void updatePointLose(string player, char p)
        {
            using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext())
            {
                var UserLose = (from u in ctx.Users
                                where u.UserName == player
                                select u).FirstOrDefault();

                if (checkInCol(p))
                {
                    UserLose.Points += 100;
                }
                UserLose.Points      += (10 * cntSquare(p));
                UserLose.NumOfGames  += 1;
                UserLose.NumOfLosses += 1;
                ctx.SaveChanges();
            }
        }
コード例 #5
0
        public void StartGameBetweenPlayers(string p1, string p2)
        {
            this.avilableClinets[p2].StartGameUser(p1);
            GameZone gameZone = new GameZone(p1, p2, this.avilableClinets[p1], this.avilableClinets[p2]);

            games.Add(p1, gameZone);
            games.Add(p2, gameZone);
            using (var ctx = new fourinrowDB_RoniShoseov_EilonOsherContext())
            {
                DateTime localTime = DateTime.Now;

                SingleGame newGame = new SingleGame
                {
                    Date             = localTime,
                    Player1_UserName = p1,
                    Player2_UserName = p2,
                    GamePoint        = 0,
                    Status           = true
                };
                ctx.SingleGames.Add(newGame);
                ctx.SaveChanges();
            }
            updateAllOtherUserToUpdateList(p1, p2);
        }