Example #1
0
        public bool IsRoadConnectedToStart(Point curPoint, CaveCard card) //목적지 포인트
        {
            CaveCard copy = new CaveCard(card.getDir(), card.getIsConnected());

            caveCards[curPoint.R, curPoint.C] = copy;
            caveCards[curPoint.R, curPoint.C].setIsConnected(true);
            int[] ctr = { 0, -1, 0, 1, 0 }; // LEFT, UP, RIGHT, DOWN

            Dir[] dir   = { Dir.LEFT, Dir.UP, Dir.RIGHT, Dir.DOWN };
            Dir[] dirOp = { Dir.RIGHT, Dir.DOWN, Dir.LEFT, Dir.UP };

            Stack <Point> stack = new Stack <Point>();

            visited = new bool[CONST.MAP_ROW, CONST.MAP_COL];
            stack.Push(curPoint);

            while (stack.Count != 0)
            {
                Point visitedPoint = stack.Pop();

                if (isStart(visitedPoint))
                {
                    caveCards[curPoint.R, curPoint.C] = new CaveCard();
                    return(true);
                }

                if (!caveCards[visitedPoint.R, visitedPoint.C].getIsConnected() ||
                    visited[visitedPoint.R, visitedPoint.C])
                {
                    continue;
                }

                visited[visitedPoint.R, visitedPoint.C] = true;

                for (int i = 0; i < ctr.Length - 1; i++)
                {
                    int   r = visitedPoint.R + ctr[i], c = visitedPoint.C + ctr[i + 1]; // 주변 좌표
                    Point watch = new Point(r, c);

                    if (checkBoundary(watch) &&
                        (caveCards[visitedPoint.R, visitedPoint.C].getDir() & dir[i]) == dir[i] &&
                        (caveCards[watch.R, watch.C].getDir() & dirOp[i]) == dirOp[i])
                    {
                        stack.Push(watch);
                    }
                }
            }

            caveCards[curPoint.R, curPoint.C] = new CaveCard();
            return(false);
        }
Example #2
0
        private void DrawCardOnField()
        {
            CaveCard curCard  = null;
            Point    location = new Point();

            for (int i = 0; i < CONST.MAP_ROW; i++)
            {
                for (int j = 0; j < CONST.MAP_COL; j++)
                {
                    curCard = field.GetCard(i, j);

                    if (prevMap[i, j] == curCard)
                    {
                        continue;
                    }

                    location = ConvertCoordsToLocation(i, j);

                    // Draw Start Card
                    if (curCard is StartCard)
                    {
                        AddImage(location, imgCards.Images[START_CARD_INDEX]);
                    }

                    // Draw Dest Card
                    else if (curCard is DestCard)
                    {
                        DestCard dest = (DestCard)curCard;
                        Image    image;
                        if (dest.face == CardFace.FRONT)
                        {
                            if (dest.getIsGoldCave())
                            {
                                image = imgCards.Images["goal_gold.png"];
                                MessageBox.Show("금을 찾았습니다!\r\n광부 승!!");
                            }

                            else
                            {
                                image = imgCards.Images["goal_stone_down_left.png"];
                                MessageBox.Show("돌입니다!\r\n다른 목적지를 방문해보세요.");
                            }
                        }
                        else
                        {
                            image = imgCards.Images["goal_back.png"];
                        }

                        AddImage(location, image);
                    }

                    // Draw Cave Card
                    else
                    {
                        if (!curCard.isEmpty() && prevMap[i, j].isEmpty())
                        {
                            Image curImage = GetCardImage(curCard);

                            if (curImage != null)
                            {
                                AddImage(location, curImage);
                            }
                        }
                        else if (curCard.isEmpty() && !prevMap[i, j].isEmpty())
                        {
                            DeleteImage(i, j);
                        }
                    }

                    prevMap[i, j].setDir(curCard.getDir());
                    prevMap[i, j].setIsConnected(curCard.getIsConnected());
                    prevMap[i, j].setType(curCard.getType());
                    prevMap[i, j].face = curCard.face;
                }
            }
        }
