Beispiel #1
0
        private void UpdateCards()
        {
            LayoutRoot.Children.Clear();
            //foreach (var child in LayoutRoot.Children)
            //{
            //    if (child is SlotControl)
            //    {
            //        LayoutRoot.Children.Remove(child);
            //    }

            //}


            if (Hand.Cards != null)
            {
                for (int i = 0; i < Hand.Cards.Count; i++)
                {
                    //Card theCard = Cards[i];

                    //if (theCard != null)
                    //if (theCard.Value > 5)
                    //{
                    //    threeC threeClubs = new threeC();
                    //    threeClubs.SetValue(Canvas.LeftProperty, 5d);
                    //    threeClubs.SetValue(Canvas.TopProperty, i * 25d);

                    //    LayoutRoot.Children.Add(threeClubs);
                    //}

                    CardControl     cardControl = new CardControl();
                    double          angle       = GetRandomNumber(-3d, 3d);
                    RotateTransform transform   = new RotateTransform()
                    {
                        Angle = angle
                    };
                    //   cardControl.RenderTransform = transform;
                    // cardControl.InitializeCard(c, null);
                    cardControl.Card = Hand.Cards[i];
                    //     cardControl.InitializeCard();
                    cardControl.SetValue(Canvas.LeftProperty, -10d);

                    if (i == 0)
                    {
                        cardControl.SetValue(Canvas.TopProperty, 1 * 15d);
                    }
                    else
                    {
                        cardControl.SetValue(Canvas.TopProperty, (10d + (i * 25d)));
                    }



                    LayoutRoot.Children.Add(cardControl);
                }
            }
            scorePopper1.HandScore = Hand.Total;
        }
Beispiel #2
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/Run21;component/UserControls/DeckControl.xaml", System.UriKind.Relative));
     this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.shownCard  = ((Run21.UserControls.CardControl)(this.FindName("shownCard")));
     this.secondCard = ((Run21.UserControls.CardControl)(this.FindName("secondCard")));
 }
Beispiel #3
0
        private static void OnCardChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue == null)
            {
                return;
            }

            CardControl c = d as CardControl;
            // c.cardValue.Text = c.Card.Value.ToString();



            var resource = Application.GetResourceStream(c.Card.XamlLocation);

            if (resource == null)
            {
                resource = Application.GetResourceStream(new Uri(@"/Run21;component/UserControls/Cards/12C.xaml", UriKind.Relative));
            }


            using (StreamReader reader = new StreamReader(resource.Stream))
            {
                c.cardContent.Content = (Canvas)XamlReader.Load(reader.ReadToEnd());
            }

            var backresource = Application.GetResourceStream(new Uri(@"/Run21;component/UserControls/Cards/redback.xaml", UriKind.Relative));

            if (backresource == null)
            {
                backresource = Application.GetResourceStream(new Uri(@"/Run21;component/UserControls/Cards/12C.xaml", UriKind.Relative));
            }


            using (StreamReader reader = new StreamReader(backresource.Stream))
            {
                c.backContent.Content = (Canvas)XamlReader.Load(reader.ReadToEnd());
            }
        }
Beispiel #4
0
        private void AddCard()
        {
            var gestureListener = toolkit.GestureService.GetGestureListener(this);

            gestureListener.Tap -= new EventHandler <toolkit.GestureEventArgs>(GestureListener_Tap);

            CardControl cardControl = new CardControl();

            cardControl.Card = Hand.Cards.Last();


            double          angle     = GetRandomNumber(-3d, 3d);
            RotateTransform transform = new RotateTransform()
            {
                Angle = angle
            };

            cardControl.RenderTransform = transform;

            //     cardControl.InitializeCard();
            cardControl.SetValue(Canvas.LeftProperty, 0d);


            cardControl.SetValue(Canvas.TopProperty, (10d + (lastCardPosition)));
            lastCardPosition = lastCardPosition + 25d;
            LayoutRoot.Children.Add(cardControl);

            Random rand = new Random();

            if (rand.Next(0, 2) == 0)
            {
                using (var stream = TitleContainer.OpenStream("sounds/deal.wav"))
                {
                    var effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();
                }
            }

            else
            {
                using (var stream = TitleContainer.OpenStream("sounds/deal1.wav"))
                {
                    var effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();
                }
            }



            scorePopper1.HandScore = Hand.Total;


            gestureListener.Tap += new EventHandler <toolkit.GestureEventArgs>(GestureListener_Tap);

            if (scorePopper1.HandScore == 21)
            {
                foreach (var s in LayoutRoot.Children.OfType <CardControl>())
                {
                    using (var stream = TitleContainer.OpenStream("sounds/bleep.wav"))
                    {
                        var effect = SoundEffect.FromStream(stream);
                        FrameworkDispatcher.Update();
                        effect.Play();
                    }

                    s.FlipCard();
                    //turn off ability to add cards

                    gestureListener.Tap -= new EventHandler <toolkit.GestureEventArgs>(GestureListener_Tap);
                }
            }

            if (scorePopper1.HandScore > 21)
            {
                theBorder.Opacity      = .5;
                bustControl.Visibility = Visibility.Visible;
                bustControl.Throb.Begin();
                //turn off ability to add cards

                gestureListener.Tap -= new EventHandler <toolkit.GestureEventArgs>(GestureListener_Tap);

                using (var stream = TitleContainer.OpenStream("sounds/break.wav"))
                {
                    var effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    effect.Play();
                }
            }
        }
Beispiel #5
0
        private void GestureListener_Tap(object sender, toolkit.GestureEventArgs e)
        {
            CardControl firstCard = LayoutRoot.Children.OfType <CardControl>().FirstOrDefault();

            firstCard.FlipCard();
        }