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 int Score;
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);
}
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);
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) {
// 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;
return Task.CompletedTask;
}

View File

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

View File

@ -46,7 +46,7 @@ public class PongRoom {
_ = Task.Run(PlayersChanged);
}
private BackgroundWorker gameWorker = new() {
private readonly BackgroundWorker gameWorker = new() {
WorkerSupportsCancellation = true
};
@ -87,11 +87,11 @@ public class PongRoom {
public void MovePaddle(PongPlayer player, PongPaddleDirection direction) {
if (Player1 == player) {
State.Paddle1.Direction = direction;
Logger.LogInformation(DIRECTION_LOG_TEMPLATE, ID, 1, player, direction);
Logger.LogDebug(DIRECTION_LOG_TEMPLATE, ID, 1, player, direction);
return;
} else if (Player2 == player) {
State.Paddle2.Direction = direction;
Logger.LogInformation(DIRECTION_LOG_TEMPLATE, ID, 2, player, direction);
Logger.LogDebug(DIRECTION_LOG_TEMPLATE, ID, 2, player, direction);
return;
}
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;
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;
public class PrivacyModel : PageModel {

View File

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