コード例 #1
0
        // 获取地图的边缘字符表示
        //22222222222
        //82000000002
        //22000000002
        //22000000002
        //22000000002
        //22000000002
        //22000000002
        //22000000002
        //22222222222
        //22222222229
        //222222222222
        public void GenBorderCharView()
        {
            _charView = new SiteType[_gameSizeH * 2 + 1][];

            for (int x = 0; x < _gameSizeH * 2 + 1; x++)
            {
                _charView[x] = new SiteType[_gameSizeW + 1];
            }

            for (int x = 0; x < _gameSizeH; x++)
            {
                for (int y = 0; y < _gameSizeW; y++)
                {
                    Room currentRoom = GetRoom(x, y);
                    if (currentRoom.GetSite(Direction.East) != null)
                    {
                        SetViewSite(x, y, Direction.East, currentRoom.GetSite(Direction.East).Iam());
                    }
                    if (currentRoom.GetSite(Direction.South) != null)
                    {
                        SetViewSite(x, y, Direction.South, currentRoom.GetSite(Direction.South).Iam());
                    }
                }
            }

            SetOuterWall();
        }
コード例 #2
0
        // 玩家移动
        public bool Move(Direction direction)
        {
            Room     currentRoom = _maze.GetRoom(_man.GetLocation());
            IMapSite dstSite     = currentRoom.GetSite(direction);

            if (dstSite != null && dstSite.EnterAble)
            {
                Room dstRoom     = dstSite.Enter(currentRoom);
                var  dstLocation = dstRoom.GetLocation();
                if (dstLocation - _man.GetLocation() == 1)
                {
                    // neighbor
                    _man.Move(direction);
                }
                else
                {
                    _man.SetLocation(dstLocation);
                }
                return(true);
            }

            return(false);
        }