fix flagging issue

This commit is contained in:
Alexander Bass 2022-06-24 15:25:38 -04:00
parent 288108282f
commit 43a3535442
5 changed files with 8 additions and 10 deletions

View file

@ -154,7 +154,7 @@ function createGameClick(event) {
const name = ID("createGameUsername").value const name = ID("createGameUsername").value
const width = Number(widthBox.value); const width = Number(widthBox.value);
const height = Number(heightBox.value); const height = Number(heightBox.value);
const color = Number(colorPicker.selected); const color = Number(colorPicker.selected + 1);
if (name == '' || mines == '' || width == '' || height == '' || status.get() == 'disconnected') return if (name == '' || mines == '' || width == '' || height == '' || status.get() == 'disconnected') return
const options = { mines: mines, width: width, height: height}; const options = { mines: mines, width: width, height: height};
const data = {name: name, color: color, options: options}; const data = {name: name, color: color, options: options};

View file

@ -64,6 +64,5 @@ socket.on('inGame', function(data){
socket.on('sync', function (sync){ socket.on('sync', function (sync){
game.world = sync.world; game.world = sync.world;
console.log(game.world)
render() render()
}) })

View file

@ -57,7 +57,7 @@ function connected(client:any) {
client.on('clickCanvas', function(data:any){ client.on('clickCanvas', function(data:any){
if (!roomManager.getAllPlayerIDs().includes(client.id)) return new IllegalAction(client.id, 1) if (!roomManager.getAllPlayerIDs().includes(client.id)) return new IllegalAction(client.id, 1)
client.game.world.click(data.tilePosition[0],data.tilePosition[1], data.mode, client.player) client.game.world.click(data.tilePosition[0],data.tilePosition[1], data.mode, client.player.color)
client.sync() client.sync()
}) })
} }

View file

@ -1,12 +1,11 @@
import {WorldData} from "./world.js" import {WorldData} from "./world.js"
import {Player} from "../player.js" import {Player} from "../player.js"
export function flag(x:number, y:number, data:WorldData, player:Player):WorldData { export function flag(x:number, y:number, data:WorldData, playerColor:number):WorldData {
let tile = data[x][y] let tile = data[x][y]
if (!tile.mask || tile.flag === 0) return data if (!tile.mask) return data
const color:number = +player.color const color:number = +playerColor
console.log(player)
switch (tile.flag) { switch (tile.flag) {
case (0): case (0):
@ -18,7 +17,7 @@ export function flag(x:number, y:number, data:WorldData, player:Player):WorldDat
default: default:
tile.flag = 0; tile.flag = 0;
} }
console.log(tile.flag)
data[x][y] = tile data[x][y] = tile
return data; return data;
} }

View file

@ -31,10 +31,10 @@ export class World {
} }
} }
click (x:number, y:number, mode:number, player:Player) { click (x:number, y:number, mode:number, playerColor:number) {
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, playerColor)
} }
if (mode === 0) { if (mode === 0) {