Ejemplo n.º 1
0
        public void UpdateScore_When_addOrRemove_IsNull_unitOfWork_ScoreCards_GetSingleScoreCardAndIncludePlayerCardAndHoleCardBy_And_unitOfWork_Holes_GetCourseHole_Calls_Once()
        {
            //Arange
            var expectedScoreCardID = Guid.NewGuid();
            var expectedholeID      = Guid.NewGuid();

            var username    = "******";
            var holeNumber  = "5";
            var scoreCardID = expectedScoreCardID.ToString();
            var scoreCard   = new ScoreCard
            {
                CourseID    = Guid.NewGuid(),
                ScoreCardID = Guid.Parse(scoreCardID)
            };

            var hole = new Hole
            {
                HoleID = expectedholeID
            };

            _unitOfworkMock.Setup(x => x.ScoreCards.GetSingleScoreCardAndIncludePlayerCardAndHoleCardBy(x => x.ScoreCardID == Guid.Parse(scoreCardID))).Returns(scoreCard);
            _unitOfworkMock.Setup(x => x.Holes.GetCourseHole(scoreCard.CourseID, Convert.ToInt32(holeNumber))).Returns(hole);

            //Act
            var result = _sut.UpdateScore(scoreCardID, holeNumber, null, username);

            //Assert
            _unitOfworkMock.Verify(x => x.ScoreCards.GetSingleScoreCardAndIncludePlayerCardAndHoleCardBy(x => x.ScoreCardID == Guid.Parse(scoreCardID)), Times.Once());
            _unitOfworkMock.Verify(x => x.Holes.GetCourseHole(scoreCard.CourseID, Convert.ToInt32(holeNumber)), Times.Once());
        }
Ejemplo n.º 2
0
        private OperationResult UpdatingScoreCard(string scoreCardEncrypt)
        {
            var messageBuilder   = new StringBuilder();
            var scoreCardDecrypt = _rsaEncryption.DecryptData(scoreCardEncrypt);

            _scoreCard = JsonConvert.DeserializeObject <ScoreCard>(scoreCardDecrypt);
            var extractors = GetExtractors();

            foreach (var feature in _scoreCard.Features)
            {
                var ifExistsExtractor = extractors.Any(extractor => string.Equals(feature.ExtractorId, extractor.Identifier));
                if (ifExistsExtractor)
                {
                    messageBuilder.AppendLine($"Not found extractor for score card feature - {feature.ExtractorId}");
                }
            }
            _initializeProcessScoreCard.Set();
            var messages = messageBuilder.ToString();

            if (string.IsNullOrEmpty(messages))
            {
                //todo: do need refresh keys?
                _rsaEncryption.RefreshKeys();
                return(new OperationResult(OperationStatus.SuccessInitializedScoreCard));
            }
            _scoreCard = null;
            return(new OperationResult(OperationStatus.FailedInitializeScoreCard, messages));
        }
Ejemplo n.º 3
0
        public void OpenScoreCard_Assert_ExpectedScoreCardID_And_ExpectedHoleID_Are_Equal_Result_Values()
        {
            //Arange
            var expectedScoreCardID = Guid.NewGuid();
            var expectedholeID      = Guid.NewGuid();

            var scoreCardID = expectedScoreCardID.ToString();
            var scoreCard   = new ScoreCard
            {
                CourseID    = Guid.NewGuid(),
                ScoreCardID = Guid.Parse(scoreCardID)
            };

            var hole = new Hole
            {
                HoleID = expectedholeID
            };

            _unitOfworkMock.Setup(x => x.ScoreCards.GetSingleScoreCardAndIncludePlayerCardAndHoleCardBy(x => x.ScoreCardID == Guid.Parse(scoreCardID))).Returns(scoreCard);
            _unitOfworkMock.Setup(x => x.Holes.GetCourseHole(scoreCard.CourseID, 1)).Returns(hole);


            //Act
            var result = _sut.OpenScoreCard(scoreCardID);

            //Assert
            Assert.Equal(expectedScoreCardID, result.ScoreCard.ScoreCardID);
            Assert.Equal(expectedholeID, result.Hole.HoleID);
        }
 //TODO: need to generalize more
 private static string PopulateTopLevelDetails(ScoreCard scoreCard, string templateContent)
 {
     templateContent = templateContent.Replace("@@year", DateTime.Now.Year.ToString());
     templateContent = templateContent.Replace("@@score-class", scoreCard.ResultColor.ToString().ToLower());
     templateContent = templateContent.Replace("@@score", scoreCard.Aggregate.ToString());
     return(templateContent);
 }
