private void Start_Click(object sender, RoutedEventArgs e)
        {
            playerOne = P1.Text;
            playerTwo = P2.Text;

            if (playerOne == "" || playerTwo == "")
            {
                MessageBox.Show("Please enter names!");
            }
            else
            {
                (App.Current as App).player1 = P1.Text.ToString();
                (App.Current as App).player2 = P2.Text.ToString();
                using (var db = new Connect4Entities1())
                {
                    Player newPlayer  = new Player();
                    Player newPlayer2 = new Player();
                    newPlayer.Name    = playerOne;
                    newPlayer.Wins    = 0;
                    newPlayer.Losses  = 0;
                    newPlayer2.Name   = playerTwo;
                    newPlayer2.Wins   = 0;
                    newPlayer2.Losses = 0;
                    db.Players.Add(newPlayer);
                    db.Players.Add(newPlayer2);
                    db.SaveChanges();
                }
            }
            GameWindow gameWindow = new GameWindow();

            this.Close();
            gameWindow.Show();
        }
Esempio n. 2
0
 void Initialise()
 {
     using (var db = new Connect4Entities1())
     {
         Scores = db.Players.ToList();
         PlayerOneScore.Text = Scores[0].Wins.ToString();
         PlayerTwoScore.Text = Scores[0].Wins.ToString();
     }
 }
 void Initialise()
 {
     using (var db = new Connect4Entities1())
     {
         Leaderboard.ItemsSource = null;
         players = db.Players.OrderByDescending(w => w.Wins).ToList();
     }
     Leaderboard.DisplayMemberPath = "Name";
     //Leaderboard.DisplayMemberPath = "Wins";
     //ListBoxCustomers.ItemsSource = customers;
     Leaderboard.ItemsSource = players;
 }
Esempio n. 4
0
        public void UpdateScores()
        {
            if (BurlyPlayerWinner.IsEnabled == true && Connect4Style.CanIncreaseBurlyScore == true)
            {
                p1Count++;
                PlayerOneScore.Text = p1Count.ToString();
                //player = (Player)PlayerOne.Content;
                using (var db = new Connect4Entities1())
                {
                    //var updatePlayer = db.Players.Find(player.Id);
                    //updatePlayer.Wins = p1Count;

                    /*var updatePlayer = from player in db.Players
                     *                 where player.Name == PlayerOne.Content.ToString()
                     *                 orderby player.Id descending
                     *                 let p1Count = player.Wins
                     *                 select player;*/

                    //var updatePlayer = new Player();
                    var updatePlayer = db.Players.OrderByDescending(p => p.Id).Skip(1).First();
                    updatePlayer.Wins = p1Count;
                    var updatePlayer2 = db.Players.OrderByDescending(p => p.Id).First();
                    updatePlayer2.Losses++;
                    db.SaveChanges();
                    //var updatePlayer = db.Players.Select(p => { p.Wins = p1Count; return p; })
                }
            }

            if (GrayPlayerWinner.IsInitialized == true && Connect4Style.CanIncreaseGrayScore == true)
            {
                p2Count++;
                PlayerTwoScore.Text = p2Count.ToString();
                //player = (Player)PlayerTwo.Content;
                using (var db = new Connect4Entities1())
                {
                    //var updatePlayer = db.Players.Find(player.Id);
                    //updatePlayer.Wins = p2Count;

                    /*var updatePlayer = from player in db.Players
                     *                 where player.Name == PlayerTwo.Content.ToString()
                     *                 orderby player.Id descending
                     *                 let p2Count = player.Wins
                     *                 select player;*/
                    //var updatePlayer = new Player();
                    var updatePlayer = db.Players.OrderByDescending(p => p.Id).Skip(1).First();
                    updatePlayer.Losses++;
                    var updatePlayer2 = db.Players.OrderByDescending(p => p.Id).First();
                    updatePlayer2.Wins = p2Count;
                    db.SaveChanges();
                }
            }
        }