Beispiel #1
0
        public void PlayerRegister(string fullName, string userName, string password, decimal money, string sex, byte[] image)
        {
            using (var db = new PlayerEntities())
            {
                var query = db.Players.Where(p => p.Username == userName);

                // if there aren't players with that username Any allows register
                if (!query.Any())
                {
                    var player = new Player
                    {
                        FullName = fullName,
                        Username = userName,
                        Password = password,
                        Money    = money,
                        Sex      = sex,
                        Image    = image
                    };

                    db.Players.Add(player);
                    db.SaveChanges();
                }
                else
                {
                    MessageBox.Show("This username is taken, choose another one!", "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
 public Player GetCurrentPlayer()
 {
     using (var db = new PlayerEntities())
     {
         Player player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         return(player);
     }
 }
Beispiel #3
0
 public void PlayerDeleteAccount()
 {
     using (var db = new PlayerEntities())
     {
         Player player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         db.Players.Remove(player);
         db.SaveChanges();
     }
 }
Beispiel #4
0
 public void PlayerPasswordChange(string password)
 {
     using (var db = new PlayerEntities())
     {
         Player player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         player.Password = password;
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public void PlayerMoney(decimal money, decimal loan)
 {
     using (var db = new PlayerEntities())
     {
         var player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         player.Money = money;
         player.Loan  = loan;
         db.SaveChanges();
     }
 }
Beispiel #6
0
 public MemoryStream ConvertByteToImage()
 {
     using (var db = new PlayerEntities())
     {
         var    player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         byte[] image  = player.Image;
         var    ms     = new MemoryStream(image);
         return(ms);
     }
 }
Beispiel #7
0
        private void FormRanglist_Load(object sender, EventArgs e)
        {
            using (var db = new PlayerEntities())
            {
                var players = db.Players.OrderByDescending(p => p.Money).Take(10);

                foreach (var player in players)
                {
                    lbHighScoreRanglist.Items.Add($"{player.Username} ---> {player.Money:C2}");
                }
            }
        }
Beispiel #8
0
 public void PlayerRestartAccount()
 {
     using (var db = new PlayerEntities())
     {
         Player player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         player.Money        = 0;
         player.Gold         = 0;
         player.Petrol       = 0;
         player.Bitcoin      = 0;
         player.Antiques     = 0;
         player.Shares       = 0;
         player.Technologies = 0;
         db.SaveChanges();
     }
 }
Beispiel #9
0
        public IQueryable <Player> PlayerLogin(string userName, string password)
        {
            using (var db = new PlayerEntities())
            {
                var query = db.Players.Where(p => p.Username == userName && p.Password == password);

                if (!query.Any())
                {
                    return(null);
                }
                else
                {
                    currentPlayerUsername = userName;
                    return(query);
                }
            }
        }
Beispiel #10
0
        private void btnSaveGame_Click(object sender, EventArgs e)
        {
            using (var db = new PlayerEntities())
            {
                var player = db.Players.SingleOrDefault(p => p.Username == PlayerManager.currentPlayerUsername);

                player.Money        = decimal.Parse(lblMoneyGame.Text);
                player.Gold         = long.Parse(lblGoldGame.Text);
                player.Petrol       = long.Parse(lblPetrolGame.Text);
                player.Bitcoin      = long.Parse(lblBitcoinGame.Text);
                player.Technologies = long.Parse(lblTechnologiesGame.Text);
                player.Antiques     = long.Parse(lblAntiquesGame.Text);
                player.Shares       = long.Parse(lblSharesGame.Text);

                db.SaveChanges();

                FormGame.ActiveForm.Dispose();
                FormProfile frmP = new FormProfile();
                frmP.ShowDialog();
            }
        }
Beispiel #11
0
 public void PlayerImageChange(PictureBox pictureBox)
 {
     using (var db = new PlayerEntities())
     {
         var player = db.Players.SingleOrDefault(p => p.Username == currentPlayerUsername);
         using (var dialog = new OpenFileDialog()
         {
             Filter = "PNG|*.png|JPG|*.jpg|GIF|*.gif", Title = "Please select a photo", Multiselect = false
         })
         {
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 pictureBox.ImageLocation = dialog.FileName;
                 string imagePath = pictureBox.ImageLocation;
                 byte[] image     = ConvertImageToByte(imagePath);
                 player.Image = image;
                 db.SaveChanges();
             }
         }
     }
 }