Fixed Ghost being mistaken for Pac-Man on receive message
This commit is contained in:
parent
63c531635e
commit
209a33830d
@ -69,9 +69,9 @@ export const GameComponent: Component = () => {
|
||||
const characterIndex = characters.findIndex(c => c.colour === updatedCharacter.colour);
|
||||
|
||||
if (characters[characterIndex]) {
|
||||
if (updatedCharacter satisfies PacMan) {
|
||||
if (updatedCharacter["box"] !== undefined) { // If Pac-Man
|
||||
(characters[characterIndex] as PacMan) = new PacMan(updatedCharacter);
|
||||
} else if (updatedCharacter satisfies Ghost) {
|
||||
} else if (updatedCharacter satisfies CharacterProps) {
|
||||
(characters[characterIndex] as Ghost) = new Ghost(updatedCharacter);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
import Pellet from "./pellet";
|
||||
|
||||
export interface BoxProps {
|
||||
pellets?: Pellet[],
|
||||
readonly colour: Colour,
|
||||
}
|
||||
|
||||
export default class Box {
|
||||
public pellets: Pellet[];
|
||||
public readonly colour: Colour;
|
||||
|
@ -1,13 +1,6 @@
|
||||
import Box, {BoxProps} from "./box";
|
||||
import Box from "./box";
|
||||
import {Direction} from "./direction";
|
||||
|
||||
interface CharacterProps {
|
||||
colour: Colour,
|
||||
position?: Path,
|
||||
isEatable?: boolean,
|
||||
spawnPosition: DirectionalPosition
|
||||
}
|
||||
|
||||
export abstract class Character {
|
||||
public readonly colour: Colour;
|
||||
public position: Path;
|
||||
@ -36,10 +29,6 @@ export abstract class Character {
|
||||
}
|
||||
}
|
||||
|
||||
interface PacManProps extends CharacterProps {
|
||||
box?: BoxProps,
|
||||
}
|
||||
|
||||
export class PacMan extends Character {
|
||||
|
||||
public box: Box;
|
||||
|
@ -10,3 +10,19 @@ interface ComponentProps {
|
||||
interface ChildProps extends ComponentProps {
|
||||
children?: React.JSX.Element,
|
||||
}
|
||||
|
||||
interface CharacterProps {
|
||||
colour: Colour,
|
||||
position?: Path,
|
||||
isEatable?: boolean,
|
||||
spawnPosition: DirectionalPosition
|
||||
}
|
||||
|
||||
interface PacManProps extends CharacterProps {
|
||||
box?: BoxProps,
|
||||
}
|
||||
|
||||
interface BoxProps {
|
||||
pellets?: import("../game/pellet").default[],
|
||||
readonly colour: Colour,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user