Example #1
0
        public int CreateJumbledNumber(JumbledNumber NumJumObj, int difficulty)
        {
            IJumbledNumberSvc jumnumSvc =
                (IJumbledNumberSvc)GetService(typeof(IJumbledNumberSvc).Name);

            return jumnumSvc.GetJumbledNumber(NumJumObj, difficulty);
        }
Example #2
0
        public void GMCheckWinTest()
        {
            int testNumDigits = 4,
                testNumCorrect1 = 4,
                testNumCorrect2 = 3;
            long testCurrNumJum = 1234;
            long testCurrGuess = 1111;
            bool testStatus = false;

            JumbledNumber testNumJum = new JumbledNumber(testNumDigits, testCurrNumJum, testCurrGuess, 0, 0, true);
            Player testPlayer = new Player("Link");

            GameManager testGameManager = new GameManager();

            // Set win condition and test
            testNumJum.NumCorrect = testNumCorrect1;

            testStatus = testGameManager.CheckWin(testNumJum, testPlayer);
            Assert.IsTrue(testStatus);

            // Set win condition and test
            testNumJum.NumCorrect = testNumCorrect2;

            testStatus = testGameManager.CheckWin(testNumJum, testPlayer);
            Assert.IsFalse(testStatus);
        }
Example #3
0
        public void StopGame(JumbledNumber NumJum)
        {
            IGameSvc gameSvc =
                (IGameSvc)GetService(typeof(IGameSvc).Name);

            gameSvc.ChangeGameStatus(NumJum, false);
        }
Example #4
0
        public bool CheckGameStatus(JumbledNumber NumJumObj)
        {
            IJumbledNumberSvc jumnumSvc =
                (IJumbledNumberSvc)GetService(typeof(IJumbledNumberSvc).Name);

            return jumnumSvc.GetGameStatus(NumJumObj);
        }
Example #5
0
        // Add Guess
        public void AddGuess(JumbledNumber NumJumObj, long guess)
        {
            // Store guess in object
            NumJumObj.CurGuess = guess;

            // Incremnt Count
            NumJumObj.IncNumberGuesses();
        }
Example #6
0
        public void CompareGuessandNumJumTest()
        {
            long testGuess1 = 1234,
                testGuess2 = 5612,
                testGuess3 = 5278,
                testnumJum = 5678;

            int testNumCorrect = 0;

            JumbledNumber testJumbledNumObj = new JumbledNumber(4, testnumJum);

            Factory testFactory = Factory.GetInstance();
            IGameSvc testSVC = (IGameSvc)
                testFactory.GetService(typeof(IGameSvc).Name);

            // Update guess with test 1
            testSVC.AddGuess(testJumbledNumObj, testGuess1);

            // Compare values and store number correct
            testNumCorrect = testSVC.CompareGuessandNumJum(testJumbledNumObj);

            // Update number correct
            testSVC.UpdateNumberCorrect(testJumbledNumObj, testNumCorrect);

            // Perform Test
            Assert.AreEqual(0, testNumCorrect);
            Assert.AreEqual(0, testJumbledNumObj.NumCorrect);

            // Update guess with test 2
            testSVC.AddGuess(testJumbledNumObj, testGuess2);

            // Compare values and store number correct
            testNumCorrect = testSVC.CompareGuessandNumJum(testJumbledNumObj);

            // Update number correct
            testSVC.UpdateNumberCorrect(testJumbledNumObj, testNumCorrect);

            // Perform Test
            Assert.AreEqual(2, testNumCorrect);
            Assert.AreEqual(2, testJumbledNumObj.NumCorrect);

            // Update guess with test 3
            testSVC.AddGuess(testJumbledNumObj, testGuess3);

            // Compare values and store number correct
            testNumCorrect = testSVC.CompareGuessandNumJum(testJumbledNumObj);

            // Update number correct
            testSVC.UpdateNumberCorrect(testJumbledNumObj, testNumCorrect);

            // Perform Test
            Assert.AreEqual(3, testNumCorrect);
            Assert.AreEqual(3, testJumbledNumObj.NumCorrect);

            // Final Test
            Assert.AreEqual(3, testJumbledNumObj.NumGuesses);
        }
