diff --git a/Project-Unite/Controllers/StatsController.cs b/Project-Unite/Controllers/StatsController.cs new file mode 100644 index 0000000..71d2adc --- /dev/null +++ b/Project-Unite/Controllers/StatsController.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; +using Project_Unite.Models; + +namespace Project_Unite.Controllers +{ + public class StatsController : Controller + { + // GET: Stats + public ActionResult Pong(int id = 1) + { + var db = new ApplicationDbContext(); + var highscores = new List(); + foreach(var user in db.Users) + { + highscores.Add(new PongHighscore + { + UserId = user.Id, + Level = user.Pong_HighestLevel, + CodepointsCashout = user.Pong_HighestCodepointsCashout + }); + } + + int pagecount = highscores.GetPageCount(10); + if (id > pagecount || id < 1) + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + + var pages = highscores.OrderByDescending(x=>x.Level).ToArray().GetItemsOnPage(id, 10); + + var model = new PongStatsViewModel + { + Highscores = pages, + CurrentPage = id, + PageCount = 10 + }; + + return View(model); + } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index e11d675..2e1bf31 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -39,6 +39,10 @@ namespace Project_Unite.Models } + public int Pong_HighestLevel { get; set; } + public int Pong_HighestCodepointsCashout { get; set; } + + public ForumPost[] UnreadPosts { get diff --git a/Project-Unite/Models/PongHighscore.cs b/Project-Unite/Models/PongHighscore.cs new file mode 100644 index 0000000..374a3b2 --- /dev/null +++ b/Project-Unite/Models/PongHighscore.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Project_Unite.Models +{ + public class PongHighscore + { + public string UserId { get; set; } + public int CodepointsCashout { get; set; } + public int Level { get; set; } + } + + public class PongStatsViewModel + { + public int PageCount { get; set; } + public int CurrentPage { get; set; } + public List Highscores { get; set; } + } +} \ No newline at end of file diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 07bcda5..3f73890 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -263,6 +263,7 @@ + Global.asax @@ -444,6 +445,7 @@ + @@ -583,6 +585,7 @@ + diff --git a/Project-Unite/Views/Stats/Pong.cshtml b/Project-Unite/Views/Stats/Pong.cshtml new file mode 100644 index 0000000..c14ed4a --- /dev/null +++ b/Project-Unite/Views/Stats/Pong.cshtml @@ -0,0 +1,42 @@ +@model Project_Unite.Models.PongStatsViewModel +@{ + ViewBag.Title = "Pong - Highscores"; +} + +

Pong highscores

+ +

One of the apps in ShiftOS is a recreation of Pong where the game is split into levels that are 60 minutes in length.

+ +

You can earn Codepoints in Pong by either beating the AI, or surviving a level. You can cash out at the end of the level. Just be ware, if the ball gets past you, you lose all those Codepoints.

+ +

Below is a list of everyone's Pong scores - the top players at the top of the list.

+ + + + + + + +@foreach(var entry in Model.Highscores) +{ + + + + + +} +
UserLevelCodepoints
@Html.UserLink(entry.UserId)@entry.Level@entry.CodepointsCashout CP
+ +
    + @for(int i = 1; i <= Model.PageCount; i++) + { + @if (i == Model.CurrentPage) + { +
  • @Html.ActionLink(i.ToString(), "Pong", "Stats", null, new { id = i })
  • + } + else + { +
  • @Html.ActionLink(i.ToString(), "Pong", "Stats", null, new { id = i })
  • + } + } +
\ No newline at end of file