initial commit

This commit is contained in:
2025-08-14 08:35:04 +02:00
commit 6d40bfcf4c
96 changed files with 85096 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
@{
ViewData["Title"] = "Access Denied";
}
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h2 class="text-center text-danger">🚫 Access Denied</h2>
</div>
<div class="card-body text-center">
<p class="lead">You do not have permission to access this resource.</p>
<p>Please contact an administrator if you believe this is an error.</p>
<div class="mt-4">
<a asp-controller="Home" asp-action="Index" class="btn btn-primary">Go to Home</a>
<a asp-controller="Account" asp-action="Login" class="btn btn-secondary">Login</a>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,50 @@
@model YatzyGame.Models.LoginViewModel
@{
ViewData["Title"] = "Log in";
}
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h2 class="text-center">🎲 Login to Yatzy</h2>
</div>
<div class="card-body">
<form asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group mb-3">
<label asp-for="Username" class="form-label"></label>
<input asp-for="Username" class="form-control" placeholder="Enter your username" />
<span asp-validation-for="Username" class="text-danger"></span>
</div>
<div class="form-group mb-3">
<label asp-for="Password" class="form-label"></label>
<input asp-for="Password" class="form-control" placeholder="Enter your password" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<div class="form-check mb-3">
<input asp-for="RememberMe" class="form-check-input" />
<label asp-for="RememberMe" class="form-check-label"></label>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Log in</button>
</div>
</form>
<hr />
<div class="text-center">
<p>Don't have an account? <a asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]">Register here</a></p>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

View File

@@ -0,0 +1,51 @@
@model YatzyGame.Models.RegisterViewModel
@{
ViewData["Title"] = "Register";
}
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h2 class="text-center">🎲 Join Yatzy</h2>
</div>
<div class="card-body">
<form asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group mb-3">
<label asp-for="Username" class="form-label"></label>
<input asp-for="Username" class="form-control" placeholder="Choose a username" />
<span asp-validation-for="Username" class="text-danger"></span>
</div>
<div class="form-group mb-3">
<label asp-for="Password" class="form-label"></label>
<input asp-for="Password" class="form-control" placeholder="Choose a password" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<div class="form-group mb-3">
<label asp-for="ConfirmPassword" class="form-label"></label>
<input asp-for="ConfirmPassword" class="form-control" placeholder="Confirm your password" />
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-success">Register</button>
</div>
</form>
<hr />
<div class="text-center">
<p>Already have an account? <a asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]">Login here</a></p>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

View File

