This commit is contained in:
Alexander Bass 2022-06-26 09:18:16 -04:00
parent 43a3535442
commit 406c848eca
No known key found for this signature in database
GPG key ID: E8BAFE5E7B66D6C5
5 changed files with 32 additions and 11 deletions

View file

@ -1,2 +0,0 @@
scss client/scss/main.scss dist/www/style.css
rm -rf .sass-cache

View file

@ -5,8 +5,7 @@
"main": "",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": ""
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",

View file

@ -58,7 +58,6 @@ class RoomManager {
if (this.getAllPlayerIDs().includes(playerID)) {
// return new IllegalAction(playerID, 22)
}
console.log(options)
const id = util.createCode()
const game = this.addGame(id, options)
const player = game.addPlayer(playerID, playerName, playerColor);

View file

@ -1,6 +1,8 @@
import {IllegalAction} from "./illegalAction.js"
import {roomManager} from "../roomManager.js"
import {io} from "./io.js"
import {Player} from "../player.js"
import {Game} from "../game.js"
io.on('connection', function(client:any){
connected(client)
@ -21,14 +23,15 @@ function connected(client:any) {
const id = client.game.id
client.emit('message', id)
}
client.game = "";
client.player = "";
client.game = null;
client.player = null;
client.on('disconnect', function(){
if (!roomManager.getAllPlayerIDs().includes(client.id)) return new IllegalAction(client.id, 22)
client.game.removePlayerByID(client.id)
client.sendMeta();
client.game = null
client.player = null
})
client.on('joinGame', function(data:any){
@ -40,9 +43,31 @@ function connected(client:any) {
client.emit('inGame', true)
client.sendMeta()
})
type CreateGameOptions = {width: number, height: number, mines: number}
type CreateGameData = {options: CreateGameOptions, name: string, color: number}
client.on('createGame', function(data:any){
const info = roomManager.playerCreateGame(data.options, data.name, data.color, client.id)
if (
typeof data.name === "string" &&
typeof data.color === "number" &&
typeof data.options.width === "number" &&
typeof data.options.height === "number" &&
typeof data.options.mines === "number"
) {
console.log("good 2")
} else {return false}
if (
data.name.length < 9 &&
data.color > 0 && data.color < 9 &&
data.options.width > 8 && data.options.width < 500 &&
data.options.height > 8 && data.options.height < 500 &&
data.options.mines > 6 && data.options.mines < (data.options.height * data.options.width)
) {
console.log("good 3")
} else {return false}
const createGameData: CreateGameData = data as CreateGameData;
console.log(createGameData)
const info = roomManager.playerCreateGame(createGameData.options, createGameData.name, createGameData.color, client.id)
client.join(info[0].id)
client.game = info[0];
client.player = info[1]

View file

@ -18,8 +18,8 @@ export class World {
data: WorldData;
constructor(options:any) {
this.mines = options.mines
this.width = options.width*1
this.height = options.height*1
this.width = options.width
this.height = options.height
this.isGenerated = false;
this.isObfuscated = false;
this.isMarked = false;