Esempio n. 1
0
        static void Main(string[] args)
        {
            Random random = new Random();
            List<Card> Cards = new List<Card>();
            CardComparer_byValue comparer = new CardComparer_byValue();
            int numberOfRandomCards = 10;

            for (int i = 0; i < numberOfRandomCards; i++)
            {
                 int numberBetween0And3 = random.Next(4);
                 int numberBetween1And13 = random.Next(1, 14);

                 Card card = new Card((Suits)numberBetween0And3,
                                      (Values)numberBetween1And13);
                 Cards.Add(card);
            }

            Console.WriteLine(numberOfRandomCards + " random cards: ");
            foreach (var item in Cards)
            {
                Console.WriteLine(item.Name);
            }

            Cards.Sort(comparer);

            Console.WriteLine("\n\r" + "The same " + numberOfRandomCards + " cards, sorted: ");
            foreach (var item in Cards)
            {
                 Console.WriteLine(item.Name);
            }

            Console.ReadKey();
        }
		public CardDetailsView (Card card)
		{
			BackgroundColor = Color.White;

			Label TitleText = new Label () {
				FormattedText = card.Title,
				FontSize = 18,
				TextColor = StyleKit.LightTextColor
			};

			Label DescriptionText = new Label () {
				FormattedText = card.Description,
				FontSize = 12,
				TextColor = StyleKit.LightTextColor
			};

			var stack = new StackLayout () {
				Spacing = 0,
				Padding = new Thickness (10, 0, 0, 0),
				VerticalOptions = LayoutOptions.CenterAndExpand,
				Children = {
					TitleText,
					DescriptionText,
					new DateTimeView (card)
				}
			};

			Content = stack;
		}
		public CardStatusView (Card card)
		{
			var statusBoxView = new BoxView {
				VerticalOptions = LayoutOptions.Fill,
				HorizontalOptions = LayoutOptions.Fill
			};

			switch (card.Status) {
			case  CardStatus.Alert:
				statusBoxView.BackgroundColor = StyleKit.Status.AlertColor;
				break;
			case CardStatus.Completed:
				statusBoxView.BackgroundColor = StyleKit.Status.CompletedColor;
				break;
			case CardStatus.Unresolved:
				statusBoxView.BackgroundColor = StyleKit.Status.UnresolvedColor;
				break;
			default:
				statusBoxView.BackgroundColor = StyleKit.Status.UnresolvedColor;
				break;
			}
			;

			Content = statusBoxView;
		}
Esempio n. 4
0
 Card getWinner()
 {
     var list = Cards;
     Card card = new Card (0);
     if (count > 0) {
         list = list.OrderBy (c => c.Value).ToList ();
         card = list [list.Count-1];
     }
     return card;
 }
Esempio n. 5
0
File: Deck.cs Progetto: middas/Poker
        public Card[] Draw(int count)
        {
            Card[] cards = new Card[count];

            for (int i = 0; i < count; i++)
            {
                cards[i] = Cards[i + Index];
                Index++;
            }

            return cards;
        }
Esempio n. 6
0
        private void showCard_Click(object sender, EventArgs e)
        {
            Random random = new Random();
            int numberBetween0And3 = random.Next(4);
            int numberBetween1And13 = random.Next(1, 14);
            //    int anyRandomInteger = random.Next();

            Card card = new Card((Suits)numberBetween0And3, (Values)numberBetween1And13);
            string cardName = card.Name;

            MessageBox.Show(cardName);
        }
