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) {
|
export function flag(x, y, data, player) {
|
||||||
let tile = data[x][y];
|
let tile = data[x][y];
|
||||||
if (!tile.mask || tile.color === 0)
|
if (!tile.mask || tile.flag === 0)
|
||||||
return data;
|
return data;
|
||||||
const color = player.color * 1;
|
const color = +player.color;
|
||||||
console.log(player);
|
console.log(player);
|
||||||
switch (tile.flag) {
|
switch (tile.flag) {
|
||||||
case (0):
|
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]
|
[-1, -1], [0, -1], [1, -1]
|
||||||
];
|
];
|
||||||
export function reveal(x, y, data) {
|
export function reveal(x, y, data) {
|
||||||
if (data[x][y].type !== 5) {
|
if (data[x][y].type === 5)
|
||||||
var toSearch = [];
|
return data;
|
||||||
var searchedLocations = [];
|
var toSearch = [];
|
||||||
toSearch.push([x, y]);
|
var searchedLocations = [];
|
||||||
if (data[x][y].type === 1) {
|
toSearch.push([x, y]);
|
||||||
while (toSearch.length > 0) {
|
if (data[x][y].type === 1) {
|
||||||
const x = toSearch[0][0];
|
while (toSearch.length > 0) {
|
||||||
const y = toSearch[0][1];
|
const x = toSearch[0][0];
|
||||||
searchedLocations.push(toSearch[0]);
|
const y = toSearch[0][1];
|
||||||
toSearch.shift();
|
searchedLocations.push(toSearch[0]);
|
||||||
searchLoc.forEach(loc => {
|
toSearch.shift();
|
||||||
const tempx = x + loc[0];
|
searchLoc.forEach(loc => {
|
||||||
const tempy = y + loc[1];
|
const tempx = x + loc[0];
|
||||||
if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) {
|
const tempy = y + loc[1];
|
||||||
if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) {
|
if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) {
|
||||||
if (!toSearch.includes([tempx, tempy]) && !searchedLocations.includes([tempx, tempy])) {
|
if (data[tempx][tempy].type === 1 && data[tempx][tempy].mask === true) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class Game {
|
||||||
this.world = new World(options)
|
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
|
// if (this.getAllNames().includes(name)) return false
|
||||||
const player = new Player(id, name, color);
|
const player = new Player(id, name, color);
|
||||||
this.players.push(player);
|
this.players.push(player);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
export class Player {
|
export class Player {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
color: string;
|
color: number;
|
||||||
constructor(id:string, name:string, color:string) {
|
constructor(id:string, name:string, color:number) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
|
@ -39,7 +39,7 @@ class RoomManager {
|
||||||
return ids
|
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
|
// See if the client is already in a game
|
||||||
if (this.getAllPlayerIDs().includes(playerID)) {
|
if (this.getAllPlayerIDs().includes(playerID)) {
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ class RoomManager {
|
||||||
return [game, player]
|
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)) {
|
if (this.getAllPlayerIDs().includes(playerID)) {
|
||||||
// return new IllegalAction(playerID, 22)
|
// 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]
|
let tile = data[x][y]
|
||||||
|
|
||||||
if (!tile.mask || tile.color === 0) return data
|
if (!tile.mask || tile.flag === 0) return data
|
||||||
const color = player.color * 1
|
const color:number = +player.color
|
||||||
console.log(player)
|
console.log(player)
|
||||||
|
|
||||||
switch (tile.flag) {
|
switch (tile.flag) {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import * as util from "../util.js"
|
import * as util from "../util.js"
|
||||||
|
import {WorldData, World} from "./world.js"
|
||||||
|
|
||||||
const searchLoc =
|
const searchLoc =
|
||||||
[
|
[
|
||||||
[-1,1], [0,1], [1,1],
|
[-1,1], [0,1], [1,1],
|
||||||
|
@ -6,7 +8,7 @@ const searchLoc =
|
||||||
[-1,-1],[0,-1],[1,-1]
|
[-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;
|
var minesPlanted = 0;
|
||||||
while (minesPlanted < world.mines || !(minesPlanted <= world.width*world.height-15)) {
|
while (minesPlanted < world.mines || !(minesPlanted <= world.width*world.height-15)) {
|
||||||
const x = util.randomNumber(0,world.width)
|
const x = util.randomNumber(0,world.width)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {WorldData, World} from "./world.js"
|
||||||
|
|
||||||
const searchLoc =
|
const searchLoc =
|
||||||
[
|
[
|
||||||
[-1,1], [0,1], [1,1],
|
[-1,1], [0,1], [1,1],
|
||||||
|
@ -5,7 +7,7 @@ const searchLoc =
|
||||||
[-1,-1],[0,-1],[1,-1]
|
[-1,-1],[0,-1],[1,-1]
|
||||||
]
|
]
|
||||||
// Place Numbers
|
// Place Numbers
|
||||||
export function mark(world:any):any {
|
export function mark(world:World):World {
|
||||||
|
|
||||||
for(let x = 0; x < world.width; x++){
|
for(let x = 0; x < world.width; x++){
|
||||||
for(let y = 0; y < world.height; y++){
|
for(let y = 0; y < world.height; y++){
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import {WorldData, World} from "./world.js"
|
||||||
export function obfuscate(world:any):any {
|
export function obfuscate(world:World):World {
|
||||||
let tempWorld = world;
|
let tempWorld = world;
|
||||||
for(let x = 0; x < tempWorld.width; x++){
|
for(let x = 0; x < tempWorld.width; x++){
|
||||||
for(let y = 0; y < tempWorld.height; y++){
|
for(let y = 0; y < tempWorld.height; y++){
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import * as revealer from "./revealer.js"
|
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];
|
let tile = data[x][y];
|
||||||
if (tile.mask === true) {
|
if (tile.mask === true) {
|
||||||
if (tile.mask && tile.flag === 0) {
|
if (tile.mask && tile.flag === 0) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import {WorldData} from "./world.js"
|
||||||
|
|
||||||
const searchLoc =
|
const searchLoc =
|
||||||
[
|
[
|
||||||
|
@ -6,38 +7,36 @@ const searchLoc =
|
||||||
[-1,-1],[0,-1],[1,-1]
|
[-1,-1],[0,-1],[1,-1]
|
||||||
]
|
]
|
||||||
|
|
||||||
export function reveal(x:number, y:number, data:any):any {
|
export function reveal(x:number, y:number, data:WorldData):WorldData {
|
||||||
if (data[x][y].type !== 5) {
|
if (data[x][y].type === 5) return data;
|
||||||
|
|
||||||
var toSearch:any[] = [];
|
var toSearch:any[] = [];
|
||||||
var searchedLocations:any[] = [];
|
var searchedLocations:any[] = [];
|
||||||
toSearch.push([x, y])
|
toSearch.push([x, y])
|
||||||
|
|
||||||
if (data[x][y].type === 1) {
|
if (data[x][y].type === 1) {
|
||||||
while (toSearch.length > 0) {
|
while (toSearch.length > 0) {
|
||||||
const x = toSearch[0][0]
|
const x = toSearch[0][0]
|
||||||
const y = toSearch[0][1]
|
const y = toSearch[0][1]
|
||||||
searchedLocations.push(toSearch[0])
|
searchedLocations.push(toSearch[0])
|
||||||
toSearch.shift()
|
toSearch.shift()
|
||||||
searchLoc.forEach(loc => {
|
searchLoc.forEach(loc => {
|
||||||
const tempx = x + loc[0]
|
const tempx = x + loc[0]
|
||||||
const tempy = y + loc[1]
|
const tempy = y + loc[1]
|
||||||
if (tempx >= 0 && tempy >= 0 && tempx < data.length && tempy < data[0].length) {
|
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])) {
|
if (!toSearch.includes([tempx,tempy]) && !searchedLocations.includes([tempx,tempy])) {
|
||||||
toSearch.push([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 marker from "./marker.js"
|
||||||
import * as flagger from "./flagger.js"
|
import * as flagger from "./flagger.js"
|
||||||
import * as placer from "./placer.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 {
|
export class World {
|
||||||
mines: number;
|
mines: number;
|
||||||
|
@ -11,7 +15,7 @@ export class World {
|
||||||
isGenerated: boolean;
|
isGenerated: boolean;
|
||||||
isObfuscated: boolean;
|
isObfuscated: boolean;
|
||||||
isMarked: boolean;
|
isMarked: boolean;
|
||||||
data: any;
|
data: WorldData;
|
||||||
constructor(options:any) {
|
constructor(options:any) {
|
||||||
this.mines = options.mines
|
this.mines = options.mines
|
||||||
this.width = options.width*1
|
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 (this.isGenerated) {
|
||||||
if (mode === 2) {
|
if (mode === 2) {
|
||||||
this.data = flagger.flag(x, y, this.data, player)
|
this.data = flagger.flag(x, y, this.data, player)
|
||||||
|
|
|
@ -16,8 +16,6 @@ export function init(){
|
||||||
|
|
||||||
ID("createRoomButton").addEventListener("click", e => {
|
ID("createRoomButton").addEventListener("click", e => {
|
||||||
create(e)
|
create(e)
|
||||||
// picker.destroy("createGameSelectColorBar")
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const mineSlider = ID("createGameOptionsMinePercent")
|
const mineSlider = ID("createGameOptionsMinePercent")
|
||||||
|
|
Loading…
Reference in a new issue