示例#1
0
        private static Bitmap GetPicture(UnoColor c, UnoCardType t)
        {
            float cardWidth    = 4096 / 10f;
            float cardHeight   = 4096 / 7f;
            int   CutOutWidth  = (int)cardWidth + 29;
            int   CutOutHeight = (int)cardHeight + 40;

            if (IsNumber(t))
            {
                int X       = (int)(cardWidth * (ToNumber(t) - 1));
                int YNumber = c == UnoColor.red ? 0 : (c == UnoColor.yellow ? 1 : (c == UnoColor.blue ? 2 : (c == UnoColor.green ? 3 : -1)));
                int Y       = (int)(cardHeight * YNumber);
                return(CardsTexture.CropImage(new Rectangle(X, Y, CutOutWidth, CutOutHeight), false));
            }
            else
            {
                if (t == UnoCardType.changecolor)
                {
                    return(CardsTexture.CropImage(new Rectangle((int)(9 * cardWidth), (int)(0 * cardHeight), CutOutWidth, CutOutHeight), false));
                }
                else if (t == UnoCardType.plus4)
                {
                    return(CardsTexture.CropImage(new Rectangle((int)(9 * cardWidth), (int)(2 * cardHeight), CutOutWidth, CutOutHeight), false));
                }
                else if (t == UnoCardType.skip)
                {
                    int XNumber = c == UnoColor.red ? 0 : (c == UnoColor.yellow ? 1 : (c == UnoColor.blue ? 2 : (c == UnoColor.green ? 3 : -1)));
                    return(CardsTexture.CropImage(new Rectangle((int)(XNumber * cardWidth), (int)(4 * cardHeight), CutOutWidth, CutOutHeight), false));
                }
                else if (t == UnoCardType.plus2)
                {
                    int XNumber = 4 + (c == UnoColor.red ? 0 : (c == UnoColor.yellow ? 1 : (c == UnoColor.blue ? 2 : (c == UnoColor.green ? 3 : -1))));
                    return(CardsTexture.CropImage(new Rectangle((int)(XNumber * cardWidth), (int)(4 * cardHeight), CutOutWidth, CutOutHeight), false));
                }
                else if (t == UnoCardType.reverse)
                {
                    if (c == UnoColor.red)
                    {
                        return(CardsTexture.CropImage(new Rectangle((int)(8 * cardWidth), (int)(4 * cardHeight), CutOutWidth, CutOutHeight), false));
                    }
                    else if (c == UnoColor.yellow)
                    {
                        return(CardsTexture.CropImage(new Rectangle((int)(9 * cardWidth), (int)(4 * cardHeight), CutOutWidth, CutOutHeight), false));
                    }
                    else if (c == UnoColor.blue)
                    {
                        return(CardsTexture.CropImage(new Rectangle((int)(0 * cardWidth), (int)(5 * cardHeight), CutOutWidth, CutOutHeight), false));
                    }
                    else if (c == UnoColor.green)
                    {
                        return(CardsTexture.CropImage(new Rectangle((int)(1 * cardWidth), (int)(5 * cardHeight), CutOutWidth, CutOutHeight), false));
                    }
                }
            }
            return(null);
        }
示例#2
0
            public void PutCardOnTopOfStack(UnoCardType t, UnoColor c, ulong PlayerID, ISocketMessageChannel channel)
            {
                if (PlayerID != TurnPlayerID())
                {
                    DiscordNETWrapper.SendText("It's not your turn :thinking:", channel).Wait();
                    return;
                }
                UnoCard newCard = UnoCards.FirstOrDefault(x => (HasColor(t) ? x.Color == c : x.Color == UnoColor.none) && x.Type == t);
                Tuple <SocketUser, List <UnoCard> > player = Players.Find(x => x.Item1.Id == PlayerID);

                if (!player.Item2.Exists(x => x.Type == t && x.Color == c))
                {
                    DiscordNETWrapper.SendText("You don't even have that card :thinking:", channel).Wait();
                    return;
                }

                if (newCard != null)
                {
                    if (CanPutCardOnTopOfStack(newCard))
                    {
                        player.Item2.Remove(newCard);
                        SendDeck(player);
                        DrawCardOnStack(newCard);
                        TopStackCard = newCard;
                        CurColor     = c;
                        if (newCard.Type == UnoCardType.reverse)
                        {
                            ReversedTurns = !ReversedTurns;
                        }
                        NextPlayer();
                        if (newCard.Type == UnoCardType.skip)
                        {
                            NextPlayer();
                        }
                        if (newCard.Type == UnoCardType.plus2)
                        {
                            DrawCards(2, Players[curPlayerIndex]);
                        }
                        if (newCard.Type == UnoCardType.plus4)
                        {
                            DrawCards(4, Players[curPlayerIndex]);
                        }
                    }
                    else
                    {
                        DiscordNETWrapper.SendText("You can't put that card on top of the stack :thinking:", channel).Wait();
                    }
                }
                else
                {
                    DiscordNETWrapper.SendText("Oi that card doesn't exist!", channel).Wait();
                }
            }
示例#3
0
 static int ToNumber(UnoCardType t)
 {
     if (IsNumber(t))
     {
         if (t == UnoCardType.one)
         {
             return(1);
         }
         else if (t == UnoCardType.two)
         {
             return(2);
         }
         else if (t == UnoCardType.three)
         {
             return(3);
         }
         else if (t == UnoCardType.four)
         {
             return(4);
         }
         else if (t == UnoCardType.five)
         {
             return(5);
         }
         else if (t == UnoCardType.six)
         {
             return(6);
         }
         else if (t == UnoCardType.seven)
         {
             return(7);
         }
         else if (t == UnoCardType.eight)
         {
             return(8);
         }
         else if (t == UnoCardType.nine)
         {
             return(9);
         }
         else
         {
             return(-1);
         }
     }
     else
     {
         return(-1);
     }
 }
