Ejemplo n.º 1
0
        public static long CalculateScore(Game game)
        {
            try
            {
                double factor = game.TimeLimit + 1.0;

                double timeLeft = double.Parse(game.TimeLeft, CultureInfo.InvariantCulture);

                double timeElapsed = double.Parse("" + game.TimeLimit, CultureInfo.InvariantCulture) - timeLeft;

                double maxInterval = game.MaxInterval;
                double baseScore = game.BaseScore;
                double noOfGuesses = game.NumberOfGuesses;

                if (!Convert.ToString(timeElapsed).StartsWith("20"))
                {
                    double firstCalc = factor - timeLeft;
                    double secondCalc = maxInterval / firstCalc;
                    double thirdCalc = baseScore * secondCalc;
                    double result = thirdCalc / noOfGuesses;
                    return Convert.ToInt64(result) * 1234;
                }
                else
                {
                    return 0;
                }
            }
            catch (ArgumentNullException)
            {
                return 0;
            }
        }
Ejemplo n.º 2
0
        public void ThenTheGameShouldStart()
        {
            Game game = new Game("jens", "hard");

            int expected = 3;
            int actual = game.DifficultyInt;

            Assert.AreEqual(expected, actual);
        }
        public void ThenTheDifficultyIntervalShouldBe_(int p0, int p1)
        {
            var difficultyInput = driver.FindElement(By.Id("difficulty"));
            var actualDifficulty = difficultyInput.GetAttribute("value");
            var expectedMinInterval = p0;
            var expectedMaxInterval = p1;

            Game game = new Game("Martin", actualDifficulty);

            Assert.AreEqual(expectedMaxInterval, game.MaxInterval);
            Assert.AreEqual(expectedMinInterval, game.MinInterval);
        }
Ejemplo n.º 4
0
        public void TestScoreCalculation()
        {
            int numberOfGuesses = 1;
            string timeLeft = "5.5";
            Game game = new Game("Emhinem", "easy");
            game.Finish(numberOfGuesses, timeLeft);
            long actual = GameLogic.CalculateScore(game);
            long expected = 2387790;
            Assert.AreEqual(expected, actual);

            numberOfGuesses = 100;
            timeLeft = "0";
            game = new Game("6-Pac", "medium");
            game.Finish(numberOfGuesses, timeLeft);
            actual = GameLogic.CalculateScore(game);
            expected = 0;
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty((string)Session["playerName"]) || String.IsNullOrEmpty((string)Session["difficulty"]))
            {
                Response.Redirect("/");
            }
            else if (!Page.IsPostBack)
            {
                string name = (string)Session["playerName"];
                string difficulty = (string)Session["difficulty"];

                Game game = new Game(name, difficulty);
                Session.Add("game", game);
                string setup = "[" + game.MinInterval + "," + game.MaxInterval + "];" + game.TimeLimit + ";" + game.Number;
                gameSetup.Value = setup;
            }
            else
            {
                string timeLeft;
                int numberOfGuesses;

                string value = gameResults.Value;
                if (value != null)
                {
                    string tempNumber = value.Substring(0, value.IndexOf(","));
                    numberOfGuesses = int.Parse(tempNumber);
                    timeLeft = value.Substring(value.IndexOf(",") + 1);

                    Game game = (Game)Session["game"];
                    game.Finish(numberOfGuesses, timeLeft);

                    Response.Redirect("/endgame.aspx");
                }
                else
                {
                    Response.Redirect("/");
                }
            }
        }