Losing interest again

This commit is contained in:
Alexander Bass 2022-06-23 16:18:23 -04:00
parent 643c693496
commit c86a82ab63
6 changed files with 48 additions and 70 deletions

View file

@ -10,9 +10,8 @@ export class Game {
this.world = new World(options) this.world = new World(options)
} }
addPlayer(id, name) { addPlayer(id, name, color) {
if (this.getAllNames().includes(name)) return false if (this.getAllNames().includes(name)) return false
var color = 1
const player = new Player(id, name, color); const player = new Player(id, name, color);
this.players.push(player); this.players.push(player);
return player return player

View file

@ -62,14 +62,14 @@ class RoomManager {
return [game, player] return [game, player]
} }
playerCreateGame(options, playerName, playerID) { playerCreateGame(options, playerName, playerColor, playerID) {
if (this.getAllPlayerIDs().includes(playerID)) { if (this.getAllPlayerIDs().includes(playerID)) {
return new IllegalAction(id, 22) return new IllegalAction(id, 22)
} }
console.log(options) console.log(options)
const id = util.createCode() const id = util.createCode()
const game = this.addGame(id, options) const game = this.addGame(id, options)
const player = game.addPlayer(playerID, playerName); const player = game.addPlayer(playerID, playerName, playerColor);
return [game, player] return [game, player]
} }

View file

@ -48,7 +48,7 @@ function connected(client) {
}) })
client.on('createGame', function(data){ client.on('createGame', function(data){
const info = roomManager.playerCreateGame(data.options, data.name, client.id) const info = roomManager.playerCreateGame(data.options, data.name, data.color, client.id)
client.join(info[0].id) client.join(info[0].id)
client.game = info[0]; client.game = info[0];
client.player = info[1] client.player = info[1]

View file

@ -36,7 +36,7 @@
<input type="text" id="joinGameUsername" value="bob"> <input type="text" id="joinGameUsername" value="bob">
<button type="button" id="joinGameButton">Join</button> <button type="button" id="joinGameButton">Join</button>
</div> </div>
<div id="createGame" > <div id="createGame" style="display: none;">
<h2>Create Room</h2> <h2>Create Room</h2>
<hr> <hr>
<div class="leftRight"> <div class="leftRight">
@ -54,6 +54,7 @@
<span class="centerBar"></span> <span class="centerBar"></span>
<div class="right"> <div class="right">
<h3>Game Settings</h3> <h3>Game Settings</h3>
<div class="row"> <div class="row">
<span>Percentage mines</span> <span>Percentage mines</span>
<div class="sliderContainer"> <div class="sliderContainer">

View file

@ -7,23 +7,12 @@ import * as status from "/scripts/net/status.js"
var menuPicker, colorPicker; var menuPicker, colorPicker;
export function init(){ export function init(){
colorPicker = new Picker("createGameSelectColorBar", tileArray, [8, 16], null, 0, null) colorPicker = new Picker("createGameSelectColorBar", tileArray, [8, 16], null, 0, null)
menuPicker = new Picker ("createGameSelectModeBar", menuArray, [0,4], "wide", 0, updateMenu) menuPicker = new Picker ("createGameSelectModeBar", menuArray, [0,4], "wide", 0, updateMenu)
changeMode() changeMode()
} }
ID("createRoomButton").addEventListener("click", e => { ID("createRoomButton").addEventListener("click", e => {
create(e) create(e)
// picker.destroy("createGameSelectColorBar") // picker.destroy("createGameSelectColorBar")
@ -48,14 +37,18 @@ menuPicker.select(3)
heightBox.addEventListener("change", function(){ heightBox.addEventListener("change", function(){
updateCount(2) updateCount(2)
widthBox.value = Math.abs(Math.round(heightBox.value))
menuPicker.select(3) menuPicker.select(3)
}) })
widthBox.addEventListener("change", function(){ widthBox.addEventListener("change", function(){
updateCount(2) updateCount(2)
widthBox.value = Math.abs(Math.round(widthBox.value))
menuPicker.select(3) menuPicker.select(3)
}) })
var mines = 5; var mines = 5;
var mode = 0; var mode = 0;
@ -97,18 +90,20 @@ function updateCount(mode) {
const max = maxMines(width, height) const max = maxMines(width, height)
const min = minMines(width, height) const min = minMines(width, height)
console.log(max, min)
if (mode === 0) { if (mode === 0) {
mines = Math.ceil((mineSlider.value/10) * (width*height) /100) mines = Math.round((mineSlider.value/10) * (width*height) /100)
console.log(mines, mineBox.value)
updateCount(2) updateCount(2)
} }
else if (mode === 1) { else if (mode === 1) {
mineBox.value = Math.abs(Math.round(mineBox.value)) mineBox.value = Math.abs(Math.round(mineBox.value))
mines = mineBox.value; mines = mineBox.value;
updateCount(2) updateCount(2)
} }
else if (mode === 2) { else if (mode === 2) {
if (mines > max) { if (mines > max) {
mines = max mines = max
} }
@ -130,7 +125,7 @@ function maxMines(width, height) {
} }
function minMines(width, height) { function minMines(width, height) {
return (width * height) / 10 return Math.floor((width * height) / 10)
} }
function updatePercentageLabel(percentage) { function updatePercentageLabel(percentage) {
@ -143,6 +138,7 @@ function create(event) {
const mines = ID("createGameOptionsMines").value const mines = ID("createGameOptionsMines").value
const width = widthBox.value; const width = widthBox.value;
const height = heightBox.value; const height = heightBox.value;
const color = colorPicker.selected
if (name == '' || mines == '' || width == '' || height == '' || status.get() == 'disconnected') return if (name == '' || mines == '' || width == '' || height == '' || status.get() == 'disconnected') return
const options = { const options = {
mines: mines, mines: mines,
@ -152,6 +148,7 @@ function create(event) {
const data = const data =
{ {
name: name, name: name,
color: color,
options: options options: options
} }
console.log(data) console.log(data)

View file

@ -1,5 +1,12 @@
@font-face {
/* font-weight: 500; */
font-family: "moderndos";
src: url('fonts/moderndos.woff2') format('woff2'),
url('fonts/moderndos.ttf') format('truetype');
}
* { * {
font-family: pixserif; font-family: moderndos;
} }
h1, h2 { h1, h2 {
@ -59,7 +66,7 @@ hr {
.right { .right {
display: inline; display: inline;
margin: 40px; margin: 40px;
/* background: red; */ /* background: orange; */
} }
@ -111,7 +118,7 @@ hr {
} }
input[type=button], button, .buttonLink { input[type=button], button, .buttonLink {
width: 100%; width: 50%;
background-color: #4CAF50; background-color: #4CAF50;
color: white; color: white;
padding: 14px 20px; padding: 14px 20px;
@ -130,12 +137,7 @@ input[type=button], button, .buttonLink {
background-color: lightgray; } background-color: lightgray; }
@font-face {
/* font-weight: 500; */
font-family: "pixserif";
src: url('fonts/moderndos.woff2') format('woff2'),
url('fonts/moderndos.ttf') format('truetype');
}
span.button > img { span.button > img {
pointer-events: none; pointer-events: none;
image-rendering: optimizeSpeed; /* STOP SMOOTHING, GIVE ME SPEED */ image-rendering: optimizeSpeed; /* STOP SMOOTHING, GIVE ME SPEED */
@ -169,10 +171,7 @@ span.button {
width:90px; width:90px;
height:90px; height:90px;
margin: 5px 5px 5px 5px; margin: 5px 5px 5px 5px;
vertical-align: middle; border-radius: 1px;
border-radius: 3px;
white-space: normal;
align-items: center;
cursor: pointer; cursor: pointer;
} }
@ -197,24 +196,6 @@ span.button:hover {
} }
#wrapper {
/* display: flex; */
/* justify-content: right; */
/* left: 50%; */
/* transform: translate(-50%, 0); */
/* position: absolute; */
background: khaki;
width: 750px;
height: 750px;
}
#wrapwrap {
display: block;
margin: 0 auto;
margin-left: auto;
margin-right: auto;
}
main { main {