From 8a172e2ad2c78371eccea17a537499fa7ff6f765 Mon Sep 17 00:00:00 2001 From: Wenszel Date: Mon, 6 Jun 2022 19:50:26 +0200 Subject: [PATCH] added dice visibility for other players --- src/App.js | 3 --- src/components/Gameboard.jsx | 18 ++++++++++++---- src/components/Navbar.css | 21 ++++++++++++++++--- src/components/Navbar.jsx | 14 +++++++++++-- src/components/game-board-components/Dice.jsx | 13 +++++++----- .../navbar-components/NameContainer.jsx | 2 +- src/index.css | 6 ++++++ 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/App.js b/src/App.js index cc215aa..fa208b4 100644 --- a/src/App.js +++ b/src/App.js @@ -20,9 +20,6 @@ function App() { setPlayerData(data); data.roomId != null ? setRedirect(true) : setRedirect(false); }); - socket.on('uwaga', data => { - console.log(data); - }); setPlayerSocket(socket); }, []); diff --git a/src/components/Gameboard.jsx b/src/components/Gameboard.jsx index f6860be..86e85e7 100644 --- a/src/components/Gameboard.jsx +++ b/src/components/Gameboard.jsx @@ -55,10 +55,10 @@ const Gameboard = () => { setRolledNumber(null); setNowMoving(false); } + setMovingPlayer(nowMovingPlayer.color); } const currentPlayer = data.players.find(player => player._id === context.playerId); checkWin(); - setMovingPlayer(nowMovingPlayer.color); setIsReady(currentPlayer.ready); setPlayers(data.players); setPawns(data.pawns); @@ -76,11 +76,14 @@ const Gameboard = () => { <> {players ? ( <> - - @@ -93,3 +96,10 @@ const Gameboard = () => { }; export default Gameboard; +/* +*/ diff --git a/src/components/Navbar.css b/src/components/Navbar.css index 79e823d..e95ea1a 100644 --- a/src/components/Navbar.css +++ b/src/components/Navbar.css @@ -1,14 +1,29 @@ +.red { + position: relative; + left: 176px; +} .yellow { position: relative; - left: 38px; + flex-direction: row-reverse; + right: 170px; } .blue { position: relative; + right: 28px; top: 538px; - right: 114px; } .green { position: relative; + flex-direction: row-reverse; top: 538px; - left: 152px; + left: 36px; +} +.player-container { + display: flex; +} +.dice-container { + margin-left: 20px; + margin-right: 20px; + width: 50px; + height: 50px; } diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 4056aa0..14a3ac1 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -1,14 +1,24 @@ import React from 'react'; +import Dice from './game-board-components/Dice'; import NameContainer from './navbar-components/NameContainer'; import ReadyButton from './navbar-components/ReadyButton'; import './Navbar.css'; -const Navbar = ({ players, started, time, isReady }) => { +const Navbar = ({ players, started, time, isReady, rolledNumber, nowMoving, rolledNumberCallback, movingPlayer }) => { const colors = ['red', 'blue', 'green', 'yellow']; return (
{players.map((player, index) => ( - +
+ + +
))} {started ? null : }
diff --git a/src/components/game-board-components/Dice.jsx b/src/components/game-board-components/Dice.jsx index c4cb9dc..72e3a14 100644 --- a/src/components/game-board-components/Dice.jsx +++ b/src/components/game-board-components/Dice.jsx @@ -6,7 +6,8 @@ import three from '../../images/dice/3.png'; import four from '../../images/dice/4.png'; import five from '../../images/dice/5.png'; import six from '../../images/dice/6.png'; -const Dice = ({ rolledNumberCallback, rolledNumber, nowMoving, color }) => { + +const Dice = ({ rolledNumberCallback, rolledNumber, nowMoving, color, movingPlayer }) => { const socket = useContext(SocketContext); const [images] = useState([one, two, three, four, five, six]); const handleRoll = () => { @@ -19,10 +20,12 @@ const Dice = ({ rolledNumberCallback, rolledNumber, nowMoving, color }) => { }, []); return (
- {true ? ( - {rolledNumber} - ) : nowMoving ? ( - + {movingPlayer === color ? ( + rolledNumber ? ( + {rolledNumber} + ) : nowMoving ? ( + + ) : null ) : null}
); diff --git a/src/components/navbar-components/NameContainer.jsx b/src/components/navbar-components/NameContainer.jsx index 47e345b..18617ba 100644 --- a/src/components/navbar-components/NameContainer.jsx +++ b/src/components/navbar-components/NameContainer.jsx @@ -20,7 +20,7 @@ const NameContainer = ({ player, time, color }) => { }, [countdown]); return (

{player.name}

diff --git a/src/index.css b/src/index.css index 771d70d..97dff06 100644 --- a/src/index.css +++ b/src/index.css @@ -49,3 +49,9 @@ canvas { height: 20px; border-radius: 5px; } +#root { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +}