Code cleanup

This commit is contained in:
Michael Chen 2022-11-04 13:04:32 +01:00
parent 2fb395a8d4
commit 391b5569a4
Signed by: cnml
GPG Key ID: 5845BF3F82D5F629
7 changed files with 9 additions and 14 deletions

View File

@ -123,9 +123,8 @@ public struct PongGameState {
public PongPaddleDirection Direction; public PongPaddleDirection Direction;
public int Score; public int Score;
public static void Update(ref PongPaddleState state) { public static void Update(ref PongPaddleState state)
state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH); => state.Height = Math.Clamp(state.Height + ((int)state.Direction) * PADDLE_SPEED, PADDLE_HALF_LENGTH, HEIGHT - PADDLE_HALF_LENGTH);
}
public RectangleF GetCollider(float x) => new(x - PADDLE_WIDTH / 2, Height - PADDLE_HALF_LENGTH, PADDLE_WIDTH, PADDLE_LENGTH); public RectangleF GetCollider(float x) => new(x - PADDLE_WIDTH / 2, Height - PADDLE_HALF_LENGTH, PADDLE_WIDTH, PADDLE_LENGTH);

View File

@ -64,7 +64,7 @@ public class PongHub : Hub<IPongClient> {
public Task RequestUsernameChange(string username) { public Task RequestUsernameChange(string username) {
// TOOD: check this // TOOD: check this
Logger.LogInformation($"Player {Player} requested username change to [{username}]"); Logger.LogInformation("Player {Player} requested username change to [{username}]", Player, username);
Player.Username = username; Player.Username = username;
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -1,5 +1,4 @@
using System.Collections.Concurrent; using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR;
namespace PongGame.Hubs; namespace PongGame.Hubs;

View File

@ -46,7 +46,7 @@ public class PongRoom {
_ = Task.Run(PlayersChanged); _ = Task.Run(PlayersChanged);
} }
private BackgroundWorker gameWorker = new() { private readonly BackgroundWorker gameWorker = new() {
WorkerSupportsCancellation = true WorkerSupportsCancellation = true
}; };
@ -87,11 +87,11 @@ public class PongRoom {
public void MovePaddle(PongPlayer player, PongPaddleDirection direction) { public void MovePaddle(PongPlayer player, PongPaddleDirection direction) {
if (Player1 == player) { if (Player1 == player) {
State.Paddle1.Direction = direction; State.Paddle1.Direction = direction;
Logger.LogInformation(DIRECTION_LOG_TEMPLATE, ID, 1, player, direction); Logger.LogDebug(DIRECTION_LOG_TEMPLATE, ID, 1, player, direction);
return; return;
} else if (Player2 == player) { } else if (Player2 == player) {
State.Paddle2.Direction = direction; State.Paddle2.Direction = direction;
Logger.LogInformation(DIRECTION_LOG_TEMPLATE, ID, 2, player, direction); Logger.LogDebug(DIRECTION_LOG_TEMPLATE, ID, 2, player, direction);
return; return;
} }
throw new InvalidOperationException("Player is not in this room, but moved! Assumably players room wasn't deleted."); throw new InvalidOperationException("Player is not in this room, but moved! Assumably players room wasn't deleted.");

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace PongGame.Pages; namespace PongGame.Pages;
public class PongModel : PageModel { public class PongModel : PageModel {

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace PongGame.Pages; namespace PongGame.Pages;
public class PrivacyModel : PageModel { public class PrivacyModel : PageModel {

View File

@ -1,4 +1,3 @@
using MessagePack;
using PongGame.Hubs; using PongGame.Hubs;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);