Added some box and pellet logic
This commit is contained in:
parent
485014d28d
commit
1fd30f1a16
@ -58,7 +58,7 @@ const Board: Component<BoardProps> = (
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedCharacter && selectedDice) {
|
||||
const possiblePositions = findPossiblePositions(map, selectedCharacter.position, selectedDice.value);
|
||||
const possiblePositions = findPossiblePositions(map, selectedCharacter, selectedDice.value);
|
||||
setPossiblePositions(possiblePositions);
|
||||
} else {
|
||||
setPossiblePositions([]);
|
||||
|
@ -1,31 +1,38 @@
|
||||
type CharacterColor = "red" | "blue" | "yellow" | "green" | "purple";
|
||||
type Direction = "up" | "right" | "down" | "left";
|
||||
|
||||
export abstract class Character {
|
||||
public color: CharacterColor;
|
||||
public position: Position;
|
||||
public direction: Direction = "up";
|
||||
public isEatable: boolean = false;
|
||||
|
||||
public constructor(color: CharacterColor, startPosition: Position = {x: 0, y: 0}) {
|
||||
protected constructor(color: CharacterColor, startPosition: Position = {x: 0, y: 0}) {
|
||||
this.color = color;
|
||||
this.position = startPosition;
|
||||
}
|
||||
|
||||
public abstract moveTo(position: Position): void;
|
||||
|
||||
public moveTo(position: Position): void {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public isAt(position: Position): boolean {
|
||||
return this.position.x === position.x && this.position.y === position.y;
|
||||
}
|
||||
}
|
||||
|
||||
export class PacMan extends Character {
|
||||
moveTo(position: Position): void {
|
||||
this.position = position;
|
||||
|
||||
constructor(color: CharacterColor, startPosition: Position = {x: 0, y: 0}) {
|
||||
super(color, startPosition);
|
||||
this.isEatable = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class Ghost extends Character {
|
||||
moveTo(position: Position): void {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
constructor(color: CharacterColor, startPosition: Position = {x: 0, y: 0}) {
|
||||
super(color, startPosition);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
import {TileType} from "./tileType";
|
||||
import {Character} from "./character";
|
||||
|
||||
/**
|
||||
* Finds all the possible positions for the character to move to
|
||||
* @param board The board the character is on
|
||||
* @param currentPos The current position of the character
|
||||
* @param character The current position of the character
|
||||
* @param steps The number of steps the character can move
|
||||
*/
|
||||
export default function findPossiblePositions(board: number[][], currentPos: Position, steps: number): Position[] {
|
||||
export default function findPossiblePositions(board: number[][], character: Character, steps: number): Position[] {
|
||||
const possiblePositions: Position[] = [];
|
||||
findPossibleRecursive(board, currentPos, steps, possiblePositions, []);
|
||||
findPossibleRecursive(board, character.position, steps, possiblePositions, []);
|
||||
return possiblePositions;
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,15 @@ namespace pacMan.Controllers;
|
||||
public class GameController : GenericController
|
||||
{
|
||||
private readonly IDiceCup _diceCup;
|
||||
private readonly IPlayer _player;
|
||||
|
||||
public GameController(ILogger<GameController> logger, IWebSocketService wsService) : base(logger, wsService)
|
||||
{
|
||||
_diceCup = new DiceCup();
|
||||
_player = new Player
|
||||
{
|
||||
Box = new Box()
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -43,6 +48,11 @@ public class GameController : GenericController
|
||||
|
||||
message.Data = rolls;
|
||||
break;
|
||||
case GameAction.AppendBox:
|
||||
// TODO
|
||||
// Add pellets to box
|
||||
// Forward box to all clients
|
||||
break;
|
||||
default:
|
||||
Logger.Log(LogLevel.Information, "Forwarding message to all clients");
|
||||
break;
|
||||
|
@ -6,6 +6,7 @@ public enum GameAction
|
||||
{
|
||||
RollDice,
|
||||
MoveCharacter,
|
||||
AppendBox
|
||||
}
|
||||
|
||||
public class ActionMessage<T>
|
||||
|
@ -1,6 +1,8 @@
|
||||
namespace pacMan.Game.Interfaces;
|
||||
|
||||
public interface IBox : IEnumerable<IOrb>
|
||||
public interface IBox : IEnumerable<IPellet>
|
||||
{
|
||||
void Add(IOrb orb);
|
||||
void Add(IPellet pellet);
|
||||
|
||||
int CountNormal { get; }
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace pacMan.Game.Interfaces;
|
||||
|
||||
public interface IOrb
|
||||
{
|
||||
void Use();
|
||||
}
|
12
pac-man-board-game/Game/Interfaces/IPellet.cs
Normal file
12
pac-man-board-game/Game/Interfaces/IPellet.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace pacMan.Game.Interfaces;
|
||||
|
||||
public enum PelletType
|
||||
{
|
||||
Normal,
|
||||
PowerPellet
|
||||
}
|
||||
|
||||
public interface IPellet
|
||||
{
|
||||
PelletType Get { get; set; }
|
||||
}
|
6
pac-man-board-game/Game/Interfaces/IPlayer.cs
Normal file
6
pac-man-board-game/Game/Interfaces/IPlayer.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace pacMan.Game.Interfaces;
|
||||
|
||||
public interface IPlayer
|
||||
{
|
||||
IBox Box { get; init; }
|
||||
}
|
17
pac-man-board-game/Game/Items/Box.cs
Normal file
17
pac-man-board-game/Game/Items/Box.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using pacMan.Game.Interfaces;
|
||||
|
||||
namespace pacMan.Game.Items;
|
||||
|
||||
public class Box : IBox
|
||||
{
|
||||
private readonly IList<IPellet> _pellets = new List<IPellet>();
|
||||
|
||||
public int CountNormal => _pellets.Count(pellet => pellet.Get == PelletType.Normal);
|
||||
|
||||
public void Add(IPellet pellet) => _pellets.Add(pellet);
|
||||
|
||||
public IEnumerator<IPellet> GetEnumerator() => _pellets.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
8
pac-man-board-game/Game/Items/Pellet.cs
Normal file
8
pac-man-board-game/Game/Items/Pellet.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using pacMan.Game.Interfaces;
|
||||
|
||||
namespace pacMan.Game.Items;
|
||||
|
||||
public class Pellet : IPellet
|
||||
{
|
||||
public PelletType Get { get; set; }
|
||||
}
|
8
pac-man-board-game/Game/Items/Player.cs
Normal file
8
pac-man-board-game/Game/Items/Player.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using pacMan.Game.Interfaces;
|
||||
|
||||
namespace pacMan.Game.Items;
|
||||
|
||||
public class Player : IPlayer
|
||||
{
|
||||
public required IBox Box { get; init; }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user