cleaned up types and removed many :any's
This commit is contained in:
parent
ac0f31cc07
commit
62c6a63428
4
dist/world/flagger.js
vendored
4
dist/world/flagger.js
vendored
|
@ -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):
|
||||
|
|
48
dist/world/revealer.js
vendored
48
dist/world/revealer.js
vendored
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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++){
|
||||
|
|
|
@ -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++){
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -16,8 +16,6 @@ export function init(){
|
|||
|
||||
ID("createRoomButton").addEventListener("click", e => {
|
||||
create(e)
|
||||
// picker.destroy("createGameSelectColorBar")
|
||||
|
||||
});
|
||||
|
||||
const mineSlider = ID("createGameOptionsMinePercent")
|
||||
|
|
Loading…
Reference in a new issue