Пример #1
0
        /// <summary>
        /// 玩家移动到指定位置.
        /// </summary>
        /// <param name="oldRow"></param>
        /// <param name="oldCol"></param>
        /// <param name="newRow"></param>
        /// <param name="newCol"></param>
        /// <returns></returns>
        private bool PlayerMoveTo(int oldRow, int oldCol, int newRow, int newCol)
        {
            if ((WALL_FLAG & this.mazeItems[newRow, newCol]) != 0)
            {
                // 新的位置有墙.
                return(false);
            }

            // 将原有位置,设置为用户离开.
            this.mazeItems[oldRow, oldCol] = (byte)(this.mazeItems[oldRow, oldCol] & PLAYER_LEAVE_FLAG);

            // 目标位置,设置为用户存在.
            this.mazeItems[newRow, newCol] = (byte)(this.mazeItems[newRow, newCol] | PLAYER_FLAG);

            // 调整用户当前位置.
            playerRow = newRow;
            playerCol = newCol;



            if (Moving != null)
            {
                MoveStep ms = new MoveStep(oldRow, oldCol);
                if (oldCol == newCol)
                {
                    if (oldRow == newRow - 1)
                    {
                        // 下
                        Moving(ms, MoveDirection.Down);
                    }
                    else
                    {
                        // 上
                        Moving(ms, MoveDirection.Up);
                    }
                }
                else
                {
                    if (oldCol == newCol - 1)
                    {
                        // 右
                        Moving(ms, MoveDirection.Right);
                    }
                    else
                    {
                        // 左
                        Moving(ms, MoveDirection.Left);
                    }
                }
            }

            // 认为成功的移动了.
            return(true);
        }
Пример #2
0
        /// <summary>
        /// 开始.
        /// </summary>
        public void Start()
        {
            for (int i = 0; i < this.MazeRows; i++)
            {
                for (int j = 0; j < this.MazeColumns; j++)
                {
                    if (this.mazeItems[i, j] == START_FLAG)
                    {
                        playerRow = i;
                        playerCol = j;
                        // 人安排到  开始的位置上.
                        this.mazeItems[i, j] = (byte)(this.mazeItems[i, j] | PLAYER_FLAG);

                        if (Moving != null)
                        {
                            MoveStep ms = new MoveStep(i, j);
                            Moving(ms, MoveDirection.None);
                        }
                        return;
                    }
                }
            }
        }