Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game page/connecting boards #17

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions client/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/static/css/main.c8e9aa28.css",
"main.js": "/static/js/main.d9f2fa70.js",
"main.css": "/static/css/main.dd8c6356.css",
"main.js": "/static/js/main.9f3dceeb.js",
"static/media/forest_animation.mp4": "/static/media/forest_animation.239347dfe9755133bd14.mp4",
"static/media/wall-background.mp4": "/static/media/wall-background.9691b868f5274a0471f2.mp4",
"static/media/cryptid-background.mp4": "/static/media/cryptid-background.af864c7aa5878e2d51e9.mp4",
Expand Down Expand Up @@ -34,11 +34,11 @@
"static/media/question.svg": "/static/media/question.d7dd2c99fbcd281ede054bd70207345c.svg",
"static/media/info.svg": "/static/media/info.86375dfea0b36eba22b87e3829720254.svg",
"index.html": "/index.html",
"main.c8e9aa28.css.map": "/static/css/main.c8e9aa28.css.map",
"main.d9f2fa70.js.map": "/static/js/main.d9f2fa70.js.map"
"main.dd8c6356.css.map": "/static/css/main.dd8c6356.css.map",
"main.9f3dceeb.js.map": "/static/js/main.9f3dceeb.js.map"
},
"entrypoints": [
"static/css/main.c8e9aa28.css",
"static/js/main.d9f2fa70.js"
"static/css/main.dd8c6356.css",
"static/js/main.9f3dceeb.js"
]
}
2 changes: 1 addition & 1 deletion client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Cryptid</title><script defer="defer" src="/static/js/main.d9f2fa70.js"></script><link href="/static/css/main.c8e9aa28.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Cryptid</title><script defer="defer" src="/static/js/main.9f3dceeb.js"></script><link href="/static/css/main.dd8c6356.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1 change: 0 additions & 1 deletion client/build/static/css/main.c8e9aa28.css.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/css/main.dd8c6356.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/js/main.9f3dceeb.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/build/static/js/main.d9f2fa70.js.map

This file was deleted.

12 changes: 6 additions & 6 deletions client/src/Components/Board.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions client/src/Components/BoardInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default function BoardInfo( props ) {
props.setTurn(props.turn + 1);
} else {
state.playerTurn += 1;
props.setTurn(props.turn + 1);
}
props.setGameState(state);
setPlayerNum(props.gameState.playerTurn);
Expand Down Expand Up @@ -119,11 +120,16 @@ export default function BoardInfo( props ) {
return <div className='player-dropdown'>
{players.filter(num => num !== playerNum).map((num) => (
<div key={num} className='player-dropdown-item' style={{background: `${colours[num]}`}} onClick={() => handlePlayerChange(num)}>
{props.playerNames[num-1]}
{props.playerNames[num-1] ? props.playerNames[num-1] : `Player ${num}`}
</div>
))}
</div>
}

const handleToggleShowAvailableGuesses = () => {
console.log(props.showAvailableGueses);
props.setShowAvailableGuesses(!props.showAvailableGueses);
}

