some more code also i redid the board generator

This commit is contained in:
Ben Kyd
2021-05-09 18:38:52 +01:00
parent 29cd7f1b20
commit f189db24be
5 changed files with 125 additions and 66 deletions

View File

@@ -8,40 +8,69 @@ const BoardLookup = {
'★': 'center-star' '★': 'center-star'
}; };
// This was automatically generated, the code for it is lonnnggg gone
const BoardLocations = { const BoardLocations = {
'A1': 'TW', "0,0": "TW",
'D1': 'DL', "0,3": "DL",
'H1': 'TW', "0,7": "TW",
'L1': 'DL', "0,11": "DL",
'O1': 'TW', "0,14": "TW",
'B2': 'DW', "1,1": "DW",
'F2': 'TL', "1,5": "TL",
'J2': 'TL', "1,9": "TL",
'N2': 'DW', "1,13": "DW",
'C3': 'DW', "2,2": "DW",
'G3': 'DL', "2,6": "DL",
'I3': 'DL', "2,8": "DL",
'M3': 'DW', "2,12": "DW",
'A4': 'DL', "3,0": "DL",
'D4': 'DW', "3,3": "DW",
'H4': 'DL', "3,7": "DL",
'L4': 'DW', "3,11": "DW",
'O4': 'DL', "3,14": "DL",
'E5': 'DW', "4,4": "DW",
'K5': 'DW', "4,10": "DW",
'B6': 'TL', "5,1": "TL",
'F6': 'TL', "5,5": "TL",
'J6': 'TL', "5,9": "TL",
'N6': 'TL', "5,13": "TL",
'C7': 'DL', "6,2": "DL",
'G7': 'DL', "6,6": "DL",
'I7': 'DL', "6,8": "DL",
'M7': 'DL', "6,12": "DL",
'A8': 'TW', "7,0": "TW",
'D8': 'DL', "7,3": "DL",
'H8': '★', "7,7": "★",
'L8': 'DL', "7,11": "DL",
'O8': 'TW' "7,14": "TW",
"8,2": "DL",
"8,6": "DL",
"8,8": "DL",
"8,12": "DL",
"9,1": "TL",
"9,5": "TL",
"9,9": "TL",
"9,13": "TL",
"10,4": "DW",
"10,10": "DW",
"11,0": "DL",
"11,3": "DW",
"11,7": "DL",
"11,11": "DW",
"11,14": "DL",
"12,2": "DW",
"12,6": "DL",
"12,8": "DL",
"12,12": "DW",
"13,1": "DW",
"13,5": "TL",
"13,9": "TL",
"13,13": "DW",
"14,0": "TW",
"14,3": "DL",
"14,7": "TW",
"14,11": "DL",
"14,14": "TW"
}; };
function flip(y, size) function flip(y, size)
@@ -52,9 +81,9 @@ function flip(y, size)
window.onload = e => { window.onload = e => {
for (const location in BoardLocations) for (const location in BoardLocations)
{ {
const x = location[0].toLowerCase(); const x = String.fromCharCode(parseInt(location.split(',')[0]) + 65).toLowerCase();
const y = location[1]; const y = parseInt(location.split(',')[1]) + 1;
const boardLocation = document.querySelector(`#row-${y}`).querySelector(`#col-${x}`); const boardLocation = document.querySelector(`#row-${y}`).querySelector(`#col-${x}`);
boardLocation.classList.add(BoardLookup[BoardLocations[location]]); boardLocation.classList.add(BoardLookup[BoardLocations[location]]);
@@ -69,27 +98,4 @@ window.onload = e => {
boardLocation.innerHTML = localeThing; boardLocation.innerHTML = localeThing;
} }
// flip it
for (const location in BoardLocations)
{
const x = location[0].toLowerCase();
let y = location[1];
y = flip(y, 15);
const boardLocation = document.querySelector(`#row-${y}`).querySelector(`#col-${x}`);
boardLocation.classList.add(BoardLookup[BoardLocations[location]]);
boardLocation.classList.add('unselectable');
let localeThing = BoardLocations[location];
if (localStorage.getItem('locale') === "es" || localStorage.getItem('locale') === "pt")
{
localeThing = localeThing.replace('W', 'P');
}
boardLocation.innerHTML = localeThing;
}
}; };

View File

@@ -76,17 +76,26 @@ function mouseUp(event)
if (selectedElement.pointerEvents != 'initial') if (selectedElement.pointerEvents != 'initial')
{ {
if (magnitude(selectedElement.velocity) <= 1) if (!selectedElement.velocity)
{ {
if (piecePlaced(selectedElement)) if (piecePlaced(selectedElement))
{ {
selectedElement.pointerEvents = 'initial'; selectedElement.pointerEvents = 'initial';
} }
} } else
else
{ {
slidePiece(selectedElement); if (magnitude(selectedElement.velocity) <= 1)
selectedElement.pointerEvents = 'initial'; {
if (piecePlaced(selectedElement))
{
selectedElement.pointerEvents = 'initial';
}
}
else
{
slidePiece(selectedElement);
selectedElement.pointerEvents = 'initial';
}
} }
} }
} }

View File

@@ -21,6 +21,8 @@ let Users = [];
// just shorthand, so long as i remember to keep it updated lmao // just shorthand, so long as i remember to keep it updated lmao
let MyTurn = false; let MyTurn = false;
let pastTurns = [];
function initGame(boardstate, tileset, myplayer, players) function initGame(boardstate, tileset, myplayer, players)
{ {
// construct piece array // construct piece array
@@ -90,6 +92,20 @@ function playMyTurn(stagedpieces)
{ {
if (!MyTurn) return false; if (!MyTurn) return false;
const turn = {
playeruid: Users.filter(e => e.me)[0].uid,
// servers job
turn: -1,
turntype: 'PLACE',
// servers job
outcome: {},
}
console.log(stagedpieces);
console.log(turn);
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ function addPiecesToDrawer(pieces)
domPiece.appendChild(score); domPiece.appendChild(score);
Drawer.appendChild(domPiece); Drawer.appendChild(domPiece);
ret.push (domPiece); ret.push(domPiece);
} }
setupPieces(); setupPieces();
@@ -99,6 +99,34 @@ function boardCoordsFromScreenSpace(ssx, ssy)
return {x: x, y: y}; return {x: x, y: y};
} }
function renderBoardState(pieces)
{
// adds all lol
for (const piece of pieces)
{
if (!getPieceFromBoard(piece.pos.x, piece.pos.y))
{
const domPiece = document.createElement('piece');
domPiece.innerText = piece.letter;
domPiece.classList.add('unselectable');
domPiece.classList.add('small-piece');
domPiece.classList.add('played-piece');
const score = document.createElement('score');
score.innerText = piece.score;
domPiece.dataset.coords = JSON.stringify(piece.pos);
domPiece.appendChild(score);
Drawer.appendChild(domPiece);
placePieceOnBoard(domPiece, piece.pos.x, piece.pos.y)
}
}
setupPieces();
}
// places for board coordinate (0-14) // places for board coordinate (0-14)
function placePieceOnBoard(piece, x, y) function placePieceOnBoard(piece, x, y)
{ {

View File

@@ -95,7 +95,7 @@ function onExchangeTiles()
function onSkipTurn() function onSkipTurn()
{ {
} }
function onPlayTurn() function onPlayTurn()