forked 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
13 changed files
with
250 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const gameSchema = new mongoose.Schema({ | ||
userId:{ | ||
userId: { | ||
type: String, | ||
ref: 'User', | ||
required: true, | ||
}, | ||
questions: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref:'Question' | ||
ref: 'Question' | ||
} | ||
] | ||
|
||
], | ||
createdAt: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
const Game = mongoose.model('Game', gameSchema); | ||
|
||
module.exports = Game | ||
module.exports = 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,86 @@ | ||
import React, { useState, useEffect, useCallback } from 'react'; | ||
import axios from 'axios'; | ||
import { Container, Box, Typography, Grid, Button} from '@mui/material'; | ||
import { useUser } from './UserContext'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import HomeIcon from '@mui/icons-material/Home'; | ||
import '../App.css'; | ||
|
||
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; | ||
|
||
const EndGame = () => { | ||
|
||
const { usernameGlobal } = useUser(); | ||
const navigate = useNavigate(); | ||
const [endGame, setEndGame] = useState(''); | ||
const [error, setError] = useState(''); | ||
|
||
const getEndGame = useCallback(async () => { | ||
try { | ||
const response = await axios.get(`${apiEndpoint}/endgamestats`,{ | ||
params: { | ||
username: usernameGlobal | ||
} | ||
}); | ||
setEndGame(response.data); | ||
} catch (error) { | ||
setError(error.response.data.error); | ||
} | ||
}, [usernameGlobal]) | ||
|
||
function volverInicio() { | ||
navigate("/PantallaInicio"); | ||
} | ||
|
||
useEffect(() => { | ||
getEndGame(); | ||
}, [getEndGame]); | ||
|
||
return ( | ||
<Container component="main" maxWidth="xl" | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '100vh', | ||
width: '100%', | ||
}}> | ||
<Box border={2} borderColor="black" p={3} borderRadius={8} bgcolor="#9A77B0" width="30%" maxWidth={800} height="auto" maxHeight="600px"> | ||
<img src={require('./images/ronnie.gif')} alt="End Game" style={{ width: '100%', marginBottom: '16px', borderRadius: '8px' }} /> | ||
<Typography variant="h5" align="center" gutterBottom style={{ color: 'white', fontWeight: 'bold', marginBottom: '16px' }}> | ||
Estadísticas de la última partida | ||
</Typography> | ||
<Grid container spacing={3} justifyContent="center"> | ||
<Grid item xs={12} textAlign="center"> | ||
<Typography variant="body1" style={{ color: 'white', fontWeight: 'bold' }}> | ||
Preguntas correctas: {endGame.totalRightQuestions} | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={12} textAlign="center"> | ||
<Typography variant="body1" style={{ color: 'white', fontWeight: 'bold' }}> | ||
Preguntas incorrectas: {endGame.totalIncorrectQuestions} | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={12} textAlign="center"> | ||
<Typography variant="body1" style={{ color: 'white', fontWeight: 'bold' }}> | ||
Ratio de aciertos: {endGame.ratio} | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={12} textAlign="center"> | ||
<Typography variant="body1" style={{ color: 'white', fontWeight: 'bold' }}> | ||
Tiempo total: {endGame.totalTime} | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
<Box mt={3} textAlign="center"> | ||
<Button variant="contained" color="primary" align="center" style={{ marginTop: 4, backgroundColor: '#FCF5B8', color: '#413C3C', fontWeight: 'bold'}} onClick={volverInicio}> | ||
<HomeIcon style={{ marginRight: '8px' }} /> Volver al inicio | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default EndGame; |
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 |
---|---|---|
|
@@ -56,6 +56,7 @@ const PantallaInicio = () => { | |
)} | ||
|
||
</Container> | ||
|
||
); | ||
}; | ||
|
||
|
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,22 @@ | ||
import React from 'react'; | ||
import { Box, Typography } from '@mui/material'; | ||
|
||
const Footer = () => { | ||
return ( | ||
<Box | ||
component="footer" | ||
py={4} | ||
px={8} | ||
mt={8} | ||
sx={{ | ||
backgroundColor: '#9A77B0', | ||
color: 'black', | ||
textAlign: 'center' | ||
}} | ||
> | ||
<Typography variant="body1" fontWeight="bold">© {new Date().getFullYear()} ASW - WIQ_ES5B</Typography> | ||
</Box> | ||
); | ||
} | ||
|
||
export default Footer; |
Oops, something went wrong.