Exemplo n.º 1
0
        private void LClick(object sender, MouseButtonEventArgs e)
        {
            Rectangle s = (Rectangle)sender;
            int       x, y;                               //position
            Mine      mine = WhichMine(s, out x, out y);  //FIX LATER

            //Console.WriteLine(sender.ToString());
            //Console.WriteLine(mine.mine_count);

            if (mine.is_flag)
            {
                return;
            }

            if (first_click)
            {                                       //TODO start a game or modify sth ,start the timer or sth
                In_game                  = true;
                first_click              = false;
                dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
                dispatcherTimer.Start();
                if (mine.is_mine)
                {
                    Restart(x, y);
                    return;
                }
            }

            if (mine.is_cover)
            {
                if (mine.is_mine)
                {
                    In_game = false;
                    s.Fill  = BlockBrush.mine;
                    borders[x * col + y].Background = new SolidColorBrush(Colors.Red);
                    dispatcherTimer.Stop();
                    total_time = 0;
                    LoseGame();
                    Restart();
                }
                else
                {
                    if (ClickBlock(x, y, mine))
                    {
                        return;
                    }
                }
            }

            if (game.IsFinish(Mines))
            {
                dispatcherTimer.Stop();
                total_time = 0.001 * ((DateTime.Now - start_time).TotalMilliseconds % 1000) + (DateTime.Now - start_time).TotalMilliseconds / 1000;
                Left_mine  = "000";
                WinGame();
                Restart();
            }
        }
Exemplo n.º 2
0
        public void OpenBlock(int x, int y)
        {
            if (Mines[x, y].is_flag || !Mines[x, y].is_cover)
            {
                return;
            }
            if (Game_state == GameState.Win || Game_state == GameState.Lose)//no move
            {
                return;
            }
            if (first_click)
            {                                       //TODO start a game or modify sth ,start the timer or sth
                In_game     = true;
                first_click = false;
                Game_state  = GameState.On;

                dispatcherTimer.Start();
                if (mines[x, y].is_mine)
                {
                    Restart(x, y);            //to ensure not hit mine at first move
                    return;                   //not right, but temp
                }
            }

            Mines[x, y].is_cover = false;
            if (!Mines[x, y].is_mine)
            {
                if (!test_mode)
                {
                    Rectangles[x, y].Fill = BlockBrush.numbers[Mines[x, y].mine_count];
                }
            }
            else
            {
                Rectangles[x, y].Fill           = BlockBrush.mine;
                borders[x * col + y].Background = new SolidColorBrush(Colors.Red);
                LoseGame();
                Game_state = GameState.Lose;
                //Restart();
                return;
            }

            if (Mines[x, y].Is_blank)
            {
                for (int i = x - 1; i < x + 2; i++)
                {
                    for (int j = y - 1; j < y + 2; j++)
                    {
                        if (InBorder(i, j) && Mines[i, j].is_cover)
                        {
                            OpenBlock(i, j);
                        }
                    }
                }
            }


            if (game.IsFinish(Mines))
            {
                Left_mine = "000";
                WinGame();
                Game_state = GameState.Win;
                //Console.WriteLine("test {0} {1}", x, y);
                //Restart();
                return;
            }

            return;
        }