Esempio n. 7
0
		public CardView (Card card)
		{
			Grid grid = new Grid {
				Padding = new Thickness (0, 1, 1, 1),
				RowSpacing = 1,
				ColumnSpacing = 1,		
				BackgroundColor = StyleKit.CardBorderColor,
				VerticalOptions = LayoutOptions.FillAndExpand,
				RowDefinitions = {
					new RowDefinition { Height = new GridLength (70, GridUnitType.Absolute) },
					new RowDefinition { Height = new GridLength (30, GridUnitType.Absolute) }
				},
				ColumnDefinitions = {
					new ColumnDefinition { Width = new GridLength (4, GridUnitType.Absolute) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (100, GridUnitType.Absolute) },
					new ColumnDefinition { Width = new GridLength (50, GridUnitType.Absolute) }
				}
			};

			grid.Children.Add (
				new CardStatusView (card)
		, 0, 1, 0, 2);

			grid.Children.Add (new CardDetailsView (card), 1, 4, 0, 1);

			grid.Children.Add (
				new IconLabelView (
					card.StatusMessageFileSource,
					card.StatusMessage
				)
		, 1, 1);

			grid.Children.Add (
				new IconLabelView (
					card.ActionMessageFileSource,
					card.ActionMessage
				)
		, 2, 1);

			grid.Children.Add (new ConfigIconView (), 3, 1);

			Content = grid;
		}
Esempio n. 8
0
        public DateTimeView(Card card)
        {
            var labelStyle = new Style (typeof(Label))
                .Set (Label.FontSizeProperty, 8)
                .Set (Label.TextColorProperty, StyleKit.MediumGrey)
                .Set (Image.VerticalOptionsProperty, LayoutOptions.Center);

            var iconStyle = new Style (typeof(Image))
                .Set (Image.HeightRequestProperty, 10)
                .Set (Image.WidthRequestProperty, 10)
                .Set (Image.VerticalOptionsProperty, LayoutOptions.Center);

            var stack = new StackLayout () {
                VerticalOptions = LayoutOptions.Center,
                HeightRequest = 20,
                Padding = new Thickness (0),
                Orientation = StackOrientation.Horizontal,
                Children = {
                    new Image () {
                        Style = iconStyle,
                        Source = StyleKit.Icons.SmallCalendar,
                    },
                    new Label () {
                        //Text = card.DueDate.ToShortDateString (),
                        Style = labelStyle,
                    },
                    new BoxView () { Color = Color.Transparent, WidthRequest = 20 },
                    new Image () {
                        Style = iconStyle,
                        Source = StyleKit.Icons.SmallClock,
                    },
                    new Label () {
                        Text = card.DirationInMinutes.ToString () + " Minutes",
                        Style = labelStyle,
                    }
                }
            };

            Content = stack;
        }
		public ShadowCardView (Card card)
		{

			Grid grid = new Grid {
				Padding = new Thickness (0, 1, 1, 1),
				RowSpacing = 1,
				ColumnSpacing = 1,		
				BackgroundColor = Color.Transparent,
				VerticalOptions = LayoutOptions.FillAndExpand,
				RowDefinitions = {
					new RowDefinition { Height = new GridLength (70, GridUnitType.Absolute) },
					new RowDefinition { Height = new GridLength (30, GridUnitType.Absolute) }
				},
				ColumnDefinitions = {
					new ColumnDefinition { Width = new GridLength (4, GridUnitType.Absolute) },
					new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength (100, GridUnitType.Absolute) },
					new ColumnDefinition { Width = new GridLength (50, GridUnitType.Absolute) }
				}
			};

			grid.Children.Add (
				new CardStatusView (card)
				, 0, 1, 0, 2);

			grid.Children.Add (new CardDetailsView (card), 1, 4, 0, 1);

			grid.Children.Add (
				new IconLabelView (
					card.StatusMessageFileSource,
					card.StatusMessage
				)
				, 1, 1);

			grid.Children.Add (
				new IconLabelView (
					card.ActionMessageFileSource,
					card.ActionMessage
				)
				, 2, 1);

			grid.Children.Add (new ConfigIconView (), 3, 1);


			var layout = new RelativeLayout () {
				HorizontalOptions = LayoutOptions.FillAndExpand,
				HeightRequest = 125,
				Padding = new Thickness (0)
			};

			var cardBackground = new Image () { 
				Source = StyleKit.Icons.Shadow0240,
				Aspect = Aspect.Fill
			};

			layout.Children.Add (
				cardBackground,
				Constraint.Constant (0),
				Constraint.Constant (0),
				Constraint.RelativeToParent ((parent) => {
					return (parent.Width);
				}),
				Constraint.RelativeToParent ((parent) => {
					return (parent.Height);
				})
			);

			layout.Children.Add (
				grid,
				Constraint.Constant (10),
				Constraint.Constant (10),
				Constraint.RelativeToParent ((parent) => {
					return (parent.Width - 15);
				}),
				Constraint.RelativeToParent ((parent) => {
					return (parent.Height - 0);
				})
			);

			Content = layout;
		}
        private void CardPanel_Paint(object sender, PaintEventArgs e)
        {
            IEnumerable<Card> cardsToDraw = Cards as IEnumerable<Card>;
            string textToDraw = text;

            if (this.DesignMode) {
                // Advertise by drawing a few cards:
                if (designModeCards == null) {
                    designModeCards = new List<Card>();
                    for (int i = 0; i < random.Next(1, 4); i++) {
                        Card c = new Card((Suits)(random.Next(1, Enum.GetValues(typeof(Suits)).Length)),
                            (Ranks)(random.Next(Enum.GetValues(typeof(Ranks)).Length)));
                        c.FaceUp = (random.NextDouble() > 0.3);
                        designModeCards.Add(c);
                    }
                }
                cardsToDraw = designModeCards;
                textToDraw = "Sample";
            }

            // Draw cards:
            if (cardsToDraw != null) {
                int x = 10, y = 10;
                foreach (Card c in cardsToDraw) {
                    e.Graphics.DrawImage(Resources.GetImage(c.CardDisplay), x, y);
                    x += 15;
                    y += 10;
                }
            }

            // Draw text:
            if (!string.IsNullOrEmpty(textToDraw)) {
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                e.Graphics.DrawString(textToDraw, this.Font, new SolidBrush(this.ForeColor), this.ClientRectangle, sf);
            }

            // Draw a yellow highlight inside any border:
            if (Highlight) {
                Pen yellowPen = new Pen(Color.Yellow, 3.0f);
                e.Graphics.DrawRectangle(yellowPen, this.ClientRectangle);
            }
        }
