Пример #1
0
            private void swap(object sender, EventArgs e)
            {
                if (isClickable && isNeighbour) // The swap works only in the 4-neighbourhood
                {
                    // Can I do a simple swap of the objects instead of changing all of their properties?
                    tiles[hidden.X, hidden.Y].GetPicture().Visible = true; // Unhide
                    tiles[hidden.X, hidden.Y].GetPicture().Tag     = pic.Tag;
                    pic.Tag = "0";
                    setHidden();
                    setNeighbours(tiles);

                    // Check if the puzzle is solved:

                    var currentSequence = new List <int>();
                    for (int i = 0; i < backboardSize; i++)
                    {
                        for (int j = 0; j < backboardSize; j++)
                        {
                            currentSequence.Add(Convert.ToInt32(tiles[i, j].GetPicture().Tag));
                        }
                    }

                    if (currentSequence[0] == 1) // Must begin with '1'
                    {
                        bool won = true;
                        for (int i = 1; i < currentSequence.Count - 1; i++)
                        {
                            if (currentSequence[i] - currentSequence[i - 1] != 1) // Must be a sequence
                            {
                                won = false;
                                break;
                            }
                        }
                        if (won)
                        {
                            isClickable = false;
                            frm.btnRestartGame.Enabled = false;

                            frm.manageTimer(gameState.End);
                            string text = "You have won the match!\n\nTime: " + frm.txtTime.Text;
                            MessageBox.Show(text, "Congratulations!");

                            frmHighScores highScores = new frmHighScores(backboardSize, frm.txtTime.Text);
                            //highScores.records.PotentialTime = frm.txtTime.Text;
                            highScores.ShowDialog();
                        }
                    }
                }
            }
Пример #2
0
        private void btnHighScores_Click(object sender, EventArgs e)
        {
            frmHighScores highScores = new frmHighScores();

            highScores.ShowDialog();
        }