From 6a8e5cb10e65f2b984dda523b64d0a81f7612469 Mon Sep 17 00:00:00 2001
From: Fredrik Fonn Hansen <fredrfha@stud.ntnu.no>
Date: Thu, 13 Apr 2023 13:26:22 +0200
Subject: [PATCH] Add default positions

---
 .gitlab-ci.yml                            |  7 +++---
 backend/src/controllers/gameController.ts |  2 +-
 backend/src/functions/TerrainGenerator.ts |  2 +-
 backend/src/functions/console.ts          | 14 +++++++----
 backend/src/interfaces/IGame.ts           |  1 -
 backend/src/interfaces/IStats.ts          |  6 ++---
 backend/src/interfaces/ITerrain.ts        | 10 ++++----
 backend/src/models/Game.ts                |  7 ++++--
 backend/src/models/Stats.ts               |  8 +++---
 backend/src/models/Terrain.ts             | 30 +++++++++++------------
 10 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d1954ef..338d4a7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -28,10 +28,11 @@ Prettier:
   image: node:16.10.0
   stage: backend test
   needs: []
+  allow_failure: true
   script:
     - cd backend
-    - yarn
-    - yarn prettier --check .
+    - npm i
+    - npx prettier --check .
   retry: 1
 
 Typescript-compile:
@@ -92,7 +93,7 @@ Gradle-build:
 Backend (NTNU-VM):
   image: node:16.10.0
   stage: deploy
-  needs: [Typescript-compile]
+  needs: [Typescript-compile, API-test]
   before_script:
     - mkdir -p ~/.ssh
     - echo "$NTNU_VM_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
diff --git a/backend/src/controllers/gameController.ts b/backend/src/controllers/gameController.ts
index 9f747b4..15499ec 100644
--- a/backend/src/controllers/gameController.ts
+++ b/backend/src/controllers/gameController.ts
@@ -57,4 +57,4 @@ export const getTerrain = async (req: Request, res: Response): Promise<void> =>
   } else {
     res.status(404).send('Game not found');
   }
-}
+};
diff --git a/backend/src/functions/TerrainGenerator.ts b/backend/src/functions/TerrainGenerator.ts
index 31fe85b..ed49a02 100644
--- a/backend/src/functions/TerrainGenerator.ts
+++ b/backend/src/functions/TerrainGenerator.ts
@@ -17,4 +17,4 @@ function generateYValues(maxY: number, numValues: number): number[] {
   return yValues;
 }
 
-export default generateYValues;
\ No newline at end of file
+export default generateYValues;
diff --git a/backend/src/functions/console.ts b/backend/src/functions/console.ts
index b208df5..d1b44c8 100644
--- a/backend/src/functions/console.ts
+++ b/backend/src/functions/console.ts
@@ -12,17 +12,21 @@ export function log(message: string): void {
   console.log(time + ' | ' + paddedFile + '| ' + message);
 }
 
-
 /**
  * slopePreview() is a helper function for visualizing the terrain generated by the generateYValues() function.
  * It takes an array of y-values and prints a preview of the terrain to the console.
- * 
+ *
  * @param yValues An array of y-values
  * @param maxY The maximum y-value in the array
  * @param width The width of the terrain preview
  * @param height The height of the terrain preview
  */
