Skip to content

Commit

Permalink
Merge branch 'main' of github.com:webdevcody/survive-the-night-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
webdevcody committed Oct 16, 2024
2 parents b8bc586 + bc9081b commit e001e00
Show file tree
Hide file tree
Showing 16 changed files with 956 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const metadata: Metadata = {
title: "Convex + Next.js + Convex Auth",
description: "Generated by npm create convex",
icons: {
icon: "/convex.svg",
icon: "/logo.png",
},
};

Expand Down
69 changes: 69 additions & 0 deletions games/ZombieSurvival/Direction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Position } from "./Position";

export enum Direction {
Down,
Left,
Right,
Up,
}

export const allDirections = [
Direction.Down,
Direction.Left,
Direction.Right,
Direction.Up,
];

export function directionToString(direction: Direction): string {
switch (direction) {
case Direction.Down: {
return "0";
}
case Direction.Left: {
return "1";
}
case Direction.Right: {
return "2";
}
case Direction.Up: {
return "3";
}
}
}

export function directionFromString(val: string): Direction {
switch (val) {
case "0": {
return Direction.Down;
}
case "1": {
return Direction.Left;
}
case "2": {
return Direction.Right;
}
case "3": {
return Direction.Up;
}
default: {
throw new Error("Can't parse direction");
}
}
}

export function move(position: Position, direction: Direction): Position {
switch (direction) {
case Direction.Down: {
return { ...position, y: position.y + 1 };
}
case Direction.Left: {
return { ...position, x: position.x - 1 };
}
case Direction.Right: {
return { ...position, x: position.x + 1 };
}
case Direction.Up: {
return { ...position, y: position.y - 1 };
}
}
}
8 changes: 8 additions & 0 deletions games/ZombieSurvival/Position.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Position {
x: number;
y: number;
}

export function positionAsNumber(position: Position): number {
return position.x + position.y;
}
Loading

0 comments on commit e001e00

Please sign in to comment.