Skip to content
Snippets Groups Projects
Commit 17ab0ee1 authored by Fredrik Fonn Hansen's avatar Fredrik Fonn Hansen :8ball:
Browse files

Merge branch 'backend-position' into 'main'

Add default positions

See merge request !47
parents 05a0adcb 6a8e5cb1
No related branches found
No related tags found
1 merge request!47Add default positions
Pipeline #215183 passed
...@@ -28,10 +28,11 @@ Prettier: ...@@ -28,10 +28,11 @@ Prettier:
image: node:16.10.0 image: node:16.10.0
stage: backend test stage: backend test
needs: [] needs: []
allow_failure: true
script: script:
- cd backend - cd backend
- yarn - npm i
- yarn prettier --check . - npx prettier --check .
retry: 1 retry: 1
Typescript-compile: Typescript-compile:
...@@ -92,7 +93,7 @@ Gradle-build: ...@@ -92,7 +93,7 @@ Gradle-build:
Backend (NTNU-VM): Backend (NTNU-VM):
image: node:16.10.0 image: node:16.10.0
stage: deploy stage: deploy
needs: [Typescript-compile] needs: [Typescript-compile, API-test]
before_script: before_script:
- mkdir -p ~/.ssh - mkdir -p ~/.ssh
- echo "$NTNU_VM_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa - echo "$NTNU_VM_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
......
...@@ -57,4 +57,4 @@ export const getTerrain = async (req: Request, res: Response): Promise<void> => ...@@ -57,4 +57,4 @@ export const getTerrain = async (req: Request, res: Response): Promise<void> =>
} else { } else {
res.status(404).send('Game not found'); res.status(404).send('Game not found');
} }
} };
...@@ -17,4 +17,4 @@ function generateYValues(maxY: number, numValues: number): number[] { ...@@ -17,4 +17,4 @@ function generateYValues(maxY: number, numValues: number): number[] {
return yValues; return yValues;
} }
export default generateYValues; export default generateYValues;
\ No newline at end of file
...@@ -12,17 +12,21 @@ export function log(message: string): void { ...@@ -12,17 +12,21 @@ export function log(message: string): void {
console.log(time + ' | ' + paddedFile + '| ' + message); console.log(time + ' | ' + paddedFile + '| ' + message);
} }
/** /**
* slopePreview() is a helper function for visualizing the terrain generated by the generateYValues() function. * 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. * 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 yValues An array of y-values
* @param maxY The maximum y-value in the array * @param maxY The maximum y-value in the array
* @param width The width of the terrain preview * @param width The width of the terrain preview
* @param height The height 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[][] = []; const terrain: string[][] = [];
for (let i = 0; i < height; i++) { for (let i = 0; i < height; i++) {
...@@ -38,6 +42,6 @@ export default function slopePreview(yValues: number[], maxY: number, width: num ...@@ -38,6 +42,6 @@ export default function slopePreview(yValues: number[], maxY: number, width: num
terrain[y][x] = '#'; terrain[y][x] = '#';
} }
const terrainString = terrain.map(row => row.join('')).join('\n'); const terrainString = terrain.map((row) => row.join('')).join('\n');
console.log(terrainString); console.log(terrainString);
} }
\ No newline at end of file
...@@ -37,5 +37,4 @@ export interface IGame { ...@@ -37,5 +37,4 @@ export interface IGame {
getUsers(): [User, IStats][]; getUsers(): [User, IStats][];
getTerrain(): ITerrain; getTerrain(): ITerrain;
} }
import { User } from '../../types/User'; import { User } from '../../types/User';
export interface IStats { export interface IStats {
position: number[]; position: number;
turretAngle: number; turretAngle: number;
isMirrored: boolean; isMirrored: boolean;
health: number; health: number;
...@@ -10,8 +10,8 @@ export interface IStats { ...@@ -10,8 +10,8 @@ export interface IStats {
tankType: string; tankType: string;
score: number; score: number;
getPosition(): number[]; getPosition(): number;
setPosition(position: number[]): void; setPosition(position: number): void;
getTurretAngle(): number; getTurretAngle(): number;
setTurretAngle(turretAngle: number): void; setTurretAngle(turretAngle: number): void;
getIsMirrored(): boolean; getIsMirrored(): boolean;
......
export interface ITerrain { export interface ITerrain {
yValues: number[]; yValues: number[];
xPoints: number; xPoints: number;
maxY: number; maxY: number;
generate(): number[]; generate(): number[];
getYValues(): number[]; getYValues(): number[];
} }
...@@ -27,15 +27,18 @@ export class Game implements IGame { ...@@ -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 // 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 = 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 // set the stats for the left and right user
// todo add random tank type // todo add random tank type
this.users[0][1].setTankType('M107'); this.users[0][1].setTankType('M107');
this.users[0][1].setTankDirection('left'); 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].setTankType('M1A2');
this.users[1][1].setTankDirection('right'); 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 // make random number 0 or 1 to determine who starts
this.currentTurn = Math.round(Math.random()); this.currentTurn = Math.round(Math.random());
......
import { IStats } from '../interfaces/IStats'; import { IStats } from '../interfaces/IStats';
export class Stats implements IStats { export class Stats implements IStats {
position: number[]; position: number;
turretAngle: number; turretAngle: number;
isMirrored: boolean; isMirrored: boolean;
health: number; health: number;
...@@ -11,7 +11,7 @@ export class Stats implements IStats { ...@@ -11,7 +11,7 @@ export class Stats implements IStats {
score: number; score: number;
constructor() { constructor() {
this.position = [0, 0]; this.position = 0;
this.turretAngle = 0; this.turretAngle = 0;
this.health = 100; this.health = 100;
this.ammunition = 100; this.ammunition = 100;
...@@ -22,11 +22,11 @@ export class Stats implements IStats { ...@@ -22,11 +22,11 @@ export class Stats implements IStats {
} }
// create getters and setters // create getters and setters
getPosition(): number[] { getPosition(): number {
return this.position; return this.position;
} }
setPosition(position: number[]): void { setPosition(position: number): void {
this.position = position; this.position = position;
} }
......
...@@ -2,21 +2,21 @@ import generateYValues from '../functions/TerrainGenerator'; ...@@ -2,21 +2,21 @@ import generateYValues from '../functions/TerrainGenerator';
import { ITerrain } from '../interfaces/ITerrain'; import { ITerrain } from '../interfaces/ITerrain';
export class Terrain implements ITerrain { export class Terrain implements ITerrain {
yValues: number[]; yValues: number[];
maxY: number; maxY: number;
xPoints: number; xPoints: number;
constructor(maxY: number = 15, numValues: number = 1000) { constructor(maxY: number = 15, numValues: number = 1000) {
this.maxY = maxY; this.maxY = maxY;
this.xPoints = numValues; this.xPoints = numValues;
this.yValues = this.generate(); this.yValues = this.generate();
} }
generate(): number[] { generate(): number[] {
return generateYValues(this.maxY, this.xPoints); return generateYValues(this.maxY, this.xPoints);
} }
getYValues(): number[] { getYValues(): number[] {
return this.yValues; return this.yValues;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment