예제 #1
0
        private void gameToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            timePlayed = 0;
            if (grid != null)
            {
                this.Controls.Remove(grid);
                grid.Dispose();
                gameTimer.Stop();
            }
            int column, row, pair, diffPic;

            readFromConfig(out column, out row, out pair, out diffPic);
            grid          = new MemoryGrid(row, column, pair, diffPic);
            grid.Location = new Point(0, labelTimer.Location.Y + labelTimer.Height);

            grid.firstOpened += new EventHandler(timerStart);
            grid.lastOpened  += new EventHandler(timerStop);
            this.Controls.Add(grid);

            labelTimer.Text     = "0";
            labelTimer.Location = new Point((grid.Width - labelTimer.Width) / 2, labelTimer.Location.Y);
            labelTimer.Visible  = true;
        }
예제 #2
0
 public MainWindow()
 {
     InitializeComponent();
     grid = new MemoryGrid(GameGrid, 4, 4);
 }
예제 #3
0
        /// <summary>
        /// Timer + window visibility
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectWindowPlay(object sender, RoutedEventArgs e)
        {
            name1 = Name1.Text;
            name2 = Name2.Text;
            if (!String.IsNullOrEmpty(name1) && !String.IsNullOrEmpty(name2))
            {
                int    index      = GridSelection.SelectedIndex;
                int    themeindex = ThemeSelection.SelectedIndex;
                string theme      = "";

                ImageBrush myBrush = new ImageBrush();
                ParentGrid.Background = myBrush;

                switch (index)
                {
                case 0:
                    rows = 4;
                    cols = 4;
                    break;

                case 1:
                    rows = 4;
                    cols = 5;
                    break;

                case 2:
                    rows = 4;
                    cols = 6;
                    break;

                case 3:
                    rows = 5;
                    cols = 6;
                    break;

                case 4:
                    rows = 6;
                    cols = 6;
                    break;

                default:
                    rows = 4;
                    cols = 4;
                    break;
                }
                switch (themeindex)
                {
                case 0:
                    theme = "Bicycles";
                    size  = 8;
                    break;

                case 1:
                    theme = "Halloween";
                    size  = 18;
                    break;

                case 2:
                    theme = "Thanksgiving";
                    size  = 18;
                    break;
                }
                if ((size * 2) >= (rows * cols))
                {
                    Players players = new Players(name1, name2, NameOne, NameTwo, ScoreOne, ScoreTwo, PlayerTurn, PlayerTurnColor);
                    memoryGrid              = new MemoryGrid(GameGrid, rows, cols, players, theme);
                    myBrush.ImageSource     = new BitmapImage(new Uri("../../Images/" + theme + "/Background.jpg", UriKind.Relative));
                    SelectWindow.Visibility = Visibility.Collapsed;
                    GameWindow.Visibility   = Visibility.Visible;

                    if (theme == "Halloween")
                    {
                        GameHome.Source   = new BitmapImage(new Uri("../../Images/Halloween/home.png", UriKind.Relative));
                        GameLoad.Source   = new BitmapImage(new Uri("../../Images/Halloween/load.png", UriKind.Relative));
                        GameSave.Source   = new BitmapImage(new Uri("../../Images/Halloween/save.png", UriKind.Relative));
                        ExtrasHome.Source = new BitmapImage(new Uri("../../Images/Halloween/home.png", UriKind.Relative));
                        SelectHome.Source = new BitmapImage(new Uri("../../Images/Halloween/home.png", UriKind.Relative));
                        GameReset.Source  = new BitmapImage(new Uri("../../Images/Halloween/reset.png", UriKind.Relative));
                    }
                    else
                    {
                        GameHome.Source   = new BitmapImage(new Uri("../../Images/home.png", UriKind.Relative));
                        GameLoad.Source   = new BitmapImage(new Uri("../../Images/load.png", UriKind.Relative));
                        GameSave.Source   = new BitmapImage(new Uri("../../Images/save.png", UriKind.Relative));
                        ExtrasHome.Source = new BitmapImage(new Uri("../../Images/home.png", UriKind.Relative));
                        SelectHome.Source = new BitmapImage(new Uri("../../Images/home.png", UriKind.Relative));
                        GameReset.Source  = new BitmapImage(new Uri("../../Images/reset.png", UriKind.Relative));
                    }
                    dt.Interval = TimeSpan.FromMilliseconds(50);
                    dt.Tick    += dtTicker;
                    dt.Start();
                }
                else
                {
                    myBrush.ImageSource          = new BitmapImage(new Uri("../../Images/Bicycles/Background.jpg", UriKind.Relative));
                    PlayerWarningBox2.Visibility = Visibility.Visible;
                    Task.Delay(2000).ContinueWith(_ =>
                    {
                        PlayerWarningBox2.Visibility = Visibility.Collapsed;
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
            else
            {
                PlayerWarningBox.Visibility = Visibility.Visible;
                Task.Delay(2000).ContinueWith(_ =>
                {
                    PlayerWarningBox.Visibility = Visibility.Collapsed;
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }