Пример #1
0
        private void SnakeBoard_Paint(object sender, PaintEventArgs e)
        {
            Graphics g    = e.Graphics;
            Font     font = new Font("Consolas", 50);

            // Make fences
            for (FencePosition pos = FencePosition.Top; pos <= FencePosition.Right; pos++)
            {
                for (int i = 0; i < 40; i++)
                {
                    fences[i] = new Fence(pos, i).rect;
                }
                g.DrawRectangles(Fence.edgePen, fences);
            }

            // Feed
            if (feedBowl.Count == 0)
            {
                for (int i = 0; i < 10; i++)
                {
                    int posX = foodPosition.Next(1, 39);
                    int posY = foodPosition.Next(1, 39);
                    while (posX == posY)
                    {
                        posY = foodPosition.Next(1, 39);
                    }

                    feedBowl.Add(new Food(posX, posY));
                }
            }
            foreach (Food food in feedBowl)
            {
                g.FillRectangle(Food.foodColor, food.rect);
            }

            // Draw snake
            foreach (Snake body in snake)
            {
                g.DrawRectangle(Snake.skinColorPen, body.rect.X, body.rect.Y, body.rect.Width, body.rect.Height);
                g.FillRectangle(Snake.bodyColorBrush, body.rect);
            }

            // View score
            g.DrawString("" + score, font, Brushes.Gold, this.ClientRectangle.Right / 2, this.ClientRectangle.Bottom / 2);
        }
Пример #2
0
 public Fence(FencePosition pos, int i)
 {
     if (pos == FencePosition.Top)
     {
         this.rect = new RectangleF(i * DIA, 0, DIA, DIA);
     }
     else if (pos == FencePosition.Bottom)
     {
         this.rect = new RectangleF(i * DIA, DIA * 39, DIA, DIA);
     }
     else if (pos == FencePosition.Left)
     {
         this.rect = new RectangleF(0, i * DIA, DIA, DIA);
     }
     else if (pos == FencePosition.Right)
     {
         this.rect = new RectangleF(DIA * 39, i * DIA, DIA, DIA);
     }
 }
Пример #3
0
    FencePosition GetOppositePosition(FencePosition pos)
    {
        switch (pos)
        {
        case FencePosition.Down:
            return(FencePosition.Up);

        case FencePosition.Left:
            return(FencePosition.Right);

        case FencePosition.Up:
            return(FencePosition.Down);

        case FencePosition.Right:
            return(FencePosition.Left);

        default:
            return(FencePosition.Left);
        }
    }
Пример #4
0
 public void ShowFence(FencePosition dir, bool show)
 {
     if (fences != null)
     {
         var obj = fences[(byte)dir];
         if (obj != null)
         {
             if (obj.activeSelf != show)
             {
                 obj.SetActive(show);
             }
         }
         else
         {
             Debug.LogError(string.Format("坐标:({0},{1}),第{2}围栏为空", Coord.x, Coord.y, (byte)dir));
         }
     }
     else
     {
         Debug.LogError(string.Format("坐标:({0},{1} 建筑围栏数据为空", Coord.x, Coord.y));
     }
 }
Пример #5
0
    public static FencePosition GetOpposite(this FencePosition position)
    {
        var oppositePosition = FencePosition.Up;

        if (position == FencePosition.Up)
        {
            oppositePosition = FencePosition.Down;
        }
        else if (position == FencePosition.Down)
        {
            oppositePosition = FencePosition.Up;
        }
        else if (position == FencePosition.Left)
        {
            oppositePosition = FencePosition.Right;
        }
        else if (position == FencePosition.Right)
        {
            oppositePosition = FencePosition.Left;
        }

        return(oppositePosition);
    }
Пример #6
0
    public void SetPlank(FencePosition position, bool value)
    {
        switch (position)
        {
        case FencePosition.Up:
            this.up.SetActive(value);
            break;

        case FencePosition.Down:
            this.down.SetActive(value);
            break;

        case FencePosition.Right:
            this.right.SetActive(value);
            break;

        case FencePosition.Left:
            this.left.SetActive(value);
            break;

        default:
            break;
        }
    }
