-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ThePhoenix08/responsive
Make 4-player chess app responsive and refactor chess piece mechanics
- Loading branch information
Showing
14 changed files
with
537 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
.game-layout { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.game-layout > .middle-panel { | ||
display: flex; | ||
} | ||
|
||
.game-layout > .panel-area, .game-layout > .middle-panel > .panel-area { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 4px; | ||
} | ||
|
||
.middle-panels > .player-panel { | ||
writing-mode: vertical-rl; | ||
height: calc(var(--tile-size) * 8); | ||
width: .5vw; | ||
} | ||
|
||
.game-layout > .panel-area > .player-panel { | ||
height: .5vw; | ||
width: calc(var(--tile-size) * 8); | ||
} | ||
|
||
div#left-panel { | ||
transform: rotate(-180deg); | ||
} | ||
|
||
.player-panel { | ||
padding: 10px 15px; | ||
border: 2px solid transparent; | ||
border-radius: 10px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.game-display { | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
width: fit-content; | ||
margin: 0 auto; | ||
padding: .2vh 3vw; | ||
gap: 10px; | ||
border: 2px solid whitesmoke; | ||
height: var(--tile-size); | ||
border-radius: var(--tile-size); | ||
margin-bottom: 10px; | ||
} | ||
|
||
.game-display > .currentPlayerDisplay { | ||
color: whitesmoke; | ||
padding: 2px 10px; | ||
border-radius: calc(1rem + 2px); | ||
} | ||
|
||
.game-display > .interactionModeToggleDiv { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.game-display > .interactionModeToggleDiv > .interactionModeToggleBtn { | ||
padding: 5px; | ||
border-radius: calc(1rem + 5px); | ||
width: 5vw; | ||
min-width: fit-content; | ||
} | ||
|
||
@media all and (max-width: 768px) { | ||
/* phone styles here */ | ||
.game-layout > .panel-area, .game-layout > .middle-panel > .panel-area { | ||
padding: 2px; | ||
} | ||
|
||
.player-panel > .player-name { | ||
display: none; | ||
} | ||
|
||
.middle-panels > .player-panel { | ||
padding: 0; | ||
width: 2px; | ||
} | ||
|
||
.game-layout > .panel-area > .player-panel { | ||
padding: 0; | ||
height: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import "./ChessWrapper.css"; | ||
import { useChessContext } from "../context/ChessContext"; | ||
|
||
/** Wrapper component for the chess board, holds player panels surrounding the board */ | ||
export default function ChessWrapper({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const { currentPlayer } = useChessContext(); | ||
const {interactionMode, setInteractionMode} = useChessContext(); | ||
|
||
const players = [ | ||
{ name: "Red Player", color: "red", id: "r" }, | ||
{ name: "Blue Player", color: "blue", id: "b" }, | ||
{ name: "Yellow Player", color: "yellow", id: "y" }, | ||
{ name: "Green Player", color: "green", id: "g" }, | ||
]; | ||
|
||
const displayBgColor = players.find((p) => p.id === currentPlayer)?.color || "grey"; | ||
|
||
return ( | ||
<div className="chess-wrapper"> | ||
<div className="game-display"> | ||
<div className="currentPlayerDisplay" style={{backgroundColor: displayBgColor}}> | ||
{players.find((p) => p.id === currentPlayer)?.name} | ||
</div> | ||
<div className="interactionModeToggleDiv"> | ||
<button | ||
className="interactionModeToggleBtn" | ||
onClick={() => setInteractionMode(interactionMode === "drag" ? "select" : "drag")} | ||
>{interactionMode === "drag" ? "Select" : "Drag"}</button> | ||
</div> | ||
</div> | ||
<div className="game-layout"> | ||
<div className="panel-area"> | ||
<PlayerPanel | ||
name="Yellow Player" | ||
color="yellow" | ||
isActive={currentPlayer === "y"} | ||
/> | ||
</div> | ||
<div className="middle-panel"> | ||
<div className="panel-area middle-panels" id="left-panel"> | ||
<PlayerPanel | ||
name="Blue Player" | ||
color="blue" | ||
isActive={currentPlayer === "b"} | ||
/> | ||
</div> | ||
<div className="panel-area chessboard-container">{children}</div> | ||
<div className="panel-area middle-panels"> | ||
<PlayerPanel | ||
name="Green Player" | ||
color="green" | ||
isActive={currentPlayer === "g"} | ||
/> | ||
</div> | ||
</div> | ||
<div className="panel-area"> | ||
<PlayerPanel | ||
name="Red Player" | ||
color="red" | ||
isActive={currentPlayer === "r"} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
interface PlayerPanelProps { | ||
name: string; | ||
color: string; | ||
isActive: boolean; | ||
} | ||
|
||
/** Player panel component, holds player name and indicates active player */ | ||
function PlayerPanel({ name, color, isActive }: PlayerPanelProps) { | ||
return ( | ||
<div | ||
className={`player-panel ${isActive ? "active" : ""}`} | ||
style={{ backgroundColor: isActive ? color : "grey" }} | ||
> | ||
<div className="player-name">{name}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.