Example #7
0
        public void TestIncNumberCorrect()
        {
            int TestNumDigits = 4;
            long TestJNumberValue = 1234;
            int TestExpIncVal = 2;
            JumbledNumber TestNumJum = new JumbledNumber(TestNumDigits, TestJNumberValue);

            TestNumJum.IncNumberCorrect();                      // Increment to 1
            TestNumJum.IncNumberCorrect();                      // Increment to 2

            Assert.AreEqual(TestExpIncVal, TestNumJum.NumCorrect);
        }
Example #8
0
        public void TestIncNumberGuesses()
        {
            int TestNumDigits = 4;
            long TestJNumberValue = 5678;
            int TestGuessNum = 3;
            JumbledNumber TestNumJum = new JumbledNumber(TestNumDigits, TestJNumberValue);

            // Add 3 guesses
            TestNumJum.IncNumberGuesses();
            TestNumJum.IncNumberGuesses();
            TestNumJum.IncNumberGuesses();

            Assert.AreEqual(TestGuessNum, TestNumJum.NumGuesses);
        }
Example #9
0
        // Compare guess and Jumbled Number
        // Returns number of correct digits
        public int CompareGuessandNumJum(JumbledNumber NumJumObj)
        {
            long currGuess,
                currNumJum;

            int numDigits,
                numCorrect = 0,
                gint,
                njint;

            // Get values form NumJum Object
            currGuess = NumJumObj.CurGuess;
            currNumJum = NumJumObj.JNumberValue;
            numDigits = NumJumObj.NumDigits;

            ArrayList guessArray = new ArrayList(),
                numJumArray = new ArrayList();

            // Build array for both the guess and the NumJum for comparison

            for (int i = 0; i < numDigits; i++)
            {
                guessArray.Add((int)(currGuess % 10));
                numJumArray.Add((int)(currNumJum % 10));

                currGuess = (currGuess / 10);
                currNumJum = (currNumJum / 10);
            }

            // Reverse arrays to get in correct order
            guessArray.Reverse();
            numJumArray.Reverse();

            // Use for loops and if statements to compare values

            for (int i = 0; i < numDigits; i++)
            {
                // Use CompareTo method to determine if values are the same
                gint = (int)guessArray[i];
                njint = (int)numJumArray[i];

                if ((gint.CompareTo(njint) == 0))
                {
                    numCorrect++;
                }
            }

            return numCorrect;
        }
Example #10
0
 public bool CheckWin(JumbledNumber NumJum, Player player)
 {
     if (NumJum.NumCorrect == NumJum.NumDigits)
     {
         // Set player win value to true
         player.GameStatus = true;
         return true;
     }
     else
     {
         // Set player win to false
         player.GameStatus = false;
         return false;
     }
 }
Example #11
0
        public void ChangeGameStatusTest()
        {
            JumbledNumber testJumbledNumber = new JumbledNumber();

            Factory testFactory = Factory.GetInstance();

            IGameSvc testGameSvc =
                (IGameSvc)testFactory.GetService(typeof(IGameSvc).Name);

            testGameSvc.ChangeGameStatus(testJumbledNumber, true);

            Assert.IsTrue(testJumbledNumber.GameInProgress);

            testGameSvc.ChangeGameStatus(testJumbledNumber, false);

            Assert.IsFalse(testJumbledNumber.GameInProgress);
        }
Example #12
0
        public void CheckGuess(JumbledNumber NumJum, long guess)
        {
            int NumCorrect = 0;

            IGameSvc gameSvc =
                (IGameSvc)GetService(typeof(IGameSvc).Name);

            // Add guess and increment number of guesses in object
            gameSvc.AddGuess(NumJum, guess);

            // Compare guess with Jumbled Number
            NumCorrect = gameSvc.CompareGuessandNumJum(NumJum);

            // Store number of correct digits in object
            gameSvc.UpdateNumberCorrect(NumJum, NumCorrect);

            //return NumCorrect;
        }
