Code cleanup
This commit is contained in:
parent
2fb395a8d4
commit
391b5569a4
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Concurrent;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
|
||||||
|
|
||||||
namespace PongGame.Hubs;
|
namespace PongGame.Hubs;
|
||||||
|
|
||||||
|
@ -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.");
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using MessagePack;
|
|
||||||
using PongGame.Hubs;
|
using PongGame.Hubs;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
Loading…
Reference in New Issue
Block a user