Ejemplo n.º 1
0
        protected void loadAndSetHighscore(int id)
        {
            HighScoreRepository hRep = new HighScoreRepository();
            Highscore           h    = hRep.getHighscoreById(id);

            setView(h);
        }
        protected Highscore getHighscore(int id)
        {
            HighScoreRepository hRep = new HighScoreRepository();
            Highscore           h    = hRep.getHighscoreById(id);

            return(h);
        }
        public void ReturnEmptyListIfFileNotExists()
        {
            var repository = new HighScoreRepository("c:\\test\\nothing.csv", new Clock());
            var players    = repository.GetBestPlayers();

            players.Should().BeEmpty();
        }
        public void RetrieveBestPlayerOrderedByLevelAndDate()
        {
            var clock = new FakeClock(new DateTime(2019, 11, 18, 13, 0, 0));

            using var tempFile = TestTempFile.New;
            var repository = new HighScoreRepository(tempFile.FilePath, clock);

            repository.AddBesPlayer("Name1", 1);
            clock.IncrementDay();
            repository.AddBesPlayer("Name2", 1);
            clock.IncrementDay();
            repository.AddBesPlayer("Name3", 2);
            clock.IncrementDay();
            repository.AddBesPlayer("Name4", 2);

            var players = repository.GetBestPlayers();

            players.Should().NotBeEmpty();

            players.Should().BeEquivalentTo(new List <Player>()
            {
                new Player(1, "Name3", 2, _clock.Now),
                new Player(2, "Name4", 2, _clock.Now),
                new Player(3, "Name1", 1, _clock.Now),
                new Player(4, "Name2", 1, _clock.Now),
            }, a => a.WithStrictOrdering().Excluding(b => b.Date));
        }
        private void FillListBox()
        {
            HighScoreRepository highScore = new HighScoreRepository();
            List <Highscore>    ls        = highScore.GetAll().ToList();

            foreach (var item in ls)
            {
                string s = "Name: " + item.Name.ToString() + " Score: " + item.Score.ToString();
                this.lista.Items.Add(s);
            }
        }
        public void TellYouIfYourInHightScore(int count, int level, bool expected)
        {
            using var tempFile = TestTempFile.New;
            var repository = new HighScoreRepository(tempFile.FilePath, _clock);

            for (int i = 0; i < count; i++)
            {
                repository.AddBesPlayer("Player", 10);
            }

            repository.IsHighScore(level).Should().Be(expected);
        }
Ejemplo n.º 7
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            HighScoreRepository hRep = new HighScoreRepository();
            string strId             = Request.QueryString["hId"];

            if (!string.IsNullOrEmpty(strId)) // existiert schon
            {
                hId = Convert.ToInt32(strId);
            }
            hRep.Delete(hId.Value);

            Response.Redirect("~/HighscoreList.aspx");
        }
        public void StoreAPlayer()
        {
            using var tempFile = TestTempFile.New;
            var repository = new HighScoreRepository(tempFile.FilePath, _clock);

            repository.AddBesPlayer("Aurelien", 1);

            File.Exists(tempFile.FilePath).Should().BeTrue();
            var lines = File.ReadAllLines(tempFile.FilePath);

            lines.Should().HaveCount(1);
            lines.First().Should().Be("\"Aurelien\";1;\"15/11/2019 13:00:00\"");
        }
        protected void btnOk_Click(object sender, EventArgs e)
        {
            if (validateName() == null)
            {
                Highscore h = getHighscore(getHid());
                h.Name = txtBoxHName.Text;
                HighScoreRepository hRep = new HighScoreRepository();
                hRep.Save(h);
                Response.Redirect("~/PlayerHighScoreList.aspx?hId=" + getHid());
            }

            txtBoxError.Visible = true;
            txtBoxError.Text    = validateName();
        }
        protected void SetHighScore()
        {
            Highscore score = new Highscore();

            score.GameDuration     = (DateTime.Now - ((DateTime)Session["StartTime"])).Seconds;
            score.MomentOfGame     = (DateTime)Session["StartTime"];
            score.Points           = GetPoints();
            score.WeightedPoints   = -1;
            score.PlayedCategories = getCids().Select(x => new PlayedCategories()
            {
                CategoryId = x
            }).ToList();

            HighScoreRepository hRep = new HighScoreRepository();

            hRep.Save(score);
            Session["HighscoreId"] = score.Id;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HighScoreRepository hRep   = new HighScoreRepository();
            List <Highscore>    list   = hRep.GetAllHighscores();
            CategoryRepository  catRep = new CategoryRepository();
            int ranking = 1;
            List <VmHighScoreGvItem> vmList = new List <VmHighScoreGvItem>();

            foreach (var h in list)
            {
                List <int> catIds = h.PlayedCategories.Select(x => x.CategoryId).ToList();
                vmList.Add(ToGvItem(h, catRep.GetCategoriesByIds(catIds), ranking));
                ranking++;
            }

            gvHighscore.DataSource = vmList;
            gvHighscore.DataBind();
        }
        private void GameOver()
        {
            if (this.model.Player.Life == 0)
            {
                this.dispatcherTimer.Stop();
                this.enemyMover.Stop();
                this.enemybulletMove.Stop();

                // MessageBox.Show("Game Over!\n\nHighscore: " + this.model.Score, "GameOver", MessageBoxButton.OK, MessageBoxImage.Hand);
                NameAsk nameAsk = new NameAsk();
                nameAsk.ShowDialog();
                HighScoreRepository highScore = new HighScoreRepository();
                this.saveLogic = new SaveLogic(highScore, this.model);
                this.saveLogic.HighscoreInstance(PlayerName);
                Window win = Window.GetWindow(this);
                win.Close();
                MainMenuWindow mainMenuWindow = new MainMenuWindow();
                mainMenuWindow.Show();
            }
        }
        public void RetrieveBestPlayerOrderedByLevel()
        {
            using var tempFile = TestTempFile.New;
            var repository = new HighScoreRepository(tempFile.FilePath, _clock);

            repository.AddBesPlayer("Name1", 1);
            repository.AddBesPlayer("Name2", 2);
            repository.AddBesPlayer("Name3", 3);
            repository.AddBesPlayer("Name4", 4);

            var players = repository.GetBestPlayers();

            players.Should().NotBeEmpty();

            players.Should().BeEquivalentTo(new List <Player>()
            {
                new Player(1, "Name4", 4, _clock.Now),
                new Player(2, "Name3", 3, _clock.Now),
                new Player(3, "Name2", 2, _clock.Now),
                new Player(4, "Name1", 1, _clock.Now),
            }, a => a.WithStrictOrdering());
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SaveLogic"/> class.
 /// </summary>
 /// <param name="highScore">init highscore.</param>
 /// <param name="model">init model.</param>
 public SaveLogic(HighScoreRepository highScore, IGameModel model)
 {
     this.highScore = highScore;
     this.model     = model;
 }