Esempio n. 1
0
        /// <summary>
        /// Updates the UI from the board.matrix, if the match has ended it adds the two player to the database.
        /// </summary>
        private void updateBoard()
        {
            grid.Children.Clear();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (gameEngine.getBoard().matrix[i, j] is Tile)
                    {
                        Ellipse el1 = new Ellipse();
                        el1.Fill = new SolidColorBrush(getColor(gameEngine.getBoard().matrix[i, j].isBlack));
                        Grid.SetRow(el1, i);
                        Grid.SetColumn(el1, j);
                        grid.Children.Add(el1);
                    }
                    else
                    {
                        Button btn = new Button();
                        Grid.SetRow(btn, i);
                        Grid.SetColumn(btn, j);
                        btn.Opacity = 0;
                        btn.Click  += CellClicker;
                        grid.Children.Add(btn);
                    }
                    if (gameEngine.blackTurn)
                    {
                        turn.Text = "Black turn";
                    }
                    else
                    {
                        turn.Text = "White turn";
                    }
                    score.Text = string.Format("Score:\nBlack: {0}\nWhite: {1}", gameEngine.blackScore, gameEngine.whiteScore);
                }
            }
            if (!gameEngine.hasPossibleMove(gameEngine.blackTurn))
            {
                if (gameEngine.blackScore > gameEngine.whiteScore)
                {
                    MessageBox.Show("Black won!");
                }
                else
                {
                    MessageBox.Show("White won!");
                }
                sw_B.Stop();
                sw_W.Stop();
                _isFinished = true;
            }
            if (_isFinished)
            {
                if (!isAgainstAI)
                {
                    TimeSpan ts_b    = sw_B.Elapsed;
                    TimeSpan ts_w    = sw_W.Elapsed;
                    Person   player1 = new Person();
                    Person   player2 = new Person();
                    player1.firstName = p1_firstname; player1.lastName = p1_lastname; player1.time = String.Format("{0:00}:{1:00}:{2:00}",
                                                                                                                   ts_b.Minutes, ts_b.Seconds, ts_b.Milliseconds / 10); player1.bestScore = gameEngine.blackScore;
                    player2.firstName = p2_firstname; player2.lastName = p2_lastname; player2.time = String.Format("{0:00}:{1:00}:{2:00}",
                                                                                                                   ts_w.Minutes, ts_w.Seconds, ts_w.Milliseconds / 10); player2.bestScore = gameEngine.whiteScore;
                    SqliteDataAccess.SavePerson(player1);
                    SqliteDataAccess.SavePerson(player2);
                }
                this.Close();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Load the people from the database to a list.
 /// </summary>
 private void LoadPeopleList()
 {
     list = SqliteDataAccess.LoadPeople();
     list = list.OrderByDescending(Person => Person.bestScore).ToList();
 }