示例#4
0
 public UnoCard(UnoCardColor Color, UnoCardType Type)
 {
     this.Color = Color;
     this.Type  = Type;
 }
示例#5
0
 public UnoCard(UnoCardType cardType)
 {
     CardType = cardType;
 }
示例#6
0
 public UnoCard(UnoCardType cardType, UnoCardSuit cardSuit)
 {
     CardType = cardType;
     CardSuit = cardSuit;
 }
示例#7
0
        public override void Execute(IMessage messageIn)
        {
            if (!(messageIn is SocketMessage))
            {
                DiscordNETWrapper.SendText("This command only works on discord", messageIn.Channel).Wait();
                return;
            }
            var message = messageIn as SocketMessage;

            string[] split = message.Content.Split(' ');
            if (split.Contains("new"))
            {
                UnoGame newGame = new UnoGame(message.MentionedUsers.Distinct().Append(message.Author).ToList());
                if (newGame.Players.Count < 2)
                {
                    DiscordNETWrapper.SendText("You need more players to play Uno!", message.Channel).Wait();
                    return;
                }
                if (newGame.Players.Exists(x => x.Item1.IsBot))
                {
                    DiscordNETWrapper.SendText("Bots can't play Uno!", message.Channel).Wait();
                    return;
                }
                if (UnoGames.Exists(x => x.Players.Exists(y => y.Item1.Id == message.Author.Id)))
                {
                    DiscordNETWrapper.SendText("You are already in a uno game!", message.Channel).Wait();
                    return;
                }
                UnoGames.Add(newGame);
                newGame.Send(message.Channel);
                foreach (Tuple <SocketUser, List <UnoCard> > player in newGame.Players)
                {
                    newGame.SendDeck(player);
                }
            }
            else if (split.Contains("print_cards") && message.Author.Id == Program.Master.Id) // Size = {Width = 434 Height = 621}
            {
                foreach (UnoCard c in UnoCards)
                {
                    DiscordNETWrapper.SendBitmap(c.Picture, message.Channel, c.Type.ToString() + " " + c.Color.ToString()).Wait();
                }
            }
            else if (split.Contains("print"))
            {
                UnoGame game = UnoGames.FirstOrDefault(x => x.Players.Exists(y => y.Item1.Id == message.Author.Id));
                if (game != null)
                {
                    game.Send(message.Channel);
                }
                else
                {
                    DiscordNETWrapper.SendText("You are not in a game :thinking:", message.Channel).Wait();
                }
            }
            else if (split.Length >= 2 && split[1] == "draw")
            {
                UnoGame game = UnoGames.FirstOrDefault(x => x.Players.Exists(y => y.Item1.Id == message.Author.Id));
                if (game.TurnPlayerID() != message.Author.Id)
                {
                    DiscordNETWrapper.SendText("It's not your turn :thinking:", message.Channel).Wait();
                    return;
                }
                if (game != null)
                {
                    game.DrawCards(1, message.Author.Id);
                }
                else
                {
                    DiscordNETWrapper.SendText("You are not in a game :thinking:", message.Channel).Wait();
                    return;
                }
            }
            else if (split.Length >= 2 && split[1] == "cancel")
            {
                UnoGame game = UnoGames.FirstOrDefault(x => x.Players.Exists(y => y.Item1.Id == message.Author.Id));
                DiscordNETWrapper.SendText($"`{message.Author.Username}` canceled the match! :cold_sweat: :scream: :dizzy_face: :skull_crossbones: ", message.Channel).Wait();
                UnoGames.Remove(game);
            }
            else if (split.Length >= 4 && split[1] == "move")
            {
                UnoGame game = UnoGames.FirstOrDefault(x => x.Players.Exists(y => y.Item1.Id == message.Author.Id));
                if (game == null)
                {
                    DiscordNETWrapper.SendText("You are not in a game :thinking:", message.Channel).Wait();
                    return;
                }

                UnoCardType t = UnoCardType.one;
                UnoColor    c = UnoColor.none;
                Enum.TryParse(split[2].ToLower(), out t);
                Enum.TryParse(split[3].ToLower(), out c);
                if (split[2].Length > 0 && char.IsDigit(split[2][0]))
                {
                    t = ToUnoType(Convert.ToInt32(split[2]));
                }
                game.PutCardOnTopOfStack(t, c, message.Author.Id, message.Channel);
                game.Send(message.Channel);

                Tuple <SocketUser, List <UnoCard> > winner = game.Players.FirstOrDefault(x => x.Item2.Count == 0);
                if (winner != null)
                {
                    DiscordNETWrapper.SendText($"`{winner.Item1.Username}` won! :trophy: :tada: ", message.Channel).Wait();
                    UnoGames.Remove(game);
                }
            }
            else
            {
                DiscordNETWrapper.SendEmbed(HelpMenu, message.Channel).Wait();
            }
            return;
        }
示例#8
0
 static bool IsNumber(UnoCardType t)
 {
     return(t != UnoCardType.changecolor && t != UnoCardType.plus4 && t != UnoCardType.skip && t != UnoCardType.reverse && t != UnoCardType.plus2);
 }
示例#9
0
 static bool HasColor(UnoCardType t)
 {
     return(t != UnoCardType.changecolor && t != UnoCardType.plus4);
 }
示例#10
0
 public UnoCard(UnoColor Color, UnoCardType Type)
 {
     this.Color   = Color;
     this.Type    = Type;
     this.Picture = GetPicture(Color, Type);
 }