Example #13
0
        public int StartGame(JumbledNumber NumJum, int difficulty)
        {
            int numDigits;

            IGameSvc gameSvc =
                (IGameSvc)GetService(typeof(IGameSvc).Name);

            IJumbledNumberSvc numjumSvc =
                (IJumbledNumberSvc)GetService(typeof(IJumbledNumberSvc).Name);

            // Create Jumbled Number
            numDigits = numjumSvc.GetJumbledNumber(NumJum, difficulty);

            // Toggle Game Status
            gameSvc.ChangeGameStatus(NumJum, true);

            return numDigits;
        }
Example #14
0
        public void AddGuessTest()
        {
            long testGuess = 1234,
                testnumJum = 5678;

            Factory testFactory = Factory.GetInstance();

            JumbledNumber testJumbledNumObj = new JumbledNumber(4, testnumJum);

            IGameSvc testSVC = (IGameSvc)
                testFactory.GetService(typeof(IGameSvc).Name);

            // Create JumbledNumber Object using Factory
            testSVC.AddGuess(testJumbledNumObj, testGuess);

            Assert.AreEqual(testGuess, testJumbledNumObj.CurGuess);
            Assert.AreEqual(1, testJumbledNumObj.NumGuesses);
        }
        public void GMCheckGameStatusTest()
        {
            bool test1 = false,
                test2 = true;

            JumbledNumber testJumbledNumber = new JumbledNumber();

            JumbledNumberManager testJumNumManager = new JumbledNumberManager();

            // Set game status and test
            testJumbledNumber.GameInProgress = true;
            test1 = testJumNumManager.CheckGameStatus(testJumbledNumber);
            Assert.IsTrue(test1);
            Assert.IsTrue(testJumbledNumber.GameInProgress);

            testJumbledNumber.GameInProgress = false;
            test2 = testJumNumManager.CheckGameStatus(testJumbledNumber);
            Assert.IsFalse(test2);
            Assert.IsFalse(testJumbledNumber.GameInProgress);
        }
Example #16
0
        public void GMCheckGuessTest()
        {
            int testNumDigits = 4;
            long testCurrNumJum = 1234;
            long testCurrGuess = 1111;

            JumbledNumber testNumJum = new JumbledNumber();

            testNumJum.JNumberValue = testCurrNumJum;
            testNumJum.CurGuess = testCurrGuess;
            testNumJum.NumDigits = testNumDigits;

            Console.WriteLine("Stored NumJum " + testNumJum.JNumberValue.ToString());
            Console.WriteLine("Stored Guess " + testNumJum.CurGuess.ToString());

            GameManager testGameManager = new GameManager();

            testGameManager.CheckGuess(testNumJum, testCurrGuess);

            Assert.AreEqual(1, testNumJum.NumCorrect);
        }
