Fixed not being able to pick up pellets
This commit is contained in:
parent
e894aab4f4
commit
ee5f48b1f9
6
.idea/.idea.pac-man-board-game/.idea/compiler.xml
generated
Normal file
6
.idea/.idea.pac-man-board-game/.idea/compiler.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="TypeScriptCompiler">
|
||||
<option name="showAllErrors" value="true" />
|
||||
</component>
|
||||
</project>
|
@ -159,7 +159,7 @@ public class ActionServiceTests
|
||||
var result = _service.Ready();
|
||||
// If selected the state is changed to InGame
|
||||
_whitePlayer.State = State.InGame;
|
||||
Assert.That(result.GetType().GetProperty("Starter")?.GetValue(result), Is.EqualTo(_whitePlayer));
|
||||
Assert.That(result.GetType().GetProperty("Starter")?.GetValue(result), Is.EqualTo(_whitePlayer.Name));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -178,7 +178,7 @@ public class ActionServiceTests
|
||||
result = _service.Ready();
|
||||
|
||||
Assert.That(result.GetType().GetProperty("Starter")?.GetValue(result),
|
||||
Is.EqualTo(_whitePlayer).Or.EqualTo(_blackPlayer));
|
||||
Is.EqualTo(_whitePlayer.Name).Or.EqualTo(_blackPlayer.Name));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -27,6 +27,9 @@ const Board: Component<BoardProps> = (
|
||||
const [hoveredPosition, setHoveredPosition] = useState<Path>();
|
||||
|
||||
function handleSelectCharacter(character: Character): void {
|
||||
if (character.isPacMan() && currentPlayer?.PacMan.Colour !== character.Colour) {
|
||||
return;
|
||||
}
|
||||
setSelectedCharacter(character);
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,8 @@ import GameButton from "./gameButton";
|
||||
|
||||
const wsService = new WebSocketService(import.meta.env.VITE_API);
|
||||
|
||||
// TODO do not allow players to move other players' characters
|
||||
// TODO do not allow players to roll dice multiple times
|
||||
// TODO fix tailwind colours from getBgCssColour
|
||||
|
||||
export const GameComponent: Component<{ player: Player }> = ({player}) => {
|
||||
const players = useAtomValue(playersAtom);
|
||||
|
@ -3,7 +3,7 @@ import {CharacterType, Ghost} from "../game/character";
|
||||
import {getCharacterSpawns, testMap} from "../game/map";
|
||||
import {TileType} from "../game/tileType";
|
||||
import {getDefaultStore} from "jotai";
|
||||
import {currentPlayerAtom, diceAtom, ghostsAtom, playersAtom} from "./state";
|
||||
import {currentPlayerNameAtom, diceAtom, ghostsAtom, playersAtom} from "./state";
|
||||
import {Colour} from "../game/colour";
|
||||
|
||||
export enum GameAction {
|
||||
@ -94,7 +94,7 @@ function playerInfo(data?: PlayerProps[]): void {
|
||||
}
|
||||
|
||||
type ReadyData =
|
||||
| { AllReady: true, Starter: PlayerProps, Players: PlayerProps[] }
|
||||
| { AllReady: true, Starter: string, Players: PlayerProps[] }
|
||||
| { AllReady: false, Players: PlayerProps[] }
|
||||
| string;
|
||||
|
||||
@ -103,7 +103,7 @@ function ready(data?: ReadyData): void {
|
||||
const players = data.Players.map(p => new Player(p));
|
||||
store.set(playersAtom, players);
|
||||
if (data.AllReady) {
|
||||
store.set(currentPlayerAtom, players.find(p => p.Name === data.Starter.Name));
|
||||
store.set(currentPlayerNameAtom, data.Starter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,25 @@ import {atomWithStorage, createJSONStorage} from "jotai/utils";
|
||||
import {Ghost} from "../game/character";
|
||||
|
||||
const playerStorage = createJSONStorage<Player | undefined>(() => sessionStorage);
|
||||
|
||||
/**
|
||||
* All players in the game.
|
||||
*/
|
||||
export const playersAtom = atom<Player[]>([]);
|
||||
/**
|
||||
* All player characters (Pac-Man) in the game.
|
||||
*/
|
||||
export const playerCharactersAtom = atom(get => get(playersAtom).map(player => player.PacMan));
|
||||
/**
|
||||
* All ghosts in the game.
|
||||
*/
|
||||
export const ghostsAtom = atom<Ghost[]>([]);
|
||||
/**
|
||||
* All characters in the game.
|
||||
*/
|
||||
export const allCharactersAtom = atom(get => [...get(playerCharactersAtom), ...get(ghostsAtom)]);
|
||||
/**
|
||||
* The player that is currently using this browser.
|
||||
*/
|
||||
export const thisPlayerAtom = atomWithStorage<Player | undefined>("player", undefined, {
|
||||
...playerStorage,
|
||||
getItem(key, initialValue): Player | undefined {
|
||||
@ -16,6 +30,22 @@ export const thisPlayerAtom = atomWithStorage<Player | undefined>("player", unde
|
||||
return playerProps ? new Player(playerProps) : undefined;
|
||||
},
|
||||
});
|
||||
/**
|
||||
* All dice that have been rolled.
|
||||
*/
|
||||
export const diceAtom = atom<number[] | undefined>(undefined);
|
||||
/**
|
||||
* The dice that have been selected by the player.
|
||||
*/
|
||||
export const selectedDiceAtom = atom<SelectedDice | undefined>(undefined);
|
||||
export const currentPlayerAtom = atom<Player | undefined>(undefined);
|
||||
/**
|
||||
* The name of the player whose turn it is.
|
||||
*/
|
||||
export const currentPlayerNameAtom = atom<string | undefined>(undefined);
|
||||
/**
|
||||
* The player whose turn it is.
|
||||
*/
|
||||
export const currentPlayerAtom = atom<Player | undefined>(get => {
|
||||
const currentPlayerName = get(currentPlayerNameAtom);
|
||||
return get(playersAtom).find(player => player.Name === currentPlayerName);
|
||||
});
|
||||
|
@ -83,7 +83,7 @@ public class ActionService : IActionService
|
||||
{
|
||||
// TODO roll to start
|
||||
Group.SetAllInGame();
|
||||
data = new { AllReady = true, Players = players, Starter = Group.RandomPlayer };
|
||||
data = new { AllReady = true, Players = players, Starter = Group.RandomPlayer.Name };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user