diff --git a/dist/world/flagger.js b/dist/world/flagger.js index 1cd456a..7a0cb9f 100644 --- a/dist/world/flagger.js +++ b/dist/world/flagger.js @@ -1,8 +1,8 @@ export function flag(x, y, data, player) { let tile = data[x][y]; - if (!tile.mask || tile.color === 0) + if (!tile.mask || tile.flag === 0) return data; - const color = player.color * 1; + const color = +player.color; console.log(player); switch (tile.flag) { case (0): diff --git a/dist/world/revealer.js b/dist/world/revealer.js index 7351f4f..5dd6c47 100644 --- a/dist/world/revealer.js +++ b/dist/world/revealer.js @@ -4,32 +4,32 @@ const searchLoc = [ [-1, -1], [0, -1], [1, -1] ]; export function reveal(x, y, data) { - if (data[x][y].type !== 5) { - var toSearch = []; - var searchedLocations = []; - toSearch.push([x, y]); - if (data[x][y].type === 1) { - while (toSearch.length > 0) { - const x = toSearch[0][0]; - const y = toSearch[0][1]; - searchedLocations.push(toSearch[0]); - toSearch.shift(); - searchLoc.forEach(loc => { - const tempx = x + loc[0]; - const tempy = y + loc[1]; - if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) { - if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) { - if (!toSearch.includes([tempx, tempy]) && !searchedLocations.includes([tempx, tempy])) { - toSearch.push([tempx, tempy]); - } - } - if (data[tempx][tempy].type !== 5) { - data[tempx][tempy].mask = false; + if (data[x][y].type === 5) + return data; + var toSearch = []; + var searchedLocations = []; + toSearch.push([x, y]); + if (data[x][y].type === 1) { + while (toSearch.length > 0) { + const x = toSearch[0][0]; + const y = toSearch[0][1]; + searchedLocations.push(toSearch[0]); + toSearch.shift(); + searchLoc.forEach(loc => { + const tempx = x + loc[0]; + const tempy = y + loc[1]; + if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) { + if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) { + if (!toSearch.includes([tempx, tempy]) && !searchedLocations.includes([tempx, tempy])) { + toSearch.push([tempx, tempy]); } } - }); - } + if (data[tempx][tempy].type !== 5) { + data[tempx][tempy].mask = false; + } + } + }); } - return data; } + return data; } diff --git a/src/game.ts b/src/game.ts index 1853d61..c681707 100644 --- a/src/game.ts +++ b/src/game.ts @@ -12,7 +12,7 @@ export class Game { this.world = new World(options) } - addPlayer(id:string, name:string, color:string):Player { + addPlayer(id:string, name:string, color:number):Player { // if (this.getAllNames().includes(name)) return false const player = new Player(id, name, color); this.players.push(player); diff --git a/src/player.ts b/src/player.ts index 106bb0c..388e4f1 100644 --- a/src/player.ts +++ b/src/player.ts @@ -1,8 +1,8 @@ export class Player { id: string; name: string; - color: string; - constructor(id:string, name:string, color:string) { + color: number; + constructor(id:string, name:string, color:number) { this.id = id; this.name = name; this.color = color; diff --git a/src/roomManager.ts b/src/roomManager.ts index 65ae215..5ca2ccd 100644 --- a/src/roomManager.ts +++ b/src/roomManager.ts @@ -39,7 +39,7 @@ class RoomManager { return ids } - playerJoinGame(roomCode:string, playerName:string, playerColor:string, playerID:string):any[] { + playerJoinGame(roomCode:string, playerName:string, playerColor:number, playerID:string):any[] { // See if the client is already in a game if (this.getAllPlayerIDs().includes(playerID)) { } @@ -54,7 +54,7 @@ class RoomManager { return [game, player] } - playerCreateGame(options:any, playerName:string, playerColor:string, playerID:string):any[] { + playerCreateGame(options:any, playerName:string, playerColor:number, playerID:string):any[] { if (this.getAllPlayerIDs().includes(playerID)) { // return new IllegalAction(playerID, 22) } diff --git a/src/world/flagger.ts b/src/world/flagger.ts index 269e7bb..97ec29d 100644 --- a/src/world/flagger.ts +++ b/src/world/flagger.ts @@ -1,9 +1,11 @@ +import {WorldData} from "./world.js" +import {Player} from "../player.js" -export function flag(x:number, y:number, data:any, player:any):any { +export function flag(x:number, y:number, data:WorldData, player:Player):WorldData { let tile = data[x][y] - if (!tile.mask || tile.color === 0) return data - const color = player.color * 1 + if (!tile.mask || tile.flag === 0) return data + const color:number = +player.color console.log(player) switch (tile.flag) { diff --git a/src/world/generator.ts b/src/world/generator.ts index f9ddb11..6f7b731 100644 --- a/src/world/generator.ts +++ b/src/world/generator.ts @@ -1,4 +1,6 @@ import * as util from "../util.js" +import {WorldData, World} from "./world.js" + const searchLoc = [ [-1,1], [0,1], [1,1], @@ -6,7 +8,7 @@ const searchLoc = [-1,-1],[0,-1],[1,-1] ] -export function generate(avoidX:number, avoidY:number, world:any):any { +export function generate(avoidX:number, avoidY:number, world:World):World { var minesPlanted = 0; while (minesPlanted < world.mines || !(minesPlanted <= world.width*world.height-15)) { const x = util.randomNumber(0,world.width) diff --git a/src/world/marker.ts b/src/world/marker.ts index 821f892..9b07bbe 100644 --- a/src/world/marker.ts +++ b/src/world/marker.ts @@ -1,3 +1,5 @@ +import {WorldData, World} from "./world.js" + const searchLoc = [ [-1,1], [0,1], [1,1], @@ -5,7 +7,7 @@ const searchLoc = [-1,-1],[0,-1],[1,-1] ] // Place Numbers -export function mark(world:any):any { +export function mark(world:World):World { for(let x = 0; x < world.width; x++){ for(let y = 0; y < world.height; y++){ diff --git a/src/world/obfuscator.ts b/src/world/obfuscator.ts index 4921082..d074565 100644 --- a/src/world/obfuscator.ts +++ b/src/world/obfuscator.ts @@ -1,5 +1,5 @@ - -export function obfuscate(world:any):any { +import {WorldData, World} from "./world.js" +export function obfuscate(world:World):World { let tempWorld = world; for(let x = 0; x < tempWorld.width; x++){ for(let y = 0; y < tempWorld.height; y++){ diff --git a/src/world/placer.ts b/src/world/placer.ts index 7f08726..c32baa6 100644 --- a/src/world/placer.ts +++ b/src/world/placer.ts @@ -1,5 +1,7 @@ import * as revealer from "./revealer.js" -export function place(x:number, y:number, data:any):any { +import {WorldData} from "./world.js" + +export function place(x:number, y:number, data:WorldData):WorldData { let tile = data[x][y]; if (tile.mask === true) { if (tile.mask && tile.flag === 0) { diff --git a/src/world/revealer.ts b/src/world/revealer.ts index 5b53995..ec5048e 100644 --- a/src/world/revealer.ts +++ b/src/world/revealer.ts @@ -1,3 +1,4 @@ +import {WorldData} from "./world.js" const searchLoc = [ @@ -6,38 +7,36 @@ const searchLoc = [-1,-1],[0,-1],[1,-1] ] -export function reveal(x:number, y:number, data:any):any { - if (data[x][y].type !== 5) { +export function reveal(x:number, y:number, data:WorldData):WorldData { + if (data[x][y].type === 5) return data; - var toSearch:any[] = []; - var searchedLocations:any[] = []; - toSearch.push([x, y]) + var toSearch:any[] = []; + var searchedLocations:any[] = []; + toSearch.push([x, y]) - if (data[x][y].type === 1) { - while (toSearch.length > 0) { - const x = toSearch[0][0] - const y = toSearch[0][1] - searchedLocations.push(toSearch[0]) - toSearch.shift() - searchLoc.forEach(loc => { - const tempx = x + loc[0] - const tempy = y + loc[1] - if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) { + if (data[x][y].type === 1) { + while (toSearch.length > 0) { + const x = toSearch[0][0] + const y = toSearch[0][1] + searchedLocations.push(toSearch[0]) + toSearch.shift() + searchLoc.forEach(loc => { + const tempx = x + loc[0] + const tempy = y + loc[1] + if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) { - if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) { + if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) { - if (!toSearch.includes([tempx,tempy]) && !searchedLocations.includes([tempx,tempy])) { - toSearch.push([tempx,tempy]) - } + if (!toSearch.includes([tempx,tempy]) && !searchedLocations.includes([tempx,tempy])) { + toSearch.push([tempx,tempy]) } - if (data[tempx][tempy].type !== 5) { - data[tempx][tempy].mask = false; } + if (data[tempx][tempy].type !== 5) { + data[tempx][tempy].mask = false; } - }) - - } + } + }) } - return data } + return data } diff --git a/src/world/world.ts b/src/world/world.ts index 34fca17..1148d33 100644 --- a/src/world/world.ts +++ b/src/world/world.ts @@ -3,6 +3,10 @@ import * as generator from "./generator.js" import * as marker from "./marker.js" import * as flagger from "./flagger.js" import * as placer from "./placer.js" +import {Player} from "../player.js" + +export type TileData = {type: number, flag: number, mask: boolean}; +export type WorldData = TileData[][]; export class World { mines: number; @@ -11,7 +15,7 @@ export class World { isGenerated: boolean; isObfuscated: boolean; isMarked: boolean; - data: any; + data: WorldData; constructor(options:any) { this.mines = options.mines this.width = options.width*1 @@ -27,7 +31,7 @@ export class World { } } - click (x:number, y:number, mode:number, player:any) { + click (x:number, y:number, mode:number, player:Player) { if (this.isGenerated) { if (mode === 2) { this.data = flagger.flag(x, y, this.data, player) diff --git a/www/scripts/interface/mainmenu/create.js b/www/scripts/interface/mainmenu/create.js index 80b26e3..7322e7d 100644 --- a/www/scripts/interface/mainmenu/create.js +++ b/www/scripts/interface/mainmenu/create.js @@ -16,8 +16,6 @@ export function init(){ ID("createRoomButton").addEventListener("click", e => { create(e) - // picker.destroy("createGameSelectColorBar") - }); const mineSlider = ID("createGameOptionsMinePercent")