Пример #7
0
    void UpdateBothSideWideStreetBuildFence(MapBuildingFence mainBuildData, bool showMainBuild, FencePosition mainBuildSide, FencePosition oppositeBuildSide, Vector2Int oppositeBuildCoord)
    {
        if (PosValid(oppositeBuildCoord))//如果对面是在地图里面的
        {
            var oppositeBuildFenceData = GetBuildingFenceData(oppositeBuildCoord);
            if (oppositeBuildFenceData == null)
            {
                return;
            }

            if (ActivedCoords.Contains(oppositeBuildCoord))                          //如果对面是激活的
            {
                mainBuildData.ShowFence(mainBuildSide, false);                       //自己则永远不激活临近的一面

                oppositeBuildFenceData.ShowFence(oppositeBuildSide, !showMainBuild); //对面则看自己是否激活来确定激活临近自己这一边
            }
            else
            {
                mainBuildData.ShowFence(mainBuildSide, showMainBuild);
                oppositeBuildFenceData.ShowFence(oppositeBuildSide, false);
            }
        }
        else
        {
            mainBuildData.ShowFence(mainBuildSide, showMainBuild);
        }
    }
Пример #8
0
    /// <summary>
    /// 更新临款街道 建筑周围的围栏显示
    /// </summary>
    /// <param name="item">要更新的建筑坐标 </param>
    /// <param name="ambientBuildingCoords"> 周围四个建筑坐标</param>
    /// <param name="show">要更新的建筑是显示还是隐藏</param>
    /// <param name="atLeft"> 在宽街道左边 </param>
    /// <param name="atRight"> 在宽街道右边</param>
    /// <param name="atUp">在宽街道上边 </param>
    /// <param name="atDown"> 在宽街道下边</param>
    private void UpdateBuildingNearWideStreetFenceShow(Vector2Int item, List <Vector2Int> ambientBuildingCoords, bool show, bool atLeft, bool atRight, bool atUp, bool atDown)
    {
        var buildFenceData = GetBuildingFenceData(item);
        var totalCount     = 4;

        if (buildFenceData == null)
        {
            return;
        }

        int           skipIndex  = 0;
        int           skipIndex2 = 0;
        FencePosition mainSide   = FencePosition.Down;

        bool atLeftDown, atLeftUp, atRightDown, atRightUp;

        atLeftDown  = atLeft && atDown;
        atLeftUp    = atLeft && atUp;
        atRightDown = atRight && atDown;
        atRightUp   = atRight && atUp;

        if (atLeftDown || atLeftUp || atRightDown || atRightUp)
        {
            var mainSide2 = FencePosition.Right;

            if (atLeftDown)
            {
                mainSide  = FencePosition.Right;
                mainSide2 = FencePosition.Up;
            }
            else if (atLeftUp)
            {
                mainSide  = FencePosition.Right;
                mainSide2 = FencePosition.Down;
            }
            else if (atRightUp)
            {
                mainSide  = FencePosition.Left;
                mainSide2 = FencePosition.Down;
            }
            else if (atRightDown)
            {
                mainSide  = FencePosition.Left;
                mainSide2 = FencePosition.Up;
            }

            skipIndex  = (int)mainSide;
            skipIndex2 = (int)mainSide2;

            for (int i = 0; i < totalCount; i++)// 下 - 左 - 上 三条边普通处理
            {
                if (i == skipIndex || i == skipIndex2)
                {
                    continue;
                }
                UpdateBuildingOneFence(ambientBuildingCoords[i], show, i, buildFenceData);
            }

            UpdateBothSideWideStreetBuildFence(buildFenceData, show, mainSide, GetOppositePosition(mainSide), ambientBuildingCoords[skipIndex]);
            UpdateBothSideWideStreetBuildFence(buildFenceData, show, mainSide2, GetOppositePosition(mainSide2), ambientBuildingCoords[skipIndex2]);
        }
        else if (atLeft || atRight || atUp || atDown)
        {
            if (atLeft)//在街道左边,则要对自己右边建筑的 左边 围栏进行特殊处理(编号为)
            {
                mainSide = FencePosition.Right;
            }
            else if (atRight)//在街道右边,则要对自己左边建筑的  右边 围栏进行特殊处理
            {
                mainSide = FencePosition.Left;
            }
            else if (atUp)//在街道上面,则要对自己下面建筑的 上面 围栏进行特殊处理
            {
                mainSide = FencePosition.Down;
            }
            else if (atDown)//在街道下面,则要对自己上面建筑 的 下边 围栏进行特殊处理
            {
                mainSide = FencePosition.Up;
            }

            skipIndex = (int)mainSide;

            for (int i = 0; i < totalCount; i++)// 下 - 左 - 上 三条边普通处理
            {
                if (i == skipIndex)
                {
                    continue;
                }
                UpdateBuildingOneFence(ambientBuildingCoords[i], show, i, buildFenceData);
            }

            UpdateBothSideWideStreetBuildFence(buildFenceData, show, mainSide, GetOppositePosition(mainSide), ambientBuildingCoords[skipIndex]);
        }
    }