Example #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);
        }
Example #2
0
            public UnoGame(List <SocketUser> Players)
            {
                this.Players = Players.Select(x => new Tuple <SocketUser, List <UnoCard> >(x, GetStartingDeck())).ToList();

                UnoCard card = GetRandomNumberCard();

                DrawCardOnStack(card);
                TopStackCard = card;
                CurColor     = card.Color;
            }
        public static UnoCardParser Parse(string s)
        {
            var       split = s.ToLower().Replace("un ", String.Empty).Split(' ');
            UnoCardId id    = _unoCardIdDictionnarDictionary[split[0]];
            UnoColor  color = UnoColor.Black;

            if (split.Length > 1)
            {
                _unoCardColorDictionnarDictionary.TryGetValue(split[1], out color);
            }
            return(new UnoCardParser(id, color));
        }
Example #4
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();
                }
            }
 public UnoCardParser(UnoCardId id, UnoColor color)
 {
     Card = new UnoCard(id, color);
 }
		public UnoCardParser(UnoCardId id, UnoColor color)
		{
			Card = new UnoCard(id, color);
		}
Example #7
0
		public UnoCard(UnoCardId unoCardId, UnoColor unoColor)
		{
			Id = unoCardId;
			Color = unoColor;
		}
Example #8
0
 public UnoCard(UnoCardId unoCardId, UnoColor unoColor)
 {
     Id    = unoCardId;
     Color = unoColor;
 }
Example #9
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;
        }
Example #10
0
 public UnoCard(UnoColor Color, UnoCardType Type)
 {
     this.Color   = Color;
     this.Type    = Type;
     this.Picture = GetPicture(Color, Type);
 }