draw works
This commit is contained in:
29
src/layout/components/Deck.tsx
Normal file
29
src/layout/components/Deck.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import React, {FunctionComponent} from "react";
|
||||||
|
import Card from "./Card";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
currentCard: string;
|
||||||
|
actionOnClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Deck: FunctionComponent<Props> = ({currentCard, actionOnClick}) => {
|
||||||
|
|
||||||
|
const handleClick = (card: string) => {
|
||||||
|
actionOnClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="deck-container">
|
||||||
|
<div className="used-cards">
|
||||||
|
<p></p>
|
||||||
|
<Card cardString={currentCard}/>
|
||||||
|
</div>
|
||||||
|
<div className="deck">
|
||||||
|
<p></p>
|
||||||
|
<Card cardString={"AA BB"} handleClick={handleClick} isHidden={true}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Deck;
|
||||||
@@ -5,6 +5,7 @@ import {GHButton} from "../components/Button";
|
|||||||
import useTitle from "../../utils/TitleHook";
|
import useTitle from "../../utils/TitleHook";
|
||||||
import Card from "../components/Card";
|
import Card from "../components/Card";
|
||||||
import Hand from "../components/Hand";
|
import Hand from "../components/Hand";
|
||||||
|
import Deck from "../components/Deck";
|
||||||
|
|
||||||
interface GameState {
|
interface GameState {
|
||||||
PlayerName: string;
|
PlayerName: string;
|
||||||
@@ -39,8 +40,19 @@ const Room = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleCardSend = (card: string) => {
|
const handleCardSend = (card: string) => {
|
||||||
const formattedCard = JSON.stringify({CardType: card.split(' ')[0], CardValue: card.split(' ')[1]});
|
const formattedAction = JSON.stringify({
|
||||||
websocket.sendMessage(formattedCard);
|
Action: "PLAYCARD",
|
||||||
|
Data: JSON.stringify({CardType: card.split(' ')[0], CardValue: card.split(' ')[1]})
|
||||||
|
});
|
||||||
|
websocket.sendMessage(formattedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDraw = () => {
|
||||||
|
const formattedAction = JSON.stringify({
|
||||||
|
Action: "DRAW",
|
||||||
|
Data: ""
|
||||||
|
});
|
||||||
|
websocket.sendMessage(formattedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -49,9 +61,12 @@ const Room = () => {
|
|||||||
<GHButton onClick={handleLeaveRoom}>Leave Room</GHButton>
|
<GHButton onClick={handleLeaveRoom}>Leave Room</GHButton>
|
||||||
{
|
{
|
||||||
gameState.CurrentCard &&
|
gameState.CurrentCard &&
|
||||||
<Card cardString={gameState.CurrentCard}/>
|
<Deck currentCard={gameState.CurrentCard} actionOnClick={handleDraw} />
|
||||||
|
}
|
||||||
|
{
|
||||||
|
gameState.Hand &&
|
||||||
|
<Hand hand={gameState.Hand} actionOnClick={handleCardSend}/>
|
||||||
}
|
}
|
||||||
<Hand hand={gameState.Hand} actionOnClick={handleCardSend}/>
|
|
||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
gameState.Players.map((player, index) => {
|
gameState.Players.map((player, index) => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
@import "button";
|
@import "button";
|
||||||
@import "card";
|
@import "card";
|
||||||
@import "hand";
|
@import "hand";
|
||||||
|
@import "deck";
|
||||||
6
src/styles/layout/components/deck.scss
Normal file
6
src/styles/layout/components/deck.scss
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.deck-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user