-
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
1 parent
41f625d
commit b08923b
Showing
14 changed files
with
189 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "aplicador.h" | ||
#include "comandos.h" | ||
#include "controlador_clicks.h" | ||
#include "estado_nivel.h" | ||
#include "general.h" | ||
#include "globales.h" | ||
|
||
#include "vista/botones_app.h" | ||
#include <variant> | ||
|
||
#define SWITCH(variante) \ | ||
using T = std::decay_t<decltype(comando_data)>; \ | ||
if (false) { /* Para inicializar los bloques if else */ \ | ||
} | ||
#define CASE(comando, accion) \ | ||
else if constexpr (std::is_same_v<T, Comando::comando>) { \ | ||
return accion; \ | ||
} | ||
|
||
/* | ||
Aplica un comando y devuelve la nueva | ||
fase, si correspondiera cambiar | ||
*/ | ||
std::optional<FaseNivel> aplicar_comando( // | ||
RealizadorBase &realizador, // | ||
const Comando &comando // | ||
|
||
) { | ||
return std::visit( | ||
[&realizador](auto &&comando_data) -> std::optional<FaseNivel> { | ||
SWITCH(comando_data) | ||
CASE(Empezar, realizador.empezar()) | ||
CASE(Salir, FaseNivel::Saliendo) | ||
CASE(Reiniciar, FaseNivel::Reiniciando) | ||
CASE(AlternarGrid, realizador.alternar_grid()) | ||
CASE(Encargar, realizador.encargar_pizza(comando_data.tp)) | ||
CASE(Despachar, realizador.despachar_pizza(comando_data.tp)) | ||
return std::nullopt; | ||
}, | ||
comando.comando_data | ||
); | ||
} | ||
#undef SWITCH | ||
#undef CASE |
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,15 @@ | ||
#pragma once | ||
|
||
#include "comandos.h" | ||
#include "general.h" | ||
#include "realizador_base.h" | ||
#include <optional> | ||
|
||
/* | ||
Aplica un comando y devuelve la nueva | ||
fase, si correspondiera cambiar | ||
*/ | ||
std::optional<FaseNivel> aplicar_comando( // | ||
RealizadorBase &realizador, // | ||
const Comando &comando // | ||
); |
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,17 @@ | ||
#include "modelo_amplio.h" | ||
#include "aplicador.h" | ||
#include "comandos.h" | ||
#include "general.h" | ||
#include "realizador.h" | ||
|
||
ModeloAmplio::ModeloAmplio(const DatosNivel &datos_nivel) | ||
: estado(FaseNivel::MostrandoInstrucciones, datos_nivel) {} | ||
|
||
std::optional<FaseNivel> ModeloAmplio::aplica_comando( // | ||
const Comando &comando // | ||
) { | ||
|
||
Realizador r{estado}; | ||
auto result = aplicar_comando(r, comando); | ||
return result; | ||
} |
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,41 @@ | ||
#include "realizador.h" | ||
#include "estado_nivel.h" | ||
#include "general.h" | ||
#include <cassert> | ||
|
||
Realizador::Realizador(Estado &estado) : estado(estado) {} | ||
|
||
/* Encarga una pizza a la cocina del tipo indicado */ | ||
NuevaFase Realizador::encargar_pizza( // | ||
const dominio::TipoPizza tp | ||
) { | ||
assert(estado.fase_actual == FaseNivel::Activa); | ||
estado.estado_modelo.anadir_encargo(tp); | ||
return std::nullopt; | ||
} | ||
|
||
/* | ||
* Despacha una pizza a los clientes del tipo indicado. Devuelve la nueva | ||
* fase si corresponde. | ||
*/ | ||
NuevaFase Realizador::despachar_pizza( // | ||
const dominio::TipoPizza tp | ||
) { | ||
assert(estado.fase_actual == FaseNivel::Activa); | ||
const auto pedidos_cubiertos = estado.estado_modelo.despachar_pizza(tp); | ||
if (pedidos_cubiertos) { | ||
return FaseNivel::EsperaAntesDeResultado; | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
NuevaFase Realizador::alternar_grid() { | ||
assert(MODO_DESARROLLO); | ||
estado.mostrando_grid = !estado.mostrando_grid; | ||
return std::nullopt; | ||
} | ||
|
||
NuevaFase Realizador::empezar() { | ||
assert(estado.fase_actual == FaseNivel::MostrandoInstrucciones); | ||
return FaseNivel::Activa; | ||
} |
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,30 @@ | ||
#pragma once | ||
|
||
#include "modelo/dominio.h" | ||
#include "realizador_base.h" | ||
|
||
struct Estado; | ||
|
||
class Realizador : public RealizadorBase { | ||
private: | ||
Estado &estado; | ||
|
||
public: | ||
Realizador(Estado &estado); | ||
|
||
/* Encarga una pizza a la cocina del tipo indicado */ | ||
NuevaFase encargar_pizza( // | ||
const dominio::TipoPizza tp | ||
); | ||
|
||
/* | ||
* Despacha una pizza a los clientes del tipo indicado. Devuelve la nueva | ||
* fase si corresponde. | ||
*/ | ||
NuevaFase despachar_pizza( // | ||
const dominio::TipoPizza tp | ||
); | ||
|
||
NuevaFase alternar_grid(); | ||
NuevaFase empezar(); | ||
}; |
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
Oops, something went wrong.