generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
5 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,90 @@ | ||
import axios from 'axios'; | ||
import { useState } from 'react'; | ||
import MenuGame from './MenuGame'; | ||
import LobbyGame from './LobbyGame'; | ||
import PlayingGame from './PlayingGame'; | ||
import ScoreboardGame from './ScoreboardGame'; | ||
export interface Question4Answers { | ||
question: string; | ||
correctAnswer: string; | ||
incorrectAnswer1: string; | ||
incorrectAnswer2: string; | ||
incorrectAnswer3: string; | ||
} | ||
|
||
export interface User { | ||
createdAt: string; | ||
nCorrectAnswers: number; | ||
nWins: number; | ||
nWrongAnswers: number; | ||
totalScore: number; | ||
username: string; | ||
uuid: string; | ||
} | ||
|
||
export interface Player { | ||
// can be a real player or bot | ||
username: string; | ||
points: number; | ||
} | ||
|
||
|
||
const Game = () => { | ||
|
||
const [questions, setQuestions] = useState<Question4Answers[]>([]); | ||
const [currentStage, setCurrentStage] = useState(1); | ||
const [players, setPlayers] = useState<Player[]>([]); | ||
|
||
// const userUUID = localStorage.getItem("userUUID"); | ||
const username = localStorage.getItem("username"); | ||
if(!username) return <p>error</p>; | ||
|
||
|
||
|
||
const createGame = async () => { | ||
|
||
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; | ||
|
||
try { | ||
setPlayers([ | ||
{ | ||
username: username, | ||
points: 0 | ||
} | ||
]) | ||
const requestData = { | ||
players: players, | ||
}; | ||
|
||
const response = await axios.post(`${apiEndpoint}/createGame`, requestData); | ||
|
||
const createdGame = response.data; | ||
|
||
setQuestions(createdGame.questions); | ||
console.log('Juego creado:', createdGame); | ||
|
||
|
||
setCurrentStage(1); | ||
return createdGame; | ||
} catch (error) { | ||
console.error('Error al crear el juego:', error); | ||
throw error; | ||
} | ||
}; | ||
const handlePlayers = () => { | ||
return setPlayers; | ||
} | ||
|
||
createGame(); | ||
return ( | ||
<div> | ||
{currentStage === 1 && (<MenuGame />)} | ||
{currentStage === 2 && (<LobbyGame players={players} setPlayers={handlePlayers}/>)} | ||
{currentStage === 3 && (<PlayingGame questions={questions}/>)} | ||
{currentStage === 4 && (<ScoreboardGame players={players}/>)} | ||
</div> | ||
|
||
) | ||
} | ||
|
||
export default Game; |
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,13 @@ | ||
import { FC } from 'react' | ||
import { Player } from './Game'; | ||
|
||
interface LobbyGameProps { | ||
setPlayers: () => void; | ||
players: Player[] | ||
} | ||
|
||
const LobbyGame: FC<LobbyGameProps> = ({}) => { | ||
return <div>LobbyGame</div> | ||
} | ||
|
||
export default LobbyGame |
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,11 @@ | ||
import { FC } from 'react' | ||
|
||
interface MenuGameProps { | ||
|
||
} | ||
|
||
const MenuGame: FC<MenuGameProps> = ({}) => { | ||
return <div>MenuGame</div> | ||
} | ||
|
||
export default MenuGame |
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,13 @@ | ||
import { FC } from 'react' | ||
import { Question4Answers } from './Game' | ||
|
||
interface PlayingGameProps { | ||
questions: Question4Answers[] | ||
} | ||
|
||
const PlayingGame: FC<PlayingGameProps> = ({questions}) => { | ||
console.log(questions) | ||
return <div>PlayingGame</div> | ||
} | ||
|
||
export default PlayingGame |
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,13 @@ | ||
import { FC } from 'react' | ||
import { Player} from './Game' | ||
|
||
interface ScoreboardGameProps { | ||
players?: Player[]; | ||
} | ||
|
||
const ScoreboardGame: FC<ScoreboardGameProps> = ({players}) => { | ||
console.log(players) | ||
return <div>ScoreboardGame</div> | ||
} | ||
|
||
export default ScoreboardGame |
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