-export default function slopePreview(yValues: number[], maxY: number, width: number, height: number) {
+export default function slopePreview(
+  yValues: number[],
+  maxY: number,
+  width: number,
+  height: number
+) {
   const terrain: string[][] = [];
 
   for (let i = 0; i < height; i++) {
@@ -38,6 +42,6 @@ export default function slopePreview(yValues: number[], maxY: number, width: num
     terrain[y][x] = '#';
   }
 
-  const terrainString = terrain.map(row => row.join('')).join('\n');
+  const terrainString = terrain.map((row) => row.join('')).join('\n');
   console.log(terrainString);
-}
\ No newline at end of file
+}
diff --git a/backend/src/interfaces/IGame.ts b/backend/src/interfaces/IGame.ts
index d39fc80..a5d2b20 100644
--- a/backend/src/interfaces/IGame.ts
+++ b/backend/src/interfaces/IGame.ts
@@ -37,5 +37,4 @@ export interface IGame {
   getUsers(): [User, IStats][];
 
   getTerrain(): ITerrain;
-
 }
diff --git a/backend/src/interfaces/IStats.ts b/backend/src/interfaces/IStats.ts
index f33b9e0..0c5993b 100644
--- a/backend/src/interfaces/IStats.ts
+++ b/backend/src/interfaces/IStats.ts
@@ -1,7 +1,7 @@
 import { User } from '../../types/User';
 
 export interface IStats {
-  position: number[];
+  position: number;
   turretAngle: number;
   isMirrored: boolean;
   health: number;
@@ -10,8 +10,8 @@ export interface IStats {
   tankType: string;
   score: number;
 
-  getPosition(): number[];
-  setPosition(position: number[]): void;
+  getPosition(): number;
+  setPosition(position: number): void;
   getTurretAngle(): number;
   setTurretAngle(turretAngle: number): void;
   getIsMirrored(): boolean;
diff --git a/backend/src/interfaces/ITerrain.ts b/backend/src/interfaces/ITerrain.ts
index e75888b..34e271a 100644
--- a/backend/src/interfaces/ITerrain.ts
+++ b/backend/src/interfaces/ITerrain.ts
@@ -1,7 +1,7 @@
 export interface ITerrain {
-    yValues: number[];
-    xPoints: number;
-    maxY: number;
-    generate(): number[];
-    getYValues(): number[];
+  yValues: number[];
+  xPoints: number;
+  maxY: number;
+  generate(): number[];
+  getYValues(): number[];
 }
diff --git a/backend/src/models/Game.ts b/backend/src/models/Game.ts
index b537a43..ff17615 100644
--- a/backend/src/models/Game.ts
+++ b/backend/src/models/Game.ts
@@ -27,15 +27,18 @@ export class Game implements IGame {
     // insert the lobby users into the game and create a new stats object for each user
     this.users = lobby.getUsers().map((user) => [user, new Stats()]);
 
+    this.users[0][1].setPosition(100);
+    this.users[1][1].setPosition(900);
+
     // set the stats for the left and right user
     // todo add random tank type
     this.users[0][1].setTankType('M107');
     this.users[0][1].setTankDirection('left');
-    this.users[0][1].setIsMirrored(true); // this mirroring can also be done locally.
+    this.users[0][1].setIsMirrored(false); // this mirroring can also be done locally.
 
     this.users[1][1].setTankType('M1A2');
     this.users[1][1].setTankDirection('right');
-    this.users[1][1].setIsMirrored(false);
+    this.users[1][1].setIsMirrored(true);
 
     // make random number 0 or 1 to determine who starts
     this.currentTurn = Math.round(Math.random());
diff --git a/backend/src/models/Stats.ts b/backend/src/models/Stats.ts
index 221c7d5..fab075d 100644
--- a/backend/src/models/Stats.ts
+++ b/backend/src/models/Stats.ts
@@ -1,7 +1,7 @@
 import { IStats } from '../interfaces/IStats';
 
 export class Stats implements IStats {
-  position: number[];
+  position: number;
   turretAngle: number;
   isMirrored: boolean;
   health: number;
@@ -11,7 +11,7 @@ export class Stats implements IStats {
   score: number;
 
   constructor() {
-    this.position = [0, 0];
+    this.position = 0;
     this.turretAngle = 0;
     this.health = 100;
     this.ammunition = 100;
@@ -22,11 +22,11 @@ export class Stats implements IStats {
   }
 
   // create getters and setters
-  getPosition(): number[] {
+  getPosition(): number {
     return this.position;
   }
 
-  setPosition(position: number[]): void {
+  setPosition(position: number): void {
     this.position = position;
   }
 
diff --git a/backend/src/models/Terrain.ts b/backend/src/models/Terrain.ts
index 65eea14..b819bc5 100644
--- a/backend/src/models/Terrain.ts
+++ b/backend/src/models/Terrain.ts
@@ -2,21 +2,21 @@ import generateYValues from '../functions/TerrainGenerator';
 import { ITerrain } from '../interfaces/ITerrain';
 
 export class Terrain implements ITerrain {
-    yValues: number[];
-    maxY: number;
-    xPoints: number;
+  yValues: number[];
+  maxY: number;
+  xPoints: number;
 
-    constructor(maxY: number = 15, numValues: number = 1000) {
-        this.maxY = maxY;
-        this.xPoints = numValues;
-        this.yValues = this.generate();
-    }
+  constructor(maxY: number = 15, numValues: number = 1000) {
+    this.maxY = maxY;
+    this.xPoints = numValues;
+    this.yValues = this.generate();
+  }
 
-    generate(): number[] {
-        return generateYValues(this.maxY, this.xPoints);
-    }
+  generate(): number[] {
+    return generateYValues(this.maxY, this.xPoints);
+  }
 
-    getYValues(): number[] {
-        return this.yValues;
-    }
-}
\ No newline at end of file
+  getYValues(): number[] {
+    return this.yValues;
+  }
+}
-- 
GitLab