// Render the main structure of the BoardInfo component
return (
Expand Down Expand Up @@ -163,7 +169,7 @@ export default function BoardInfo( props ) {
<img className='header-icon' src={avatar} /><h2>TURN</h2>
</div>
<div className='text'>
{props.playerNames[playerNum-1]}
{props.playerNames[playerNum-1] ? props.playerNames[playerNum-1] : `Player ${playerNum}`}

{showPlayerDropdown ? handleShowPlayerDropdown()
:
Expand Down Expand Up @@ -234,6 +240,12 @@ export default function BoardInfo( props ) {
</div> : <></>}
</li>

<li className='board-info-information-item'>
<div className='board-info-information-item-text' onClick={handleToggleShowAvailableGuesses}>
Toggle: Show only valid hexes based on clue ({props.showAvailableGueses ? `Currently On` : `Currently Off`})
</div>
</li>

{!viewHint
?
<li className='board-info-information-item' onClick={handleViewHint}>
Expand Down
4 changes: 3 additions & 1 deletion client/src/Components/Hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import search from '../Icons/search.svg'

export default function Hex( props ) {

console.log(props.validGuess)

// State variables for mouse coordinates and tooltip visibility
const [mouseX, setMouseX] = useState(0);
const [mouseY, setMouseY] = useState(0);
Expand Down Expand Up @@ -140,7 +142,7 @@ export default function Hex( props ) {
}

return (
<div className={'hex hex-'+props.hexNum+' '+(props.revealCryptid ? revealCryptidStyle() : '')} >
<div className={'hex hex-'+props.hexNum+' '+(props.revealCryptid ? revealCryptidStyle() : '')+(props.showAvailableGueses ? ' '+(props.validGuess ? 'hex-valid-guess' : 'hex-invalid-guess') : '')} >
<div className='hex-hitbox' onClick={handleClick} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}></div>
<div className='hex-top-bottom bottom-face'>
<div className='top'></div>
Expand Down
15 changes: 14 additions & 1 deletion client/src/Components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,24 @@ export default function Map( props ) {
// We repeat similar checks for all the other piece types
return allPieces;
}

const validatePieceGuess = (row, col, tileNumByPosition) => {
for (let i = 0; i < props.allAvailableGuesses.length; i++) {
const hex = props.allAvailableGuesses[i];

if (hex.row === row && hex.col === col && hex.tileNumByPosition === tileNumByPosition) {
return true;
}
}

return false;
}

return (
<div className={'map-root '+'map-root-'+props.mapSide}>
<div className='map-number'>{props.mapNum}</div>
{ props.hexes.map((hex) => {
return <Hex turn={props.turn} movesList={props.movesList} setMovesList={props.setMovesList} destination={props.destination} revealCryptid={props.revealCryptid} placeSearch={props.placeSearch} setPlaceSearch={props.setPlaceSearch} placePositive={props.placePositive} setPlacePositive={props.setPlacePositive} placeNegative={props.placeNegative} setPlaceNegative={props.setPlaceNegative} gameState={props.gameState} setGameState={props.setGameState} setHexHover={props.setHexHover} tileNum={props.mapNum} tileNumByPosition={props.tileNumByPosition} pieces={getAllPieces(hex.row*6 + hex.col)} type={hex.type} animalTerritory={hex.animal_territory} hexNum={hex.row*6 + hex.col} hexRow={hex.row} hexCol={hex.col} picture={require(`../Images/CryptidTiles/Board ${hex.tile_number}/${hex.tile_image}`)}></Hex>
return <Hex showAvailableGueses={props.showAvailableGueses} validGuess={validatePieceGuess(hex.row, hex.col, props.tileNumByPosition)} turn={props.turn} movesList={props.movesList} setMovesList={props.setMovesList} destination={props.destination} revealCryptid={props.revealCryptid} placeSearch={props.placeSearch} setPlaceSearch={props.setPlaceSearch} placePositive={props.placePositive} setPlacePositive={props.setPlacePositive} placeNegative={props.placeNegative} setPlaceNegative={props.setPlaceNegative} gameState={props.gameState} setGameState={props.setGameState} setHexHover={props.setHexHover} tileNum={props.mapNum} tileNumByPosition={props.tileNumByPosition} pieces={getAllPieces(hex.row*6 + hex.col)} type={hex.type} animalTerritory={hex.animal_territory} hexNum={hex.row*6 + hex.col} hexRow={hex.row} hexCol={hex.col} picture={require(`../Images/CryptidTiles/Board ${hex.tile_number}/${hex.tile_image}`)}></Hex>
})
}
</div>
Expand Down
38 changes: 35 additions & 3 deletions client/src/Pages/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export default function Game( props ) {

const [playerNames, setPlayerNames] = useState(["","","","",""]);

const [turn, setTurn] = useState(1);
const [turn, setTurn] = useState(1);

const [allAvailableGuesses, setAllAvailableGuesses] = useState({});
const [showAvailableGueses, setShowAvailableGuesses] = useState(false);

const handlePlaceNegative = (value) => {
setPlacePositive(false);
Expand Down Expand Up @@ -138,9 +141,35 @@ export default function Game( props ) {
const grid = await parseInfo(newMap, allTiles, allPieces);
console.log(grid);
const availableGuesses = getAvailableGuesses(grid);
setAllAvailableGuesses(availableGuesses);
return newMap;
}

const processHexNumbers = (availableGuesses) => {
for (let player = 1; player <= props.localGameInfo.players; player++) {
const newAvailableGuesses = availableGuesses[player];
for (let i = 0; i < newAvailableGuesses.length; i++) {
const tile = newAvailableGuesses[i];
const row = tile.row;
const col = tile.col;

// Retrieve which tile number we are on
const tile_row = Math.floor(row/3);
const tile_col = Math.floor(col/6);
const tile_num = tile_row*2 + tile_col + 1

const actual_row = row % 3;
const actual_col = col % 6;

newAvailableGuesses[i].row = actual_row;
newAvailableGuesses[i].col = actual_col;
newAvailableGuesses[i].tileNumByPosition = tile_num;
}
availableGuesses[player] = newAvailableGuesses;
}
return availableGuesses;
}

const getAvailableGuesses = (boardState) => {
const { grid, clues, hint } = boardState;
const availableGuesses = {};
Expand All @@ -152,8 +181,7 @@ export default function Game( props ) {
const allowedTiles = processClue(clue, grid);
availableGuesses[player] = allowedTiles;
}
console.log(availableGuesses)
return availableGuesses;
return processHexNumbers(availableGuesses);
}


Expand Down Expand Up @@ -354,6 +382,8 @@ export default function Game( props ) {
<div className='game-board-info'>
{!revealCryptid ?
<BoardInfo
showAvailableGueses={showAvailableGueses}
setShowAvailableGuesses={setShowAvailableGuesses}
turn={turn}
setTurn={setTurn}
numPlayers={props.localGameInfo.players}
Expand Down Expand Up @@ -383,6 +413,8 @@ export default function Game( props ) {
<div className='game-board-container'>
<div className='game-board-root'>
<Board
showAvailableGueses={showAvailableGueses}
allAvailableGuesses={allAvailableGuesses}
turn={turn}
setTurn={setTurn}
movesList={props.movesList}
Expand Down
6 changes: 6 additions & 0 deletions client/src/Styles/Hex.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@
opacity: 0.5;
transition: 3s;
}

.hex-invalid-guess > * {
filter: grayscale(0.5);
opacity: 0.1;
pointer-events: none;
}
Loading