Ejemplo n.º 1
0
Archivo: Deck.cs Proyecto: kseci/RunIt
        public void CheckForRoyal()
        {
            Deck deck = new Deck();
            int y = 0;
            while (y < 649739)
            {
                RealShuffle();
                for (int x = 0; x < 5; x++)
                {
                    deck.DealCard();

                }
                y++;
                CheckForRoyalInSpades();
                CheckForRoyalInHearts();
                CheckForRoyalInDiamonds();
                CheckForRoyalInClubs();
                deck = new Deck();
            }
        }
 //funtion
 public void DrawToHand(Deck dck)
 {
     _cardInHand.Add(dck.DrawCard()); //player draw card into hand then save cards in hand
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            ThreadManager tm = new ThreadManager();
            tm.go();
            Deck deck = new Deck();
            Deck test = new Deck();
            Thread okay = new Thread(new ThreadStart(deck.CheckForRoyal));
            Console.WriteLine("---------STARTING THREAD------");
            okay.Start();
            Console.WriteLine("---------SPINNING-----");
            Console.WriteLine("---------SPINNING-----");
            while (!okay.IsAlive) ;
            Console.WriteLine("---------Thread sleep-----");
            Console.WriteLine("---------Thread sleep-----");
            Thread.Sleep(100);
            Console.WriteLine("---------oThread abort-----");
            Console.WriteLine("---------oThread abort-----");
            okay.Abort();
            Console.WriteLine("---------oThread join-----");
            Console.WriteLine("---------oThread join-----");
            okay.Join();

            Console.WriteLine();
            Console.WriteLine("Alpha.Beta has finished");

            try
            {
                Console.WriteLine("Try to restart the Alpha.Beta thread");
                okay.Start();
            }
            catch (ThreadStateException)
            {
                Console.Write("ThreadStateException trying to retard Alpha.Beta");
                Console.WriteLine("Expected since aborted threads cannot be restarted");
            }

            //Console.WriteLine("AAAA");
            //while (!okay.IsAlive) ;

            //Thread.Sleep(1);

            //okay.Abort();

            //okay.Join();

            //Console.WriteLine();
            //Console.WriteLine("TEST FINISHED");

            ////     deck.DeleteCard("Hearts", "Five");
            ////    deck.PrintDeck();
            ////    deck.PrintDeck();

            //int y = 0;
            //while (y < 649739) {
            //deck.RealShuffle();
            //for (int x = 0; x < 5; x++) {
            //deck.DealCard();

            //    }
            //    y++;
            //    deck.CheckForRoyalInSpades();
            //    deck.CheckForRoyalInHearts();
            //    deck.CheckForRoyalInDiamonds();
            //    deck.CheckForRoyalInClubs();
            //    deck = new Deck();
            //}
        }
        public void Start()
        {
            Console.WriteLine("Welcome to The HIGH-LOW Games");
            Console.WriteLine("Let's Have some FUN!");

            Console.WriteLine("First Player Name :");
            string name1 = Console.ReadLine();

            Console.WriteLine("Second Player Name :");
            string name2 = Console.ReadLine();
            Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

            Player p1 = new Player(name1);
            Player p2 = new Player(name2);

            Deck deck = new Deck(); //create deck for play game

            while (deck.Cards.ToArray().Length > 0)
            {
                p1.DrawToHand(deck);
                p2.DrawToHand(deck);

                p1.ShowCard();
                p2.ShowCard();
                //Console.WriteLine(p1.NamePlayer + " got " + p1.LastLastCardInHand()().Face + " " + p1.LastLastCardInHand()().Suit + "" + p1.LastLastCardInHand()().Rank);
                //Console.WriteLine(p2.NamePlayer + " got " + p2.LastCardInHand().Face + " " + p2.LastCardInHand().Suit + "" + p2.LastCardInHand().Rank);

                if (p1.LastCardInHand().Rank < p2.LastCardInHand().Rank)
                {
                    p1.Score = p1.Score + 2;
                    Console.WriteLine(p1.NamePlayer + " Score is " + p1.Score);
                }
                else if (p1.LastCardInHand().Rank > p2.LastCardInHand().Rank)
                {
                    p2.Score = p2.Score + 2;
                    Console.WriteLine(p2.NamePlayer + " Score is " + p2.Score);
                }
                else //when rank card is equal
                {
                    int oldRank = p1.LastCardInHand().Rank; //keep old rank for draw cards  to looping for
                    for (int i = 0; (i < oldRank) && (deck.Cards.ToArray().Length > 0); i++) //draw card as number of rank from deck
                    {
                        p1.DrawToHand(deck);
                        p2.DrawToHand(deck);
                    }
                    p1.ShowCard(); // show last card
                    p2.ShowCard();
                    Console.WriteLine(2 + (oldRank * 2));
                    if (p1.LastCardInHand().Rank < p2.LastCardInHand().Rank)
                    {
                        p1.Score = p1.Score + 2 + (oldRank * 2);
                        Console.WriteLine(p1.NamePlayer + " Score is " + p1.Score);
                    }
                    else if (p1.LastCardInHand().Rank > p2.LastCardInHand().Rank)
                    {
                        p2.Score = p2.Score + 2 + (oldRank * 2);
                        Console.WriteLine(p2.NamePlayer + " Score is " + p2.Score);
                    }
                    else
                    {
                        deck.PutBack(p1.CardInHand); // putback all cards in hand to deck
                        deck.PutBack(p2.CardInHand);
                        p1.ClearCardsInHand(); //clear all cards in hand
                        p2.ClearCardsInHand();
                    }

                }

                Console.WriteLine("#########################################################");
            }

            if (p1.Score > p2.Score)
            {
                Console.WriteLine(p1.NamePlayer + " is The winner with " + p1.Score + " score ");

            }
            else if (p1.Score < p2.Score)
            {
                Console.WriteLine(p2.NamePlayer + " is The winner with " + p2.Score + " score ");
            }
            else
            {
                Console.WriteLine(p1.NamePlayer + " and " + p2.NamePlayer + " Draw!!");
            }
        }