Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
EsotericEnderman committed Jul 31, 2024
1 parent ef427f7 commit f927ac7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions Snake.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
class Snake {
direction: Vector;
private direction: Vector;

parts: BiDirectionalLinkedList<SnakePart> = new BiDirectionalLinkedList([]);
private parts: BiDirectionalLinkedList<SnakePart> = new BiDirectionalLinkedList([]);

get head() {
return this.parts.head;
}

get tail() {
return this.parts.tail;
}

constructor(parts?: BiDirectionalLinkedList<SnakePart>, direction?: Vector) {
this.parts = parts;
Expand All @@ -16,9 +24,7 @@ class Snake {
const directions = cloneArray(Vector.cardinalDirections);

for (let i = 0; i < directions.length; i++) {
const head = this.parts.head;

const clone = head.value.clone().addVector(directions[i]);
const clone = this.head.value.clone().addVector(directions[i]);

if (this.isOnPosition(clone)) {
directions.splice(i, 1);
Expand Down Expand Up @@ -55,8 +61,8 @@ class Snake {

const part = this.parts.elements[i];

const isFirstPart = part === this.parts.head;
const isLastPart = part === this.parts.tail;
const isFirstPart = part === this.head;
const isLastPart = part === this.tail;

if (isLastPart) {
console.log("Unplotting " + part.value.toString());
Expand Down Expand Up @@ -98,7 +104,7 @@ class Snake {
private grow() {
console.log("Growing snake");

const tail = this.parts.tail;
const tail = this.tail;

console.log("The tail is at " + tail.value.toString());

Expand All @@ -119,7 +125,7 @@ class Snake {

console.log("Checking direction " + direction.toString());

const cloned = ledSquare.wrapAround(tail.value.clone().addVector(direction));
const cloned = ledSquare.wrapAround(this.tail.value.clone().addVector(direction));

console.log("Checking position " + cloned.toString());

Expand Down
4 changes: 2 additions & 2 deletions Vector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Vector implements Cloneable<Vector> {
x: number;
y: number;
public x: number;
public y: number;

public static readonly north = new Vector(0, 1);
public static readonly east = new Vector(1, 0);
Expand Down

0 comments on commit f927ac7

Please sign in to comment.