From 13ad0ff4f3bce05e513768d4999a3f4ec471b872 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 May 2017 16:03:32 -0400 Subject: [PATCH] Pong highscore frontend. --- Project-Unite/Controllers/StatsController.cs | 44 ++++++++++++++++++++ Project-Unite/Models/IdentityModels.cs | 4 ++ Project-Unite/Models/PongHighscore.cs | 21 ++++++++++ Project-Unite/Project-Unite.csproj | 3 ++ Project-Unite/Views/Stats/Pong.cshtml | 42 +++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 Project-Unite/Controllers/StatsController.cs create mode 100644 Project-Unite/Models/PongHighscore.cs create mode 100644 Project-Unite/Views/Stats/Pong.cshtml 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 @@ public async Task GenerateUserIdentityAsync(UserManager 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