Example #1
0
        // create new board to contain tiles of image
        // reset all related states
        // [catch exception in calling function]
        private void NewBoardListView()
        {
            // crop image
            string filename = ImageListView.SelectedItem as string;

            GenerateTiles(filename, ref ImageTiles);

            // reset state
            isShowResult = false;
            TerminateGameAndRelatedThreads();

            game.Reset();

            StopTimer();
            TimerTextBlock.Text = "Timer " + MaxMinutes.ToString().PadLeft(2, '0') + ":" + "0".PadLeft(2, '0');
            countSecond         = 0;

            isBoardEnabled = false;


            // set value for board
            Board board = game.GetCurrentBoard();

            listValue = new BindingList <MyInt>();
            for (int i = 0; i < Game.NumberOfTiles; i++)
            {
                listValue.Add(new MyInt()
                {
                    Value = board.GetAt(i)
                });
            }
            BoardListView.ItemsSource = listValue;
        }
Example #2
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // icons
                icons            = new ImageName();
                this.DataContext = icons;
                this.Icon        = new BitmapImage(new Uri(icons.ApplicationIcon[0]));

                // game
                game = new Game();

                // timer
                timer          = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick    += Timer_Tick;

                TimerTextBlock.Text = "Timer " + MaxMinutes.ToString().PadLeft(2, '0') + ":" + "0".PadLeft(2, '0');
                countSecond         = 0;

                // images & board
                NewImagelistView();
                NewBoardListView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }