Exemple #1
0
 public void TestClose()
 {
     pt.Open();
     Assert.True(pt.IsOpen);
     pt.Close();
     Assert.False(pt.IsOpen);
 }
        private static void TestOpenCloseIsOpen()
        {
            Console.WriteLine("Testing Open(), Close(), IsOpen");
            Console.WriteLine();

            Random      rndGen = new Random();
            int         engVal = rndGen.Next(1, 7);
            PlayerTrain test   = new PlayerTrain(new Hand(), engVal);

            Console.WriteLine("Expect: IsOpen = False");
            Console.WriteLine("Result: IsOpen = " + test.IsOpen.ToString());
            Console.WriteLine();

            Console.WriteLine("Calling Open()");
            Console.WriteLine();

            test.Open();

            Console.WriteLine("Expect: IsOpen = True");
            Console.WriteLine("Result: IsOpen = " + test.IsOpen.ToString());
            Console.WriteLine();

            Console.WriteLine("Calling Close()");
            Console.WriteLine();

            test.Close();

            Console.WriteLine("Expect: IsOpen = False");
            Console.WriteLine("Result: IsOpen = " + test.IsOpen.ToString());
            Console.WriteLine();
        }
        public void TestPlayerTrainClose()
        {
            playerTrain.Close();
            bool expected = false;
            bool actual   = playerTrain.IsOpen;

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
 public void CloseTest()
 {
     // Tests the close method which sets the
     // playertrain to closed when called
     Assert.True(p04.IsOpen);
     p04.Close();
     Assert.False(p04.IsOpen);
 }
Exemple #5
0
        public void TestClose()
        {
            PlayerTrain newTrain = new PlayerTrain(h1, 7);

            Assert.False(newTrain.IsOpen);
            newTrain.Open();
            Assert.True(newTrain.IsOpen);
            newTrain.Close();
            Assert.False(newTrain.IsOpen);
        }
        public void TestOpenCloseTrain()
        {
            Assert.False(playerOneTrain.IsOpen);

            playerOneTrain.Open();

            Assert.True(playerOneTrain.IsOpen);

            playerOneTrain.Close();

            Assert.False(playerOneTrain.IsOpen);
        }
Exemple #7
0
        // adds a domino picture to a train
        public void ComputerPlayOnTrain(Domino d, Train train, List <PictureBox> trainPBs, int pbIndex)
        {
            PictureBox trainPB = trainPBs[pbIndex];

            LoadDomino(trainPB, d);
            if (train == computerTrain)
            {
                computerTrain.Close();
                computerTrainStatusLabel.Text      = "Closed";
                computerTrainStatusLabel.ForeColor = Color.Red;
            }
        }
Exemple #8
0
        public void UserPlayOnTrain(Domino d, PictureBox trainPB, Train train, List <PictureBox> trainPBs)
        {
            userHand.Play(d, train);

            // add the domino to train pb
            LoadDomino(trainPB, d);

            // remove the domino from the pbs
            PictureBox handPB = userHandPBs[indexOfDominoInPlay];

            handPB.Image   = null;
            handPB.Visible = false;
            userHandPBs.RemoveAt(indexOfDominoInPlay);
            this.Controls.Remove(handPB);
            handPB = null;

            // make the next trainPB playable
            SetupTrainPB(trainPB, false);
            if (MustScroll(train))
            {
                ScrollTrain(train, trainPBs);
            }
            SetupTrainPB(trainPBs[NextPBIndex(train)], true);

            // ignore doubles for right now
            if (train == userTrain)
            {
                userTrain.Close();
            }

            // disable the users hand and update labels in UI
            if (userTrain.IsOpen)
            {
                userTrainStatusLabel.Text      = "Open";
                userTrainStatusLabel.ForeColor = Color.Green;
            }
            else
            {
                userTrainStatusLabel.Text      = "Closed";
                userTrainStatusLabel.ForeColor = Color.Red;
            }

            computerLabel.ForeColor = Color.Green;
            userLabel.ForeColor     = Color.Red;
            DisableUserHandPBs();

            drawButton.Enabled = false;
            passButton.Enabled = false;

            whosTurn = COMPUTER;
        }
        private static void TestPTIsPlayable()
        {
            Console.WriteLine("Test PlayerTrain IsPlayable");
            Console.WriteLine();

            const int MAXDOTS = 6;
            BoneYard  b       = new BoneYard(MAXDOTS);

            b.Shuffle();

            Random      rndGen = new Random();
            int         engVal = rndGen.Next(1, 7);
            PlayerTrain test   = new PlayerTrain(new Hand(), engVal);

            const int LOOPS = 10;

            Console.WriteLine("Engine value = " + engVal);
            Console.WriteLine("Playable value = " + test.PlayableValue);
            Console.WriteLine();

            Domino d;

            for (int i = 0; i < LOOPS; i++)
            {
                d = b.Draw();
                Console.WriteLine(d.ToString());

                if (rndGen.Next(1, 3) % 2 == 0)
                {
                    test.Open();
                    Console.WriteLine("The player's hand is open");
                }
                else
                {
                    test.Close();
                    Console.WriteLine("The player's hand is closed");
                }
                Console.WriteLine();

                bool checkPlay = test.IsOpen && (d.Side1 == test.PlayableValue || d.Side2 == test.PlayableValue);
                bool checkFlip = checkPlay ? d.Side1 != test.PlayableValue : false;  // Good form?

                Console.WriteLine("Test IsPlayable");
                Console.WriteLine("Expect: " + checkPlay.ToString());
                Console.WriteLine("Result: " + test.IsPlayable(new Hand(), d, out bool mustFlip).ToString());
                Console.WriteLine("Test mustFlip");
                Console.WriteLine("Expect: " + checkFlip.ToString());
                Console.WriteLine("Result: " + mustFlip.ToString());
                Console.WriteLine();
            }
        }
        // plays a domino on a train.  Loads the appropriate train pb,
        // removes the domino pb from the hand, updates the train status label ,
        // disables the hand pbs and disables appropriate buttons
        public void UserPlayOnTrain(Domino d, Train train, List <PictureBox> trainPBs)
        {
            userHand.Play(d, train);

            // add the domino to train pb
            int        nextPBIndex = NextTrainPBIndex(train, trainPBs);
            PictureBox trainPB     = trainPBs[nextPBIndex];

            LoadDomino(trainPB, d);

            // remove the domino from the pbs
            RemoveDominoFromHandPB(indexOfDominoInPlay);

            // ignore doubles for right now
            if (train == userTrain)
            {
                userTrain.Close();
            }

            // disable the users hand and update labels in UI
            if (userTrain.IsOpen)
            {
                userTrainStatusLabel.Text      = "Open";
                userTrainStatusLabel.ForeColor = Color.Green;
            }
            else
            {
                userTrainStatusLabel.Text      = "Closed";
                userTrainStatusLabel.ForeColor = Color.Red;
            }

            computerLabel.ForeColor = Color.Green;
            userLabel.ForeColor     = Color.Red;
            DisableUserHandPBs();

            drawButton.Enabled = false;
            passButton.Enabled = false;

            whosTurn = COMPUTER;
        }
Exemple #11
0
        public void TestIsPlayable()
        {
            bool         flip;
            MexicanTrain a = new MexicanTrain(4);
            PlayerTrain  b = new PlayerTrain(hand1, 5);
            PlayerTrain  c = new PlayerTrain(hand2, 6);

            hand1.Add(new Domino(4, 5));
            hand1.Add(new Domino(5, 6));
            hand1.Add(new Domino(6, 4));
            hand2.Add(new Domino(4, 5));
            hand2.Add(new Domino(5, 6));
            hand2.Add(new Domino(6, 4));
            Assert.True(a.IsPlayable(hand1, hand1[0], out flip));
            Assert.True(!flip);
            Assert.True(a.IsPlayable(hand1, hand1[2], out flip));
            Assert.True(flip);
            Assert.True(b.IsPlayable(hand1, hand1[0], out flip));
            Assert.True(flip);
            Assert.True(b.IsPlayable(hand1, hand1[1], out flip));
            Assert.True(!flip);
            Assert.True(c.IsPlayable(hand2, hand2[1], out flip));
            Assert.True(flip);
            Assert.True(c.IsPlayable(hand2, hand2[2], out flip));
            Assert.True(!flip);
            Assert.True(!b.IsPlayable(hand2, hand1[0], out flip));
            Assert.True(!b.IsPlayable(hand2, hand1[1], out flip));
            Assert.True(!b.IsOpen);
            b.Open();
            Assert.True(b.IsOpen);
            Assert.True(b.IsPlayable(hand2, hand1[0], out flip));
            Assert.True(b.IsPlayable(hand2, hand1[1], out flip));
            b.Close();
            Assert.True(!b.IsOpen);
            Assert.True(!b.IsPlayable(hand2, hand1[0], out flip));
            Assert.True(!b.IsPlayable(hand2, hand1[1], out flip));
        }
Exemple #12
0
 public void TestClose()
 {
     pT.Close();
     Assert.IsFalse(pT.IsOpen);
 }
        static void Main(string[] args)
        {
            Console.WriteLine("TESTING MEXICAN TRAIN CLASS.");
            Train mt = new MexicanTrain(3);
            Hand  h  = new Hand();

            h.AddDomino(new Domino(0, 2));
            Console.WriteLine("Trains engine value should be 3 and is: " + mt.EngineValue.ToString());
            Console.WriteLine("Trying to add a 2:0 to the train, we should catch an exception");
            try
            {
                mt.Play(h, h.Discard(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            h.AddDomino(new Domino(1, 3));
            Console.WriteLine("Adding a 1:3 domino to the train, it should work and it should be flipped.");
            try
            {
                mt.Play(h, h.Discard(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            Console.WriteLine("Let's look at the train right now, we should have one domino be a 3:1 as it was flipped: " + mt.ToString());
            Console.WriteLine("MEXICAN TRAIN DONE! \n \n \n");
            Console.WriteLine("TESTING PLAYER TRAIN CLASS.");
            //
            //
            //
            //
            //
            PlayerTrain player1 = new PlayerTrain(5);
            PlayerTrain player2 = new PlayerTrain(5);

            player1.Open();
            player2.Open();
            Hand playerHand1 = new Hand();
            Hand playerHand2 = new Hand();

            playerHand1.AddDomino(new Domino(5, 2));
            playerHand1.AddDomino(new Domino(2, 3));
            playerHand1.AddDomino(new Domino(3, 8));

            playerHand2.AddDomino(new Domino(5, 2));
            playerHand2.AddDomino(new Domino(2, 3));
            playerHand2.AddDomino(new Domino(3, 8));
            Console.WriteLine("Both player trains have an engine value of 5 and we've assigned hands, let's have the players try to mess with each other's trains.");
            player1.m_Hand = playerHand1;
            player2.m_Hand = playerHand2;
            try
            {
                Console.WriteLine("Player 1 is fiddling with player 2's train, should get an exception.");
                player1.Play(playerHand2, playerHand2.GetDomino(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            try
            {
                Console.WriteLine("Player 2 is fiddling with player 1's train, should get an exception.");
                player2.Play(playerHand1, playerHand1.GetDomino(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            Console.WriteLine("Closing player 1's train.");
            player1.Close();
            try
            {
                Console.WriteLine("Player1 is attempting to add a domino to his clsoed train, we should get an exception.");
                player1.Play(playerHand1, playerHand1.GetDomino(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            Console.WriteLine("Player 2 will add dominos in the correct order for his train, he should not get any exceptions.");
            try
            {
                Console.WriteLine("First domino | Should not get an exception...");
                player2.Play(playerHand2, playerHand2.Discard(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            try
            {
                Console.WriteLine("Second domino | Should not get an exception...");
                player2.Play(playerHand2, playerHand2.Discard(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            try
            {
                Console.WriteLine("Third domino | Should not get an exception...");
                player2.Play(playerHand2, playerHand2.Discard(0));
            }
            catch (Exception e)
            {
                Console.WriteLine("CAUGHT EXCEPTION: " + e.Message);
            }
            Console.WriteLine("Showing the chain of dominos: " + player2.ToString());
            Console.WriteLine("Closing player 2 and opening player 1.");
            if (player2.IsOpen)
            {
                player2.Close();
            }
            if (!player1.IsOpen)
            {
                player1.Open();
            }
            Console.WriteLine("Player 2 should be closed and is: " + ((player2.IsOpen) ? "NOT CLOSED" : "CLOSED"));
            Console.WriteLine("Player 1 should be open and is: " + ((player1.IsOpen) ? "OPEN" : "NOT OPEN"));
            Console.WriteLine("PLAYER TRAIN DONE! \n \n \n");
        }