Ejemplo n.º 5
0
        public CalculateResult Calculate(string data, ScoreCard scoreCard, IEnumerable <IExtractor> extractors)
        {
            try
            {
                int totalScore = 0;
                Parallel.ForEach(scoreCard.Features, () => 0, (featureDto, state, resultScore) =>
                {
                    var extractor  = extractors.First(ext => ext.Identifier == featureDto.ExtractorId);
                    var totalPoint = extractor.Extract(data).Result;
                    foreach (var attribute in featureDto.Attributes)
                    {
                        if (attribute.Contains(totalPoint, extractor.IsDiscrete))
                        {
                            resultScore += (int)attribute.Score;
                        }
                    }
                    return(resultScore);
                }, (resultScore) =>
                {
                    Interlocked.Add(ref totalScore, resultScore);
                });

                return(new CalculateResult()
                {
                    Score = totalScore,
                    ScoreCardId = scoreCard.Id
                });
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 6
0
    public void refreshData(string playerName, float score, ref List <ScoreCardData> scoreCardData)
    {
        string resultText = string.Format("Player {0} won with score {1}", playerName, score.ToString("0.00"));

        resultMessageText.text = resultText;

        // Destroying previous child to panel if any exists.
        while (highscorePanel.childCount > 0)
        {
            highscorePanel.GetChild(0).SetParent(null);
            Destroy(highscorePanel.GetChild(0).gameObject);
        }

        for (int idx = 0; idx < scoreCardData.Count; idx++)
        {
            ScoreCardData scoreCard = scoreCardData[idx];
            GameObject    go        = Instantiate(scoreCardPrefab);
            ScoreCard     sc        = go.GetComponent <ScoreCard>();
            if (scoreCard.rank == -1)// If rank is -1 ,Means the score is current game score so highlight it
            {
                sc.setAsCurrentScore();
            }
            scoreCard.rank = idx + 1;
            sc.setScoreCard(scoreCard);
            go.transform.SetParent(highscorePanel);
            scoreCardData[idx] = scoreCard;
        }
    }
Ejemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync()
        {
            var pitchId = Int32.Parse(Request.Form["PitchId"].ToString());
            var judgeId = User.FindFirstValue(ClaimTypes.NameIdentifier).ToString();

            ScoreCardFields = await _context.ScoreCardField.Where(x => x.ScoringCategoryId == 1).ToListAsync();

            foreach (var field in ScoreCardFields)
            {
                ScoreCard = new ScoreCard
                {
                    PitchId          = pitchId,
                    Pitch            = _context.Pitch.Where(x => x.PitchId == pitchId).FirstOrDefault(),
                    JudgeId          = judgeId,
                    Judge            = _context.ApplicationUsers.Where(x => x.Id == judgeId).FirstOrDefault(),
                    ScoreCardFieldId = _context.ScoreCardField.Where(x => x.ScoreCardFieldDescription == field.ScoreCardFieldDescription).FirstOrDefault().ScoreCardFieldId,
                    ScoreCardField   = _context.ScoreCardField.Where(x => x.ScoreCardFieldDescription == field.ScoreCardFieldDescription).FirstOrDefault(),
                    Comment          = Request.Form[field.ScoreCardFieldDescription + "Comment"],
                    Score            = Int32.Parse(Request.Form[field.ScoreCardFieldDescription + "Score"].ToString()),
                    UpdatedBy        = judgeId,
                    UpdatedDate      = DateTime.Now,
                    IsArchived       = false
                };
                await _util.SendEmailAsync(log, "MF Pitch SC post", "PSC");

                _context.ScoreCard.Add(ScoreCard);
            }
            _context.SaveChanges();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 8
0
        public void PlayFrames_LastRoundStrike_2_Test()
        {
            int score = 0;

            BowlingFrame[] frames = GenerateFrames(
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(5, 3));

            score = BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + 5 +
                    BowlingGameExtenstions.NUM_OF_PINS + 5 + 3;

            Trace.WriteLine($"score is {score}");

            ScoreCard scoreCard = new ScoreCard(frames);

            Assert.AreEqual(score, Game.GetScore(scoreCard));
            Assert.IsTrue(Game.IsValid(scoreCard));
        }
Ejemplo n.º 9
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         ScoreCard.Next();
     }
 }
Ejemplo n.º 10
0
        public void SetComment(ScoreCard scoreCard, int scoreCriterionId, string comment, ScoreCriterionService scoreCriterionService)
        {
            if (scoreCard == null)
            {
                return;
            }

            if (scoreCard.ScorableCriteria == null || !scoreCard.ScorableCriteria.Any())
            {
                return;
            }

            var scorableCriterion = scoreCard.ScorableCriteria.FirstOrDefault(s => s.ScoreCriterion.Id == scoreCriterionId);

            if (scorableCriterion == null)
            {
                scorableCriterion = new ScorableCriterion(0, scoreCriterionService.Get(scoreCriterionId));
                scorableCriterion.SetComment(comment);
                scoreCard.ScorableCriteria.Add(scorableCriterion);
                Update(scoreCard);
            }
            else
            {
                scorableCriterion.SetComment(comment);
                AddOrUpdate(scorableCriterion);
            }
        }
        public void TestLowerFullHouse()
        {
            DiceSet   set       = new DiceSet(new Random());
            ScoreCard scoreCard = new ScoreCard();


            {
                set[0].Number = 1;
                set[1].Number = 1;
                set[2].Number = 1;
                set[3].Number = 2;
                set[4].Number = 2;


                Assert.IsTrue(scoreCard.SLOT_FULL_HOUSE.Qualifier(set), "Failed to qualifiy");
                int expected = 25;
                int actual   = scoreCard.SLOT_FULL_HOUSE.ScorePotential(set);
                Assert.AreEqual(expected, actual, "Gave wrong score for exact");
            }

            {
                set[0].Number = 1;
                set[1].Number = 1;
                set[2].Number = 3;
                set[3].Number = 2;
                set[4].Number = 2;


                Assert.IsFalse(scoreCard.SLOT_FULL_HOUSE.Qualifier(set), "Failed to qualifiy");
            }
        }
        public void TestLowerYahtzee()
        {
            DiceSet   set       = new DiceSet(new Random());
            ScoreCard scoreCard = new ScoreCard();


            {
                set[0].Number = 1;
                set[1].Number = 1;
                set[2].Number = 1;
                set[3].Number = 1;
                set[4].Number = 1;


                Assert.IsTrue(scoreCard.SLOT_YAHTZEE.Qualifier(set), "Failed to qualifiy exactly 5");
                int expected = 50;
                int actual   = scoreCard.SLOT_YAHTZEE.ScorePotential(set);
                Assert.AreEqual(expected, actual, "Gave wrong score for exact 5");
            }

            {
                set[0].Number = 1;
                set[1].Number = 1;
                set[2].Number = 1;
                set[3].Number = 3;
                set[4].Number = 3;


                Assert.IsFalse(scoreCard.SLOT_YAHTZEE.Qualifier(set), "Is qualifiy on exactly 3");
            }
        }
Ejemplo n.º 13
0
        public void PlayFrames_SpareAfterSpare_Test()
        {
            int score          = 0;
            int tryDroppedPins = 4;

            BowlingFrame[] frames = GenerateFrames(
                new Tuple <int, int>(0, 5),
                new Tuple <int, int>(tryDroppedPins, BowlingGameExtenstions.NUM_OF_PINS - tryDroppedPins),
                new Tuple <int, int>(0, BowlingGameExtenstions.NUM_OF_PINS),
                new Tuple <int, int>(5, 4),
                new Tuple <int, int>(4, 5));

            score = 5 +
                    BowlingGameExtenstions.NUM_OF_PINS + 0 +
                    BowlingGameExtenstions.NUM_OF_PINS + 5 +
                    5 + 4 +
                    4 + 5;

            Trace.WriteLine($"score is {score}");

            ScoreCard scoreCard = new ScoreCard(frames);

            Assert.AreEqual(score, Game.GetScore(scoreCard));
            Assert.IsTrue(Game.IsValid(scoreCard));
        }
Ejemplo n.º 14
0
        public ScoreCard GetScore(int testId, int studentId)
        {
            // calculating score and max marks
            var responses = _responseRepo.GetResponsesByStudentIdAndTestId(testId, studentId);
            var testQues  = _testQuesRepo.GetByTestId(testId);
            var questions = new List <Question>();
            int maxMarks  = 0;

            foreach (var item in testQues)
            {
                var ques = _questionRepo.GetById(item.QuestionId);
                maxMarks = maxMarks + ques.Marks;
            }

            int marks = 0;

            foreach (var item in responses)
            {
                var ques = _questionRepo.GetById(item.QuestionId);
                if (ques.Answer == item.Answer)
                {
                    marks = marks + ques.Marks;
                }
            }
            //calculating percentage
            var per       = (double)marks / (double)maxMarks * 100;
            var scoreCard = new ScoreCard()
            {
                MarksScored = marks,
                MaxMarks    = maxMarks,
                Percentage  = per
            };

            return(scoreCard);
        }
Ejemplo n.º 15
0
        public void It_Should_ThrowScoreCategoryAlreadyTakenException_When_PlacedOnYatzy_And_YatztyAlreadyHasAScore()
        {
            //Arrange
            var mockDice = new Mock <IDie>();

            mockDice.Setup(x => x.Value).Returns(1);
            var fiveMockDice = new List <IDie>
            {
                mockDice.Object,
                mockDice.Object,
                mockDice.Object,
                mockDice.Object,
                mockDice.Object,
            };

            var turn = new Turn(fiveMockDice);
            //turn.RollDice();
            var scoreCard = new ScoreCard();

            scoreCard.UpdateScoreCard(ScoreCategory.Yatzy, turn.Dice);

            //Act
            Action actual = () => scoreCard.UpdateScoreCard(ScoreCategory.Yatzy, turn.Dice);

            //Assert
            var exception = Assert.Throws <ScoreCategoryAlreadyTakenException>(actual);

            Assert.Equal("This score category is already take: Yatzy", exception.Message);
        }
Ejemplo n.º 16
0
 public void Perfect_Game_Should_Have_10_Frames()
 {
     var scoreCard = new ScoreCard();
     for (int i = 0; i < 12; i++)
         scoreCard.AddRoll(10);
     Assert.That(scoreCard.Count, Is.EqualTo(10));
 }
Ejemplo n.º 17
0
        public void PlayGame_InvalidLastFrame_2_Test()
        {
            ScoreCard scoreCard  = Game.GenerteEmptyScoreCards();
            ScoreCard scoreCard2 = Game.RollNewFrame(scoreCard, 3, 5);

            ScoreCard scoreCard3 = Game.RollNewFrame(scoreCard2, 2, 4);

            ScoreCard scoreCard4 = Game.RollNewFrame(scoreCard3, 2, 4);

            ScoreCard scoreCard5 = Game.RollNewFrame(scoreCard4, 2, 4);

            ScoreCard scoreCard6 = Game.RollNewFrame(scoreCard5, 2, 4);

            ScoreCard scoreCard7 = Game.RollNewFrame(scoreCard6, 2, 4);

            ScoreCard scoreCard8 = Game.RollNewFrame(scoreCard7, 2, 4);

            ScoreCard scoreCard9 = Game.RollNewFrame(scoreCard8, 2, 4);

            ScoreCard scoreCard10 = Game.RollNewFrame(scoreCard9, 2, 4);

            ScoreCard scoreCard11 = Game.RollNewFrame(scoreCard10, 0, BowlingGameExtenstions.NUM_OF_PINS); // Spare

            ScoreCard scoreCard12 = Game.RollNewFrame(scoreCard11, 2, 4);                                  // This frame is invalid
        }
Ejemplo n.º 18
0
        public void PlayGame_ValidLastFrame_2_Test()
        {
            ScoreCard scoreCard  = Game.GenerteEmptyScoreCards();
            ScoreCard scoreCard2 = Game.RollNewFrame(scoreCard, 3, 5);

            ScoreCard scoreCard3 = Game.RollNewFrame(scoreCard2, 2, 4);

            ScoreCard scoreCard4 = Game.RollNewFrame(scoreCard3, 2, 4);

            ScoreCard scoreCard5 = Game.RollNewFrame(scoreCard4, 2, 4);

            ScoreCard scoreCard6 = Game.RollNewFrame(scoreCard5, 2, 4);

            ScoreCard scoreCard7 = Game.RollNewFrame(scoreCard6, 2, 4);

            ScoreCard scoreCard8 = Game.RollNewFrame(scoreCard7, 2, 4);

            ScoreCard scoreCard9 = Game.RollNewFrame(scoreCard8, 2, 4);

            ScoreCard scoreCard10 = Game.RollNewFrame(scoreCard9, 2, 4);

            ScoreCard scoreCard11 = Game.RollNewFrame(scoreCard10, 0, BowlingGameExtenstions.NUM_OF_PINS); // Spare

            ScoreCard scoreCard12 = Game.RollNewFrame(scoreCard11, 2, 0);                                  // This frame is valid

            int score = 8 + 8 * 6 + BowlingGameExtenstions.NUM_OF_PINS + 2;

            Trace.WriteLine($"score is {score}");
            Assert.AreEqual(score, Game.GetScore(scoreCard12));
            Assert.IsTrue(Game.IsValid(scoreCard));
        }
Ejemplo n.º 19
0
        public void PlayGameExceedFrames_1_Test()
        {
            ScoreCard scoreCard  = Game.GenerteEmptyScoreCards();
            ScoreCard scoreCard2 = Game.RollNewFrame(scoreCard, 3, 5);

            ScoreCard scoreCard3 = Game.RollNewFrame(scoreCard2, 2, 4);

            ScoreCard scoreCard4 = Game.RollNewFrame(scoreCard3, 2, 4);

            ScoreCard scoreCard5 = Game.RollNewFrame(scoreCard4, 2, 4);

            ScoreCard scoreCard6 = Game.RollNewFrame(scoreCard5, 2, 4);

            ScoreCard scoreCard7 = Game.RollNewFrame(scoreCard6, 2, 4);

            ScoreCard scoreCard8 = Game.RollNewFrame(scoreCard7, 2, 4);

            ScoreCard scoreCard9 = Game.RollNewFrame(scoreCard8, 2, 4);

            ScoreCard scoreCard10 = Game.RollNewFrame(scoreCard9, 2, 4);

            ScoreCard scoreCard11 = Game.RollNewFrame(scoreCard10, 2, 4);

            ScoreCard scoreCard12 = Game.RollNewFrame(scoreCard11, 2, 4);

            ScoreCard scoreCard13 = Game.RollNewFrame(scoreCard12, 2, 4);
        }
Ejemplo n.º 20
0
        public void PlayGame_InvalidLastFrame_1_Test()
        {
            ScoreCard scoreCard  = Game.GenerteEmptyScoreCards();
            ScoreCard scoreCard2 = Game.RollNewFrame(scoreCard, 3, 5);

            ScoreCard scoreCard3 = Game.RollNewFrame(scoreCard2, 2, 4);

            ScoreCard scoreCard4 = Game.RollNewFrame(scoreCard3, 2, 4);

            ScoreCard scoreCard5 = Game.RollNewFrame(scoreCard4, 2, 4);

            ScoreCard scoreCard6 = Game.RollNewFrame(scoreCard5, 2, 4);

            ScoreCard scoreCard7 = Game.RollNewFrame(scoreCard6, 2, 4);

            ScoreCard scoreCard8 = Game.RollNewFrame(scoreCard7, 2, 4);

            ScoreCard scoreCard9 = Game.RollNewFrame(scoreCard8, 2, 4);

            ScoreCard scoreCard10 = Game.RollNewFrame(scoreCard9, 2, 4);

            ScoreCard scoreCard11 = Game.RollNewFrame(scoreCard10, 2, 8); // Spare

            ScoreCard scoreCard12 = Game.RollNewFrame(scoreCard11, 2, 4); // This frame is invalid
        }
Ejemplo n.º 21
0
        public void PlayGame_1_Test()
        {
            ScoreCard scoreCard = Game.GenerteEmptyScoreCards();

            ScoreCard scoreCard2 = Game.RollNewFrame(scoreCard, 3, 5);

            Assert.AreEqual(8, Game.GetScore(scoreCard2));

            ScoreCard scoreCard3 = Game.RollNewFrame(scoreCard2, 2, 4);

            Assert.AreEqual(14, Game.GetScore(scoreCard3));

            ScoreCard scoreCard4 = Game.RollNewFrame(scoreCard3, 2, 4);

            Assert.AreEqual(20, Game.GetScore(scoreCard4));

            // Play spare. The score stays the same
            ScoreCard scoreCard5 = Game.RollNewFrame(scoreCard4, 6, 4);

            Assert.AreEqual(20, Game.GetScore(scoreCard4));
            // The score of the Spare is unknown yet
            Assert.IsNull(Game.GetFrameScore(scoreCard5, 3));

            // Play simple frame, the score updates
            ScoreCard scoreCard6 = Game.RollNewFrame(scoreCard5, 4, 4);

            // Check the score of the Spare
            Assert.AreEqual(14, Game.GetFrameScore(scoreCard6, 3));
            Assert.AreEqual(42, Game.GetScore(scoreCard6));

            Assert.IsTrue(Game.IsEligibleForAnotherTry(scoreCard5));
            Assert.IsTrue(Game.IsValid(scoreCard));
        }
Ejemplo n.º 22
0
        public void ComputerPlaysRound()
        {
            ResetRollsLeft();

            while (RollsLeft > 0)
            {
                RollDice();

                Cat chosenCat = m_playStrategy.Use(this, RollsLeft);

                if (chosenCat != Cat.NoCategory)
                {
                    if (chosenCat == Cat.YahtzeeBonus)
                    {
                        Cat chosenBonusCat = m_playStrategy.UseYahtzeeBonus(this);
                        ScoreCard.UpdateYahtzeeBonus(Dice, chosenBonusCat);

                        RollsLeft = 0;
                        UnholdAllDice();
                    }
                    else if (ScoreCard.Update(Dice, chosenCat))
                    {
                        RollsLeft = 0;
                        UnholdAllDice();
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public void Construct()
        {
            var scoreCard = new ScoreCard(1, 2, 3, new List <Hole>
            {
                new Hole(1, 4),
                new Hole(2, 5),
                new Hole(3, 2)
            }, DateTime.Now);

            scoreCard.Should()
            .BeOfType <ScoreCard>();

            scoreCard.UserId
            .Should()
            .Be(1);

            scoreCard.CourseId
            .Should()
            .Be(2);

            scoreCard.LoopId
            .Should()
            .Be(3);

            scoreCard.Holes
            .Should()
            .NotBeNullOrEmpty()
            .And
            .HaveCount(3);
        }
Ejemplo n.º 24
0
 // Use this for initialization
 void Start()
 {
     scoreCard = FindObjectOfType <ScoreCard>();
     if (scoreCard != null)
     {
         legalSequences.text = scoreCard.GetSuccessfulLightSequenceRatio() + "(-" + scoreCard.GetUnsuccessfulLightSequences() * 41 + "pts)";
         correctStops.text   = scoreCard.GetSuccessfulStopRatio() + "(-" + scoreCard.GetUnsuccessfulStops() * 41 + "pts)";
         if (scoreCard.GetTrackFinished())
         {
             completedCircuit.text = "yes";
         }
         else
         {
             completedCircuit.text = "no (instant failure)";
         }
         timeInCorrectLane.text    = scoreCard.GetTimeInCorrectLane().ToString() + " seconds";
         timeInIncorrectLane.text  = scoreCard.GetTimeInWrongLane().ToString() + " seconds (-" + scoreCard.GetTimeInWrongLane() + "pts)";
         timeRatio.text            = (scoreCard.GetTimeInCorrectLane() / (scoreCard.GetTimeInWrongLane() + scoreCard.GetTimeInCorrectLane())).ToString();
         totalScorePercentage.text = scoreCard.GetScore().ToString() + "%";
         timeSpeeding.text         = scoreCard.GetTimeAboveSpeed().ToString() + " seconds (-" + scoreCard.GetTimeAboveSpeed() + "pts)";
     }
     else
     {
         Debug.Log("could not find score card");
     }
 }
Ejemplo n.º 25
0
        public void Simulate_FullGame_1_Test()
        {
            ScoreCard scoreCard = Game.GenerteEmptyScoreCards();

            // run as long as the game runs
            while (Game.IsEligibleForAnotherTry(scoreCard))
            {
                Tuple <int, int> tries = GenerateFrame(scoreCard);

                scoreCard = Game.RollNewFrame(scoreCard, tries.Item1, tries.Item2);
            }

            Trace.WriteLine($"score is {Game.GetScore(scoreCard)}");

            if (scoreCard.Length < BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS)
            {
                throw new IllegalBowlingActionException("invalid number of rounds");
            }

            bool isGameHasExtraRound = ((scoreCard.Length == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS + BowlingGameExtenstions.EXTRA_ROUNDS));

            if (isGameHasExtraRound &&
                (scoreCard.GetFrameType(BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1) == FrameTypeEnum.Normal ||
                 scoreCard.GetFrameType(BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1) == FrameTypeEnum.Empty))
            {
                throw new IllegalBowlingActionException("Had an extra round but the last round was not Strike or Spare");
            }

            if (!isGameHasExtraRound)
            {
                Assert.IsTrue(scoreCard.Length == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS);
            }
        }
        public async Task <bool> Set(ScoreCard entity)
        {
            var result = await _elasticClient
                         .IndexDocumentAsync(entity);

            return(result.IsValid);
        }
Ejemplo n.º 27
0
        public void PlayFrames_ThreeConsecutiveStrikes_2_Test()
        {
            int score = 0;

            BowlingFrame[] frames = GenerateFrames(
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(BowlingGameExtenstions.NUM_OF_PINS, 0),
                new Tuple <int, int>(5, 0),
                new Tuple <int, int>(5, 0));

            score = BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS +
                    BowlingGameExtenstions.NUM_OF_PINS + BowlingGameExtenstions.NUM_OF_PINS + 5 +
                    BowlingGameExtenstions.NUM_OF_PINS + 5 + 0 +
                    5 +
                    5;

            Trace.WriteLine($"score is {score}");

            ScoreCard scoreCard = new ScoreCard(frames);

            Assert.AreEqual(score, Game.GetScore(scoreCard));

            Assert.AreEqual(30, Game.GetFrameScore(scoreCard, 0));
            Assert.AreEqual(25, Game.GetFrameScore(scoreCard, 1));
        }
Ejemplo n.º 28
0
        public void It_Should__ReturnTotalScore_When_PlacedOn_Yatzy_Then_Chance()
        {
            //Arrange
            var mockDice = new Mock <IDie>();

            mockDice.Setup(x => x.Value).Returns(1);
            var fiveMockDice = new List <IDie>
            {
                mockDice.Object,
                mockDice.Object,
                mockDice.Object,
                mockDice.Object,
                mockDice.Object,
            };

            var turn = new Turn(fiveMockDice);
            //turn.RollDice();
            var scoreCard = new ScoreCard();

            scoreCard.UpdateScoreCard(ScoreCategory.Yatzy, turn.Dice);

            //Act
            scoreCard.UpdateScoreCard(ScoreCategory.Chance, turn.Dice);

            //Assert
            Assert.Equal(55, scoreCard.Total);
        }
Ejemplo n.º 29
0
        static public ScoreCard copySc(LQModelLight.ScoreCard s)
        {
            ScoreCard sc = new ScoreCard();

            sc.dt         = s.dt;
            sc.equipe     = s.equipe;
            sc.packid     = s.pack;
            sc.pseudo     = s.pseudo.ToUpper();
            sc.rank       = s.rank;
            sc.ratio      = s.ratio;
            sc.tirs       = s.tirs;
            sc.LigneScore = new List <LigneScore>();
            foreach (LQModelLight.LigneScore ls in s.Up)
            {
                LigneScore l = new LigneScore(ls.equipe, ls.pseudo.ToUpper(), typeLigneScore.UP, ls.front, ls.back, ls.gun, ls.shoulder, sc);
                if (!sc.LigneScore.Contains(l))
                {
                    sc.LigneScore.Add(l);
                }
            }
            foreach (LQModelLight.LigneScore ls in s.Down)
            {
                LigneScore l = new LigneScore(ls.equipe, ls.pseudo.ToUpper(), typeLigneScore.DOWN, ls.front, ls.back, ls.gun, ls.shoulder, sc);
                if (!sc.LigneScore.Contains(l))
                {
                    sc.LigneScore.Add(l);
                }
            }
            return(sc);
        }
Ejemplo n.º 30
0
    public static ScoreCard ReadPacket(byte[] data)
    {
        ScoreCard    sc     = new ScoreCard();
        MemoryStream stream = new MemoryStream(data);

        using (StreamReader sr = new StreamReader(stream)) {
            int ver = sr.ReadInt32();
            switch (ver)
            {
            case 1:
                sc.name   = sr.ReadString();
                sc.scores = new int[sr.ReadInt32()];
                for (int i = 0; i < sc.scores.Length; i++)
                {
                    sc.scores[i] = sr.ReadInt32();
                }
                sc.played = new bool[sr.ReadInt32()];
                for (int i = 0; i < sc.scores.Length; i++)
                {
                    sc.played [i] = sr.ReadBool();
                }
                sc.BonusScore = sr.ReadInt32();
                sc.Local      = sr.ReadBool();
                break;

            default:
                throw new Exception("Unrecognized network protocol");
            }
        }
        return(sc);
    }
Ejemplo n.º 31
0
 public void Serie_1_1_Should_Have_1_Frames()
 {
     var scoreCard = new ScoreCard();
     scoreCard.AddRoll(1);
     scoreCard.AddRoll(1);
     Assert.That(scoreCard.Count, Is.EqualTo(1));
 }
Ejemplo n.º 32
0
        public ActionResult UpdateDaily(Log log, DateTime date, User loguser)
        {
            var scores       = db.ScoreCards;
            var TotalScore   = 0;
            var AverageScore = 0;
            var count        = 0;


            foreach (ScoreCard s in scores.Where(x => x.ScoretDate <= log.LogtDate))
            {
                count        = count + 1;
                TotalScore   = TotalScore + s.DayScore;
                AverageScore = TotalScore / count;
            }
            ;
            var DayScore = (11 - Convert.ToInt16(log.Bedtime)) * 5 +
                           Convert.ToInt16(log.Meditation) +
                           Convert.ToInt16(log.Read) / 2 +
                           Convert.ToInt16(log.Veggies) * 3 +
                           Convert.ToInt16(log.Exercise) * 2 -
                           Convert.ToInt16(log.Alcohol) * 10;
            ScoreCard todayscore = new ScoreCard
            {
                ScoretDate = date,
                DayScore   = DayScore,
                WeekScore  = AverageScore,
                TotalScore = TotalScore + DayScore,
            };

            Create(todayscore);
            return(View("Index"));
        }
Ejemplo n.º 33
0
 public void Serie_1_1_Should_Have_Score_2()
 {
     var game = new ScoreCard();
     game.AddRoll(1);
     game.AddRoll(1);
     Assert.That(game.Score, Is.EqualTo(2));
 }
Ejemplo n.º 34
0
 public void Perfect_Game_Should_Have_Score_300()
 {
     var scoreCard = new ScoreCard();
     for (int i = 0; i < 12; i++)
         scoreCard.AddRoll(10);
     Assert.That(scoreCard.Score, Is.EqualTo(300));
 }
Ejemplo n.º 35
0
 public void Serie_10_10_10_Should_Have_Score_0_In_Second_Frame()
 {
     var scoreCard = new ScoreCard();
     scoreCard.AddRoll(10);
     scoreCard.AddRoll(10);
     scoreCard.AddRoll(10);
     Assert.That(scoreCard[1].Sum, Is.EqualTo(0));
 }
Ejemplo n.º 36
0
 public void Serie_10_10_10_Should_Have_30_In_First_Frame()
 {
     var scoreCard = new ScoreCard();
     scoreCard.AddRoll(10);
     scoreCard.AddRoll(10);
     scoreCard.AddRoll(10);
     Assert.That(scoreCard[0].Sum, Is.EqualTo(30));
 }
Ejemplo n.º 37
0
 public void TestInitialize()
 {
     _mockCategoryProvider = new Mock<ICategoryProvider>();
     _scoreCard = new ScoreCard(_mockCategoryProvider.Object);
 }
Ejemplo n.º 38
0
 public void Serie_1_9_4_5_Should_Have_Score_23()
 {
     var scoreCard = new ScoreCard();
     scoreCard.AddRoll(1);
     scoreCard.AddRoll(9);
     scoreCard.AddRoll(4);
     scoreCard.AddRoll(5);
     Assert.That(scoreCard.Score, Is.EqualTo(23));
 }
Ejemplo n.º 39
0
 private void AssertCannotAddRoll(ScoreCard scoreCard)
 {
     try
     {
         scoreCard.AddRoll(0);
         Assert.Fail();
     }
     catch (InvalidOperationException)
     {}
 }
Ejemplo n.º 40
0
        public void Should_Not_Be_Able_To_AddRoll_After_Worst_Game_Possible()
        {
            var scoreCard = new ScoreCard();
            for (int i = 0; i < 20; i++)
                scoreCard.AddRoll(0);

            AssertCannotAddRoll(scoreCard);
        }
Ejemplo n.º 41
0
        public void Should_Not_Be_Able_To_AddRoll_After_Perfect_Game()
        {
            var scoreCard = new ScoreCard();
            for (int i = 0; i < 12; i++)
                scoreCard.AddRoll(10);

            AssertCannotAddRoll(scoreCard);
        }
Ejemplo n.º 42
0
 public void Serie_1_Should_Have_Score_0()
 {
     var scoreCard = new ScoreCard();
     scoreCard.AddRoll(1);
     Assert.That(scoreCard.Score, Is.EqualTo(0));
 }