Example #1
0
        /// <summary>
        ///     Update de highscore lijst door middel van het highscore bestand
        /// </summary>
        public void Show()
        {
            //Verkrijg de highscore data.
            HighscoreContext highscoreContext = GameFiles.LoadHighscore();

            if (highscoreContext != null)
            {
                //Sorteer met wins
                List <HighscoreListItem> sortedList =
                    highscoreContext.HighscoreItems.OrderByDescending(x => x.wins).ToList();

                for (int i = 0; i < sortedList.Count; i++)
                {
                    HighscoreListItem item = sortedList[i];

                    //Maak een nieuwe list view item.
                    ListViewItem lvItem = new ListViewItem(new[] {
                        item.name, item.wins.ToString(), item.score.ToString()
                    });

                    //En voeg de listview item toe aan de highscore listview.
                    highscoreList.Items.Add(lvItem);
                }
            }
        }
 public async Task Initialize(HighscoreContext context)
 {
     context.Players.Add(new Player()
     {
         Name = "Caan Dalek"
     });
     await context.SaveChangesAsync();
 }
 public ActionResult <Highscore> Index(Highscore highscore)
 {
     using (var db = new HighscoreContext()) {
         db.Highscores.Add(highscore);
         db.SaveChanges();
     }
     return(highscore);
 }
 public ActionResult <List <Highscore> > Index()
 {
     using (var db = new HighscoreContext()) {
         return(db.Highscores
                .OrderByDescending(highscore => highscore.Score).ThenBy(highscore => highscore.AcquriedAt)
                .Take(10).ToList());
     }
 }
Example #5
0
 public HighscoreListTests()
 {
     options = new DbContextOptionsBuilder <HighscoreContext>()
               .UseSqlServer("Server=localhost;Database=HighscoreEntries;Trusted_Connection=True")
               .Options;
     hc      = new HighscoreContext(options);
     this.da = new DataAccess(this.hc);
 }
Example #6
0
        public UnitTest1()
        {
            var options = new DbContextOptionsBuilder <HighscoreContext>().UseCosmos("https://cosmosdbstadler.documents.azure.com:443",
                                                                                     "2p0GxSmhfq07FtMrjS5pyWDJi5ZMfMqb0B413XdpKU2QgYplUqY1oDs3LOBvHtGaknsSIt4jIhvlXLQejSqXvg==", "HighscoreExercise").Options;

            dataContext = new HighscoreContext(options);
            controller  = new HighscoresController(dataContext, Mock.Of <IConfiguration>());
        }
Example #7
0
        private HighscoreEntriesController createController(string dbName)
        {
            DbContextOptions <HighscoreContext> options = new DbContextOptionsBuilder <HighscoreContext>()
                                                          .UseInMemoryDatabase(databaseName: dbName)
                                                          .Options;
            HighscoreContext context = new HighscoreContext(options);

            return(new HighscoreEntriesController(context));
        }
        /// <summary>
        ///     Update de highscore lijst
        /// </summary>
        /// <param name="playerList"> De spelerslijst object </param>
        /// <param name="winners"> Array met de winnaars </param>
        public void UpdateHighscoreList(PlayerList playerList, Player[] winners)
        {
            //Vraag de highscore lijst op van de schijf.
            HighscoreContext highscoreList = GameFiles.LoadHighscore();

            // Als er abosluut niks in de highscore lijst staat, maak nieuwe aan.
            if (highscoreList == null)
            {
                highscoreList = new HighscoreContext();
            }

            //Ga over alle spelers heen in de speler lijst.
            for (int i = 0; i < playerList.GetPlayerCount(); i++)
            {
                //Verkrijg speler object.
                Player player = playerList.GetPlayerById(i);

                //Kijk of die gene een winaar is.
                bool isWinner = false;

                for (int w = 0; w < winners.Length; w++)
                {
                    if (winners[w].id == player.id)
                    {
                        isWinner = true;
                        break;
                    }
                }

                //Voeg HighScoreListItem toe als die niet bestaat:
                if (!highscoreList.ContainsPlayer(player))
                {
                    highscoreList.HighscoreItems.Add(new HighscoreListItem(player.name, 0, 0));
                }


                //Update alle waarden in de highscore lijst.
                for (int n = 0; n < highscoreList.HighscoreItems.Count; n++)
                {
                    HighscoreListItem item = highscoreList.HighscoreItems[n];
                    item.Update(player, isWinner);

                    highscoreList.HighscoreItems[n] = item;
                }
            }

            //Schrijf opnieuw naar schijf.
            GameFiles.CreateHighScoreList(highscoreList);
        }
 public HighscoreEntriesController(HighscoreContext context)
 {
     _context = context;
 }
 public HighscoreItemsController(HighscoreContext context)
 {
     _context = context;
 }
Example #11
0
 public HighscoresController(HighscoreContext context, IConfiguration configuration)
 {
     _configuration = configuration;
     _context       = context;
 }