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

Add default positions

parent 05a0adcb
No related branches found
No related tags found
1 merge request!47Add default positions
......@@ -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
......
......@@ -57,4 +57,4 @@ export const getTerrain = async (req: Request, res: Response): Promise<void> =>
} else {
res.status(404).send('Game not found');
}
}
};
......@@ -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;
......@@ -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
}
......@@ -37,5 +37,4 @@ export interface IGame {
getUsers(): [User, IStats][];
getTerrain(): ITerrain;
}
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;
......
export interface ITerrain {
yValues: number[];
xPoints: number;
maxY: number;
generate(): number[];
getYValues(): number[];
yValues: number[];
xPoints: number;
maxY: number;
generate(): number[];
getYValues(): number[];
}
......@@ -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());
......
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;
}
......
......@@ -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;
}
}
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