예제 #1
0
파일: Game.cs 프로젝트: Karolas/Sabateur
        public static void PutCardOnField(int id, CardType type, int col, int row)
        {
            CardSet card = Cards.Where(inHand => inHand.Id == id && inHand.Type == type).First();

            card.Owner    = "Field";
            card.FieldCol = col;
            card.FieldRow = row;

            SqlWorker.SaveData();
        }
예제 #2
0
파일: Game.cs 프로젝트: Karolas/Sabateur
        private static bool IsCardNextToGoal(CardSet putCard, CardSet goalCard)
        {
            int colDif = (int)putCard.FieldCol - (int)goalCard.FieldCol;
            int rowDif = (int)putCard.FieldRow - (int)goalCard.FieldRow;

            if (Math.Abs(colDif) + Math.Abs(rowDif) == 1)
            {
                if (rowDif == 1)
                {
                    if (putCard.Path.Value.HasFlag(Direction.Up) && putCard.IsPathUpside == false)
                    {
                        return(true);
                    }
                    if (putCard.Path.Value.HasFlag(Direction.Down) && putCard.IsPathUpside == true)
                    {
                        return(true);
                    }
                }
                if (rowDif == -1)
                {
                    if (putCard.Path.Value.HasFlag(Direction.Down) && putCard.IsPathUpside == false)
                    {
                        return(true);
                    }
                    if (putCard.Path.Value.HasFlag(Direction.Up) && putCard.IsPathUpside == true)
                    {
                        return(true);
                    }
                }
                if (colDif == 1)
                {
                    if (putCard.Path.Value.HasFlag(Direction.Left) && putCard.IsPathUpside == false)
                    {
                        return(true);
                    }
                    if (putCard.Path.Value.HasFlag(Direction.Right) && putCard.IsPathUpside == true)
                    {
                        return(true);
                    }
                }
                if (colDif == -1)
                {
                    if (putCard.Path.Value.HasFlag(Direction.Right) && putCard.IsPathUpside == false)
                    {
                        return(true);
                    }
                    if (putCard.Path.Value.HasFlag(Direction.Left) && putCard.IsPathUpside == true)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #3
0
        private static CardSet PrepareCard(int id, CardType type, BlockType?blockType = null, Direction?opening = null, Direction?path = null)
        {
            CardSet card = new CardSet();

            card.Id           = id;
            card.Type         = type;
            card.Owner        = "Deck";
            card.BlockType    = blockType;
            card.PathOpenings = opening;
            card.IsPathUpside = false;
            card.Path         = path;

            return(card);
        }
예제 #4
0
        private static CardSet SetStartCard(int id)
        {
            CardSet card = new CardSet();

            card.Id           = id;
            card.Type         = CardType.Path;
            card.Owner        = "Field";
            card.PathOpenings = Direction.Down | Direction.Left | Direction.Right | Direction.Up;
            card.Path         = Direction.Down | Direction.Left | Direction.Right | Direction.Up;
            card.IsPathUpside = false;
            card.FieldCol     = 9;
            card.FieldRow     = 3;

            return(card);
        }
예제 #5
0
        private void PathCardSelected()
        {
            PictureBoxPathPos1.Show();
            PictureBoxPathPos2.Show();
            ButtonDiscardCard.Show();

            Game.Player.SelectedCard.IsPathUpside = false;
            PictureBoxPathPos1.Image = new Bitmap(CardSpriteGenerator.GetApropriateSprite(Game.Player.SelectedCard), new Size(85, 111));
            CardSet flipedCard = new CardSet();

            flipedCard.Path          = Game.Player.SelectedCard.Path;
            flipedCard.PathOpenings  = Game.Player.SelectedCard.PathOpenings;
            flipedCard.Type          = CardType.Path;
            flipedCard.IsPathUpside  = true;
            PictureBoxPathPos2.Image = new Bitmap(CardSpriteGenerator.GetApropriateSprite(flipedCard), new Size(85, 111));
        }
예제 #6
0
파일: Game.cs 프로젝트: Karolas/Sabateur
        public static void CheckGoalCardReached(CardSet putCard)
        {
            CardSet[] goalCards = Game.Cards.Where(card => card.Type == CardType.GoalPath).ToArray();

            for (int i = 0; i < goalCards.Count(); i++)
            {
                if (IsCardNextToGoal(putCard, goalCards[i]))
                {
                    if (goalCards[i].Path == (Direction.Down | Direction.Left | Direction.Right | Direction.Up))
                    {
                        System.Windows.Forms.Application.Exit();
                    }
                    else
                    {
                        goalCards[i].Type = CardType.Path;
                    }
                    SqlWorker.SaveData();
                }
            }
        }
예제 #7
0
 public static Bitmap GetApropriateSprite(CardSet card)
 {
     if (card.Type == CardType.Path)
     {
         return(GenerateCardSprite(card));
     }
     if (card.Type == CardType.Map)
     {
         return(Properties.Resources.Map);
     }
     if (card.Type == CardType.RemovePath)
     {
         return(Properties.Resources.RemovePath);
     }
     if (card.Type == CardType.Block)
     {
         if (card.BlockType == BlockType.Cart)
         {
             return(Properties.Resources.BlockCart);
         }
         if (card.BlockType == BlockType.Lantern)
         {
             return(Properties.Resources.BlockLantern);
         }
         if (card.BlockType == BlockType.Pickaxe)
         {
             return(Properties.Resources.BlockPickaxe);
         }
         else
         {
             return(Properties.Resources.EmptyTile);
         }
     }
     else if (card.Type == CardType.AntiBlock)
     {
         if (card.BlockType == BlockType.Cart)
         {
             return(Properties.Resources.AntiBlockCart);
         }
         if (card.BlockType == BlockType.Lantern)
         {
             return(Properties.Resources.AntiBlockLantern);
         }
         if (card.BlockType == BlockType.Pickaxe)
         {
             return(Properties.Resources.AntiBlockPickaxe);
         }
         if (card.BlockType == (BlockType.Cart | BlockType.Lantern))
         {
             return(Properties.Resources.AntiBlockLanternCart);
         }
         if (card.BlockType == (BlockType.Lantern | BlockType.Pickaxe))
         {
             return(Properties.Resources.AntiBlockLanternPickaxe);
         }
         if (card.BlockType == (BlockType.Pickaxe | BlockType.Cart))
         {
             return(Properties.Resources.AntiBlockPickaxeCart);
         }
         else
         {
             return(Properties.Resources.EmptyTile);
         }
     }
     else
     {
         return(Properties.Resources.EmptyTile);
     }
 }
예제 #8
0
        public static Bitmap GenerateCardSprite(CardSet card)
        {
            Bitmap   sprite        = new Bitmap(100, 131);
            Graphics spritePainter = Graphics.FromImage(sprite);

            spritePainter.FillRectangle(Brushes.DarkGray, new Rectangle(0, 0, sprite.Width, sprite.Height));
            spritePainter.FillRectangle(Brushes.DarkGray, new Rectangle(0, 0, sprite.Width, sprite.Height));

            if (card.Path.HasValue)
            {
                if (card.Path.Value.HasFlag(Direction.Down))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 53, 24, 78));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 0, 24, 78));
                    }
                }

                if (card.Path.Value.HasFlag(Direction.Right))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 53, 62, 25));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(0, 53, 62, 25));
                    }
                }

                if (card.Path.Value.HasFlag(Direction.Left))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(0, 53, 62, 25));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 53, 62, 25));
                    }
                }

                if (card.Path.Value.HasFlag(Direction.Up))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 0, 24, 78));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 53, 24, 78));
                    }
                }
            }

            if (card.PathOpenings.HasValue)
            {
                if (card.PathOpenings.Value.HasFlag(Direction.Up))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 0, 24, 40));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 91, 24, 40));
                    }
                }

                if (card.PathOpenings.Value.HasFlag(Direction.Right))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(70, 53, 30, 24));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(0, 53, 30, 24));
                    }
                }

                if (card.PathOpenings.Value.HasFlag(Direction.Down))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 91, 24, 40));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(38, 0, 24, 40));
                    }
                }

                if (card.PathOpenings.Value.HasFlag(Direction.Left))
                {
                    if (!card.IsPathUpside.Value)
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(0, 53, 30, 24));
                    }
                    else
                    {
                        spritePainter.FillRectangle(Brushes.PeachPuff, new Rectangle(70, 53, 30, 24));
                    }
                }
            }

            return(sprite);
        }
예제 #9
0
파일: Game.cs 프로젝트: Karolas/Sabateur
        private static bool DoesPathConnect(CardSet fieldCard, CardSet cardToPlace, int colToPlace, int rowToPlace)
        {
            int rowDif = (int)rowToPlace - ((int)fieldCard.FieldRow - 1);
            int colDif = (int)colToPlace - ((int)fieldCard.FieldCol - 1);

            if (fieldCard.Path != null)
            {
                if (!(bool)cardToPlace.IsPathUpside)
                {
                    if (!(bool)fieldCard.IsPathUpside)
                    {
                        if (rowDif == 0 && colDif == 1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Right) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Left))
                        {
                            return(true);
                        }
                        if (rowDif == 0 && colDif == -1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Left) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Right))
                        {
                            return(true);
                        }
                        if (rowDif == 1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Down) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Up))
                        {
                            return(true);
                        }
                        if (rowDif == -1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Up) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Down))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (rowDif == 0 && colDif == 1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Left) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Left))
                        {
                            return(true);
                        }
                        if (rowDif == 0 && colDif == -1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Right) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Right))
                        {
                            return(true);
                        }
                        if (rowDif == 1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Up) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Up))
                        {
                            return(true);
                        }
                        if (rowDif == -1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Down) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Down))
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    if (!(bool)fieldCard.IsPathUpside)
                    {
                        if (rowDif == 0 && colDif == 1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Right) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Right))
                        {
                            return(true);
                        }
                        if (rowDif == 0 && colDif == -1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Left) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Left))
                        {
                            return(true);
                        }
                        if (rowDif == 1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Down) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Down))
                        {
                            return(true);
                        }
                        if (rowDif == -1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Up) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Up))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (rowDif == 0 && colDif == 1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Left) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Right))
                        {
                            return(true);
                        }
                        if (rowDif == 0 && colDif == -1 &&
                            fieldCard.Path.Value.HasFlag(Direction.Right) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Left))
                        {
                            return(true);
                        }
                        if (rowDif == 1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Up) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Down))
                        {
                            return(true);
                        }
                        if (rowDif == -1 && colDif == 0 &&
                            fieldCard.Path.Value.HasFlag(Direction.Down) &&
                            cardToPlace.PathOpenings.Value.HasFlag(Direction.Up))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #10
