Esempio n. 1
0
 //開關
 void gmStart()
 {
     //根據層數設定教室大小
     _width  = 5 + 2 * _level;
     _height = 5 + 2 * _level;
     this.ugdBoard.Children.Clear();
     this.ugdBoard.Columns = _width;
     this.ugdBoard.Rows    = _height;
     //設定教室內容
     _classroom = new _background[_height, _width];
     for (int row = 0; row < _height; row++)
     {
         for (int col = 0; col < _width; col++)
         {
             _background s;
             if (row % 2 == 1 && col % 2 == 1)
             {
                 s = new _background(false);
             }
             else
             {
                 s = new _background(true);
             }
             //設定紙條位置
             if (row == _width - 2 && col == _height - 2)
             {
                 s.Cheat     = true;
                 s.Done      = true;
                 cheatingRow = row;
                 cheatingCol = col;
             }
             s.Row = row;
             s.Col = col;
             _classroom[row, col] = s;
             this.ugdBoard.Children.Add(s);
         }
     }
     //設定視窗大小
     this.Width  = (_level * 2 + 5) * 88;
     this.Height = (_level * 2 + 5) * 74;
     //設定老師
     setTeacher();
 }
Esempio n. 2
0
 private void moveTeacher(object sender, EventArgs e)
 {
     getCheater();
     //當老師處於一塊地磚中間,決定移動位置
     if ((view.Margin.Top + 407) % 74 <= 6 && (view.Margin.Left + 352) % 88 <= 6)
     {
         bool directionDeciding = true;//尚未決定移動方向為true
         //判斷老師所在的格子
         int curR = (int)(((view.Margin.Top + 37 + 74 * _level) - (view.Margin.Top + 37 + 74 * _level) % 74) / 74);
         int curC = (int)(((view.Margin.Left + 44 + 88 * _level) - (view.Margin.Left + 44 + 88 * _level) % 88) / 88);
         //MessageBox.Show(curR.ToString() + " " + curC.ToString());
         //用以儲存老師前後左右的格子
         _background[] target = new _background[4];
         //預設為學生(不能行走)
         _background def = new _background(false);
         target[0] = def;
         target[1] = def;
         target[2] = def;
         target[3] = def;
         //若該格為走道,將其放入陣列
         if (curR + 1 < _height)
         {
             if (_classroom[curR + 1, curC].isFloor)
             {
                 target[0] = _classroom[curR + 1, curC];
             }
         }
         if (curC + 1 < _width)
         {
             if (_classroom[curR, curC + 1].isFloor)
             {
                 target[1] = _classroom[curR, curC + 1];
             }
         }
         if (curR - 1 >= 0)
         {
             if (_classroom[curR - 1, curC].isFloor)
             {
                 target[2] = _classroom[curR - 1, curC];
             }
         }
         if (curC - 1 >= 0)
         {
             if (_classroom[curR, curC - 1].isFloor)
             {
                 target[3] = _classroom[curR, curC - 1];
             }
         }
         while (directionDeciding)
         {
             //隨機決定移動方向
             Random random = new Random();
             int    rand   = random.Next(0, 4);
             //若移動方向為走道,放入moveStatus,已決定方向directionDeciding為false
             if (target[rand].isFloor)
             {
                 moveStatus        = rand;
                 directionDeciding = false;
             }
         }
         move();
         return;
     }
     else
     {
         move();
     }
 }