diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d1954ef21a3149eaa95e3d28da1af5ff23004077..338d4a784f0ee86b705552045ce07e719f22a8e7 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 9f747b4bc71b2588c6c6b8d48642d55b003b1601..15499ec6e6db975a1eadff7d944e8b4fa4904520 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 31fe85b8f39bbfe315123cdfccee377d80cd821c..ed49a0226bfa9f6c914b0d73a8c260bfd9800ce0 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 b208df52aec660f2c07275fee5750431412ba53a..d1b44c809153dd33789e346350b3a78b1796846e 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 d39fc802b2d13aa709e7319078019cec5b578b7d..a5d2b200cf46e8357448e1ede54ecbe329cf42e7 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 f33b9e0cfe3f41d045365aee6b1b9ac1a9eb69ad..0c5993bbee53374cc86046ad59c4a4aea464069a 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 e75888b03be8625c1cbefd1735a673f3bf8d71b9..34e271adfcd9a1ff0d9e8844dc46571d0740c227 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 b537a43fd1fa7bfb588ab832e184c354f764adeb..ff176157a1b9f189b43b88ba51d8bcaa63bda995 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 221c7d5114429d6bc3cd8af313d2cb0233b25fd6..fab075d976d0233f46f46eebae2707c43ebaaa06 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 65eea14f509c5be1ab43eac7da1ca9a708a46967..b819bc53205623fda762f3e4215068ab4fd5ff95 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; + } +}