cleaned up types and removed many :any's

This commit is contained in:
Alexander Bass 2022-06-24 12:22:44 -04:00
parent ac0f31cc07
commit 62c6a63428
13 changed files with 77 additions and 68 deletions

View file

@ -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):

View file

@ -4,7 +4,8 @@ const searchLoc = [
[-1, -1], [0, -1], [1, -1]
];
export function reveal(x, y, data) {
if (data[x][y].type !== 5) {
if (data[x][y].type === 5)
return data;
var toSearch = [];
var searchedLocations = [];
toSearch.push([x, y]);
@ -32,4 +33,3 @@ export function reveal(x, y, data) {
}
return data;
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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)
}

View file

@ -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) {

View file

@ -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)

View file

@ -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++){

View file

@ -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++){

View file

@ -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) {

View file

@ -1,3 +1,4 @@
import {WorldData} from "./world.js"
const searchLoc =
[
@ -6,8 +7,8 @@ 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[] = [];
@ -35,9 +36,7 @@ export function reveal(x:number, y:number, data:any):any {
}
}
})
}
}
return data
}
}

View file

@ -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)

View file

@ -16,8 +16,6 @@ export function init(){
ID("createRoomButton").addEventListener("click", e => {
create(e)
// picker.destroy("createGameSelectColorBar")
});
const mineSlider = ID("createGameOptionsMinePercent")