Example #3
0
        private Image GetCardImage(Card card)
        {
            if (card == null)
            {
                return(null);
            }
            // Card 뒷면
            if (card.face == CardFace.BACK)
            {
                return(imgCards.Images[22]);
            }

            // Card 앞면
            if (card is CaveCard)
            {
                CaveCard c = (CaveCard)card;

                return(DirToImage(c.getDir(), c.getIsConnected()));
            }
            else if (card is ActionCard)
            {
                if (card.getType() == CType.MAP)
                {
                    return(imgCards.Images[15]);
                }

                else if (card.getType() == CType.ROCK_DOWN)
                {
                    return(imgCards.Images[14]);
                }

                else if (card.getType() == CType.EQ_DESTRUCTION)
                {
                    switch (((EquipmentCard)card).tool)
                    {
                    case Tool.CART:
                        return(imgCards.Images[11]);

                    case Tool.LATTERN:
                        return(imgCards.Images[12]);

                    case Tool.PICKAXE:
                        return(imgCards.Images[13]);
                    }
                }

                else if (card.getType() == CType.EQ_REPAIR)
                {
                    switch (((EquipmentCard)card).tool)
                    {
                    case Tool.CART:
                        return(imgCards.Images[16]);

                    case Tool.LATTERN:
                        return(imgCards.Images[17]);

                    case Tool.LATTERNCART:
                        return(imgCards.Images[18]);

                    case Tool.PICKAXE:
                        return(imgCards.Images[19]);

                    case Tool.PICKCART:
                        return(imgCards.Images[20]);

                    case Tool.PICKLATTERN:
                        return(imgCards.Images[21]);
                    }
                }
            }
            return(null);
        }
Example #4
0
        public bool CanBeConntectedSurrounding(Point point, CaveCard cave)
        {
            bool isConnected = cave.getIsConnected();

            int      r = point.R, c = point.C;
            CaveCard watch;

            cave.setIsConnected(true);
            bool result   = true;
            bool isolated = true;

            if (r > 0 && !caveCards[r - 1, c].isEmpty() && caveCards[r - 1, c].face == CardFace.FRONT)
            {
                watch    = caveCards[r - 1, c];
                isolated = false;
                if ((watch.getDir() & Dir.DOWN) == Dir.NONE)        // [r - 1, c] no DOWN
                {
                    result &= (cave.getDir() & Dir.UP) == Dir.NONE; // [r, c] no UP
                }
                else // [r - 1, c] DOWN
                {
                    result &= (cave.getDir() & Dir.UP) == Dir.UP; // [r, c] UP
                }
            }

            if (c > 0 && !caveCards[r, c - 1].isEmpty() && caveCards[r, c - 1].face == CardFace.FRONT)
            {
                watch    = caveCards[r, c - 1];
                isolated = false;
                if ((watch.getDir() & Dir.RIGHT) == Dir.NONE)         // [r, c - 1] no RIGHT
                {
                    result &= (cave.getDir() & Dir.LEFT) == Dir.NONE; // [r, c] no LEFT
                }
                else // [r, c - 1] RIGHT
                {
                    result &= (cave.getDir() & Dir.LEFT) == Dir.LEFT; // [r, c] LEFT
                }
            }

            if (r < CONST.MAP_ROW - 1 && !caveCards[r + 1, c].isEmpty() && caveCards[r + 1, c].face == CardFace.FRONT)
            {
                watch    = caveCards[r + 1, c];
                isolated = false;
                if ((watch.getDir() & Dir.UP) == Dir.NONE)            // [r + 1, c] no UP
                {
                    result &= (cave.getDir() & Dir.DOWN) == Dir.NONE; // [r, c] no DOWN
                }
                else // [r + 1, c] UP
                {
                    result &= (cave.getDir() & Dir.DOWN) == Dir.DOWN; // [r, c] DOWN
                }
            }

            if (c < CONST.MAP_COL - 1 && !caveCards[r, c + 1].isEmpty() && caveCards[r, c + 1].face == CardFace.FRONT)
            {
                watch    = caveCards[r, c + 1];
                isolated = false;
                if ((watch.getDir() & Dir.LEFT) == Dir.NONE)           // [r, c + 1] no LEFT
                {
                    result &= (cave.getDir() & Dir.RIGHT) == Dir.NONE; // [r, c] no RIGHT
                }
                else // [r, c + 1] LEFT
                {
                    result &= (cave.getDir() & Dir.RIGHT) == Dir.RIGHT; // [r, c] RIGHT
                }
            }

            cave.setIsConnected(isConnected);
            if (isolated)
            {
                return(false);
            }

            return(result);
        }