Esempio n. 11
0
        private void b_add_Click(object sender, EventArgs e) //tworzy nowy obiekt karty z parametrami i dodaje go do listy kart do druku
        {
            if (list_box.SelectedIndex != -1)
            {
                if (pic_back.ImageLocation == null | pic_back.ImageLocation == startReversePath)
                {
                    pic_back.ImageLocation = defaultReversePath;
                    pic_back.SizeMode = PictureBoxSizeMode.Zoom;
                }

                try
                {
                    Card c;
                    c = new Card();
                    c.frontPath = list_box.SelectedItem.ToString();
                    c.reversePath = pic_back.ImageLocation;
                    c.name = list_box.SelectedItem.ToString().Substring(c.frontPath.LastIndexOf("\\") + 1);
                    c.quantity = ud_quantity.Value;
                    c.width = float.Parse(tb_width.Text, System.Globalization.CultureInfo.InvariantCulture);
                    c.height = float.Parse(tb_height.Text, System.Globalization.CultureInfo.InvariantCulture);
                    for (int i = 1; i <= c.quantity; i++)
                    {
                        cards.Add(c);
                        list_box_c.Items.Add(c); //wyswietlenie tworzonych obiektow na drugiej liscie
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Nie udało się dodać karty");
                }
            }
            else
            {
                MessageBox.Show("Nie zaznaczono karty do dodania!");
            }
        }
Esempio n. 12
0
 // LoseCard
 public virtual void LoseCard(Card card)
 {
     // The method that rids the collection of this card.
     removeCard(card);
 }
Esempio n. 13
0
 public void Remove(Card card)
 {
     switch (card.Suit) {
     case 0:
         Hearts.Remove (card);
         break;
     case 1:
         Clubs.Remove (card);
         break;
     case 2:
         Diamonds.Remove (card);
         break;
     case 3:
         Spades.Remove (card);
         break;
     default:
         break;
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     var card = new Card((Suits) _random.Next(4), (Values) _random.Next(1,14)); 
     MessageBox.Show(card.Name); 
 }
Esempio n. 15
0
 // removeCard /////////////////////////////////////
 private void removeCard(Card card)
 {
     // Removes a card from the deck.  For encapsulation.
     _Cards.Remove(card);
 }
Esempio n. 16
0
 //
 // Methods
 //
 // addCard ////////////////////////////////////////
 private void addCard(Card card)
 {
     // Adds a card to the deck.  For encapsulation.
     if (CardCount < MaxCards)
     {
         _Cards.Add(card);
     }
 }
Esempio n. 17
0
 void Next_Card()
 {
     if (count < newDeck.Count) {
         string temp = String.Format ("{0}",score);
         if (count > 0) {
             oldCard = card;
             idR = oldCard.Display;
         }
         card = cards.Pop ();
         id = card.Display;
         RunOnUiThread (() => {
             tvScore.Text = temp;
             pic.SetImageResource (id);
             if (count > 0)
                 picR.SetImageResource (idR);
         });
         count++;
     } else {
         New_Game ();
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Draw a new card from the stack, "destroying" it in the stack, add it to a GUI Card
 /// object, and return it.
 /// </summary>
 /// <returns></returns>
 private Card DestructiveDrawNewCard()
 {
     var oldCard = new Card {CardObject = card1.CardObject};
     var newCardObj = _stack.Draw();
     if (newCardObj != null)
     {
         card1.CardObject = newCardObj;
         card1.CardObject.ShowBack = _showBack;
         return oldCard;
     }
     if (card1.CardObject != null)// give the last card!
     {
         card1.CardObject = null;
         return oldCard;
     }
     return null;
 }
Esempio n. 19
0
 // AddCard ////////////////////////////////////////
 public bool AddCard(Card card)
 {
     // Adds a card to this collection.
     int cards = CardCount;
     card.Owner = this;              // Simply change the owner.  The property will call the appropriate interface methods.
     return cards != CardCount;      // On a successful add, this quantity will change.
 }
Esempio n. 20
0
 void Play_Card(object sender, EventArgs e)
 {
     int id = (int)((ImageView)sender).Tag;
     Card card = new Card (id);
     if (card.Suit == outCard.Suit || !user.Hand.HasSuit (outCard.Suit)) {
         var played = FindViewById<ImageView> (Resource.Id.play);
         RunOnUiThread (() => {
             played.SetBackgroundResource (Resource.Drawable.blank);
             played.SetImageResource (card.Display);
             ((View)sender).Visibility = ViewStates.Gone;
         });
     } else {
         Toast.MakeText (this, "You must follow suit!", ToastLength.Short).Show ();
     }
 }
Esempio n. 21
0
        //
        // Interface methods
        //
        // GainCard
        public virtual void GainCard(Card card)
        {
            // If we are not allowing duplicates, then don't let any through.
            if (!AllowDuplicates)
            {
                foreach (Card c in Cards)
                {
                    if (card.Equals(c))
                    {
                        return;
                    }
                }
            }

            // Add the card.
            addCard(card);
        }
Esempio n. 22
0
 public void Play(Card card)
 {
     Cards.Add (card);
     count++;
 }
Esempio n. 23
0
        // Equals /////////////////////////////////////////
        public bool Equals(Card card)
        {
            // If not a valid card, it's not equal.
            if (card == null)
            {
                return false;
            }

            // I am only concerned with the actual value of the card,
            // and not the owners.
            return this.Suit == card.Suit && this.Spot == card.Spot;
        }