Example #17
0
        public void GMStartGameTest()
        {
            string testName = "Link";
            int testDiff = 1,
                testNumdigts = 0;

            Player testPlayer = new Player(testName);

            JumbledNumber testNumJum = new JumbledNumber();

            GameManager testGameManager = new GameManager();

            testNumdigts = testGameManager.StartGame(testNumJum, testDiff);

            Console.WriteLine("Generated Number is: " + testNumJum.JNumberValue.ToString());
            Console.WriteLine("Player Name is: " + testPlayer.PlayerName);
            Console.WriteLine("Game status is: " + testNumJum.GameInProgress.ToString());

            Assert.IsTrue((testNumdigts > 0));
            Assert.IsTrue(testNumJum.GameInProgress);
        }
        public void GetGameStatusTest()
        {
            bool test1 = false,
                test2 = true;

            JumbledNumber testJumbledNumber = new JumbledNumber();

            Factory testFactory = Factory.GetInstance();
            IJumbledNumberSvc testSVC = (IJumbledNumberSvc)
                testFactory.GetService(typeof(IJumbledNumberSvc).Name);

            // Set object to test
            testJumbledNumber.GameInProgress = true;
            test1 = testSVC.GetGameStatus(testJumbledNumber);
            Assert.IsTrue(test1);
            Assert.IsTrue(testJumbledNumber.GameInProgress);

            testJumbledNumber.GameInProgress = false;
            test2 = testSVC.GetGameStatus(testJumbledNumber);
            Assert.IsFalse(test2);
            Assert.IsFalse(testJumbledNumber.GameInProgress);
        }
        public void GenerateJumbledNumberTest()
        {
            JumbledNumber testJumbledNumber1 = new JumbledNumber();
            JumbledNumber testJumbledNumber2 = new JumbledNumber();
            JumbledNumber testJumbledNumber3 = new JumbledNumber();
            Factory testFactory = Factory.GetInstance();
            IJumbledNumberSvc testSVC = (IJumbledNumberSvc)
                testFactory.GetService(typeof(IJumbledNumberSvc).Name);

            // Create 1st Random Number
            int testdigit1 = testSVC.GetJumbledNumber(testJumbledNumber1, 0);
            Thread.Sleep(1000);
            Console.WriteLine("Jumbled Number is: " + testJumbledNumber1.JNumberValue.ToString());
            Console.WriteLine("Stored Number of Digits: " + testJumbledNumber1.NumDigits.ToString());
            Console.WriteLine("Returned Number of Digits: " + testdigit1.ToString());
            Console.WriteLine("");

            // Create 2nd Random Number
            int testdigits2 = testSVC.GetJumbledNumber(testJumbledNumber2, 1);
            Thread.Sleep(1000);
            Console.WriteLine("Jumbled Number is: " + testJumbledNumber2.JNumberValue.ToString());
            Console.WriteLine("Stored Number of Digits: " + testJumbledNumber2.NumDigits.ToString());
            Console.WriteLine("Returned Number of Digits: " + testdigits2.ToString());
            Console.WriteLine("");

            // Create 3rd Random Number
            int testdigits3 = testSVC.GetJumbledNumber(testJumbledNumber3, 2);
            Thread.Sleep(1000);
            Console.WriteLine("Jumbled Number is: " + testJumbledNumber3.JNumberValue.ToString());
            Console.WriteLine("Stored Number of Digits: " + testJumbledNumber3.NumDigits.ToString());
            Console.WriteLine("Returned Number of Digits: " + testdigits3.ToString());
            Console.WriteLine("");

            Assert.AreEqual(testJumbledNumber1.NumDigits, testdigit1);
            Assert.AreEqual(testJumbledNumber2.NumDigits, testdigits2);
            Assert.AreEqual(testJumbledNumber3.NumDigits, testdigits3);
        }
        public void JNMGenerateJumbledNumberTest()
        {
            JumbledNumber testJumbledNumber1 = new JumbledNumber();
            JumbledNumber testJumbledNumber2 = new JumbledNumber();
            JumbledNumber testJumbledNumber3 = new JumbledNumber();

            JumbledNumberManager testJumNumManager = new JumbledNumberManager();

            // Create 1st Random Number
            int catchDigits1 = testJumNumManager.CreateJumbledNumber(testJumbledNumber1, 0);
            Thread.Sleep(1000);
            Console.WriteLine("Jumbled Number is: " + testJumbledNumber1.JNumberValue.ToString());
            Console.WriteLine("Stored Number of Digits: " + testJumbledNumber1.NumDigits.ToString());
            Console.WriteLine("Returned Number of Digits: " + catchDigits1.ToString());
            Console.WriteLine("");

            // Create 2nd Random Number
            int catchDigits2 = testJumNumManager.CreateJumbledNumber(testJumbledNumber2, 1);
            Thread.Sleep(1000);
            Console.WriteLine("Jumbled Number is: " + testJumbledNumber2.JNumberValue.ToString());
            Console.WriteLine("Stored Number of Digits: " + testJumbledNumber2.NumDigits.ToString());
            Console.WriteLine("Returned Number of Digits: " + catchDigits2.ToString());
            Console.WriteLine("");

            // Create 3rd Random Number
            int catchDigits3 = testJumNumManager.CreateJumbledNumber(testJumbledNumber3, 2);
            Thread.Sleep(1000);
            Console.WriteLine("Jumbled Number is: " + testJumbledNumber3.JNumberValue.ToString());
            Console.WriteLine("Stored Number of Digits: " + testJumbledNumber3.NumDigits.ToString());
            Console.WriteLine("Returned Number of Digits: " + catchDigits3.ToString());
            Console.WriteLine("");

            Assert.AreEqual(testJumbledNumber1.NumDigits, catchDigits1);
            Assert.AreEqual(testJumbledNumber2.NumDigits, catchDigits2);
            Assert.AreEqual(testJumbledNumber3.NumDigits, catchDigits3);
        }
