示例#1
0
        public void MarkAsDeleted(User player)
        {
            using (var db = new JaipurEntities())
            {
                var toPay = IsGameFinished ? Winner : GetEnemyData(player).User;

                PayWinner(toPay);

                Game game = db.Game.FirstOrDefault((g) => g.Id == this.Id);
                if (game == null)
                {
                    return;
                }

                if (player.Id == ChallengerData.User.Id)
                {
                    game.ChallengerDeleted = ChallengerDeleted = true;
                }
                else if (player.Id == EnemyData.User.Id)
                {
                    game.EnemyDeleted = EnemyDeleted = true;
                }

                if (EnemyDeleted && ChallengerDeleted)
                {
                    db.Game.Remove(game);
                }

                db.SaveChanges();
            }
        }
示例#2
0
        public void Save()
        {
            using (var db = new JaipurEntities())
            {
                Game game = db.Game.First((g) => g.Id == this.Id);

                game.EnemyTurn = EnemyTurn;

                game.OnTable   = SerializeCards(OnTable);
                game.OnDeck    = SerializeCards(OnDeck);
                game.Resources = SerializeResources(Resources);

                game.ChallengerId     = ChallengerData.User.Id;
                game.ChallengerHand   = SerializeCards(ChallengerData.Hand);
                game.ChallengerCamels = ChallengerData.Camels;
                game.ChallengerPoints = ChallengerData.Points;

                game.EnemyId     = EnemyData.User.Id;
                game.EnemyHand   = SerializeCards(EnemyData.Hand);
                game.EnemyCamels = EnemyData.Camels;
                game.EnemyPoints = EnemyData.Points;

                game.ChallengerDeleted = ChallengerDeleted;
                game.EnemyDeleted      = EnemyDeleted;

                game.Bet         = Bet;
                game.BetAccepted = Accepted;

                db.SaveChanges();
            }
        }
示例#3
0
    protected void GridUsers_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Challenge")
        {
            User user = Session["User"] as User;

            GridUsers.SelectedIndex = int.Parse(e.CommandArgument.ToString());
            GridUsers.DataBind();

            int enemyId = (int)GridUsers.SelectedDataKey.Value;

            if (enemyId != user.Id)
            {
                using (var db = new JaipurEntities())
                {
                    var enemy = db.User.FirstOrDefault((u) => u.Id == enemyId);

                    var gameData = JaipurSocial.Core.GameData.CreateNewGame(user, enemy);
                    var saved    = db.Game.Add(gameData.ToGame());
                    db.SaveChanges();
                    Response.Redirect("Game.aspx?GameId=" + saved.Id);
                }
            }
            else
            {
                ShowMessage(Resources.Localization.CantChallengeYourself);
            }
        }
    }
示例#4
0
    protected void GridGames_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ViewGame")
        {
            GridGames.SelectedIndex = int.Parse(e.CommandArgument.ToString());
            GridGames.DataBind();
            Response.Redirect("Game.aspx?GameId=" + GridGames.SelectedDataKey.Value);
        }

        else if (e.CommandName == "DeleteGame")
        {
            GridGames.SelectedIndex = int.Parse(e.CommandArgument.ToString());
            GridGames.DataBind();

            using (var db = new JaipurEntities())
            {
                User logged = (Session["User"] as User);
                var  gameId = int.Parse(GridGames.SelectedDataKey.Value.ToString());
                var  game   = db.Game.FirstOrDefault(g => g.Id == gameId);

                var data = new GameData(game);
                data.MarkAsDeleted(logged);

                db.SaveChanges();
            }
            Response.Redirect("Default.aspx");
        }
    }
示例#5
0
        public void PayWinner(User winner = null)
        {
            winner = winner ?? Winner;
            if (winner == null)
            {
                return;
            }

            using (var db = new JaipurEntities())
            {
                var winnerId = winner.Id;
                var win      = db.User.First(u => u.Id == winnerId);
                win.Coins   += Bet + ChallengerData.Points + EnemyData.Points;
                winner.Coins = win.Coins;
                var gameId = Id;
                var gam    = db.Game.First(g => g.Id == gameId);
                gam.Bet = Bet = 0;
                ChallengerData.Points = gam.ChallengerPoints = 0;
                EnemyData.Points      = gam.EnemyPoints = 0;
                db.SaveChanges();
            }
        }
示例#6
0
    protected void BtnRegister_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            byte[] bytes = CryptoHelper.GetHash(TxtPassword.Text);

            try
            {
                using (var db = new JaipurEntities())
                {
                    if (!db.User.Any(u => u.Login.ToLower() == TxtLogin.Text.ToLower()))
                    {
                        db.User.Add(new User
                        {
                            Login    = TxtLogin.Text,
                            Email    = TxtEmail.Text,
                            Name     = TxtName.Text,
                            Coins    = 100,
                            Password = bytes
                        });
                        db.SaveChanges();

                        ShowMessage(Resources.Localization.RegisterSuccess, "Login.aspx");
                    }
                    else
                    {
                        ShowMessage(Resources.Localization.UserAlreadyExists);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessage(Resources.Localization.RegisterError + '\n' + ex.Message);
            }
        }
    }