0
파일: Game.cs 프로젝트: Karolas/Sabateur
        public static List <int[]> AvailableFieldTiles(CardSet cardToPlace)
        {
            List <int[]> availableFieldTiles = new List <int[]>();

            CardSet[,] fieldTiles = new CardSet[9, 5];
            var cardsOnField = Cards.Where(card => card.Owner == "Field" && card.Type != CardType.GoalPath).ToArray();

            foreach (CardSet card in cardsOnField)
            {
                fieldTiles[(int)card.FieldCol - 1, (int)card.FieldRow - 1] = card;
            }

            for (int i = 0; i < 9; i++)
            {
                for (int i1 = 0; i1 < 5; i1++)
                {
                    bool isAvailable = false;

                    if (fieldTiles[i, i1] == null)
                    {
                        if (i1 - 1 >= 0 && fieldTiles[i, i1 - 1] != null)
                        {
                            if (cardToPlace.Path != null)
                            {
                                if (DoesPathConnect(fieldTiles[i, i1 - 1], cardToPlace, i, i1))
                                {
                                    isAvailable = true;
                                }
                            }
                            else
                            {
                                isAvailable = true;
                            }
                        }
                        if (i1 + 1 < 5 && fieldTiles[i, i1 + 1] != null)
                        {
                            if (cardToPlace.Path != null)
                            {
                                if (DoesPathConnect(fieldTiles[i, i1 + 1], cardToPlace, i, i1))
                                {
                                    isAvailable = true;
                                }
                            }
                            else
                            {
                                isAvailable = true;
                            }
                        }
                        if (i - 1 >= 0 && fieldTiles[i - 1, i1] != null)
                        {
                            if (cardToPlace.Path != null)
                            {
                                if (DoesPathConnect(fieldTiles[i - 1, i1], cardToPlace, i, i1))
                                {
                                    isAvailable = true;
                                }
                            }
                            else
                            {
                                isAvailable = true;
                            }
                        }
                        if (i + 1 < 9 && fieldTiles[i + 1, i1] != null)
                        {
                            if (cardToPlace.Path != null)
                            {
                                if (DoesPathConnect(fieldTiles[i + 1, i1], cardToPlace, i, i1))
                                {
                                    isAvailable = true;
                                }
                            }
                            else
                            {
                                isAvailable = true;
                            }
                        }
                    }
                    if (isAvailable == true)
                    {
                        if (i1 - 1 >= 0 && fieldTiles[i, i1 - 1] != null)
                        {
                            if (!DoCardsJoin(fieldTiles[i, i1 - 1], cardToPlace, i, i1))
                            {
                                isAvailable = false;
                            }
                        }
                        if (i1 + 1 < 5 && fieldTiles[i, i1 + 1] != null)
                        {
                            if (!DoCardsJoin(fieldTiles[i, i1 + 1], cardToPlace, i, i1))
                            {
                                isAvailable = false;
                            }
                        }
                        if (i - 1 >= 0 && fieldTiles[i - 1, i1] != null)
                        {
                            if (!DoCardsJoin(fieldTiles[i - 1, i1], cardToPlace, i, i1))
                            {
                                isAvailable = false;
                            }
                        }
                        if (i + 1 < 9 && fieldTiles[i + 1, i1] != null)
                        {
                            if (!DoCardsJoin(fieldTiles[i + 1, i1], cardToPlace, i, i1))
                            {
                                isAvailable = false;
                            }
                        }
                    }

                    if (isAvailable == true)
                    {
                        availableFieldTiles.Add(new int[] { i + 1, i1 + 1 });
                    }
                }
            }

            return(availableFieldTiles);
        }
예제 #11
0
파일: Game.cs 프로젝트: Karolas/Sabateur
        public static void DiscardCard(CardSet card)
        {
            card.Owner = "Graveyard";

            SqlWorker.SaveData();
        }