Example #21
0
        public void UpdateNumberCorrectTest()
        {
            int testCorrect,
                testNumDigits = 4;
            long testNumJum = 5678,
                testGuess = 1628;

            Factory testFactory = Factory.GetInstance();
            IGameSvc testSvc = (IGameSvc)
                testFactory.GetService(typeof(IGameSvc).Name);

            JumbledNumber testJumNum = new JumbledNumber(testNumDigits, testNumJum);

            // Add guess to object
            testSvc.AddGuess(testJumNum, testGuess);

            // Use Factory to get number of correct digits
            testCorrect = testSvc.CompareGuessandNumJum(testJumNum);

            // Test
            Assert.AreEqual(2, testCorrect);
        }
Example #22
0
 public bool GetGameStatus(JumbledNumber NumJum)
 {
     return NumJum.GameInProgress;
 }
Example #23
0
        public int GetJumbledNumber(JumbledNumber NumJumObj, int difficulty)
        {
            Random random = new Random();
            int numDigits = 0,
                curDigitCount = 0,
                placeHolder = 1;
            long buildNumber = 0,
                jumbledNumber = 0;

            // Generte a unique random number, with size determined by difficulty
            // Must build number in pieces based on length

            // Use switch to determine actual number of digits

            switch (difficulty)
            {
                case 0:
                    numDigits = random.Next(3,5);
                    break;
                case 1:
                    numDigits = random.Next(4,7);
                    break;
                case 2:
                    numDigits = random.Next(6,9);
                    break;
            }

            // Use for loops and if statements to generate unique number

            bool testDigit = true;
            ArrayList holdDigits = new ArrayList();

            for (int i = 0; i < numDigits; i++)
            {
                // Build number digit by digit
                // Make sure each digit is unique
                do
                {
                    buildNumber = random.Next(0,9);
                    testDigit = true;

                    // If first run through, add initial entry to holdDigit
                    if (curDigitCount == 0)
                        holdDigits.Add(buildNumber);

                    for (int j = 0; j < curDigitCount; j++)
                    {
                        if (buildNumber == (long)holdDigits[j])
                        {
                            testDigit = false;
                        }
                        else
                        {
                            if (testDigit == true)
                            {
                                testDigit = true;
                            }
                            else
                                testDigit = false;
                        }
                    }

                } while (testDigit == false);

                // Store unique digit
                if (curDigitCount > 0)
                    holdDigits.Add(buildNumber);

                // Increment digit counter
                curDigitCount++;

                // If digit is not 0 update Jumbled Number
                // Skipping over 0 allows for internal digits to have the
                // value of 0
                if (buildNumber != 0)
                    jumbledNumber = (buildNumber * placeHolder) + jumbledNumber;

                // Increment place holder
                placeHolder *= 10;
            }

            // Handle case of first digit being 0
            // Valid numbers cannot start with 0, compensate
            // by decreasing the appropriate counts
            if ((numDigits == curDigitCount) && (buildNumber == 0))
            {
                numDigits--;
                curDigitCount--;
            }

            // Store values in class
            NumJumObj.JNumberValue = jumbledNumber;
            NumJumObj.NumDigits = numDigits;

            // Return number of digits stored......
            return curDigitCount;
        }
Example #24
0
        public void GMStopGameTest()
        {
            JumbledNumber testNumJum = new JumbledNumber();

            GameManager testGameManager = new GameManager();

            testGameManager.StopGame(testNumJum);

            Assert.IsFalse(testNumJum.GameInProgress);
        }
Example #25
0
 // Change value of game status property
 public void ChangeGameStatus(JumbledNumber NumJumObj, bool status)
 {
     NumJumObj.GameInProgress = status;
 }
Example #26
0
 // Update Number of Correct digits
 public void UpdateNumberCorrect(JumbledNumber NumJumObj, int numCorrect)
 {
     // Update number of correct digits
     NumJumObj.NumCorrect = numCorrect;
 }