@@ -0,0 +1,277 @@
@model YatzyGame.Controllers.HomeViewModel;
@using YatzyGame.Components;
@{
ViewData["Title"] = "Home Page";
}
<script>
window.gamekey = "@Model.gameID"
const ws = new WebSocket("ws://" + document.location.host + "/ws");
ws.addEventListener("message", (event) => {
const dat = event.data.split("|");
if (dat[0] == window.gamekey && dat[1] == "update") {
ws.close();
document.location.reload();
}
if (dat[0] == window.gamekey && dat[1] == "stop") {
ws.close();
document.location.location = document.location.hostname;
}
});
</script>
<div class="flexbox">
<div style="flex: 1;">
<div class="scoreboard">
@if(Model.GameStarted) {
<div></div>
foreach(var enu in Enum.GetValues(typeof(ScoreLine))){
@if (Model.GameStarted && !enu.ToString().Equals("bonus") && !Model.CurrentPlayer.scores.ContainsKey((ScoreLine)enu) && (Model.CurrentPlayer.name.Equals(Model.player.name) || !Model.onlineMultiplayer))
{
<div class="empty-insert-dice">
<a href="@Url.Action("InsertDice", "Home", new { game = Model.gameID, id = enu })" class="">==></a>
</div>
}
else {
<div class="empty-insert-dice"></div>
}
}
<div></div>
}
<div></div>
@foreach (var enu in Enum.GetValues(typeof(ScoreLine)))
{
<div>
@GameController.TypeLabel((ScoreLine)enu)
</div>
}
<div>Sum</div>
@foreach (var player in Model.players)
{
if(!Model.GameStarted)
{
<a class="deleteuser" href="@Url.Action("DeletePlayer", "Home", new { game = Model.gameID, id = player.name })"><b>@player.name</b></a>
}
else
{
<div><b>@player.name</b></div>
}
@foreach (var test in Enum.GetValues(typeof(ScoreLine)))
{
if (player.scores.TryGetValue((ScoreLine)Enum.Parse(typeof(ScoreLine), test.ToString(), true), out var score))
{
<div>@score</div>
}
else
{
<div></div>
}
}
<div>@player.scores.Where(x => x.Key != ScoreLine.top_sum).Select(x => x.Value).Sum()</div>
}
</div>
</div>
<div class="GameArea">
@if (Model.GameStarted)
{
@if(!Model.onlineMultiplayer || !Model.CurrentPlayer.name.Equals(Model.player.name)) {
<p><span><b>Current player:</b> </span><span>@Model.CurrentPlayer.name</span></p>
}
else
{
<p class="text-success text-bold"><b>Your turn!</b></p>
}
<div class="dice-table">
@foreach (var dice in Model.Dices)
{
@if(!Model.onlineMultiplayer || Model.CurrentPlayer.name.Equals(Model.player.name)) {
<form action="@Url.Action("SelectDice", "Home", new { game = Model.gameID, id = dice.Key })" method="post">
@* <input type="hidden" name="id" value="@dice.Key" /> *@
<button type="submit">
@if (Model.selectedDices.Contains(dice.Key))
{
<div class="dice selected">
@dice.Value
</div>
}
else
{
<div class="dice">
@dice.Value
</div>
}
</button>
</form>
}
else {
<button type="submit">
@if (Model.selectedDices.Contains(dice.Key))
{
<div class="dice selected">
@dice.Value
</div>
}
else
{
<div class="dice">
@dice.Value
</div>
}
</button>
}
}
</div>
@if(!Model.onlineMultiplayer || Model.CurrentPlayer.name.Equals(Model.player.name))
{
@if(!Model.RerollsBlocked)
{
<form action="@Url.Action("RerollSelected", "Home", new {game = Model.gameID})" method="post">
<input type="submit" class="btn btn-primary mt-4 text-center" value="Reroll" />
</form>
}
else
{
<input type="button" value=Reroll class="btn btn-primary disabled mt-4 text-center" />
}
}
<div style="flex:1;"></div>
@if(Model.player.Owner) {
<form method="post" action="@Url.Action("StopGame", "Home", new { game = Model.gameID })">
<input type="submit" class="btn btn-danger mt-4 text-center" value="Stop Game" />
</form>
}
}
else
{
@if (!Model.onlineMultiplayer) {
<h3>Add player</h3>
<form method="post" action="@Url.Action("AddPlayer", "Home", new { game = Model.gameID })" class="p-4">
<label>Name</label>
<input name="Name" class="form-control" type="text" required />
<input type="submit" class="btn btn-primary mt-4 text-center" value="Create" />
</form>
}
else {
<h3>Online multiplayer</h3>
<p>Join code: <span>@Model.joinCode</span></p>
<p>Joined as: <span>@Model.player.name</span></p>
}
<div style="flex:1;"></div>
@if(Model.player.Owner) {
@if(Model.players.Count <= 0)
{
<input type="button" class="btn btn-success disabled" value="Start Game" />
}
else
{
<form action="@Url.Action("StartGame", "Home", new { game = Model.gameID })" method="post">
<input type="submit" class="btn btn-success mt-4 text-center" value="Start Game">
</form>
}
}
else if (Model.onlineMultiplayer) {
<form action="@Url.Action("LeaveGame", "Home", new {game = Model.gameID, name = Model.player.name})" method="post">
<input type="submit" class="btn btn-danger mt-4 text-center" value="Leave Game" />
</form>
}
}
</div>
</div>
<!-- Rules Button -->
<div style="position: fixed; bottom: 20px; right: 20px;">
<button type="button" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#rulesModal">
📋 Rules
</button>
</div>
<!-- Rules Modal -->
<div class="modal fade" id="rulesModal" tabindex="-1" aria-labelledby="rulesModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="rulesModalLabel">🎲 Yatzy Rules</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h5>🎯 Objective</h5>
<p>Score the most points by rolling five dice to make certain combinations.</p>
<h5>🚀 How to Setup the Game</h5>
<ol>
<li><strong>Add Players:</strong> Enter player names one by one using the "Add player" form</li>
<li><strong>Remove Players:</strong> Click on a player's name (before starting) to remove them</li>
<li><strong>Start Game:</strong> Click "Start Game" when you have at least one player added</li>
<li><strong>Game Begins:</strong> The first player will automatically be selected to start</li>
</ol>
<div class="alert alert-success">
<strong>🎮 Ready to Play:</strong> You can add 1-6 players for the best experience!
</div>
<h5>🎮 How to Play</h5>
<ol>
<li>Each player takes turns rolling 5 dice</li>
<li>After each roll, you can select which dice to keep and which to reroll</li>
<li>You get up to 3 rolls per turn (initial roll + 2 rerolls)</li>
<li>After your final roll, you must choose a scoring category</li>
<li>Each category can only be used once per game</li>
</ol>
<h5>📊 Scoring Categories</h5>
<div class="row">
<div class="col-md-6">
<h6><strong>Upper Section:</strong></h6>
<ul class="list-unstyled">
<li><strong>Ones:</strong> Sum of all 1s</li>
<li><strong>Twos:</strong> Sum of all 2s</li>
<li><strong>Threes:</strong> Sum of all 3s</li>
<li><strong>Fours:</strong> Sum of all 4s</li>
<li><strong>Fives:</strong> Sum of all 5s</li>
<li><strong>Sixes:</strong> Sum of all 6s</li>
<li><em><strong>Bonus:</strong> 50 points if upper section totals 63+</em></li>
</ul>
</div>
<div class="col-md-6">
<h6><strong>Lower Section:</strong></h6>
<ul class="list-unstyled">
<li><strong>One Pair:</strong> Sum of highest pair</li>
<li><strong>Two Pair:</strong> Sum of both pairs</li>
<li><strong>Three of a Kind:</strong> Sum of three matching dice</li>
<li><strong>Four of a Kind:</strong> Sum of four matching dice</li>
<li><strong>Small Straight:</strong> 30 points (4 consecutive)</li>
<li><strong>Large Straight:</strong> 40 points (5 consecutive)</li>
<li><strong>Full House:</strong> Sum of all dice (3+2 of a kind)</li>
<li><strong>Chance:</strong> Sum of all dice (any combination)</li>
<li><strong>Yatzy:</strong> 50 points (all 5 dice the same)</li>
</ul>
</div>
</div>
<h5>💡 Strategy Tips</h5>
<ul>
<li><strong>Upper Section Bonus:</strong> Focus early - it's worth 50 points!</li>
<li><strong>Chance Category:</strong> Use as backup when other categories don't work</li>
<li><strong>Yatzy Attempts:</strong> Save for when you have 3+ of the same number</li>
<li><strong>Bad Rolls:</strong> Consider which categories to sacrifice strategically</li>
</ul>
<div class="alert alert-info">
<strong>💭 Pro Tip:</strong> You need an average of 10.5 points per upper section category to get the bonus!
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,23 @@
<div class="flexbox">
<div class="GameArea">
<h3>Online Multiplayer</h3>
<form action="@Url.Action("CreateGame", "Home", new {type = 0})" style="display: flex; flex-direction: column;">
<input type="text" name="name" class="form-control mt-4" placeholder="Name of first player" />
<input type="submit" class="btn btn-primary mt-4 text-center" value="Create Game" />
</form>
</div>
<div class="GameArea">
<h3>Local Multiplayer</h3>
<form action="@Url.Action("CreateGame", "Home", new {type = 1})" style="display: flex; flex-direction: column;">
<input type="text" name="name" class="form-control mt-4" placeholder="Name of first player" />
<input type="submit" class="btn btn-primary mt-4 text-center" value="Create Game" />
</form>
</div>
<div class="GameArea">
<h3>Join Game</h3>
<form action="@Url.Action("JoinGame", "Home", new {type = 1})" style="display: flex; flex-direction: column;">
<input type="text" name="joinCode" class="form-control mt-4" placeholder="Code" />
<input type="submit" class="btn btn-primary mt-4 text-center" value="Join Game" />
</form>
</div>
</div>

