Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
            DifficultySelect d1 = new DifficultySelect(mainWindow);

            d1.ShowDialog();
        }
Ejemplo n.º 2
0
 public void Recreate_Click(object sender, RoutedEventArgs e)
 {
     // 暂停并询问是否继续
     Pause_Click(null, null);
     if (MessageBox.Show("是否要重新开始?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
     {
         RecreateMaze();
         // 进行难度选择
         DifficultySelect d1 = new DifficultySelect(this);
         d1.ShowDialog();
     }
     Pause_Click(null, null);
 }
Ejemplo n.º 3
0
        // 第一次进入游戏
        private void entry()
        {
            // 先介绍游戏规则
            About d1 = new About();

            d1.ShowDialog();
            // 进行难度选择
            DifficultySelect d2 = new DifficultySelect(this);

            d2.ShowDialog();
            // 初始化并启动计时器
            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);
            dispatcherTimer.Start();
            isPause = false;
        }
Ejemplo n.º 4
0
        // 倒计时
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            double timeLeft = Convert.ToDouble(time.Content);

            time.Content = (timeLeft - 0.01).ToString();
            if (timeLeft == 0.01)
            {
                MessageBox.Show("时间到,尝试降低难度吧!");
                time.Content = 60.ToString(); // 重置计时器
                // 重置迷宫
                Maze.ColumnDefinitions.RemoveRange(0, g.GetLength(0));
                Maze.RowDefinitions.RemoveRange(0, g.GetLength(1));
                this.Visibility = Visibility.Hidden;
                // 进行难度选择
                DifficultySelect d1 = new DifficultySelect(this);
                d1.ShowDialog();
            }
        }
Ejemplo n.º 5
0
 private void Window_KeyDown(object sender, KeyEventArgs e)
 {
     if (isPause == false)
     {
         Thickness move;
         if (Keyboard.IsKeyDown(Key.Left)) // 左方向键
         {
             if (g[A.X - 1, A.Y].isConnected == true)
             {
                 move = new Thickness(P.Margin.Left - A.xstep, P.Margin.Top, P.Margin.Right + A.xstep, P.Margin.Bottom);
                 A.MoveToLeft();
                 P.Margin = move;
                 Maze_.route.Add(A.X);
                 Maze_.route.Add(A.Y);
             }
         }
         else if (Keyboard.IsKeyDown(Key.Up)) // 上方向键
         {
             if (g[A.X, A.Y - 1].isConnected == true)
             {
                 move = new Thickness(P.Margin.Left, P.Margin.Top - A.ystep, P.Margin.Right, P.Margin.Bottom + A.ystep);
                 A.MoveToTop();
                 P.Margin = move;
                 Maze_.route.Add(A.X);
                 Maze_.route.Add(A.Y);
             }
         }
         else if (Keyboard.IsKeyDown(Key.Right)) // 右方向键
         {
             if (g[A.X + 1, A.Y].isConnected == true)
             {
                 move = new Thickness(P.Margin.Left + A.xstep, P.Margin.Top, P.Margin.Right - A.xstep, P.Margin.Bottom);
                 A.MoveToRight();
                 P.Margin = move;
                 Maze_.route.Add(A.X);
                 Maze_.route.Add(A.Y);
             }
         }
         else if (Keyboard.IsKeyDown(Key.Down)) // 下方向键
         {
             if (g[A.X, A.Y + 1].isConnected == true)
             {
                 move = new Thickness(P.Margin.Left, P.Margin.Top + A.ystep, P.Margin.Right, P.Margin.Bottom - A.ystep);
                 A.MoveToBottom();
                 P.Margin = move;
                 Maze_.route.Add(A.X);
                 Maze_.route.Add(A.Y);
             }
         }
         // 玩家到达终点
         if (A.isOut() == true)
         {
             Pause_Click(null, null);
             Maze_.caculateScore(Convert.ToDouble(time.Content));
             if (MessageBox.Show("恭喜闯关成功,你的成绩为" + Maze_.Score + ",是否上传成绩?否则重新开始。", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
             {
                 RecreateMaze();
                 Visibility = Visibility.Hidden;
                 scc        = new Success(this);
                 scc.ShowDialog(); // 上传成绩
             }
             else
             {
                 RecreateMaze();
                 // 进行难度选择
                 DifficultySelect d1 = new DifficultySelect(this);
                 d1.ShowDialog();
             }
             Pause_Click(null, null);
         }
     }
 }