Skip to content

Commit

Permalink
Merge pull request #60 from Arquisoft/pablo
Browse files Browse the repository at this point in the history
Implementacion contador preguntas y cambios CSS
  • Loading branch information
uo264915 authored Mar 7, 2024
2 parents 19b8584 + 18fe66d commit 4d72020
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 15 deletions.
Binary file added docs/images/07-Deployment View.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/10_1_Quality_Tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/DeplymentViewTest.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions webapp/src/components/Game.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
button[title="sigPreg"] {
margin: 1em;
margin-left: 2em;
background-color: rgba(31, 60, 134, 0.764);
}

button[title="contador"]:disabled{
margin: 1em;
background-color: rgba(31, 60, 134, 0.764);
color: white;
}

button[title="btnsPreg"]{
margin: 0.5em;
padding-top: 0.2em;
padding-bottom: 0.2em;
background-color: rgba(41, 120, 152, 0.764);
}

49 changes: 40 additions & 9 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
import React, { useState } from 'react';
import axios from 'axios';
import { Container, Typography, Button, Paper } from '@mui/material';
import './Game.css';

const colorPreguntas= 'rgba(51, 139, 173, 0.764)';
const colorOnMousePreguntas= 'rgba(28, 84, 106, 0.764)';

const Game = () => {
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

const [country, setCountry] = useState('');
const [capitalCorrect, setCapitalCorrect] = useState('');
const [capitalOptions, setcapitalOptions] = useState([]);
const [count, setCount] = useState(0);

// This method will call the create question service
const handleShowQuestion = async () => {
Expand All @@ -19,6 +24,13 @@ const Game = () => {
setCountry(response.data.responseCountry);
setCapitalCorrect(response.data.responseCapitalCorrect);
setcapitalOptions(response.data.responseCapitalOptions);
const buttons = document.querySelectorAll('button[title="btnsPreg"]');
buttons.forEach(button => {
button.name = "sinContestar";
button.disabled = false;
button.style.backgroundColor = colorPreguntas;
button.onmouse = colorOnMousePreguntas;
});
}catch (error){
console.error('Error:', error);
}
Expand All @@ -28,15 +40,31 @@ const Game = () => {
const handleAnswerClick = (option, index) => {
// Get what component is the button to change its color later
//const button = document.getElementById(`button_${index}`);
if(option === capitalCorrect){
//button.style.backgroundColor = "green";
alert("CORRECTO");
if(option === capitalCorrect) {
const buttonId = `button_${index}`;
const correctButton = document.getElementById(buttonId);
if (correctButton) {
correctButton.style.backgroundColor = "rgba(79, 141, 18, 0.726)";
increment();
}
}else{
//button.style.backgroundColor = "red";
alert("INCORRECTO");
const buttonId = `button_${index}`;
const incorrectButton = document.getElementById(buttonId);
incorrectButton.style.backgroundColor = "rgba(208, 22, 22, 0.952)";
}

const buttons = document.querySelectorAll('button[title="btnsPreg"]');
buttons.forEach(button => {
button.disabled = true;
button.onmouse = null;
});

}

const increment = () => {
setCount(count + 1);
};

return (
<Container maxWidth="md" style={{ marginTop: '2rem' }}>
<Paper elevation={3} style={{ padding: '2rem', textAlign: 'center' }}>
Expand All @@ -46,16 +74,19 @@ const Game = () => {
<Typography variant="body1" paragraph>
Pregunta: ¿Cuál es la capital de {country}?
</Typography>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginTop: '20px' }}>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', alignItems: 'center', marginTop: '2em' }}>
{capitalOptions.map((option, index) => (
<Button id={`button_${index}`} key={index} variant="contained" color="primary" onClick={() => handleAnswerClick(option,index)} >
<Button id={`button_${index}`} title="btnsPreg" key={index} variant="contained" color="primary" onClick={() => handleAnswerClick(option,index)} >
{option}
</Button>
))}
</div>
</Paper>
<Button variant="contained" color="primary" onClick={handleShowQuestion}>
Genera pregunta
<Button title="contador" onmouse="null" variant="contained" color="primary" disabled="true" >
Correctas: {count}
</Button>
<Button title="sigPreg" variant="contained" color="primary" onClick={handleShowQuestion}>
Siguiente pregunta
</Button>
</Container>
);
Expand Down
33 changes: 33 additions & 0 deletions webapp/src/components/Juego.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Juego.js
import React from 'react';
import { Button, Typography, Container, Paper } from '@mui/material';

function Juego() {
return (
<Container maxWidth="md" style={{ marginTop: '2rem' }}>
<Paper elevation={3} style={{ padding: '2rem', textAlign: 'center' }}>
<Typography variant="h4" gutterBottom>
Saber y Ganar Juego
</Typography>
<Typography variant="body1" paragraph>
Pregunta: ¿Cuál es la capital de Francia?
</Typography>
{/* Botones de opción */}
<Button variant="outlined" style={{ margin: '0.5rem' }}>
Opción A
</Button>
<Button variant="outlined" style={{ margin: '0.5rem' }}>
Opción B
</Button>
<Button variant="outlined" style={{ margin: '0.5rem' }}>
Opción C
</Button>
<Button variant="outlined" style={{ margin: '0.5rem' }}>
Opción D
</Button>
</Paper>
</Container>
);
}

export default Juego;

0 comments on commit 4d72020

Please sign in to comment.