View File

@@ -0,0 +1,9 @@
@model string;
<div class="flexbox">
<form method="post" action="@Url.Action("JoinGame", "Home", new { gameid = Model})" class="GameArea" style="margin: auto;">
<h3>Join Game</h3>
<input type="text" class="form-control mt-4" name="name" placeholder="Enter name" />
<input type="submit" value="Join Game" class="btn btn-primary mt-4 text-center" />
</form>
</div>

View File

@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

View File

@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - YatzyGame</title>
<script type="importmap"></script>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/YatzyGame.styles.css" asp-append-version="true" />
</head>
<body>
@* <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">YatzyGame</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header> *@
<div class="game-frame">
<!-- Authentication Status -->
<div style="position: fixed; top: 10px; right: 10px; z-index: 1000; background: rgba(255,255,255,0.9); padding: 10px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
@if (User.Identity.IsAuthenticated)
{
<span class="text-success">👤 @User.Identity.Name</span>
<form asp-controller="Account" asp-action="Logout" method="post" style="display: inline;">
<button type="submit" class="btn btn-sm btn-outline-danger ms-2">Logout</button>
</form>
}
else
{
<a asp-controller="Account" asp-action="Login" class="btn btn-sm btn-primary">Login</a>
<a asp-controller="Account" asp-action="Register" class="btn btn-sm btn-success ms-1">Register</a>
}
</div>
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
@* <footer class="border-top footer text-muted">
<div class="container">
&copy; 2025 - YatzyGame - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer> *@
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>

View File

@@ -0,0 +1,48 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */
a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}
a {
color: #0077cc;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}
button.accept-policy {
font-size: 1rem;
line-height: inherit;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}

View File

@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js"></script>

View File

@@ -0,0 +1,3 @@
@using YatzyGame
@using YatzyGame.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}