Add files via upload
This commit is contained in:
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
#ifdef _DEBUG
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#ifndef DBG_NEW
|
||||
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
|
||||
#define new DBG_NEW
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,46 @@
|
||||
#include "coordenada.h"
|
||||
|
||||
tCoordenada crearCoordenada(int f, int c)
|
||||
{
|
||||
tCoordenada coordenada;
|
||||
coordenada._fila = f; coordenada._columna = c;
|
||||
return coordenada;
|
||||
}
|
||||
|
||||
|
||||
bool operator== (const tCoordenada &c1, const tCoordenada &c2)
|
||||
{
|
||||
return c1._fila == c2._fila && c1._columna == c2._columna;
|
||||
}
|
||||
|
||||
bool operator!= (const tCoordenada &c1, const tCoordenada &c2)
|
||||
{
|
||||
return !(c1 == c2);
|
||||
}
|
||||
|
||||
int fila(const tCoordenada &c){
|
||||
return c._fila;
|
||||
}
|
||||
int columna(const tCoordenada &c)
|
||||
{
|
||||
return c._columna;
|
||||
}
|
||||
|
||||
void calcularCoordenada(const tCoordenada & c, int dir, tCoordenada & nc)
|
||||
{
|
||||
if ((0 <= dir) && (dir <= 2)) { nc._fila = c._fila - 1; }
|
||||
else if ((dir == 3) || (dir == 7)) { nc._fila = c._fila; }
|
||||
else { nc._fila = c._fila + 1; }
|
||||
switch (dir)
|
||||
{
|
||||
case 0:
|
||||
case 6:
|
||||
case 7:
|
||||
nc._columna = c._columna - 1; break;
|
||||
case 1:
|
||||
case 5: nc._columna = c._columna; break;
|
||||
default: nc._columna = c._columna + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#ifndef _coordenada
|
||||
#define _coordenada
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct { int _fila; int _columna; } tCoordenada;
|
||||
|
||||
|
||||
//Dada una fila y una columna construye una coordenada con ellas
|
||||
tCoordenada crearCoordenada(int f, int c);
|
||||
|
||||
//Consulta la componente fila de una coordenada
|
||||
int fila(const tCoordenada &c);
|
||||
|
||||
//Consulta la componente columna de una coordenada
|
||||
int columna(const tCoordenada &c);
|
||||
|
||||
|
||||
//Dada una coordenada y una direcci<63>n(entre 0 y 7 inclusive),
|
||||
//calcula una nueva coordenada en la direcci<63>n indicada, segun el siguiente dibujo
|
||||
// 0 1 2
|
||||
// 7 3
|
||||
// 6 5 4
|
||||
//Esta funcion no comprueba si la nueva coordenada esta dentro de los limites del jardin.
|
||||
void calcularCoordenada(const tCoordenada & c, int dir, tCoordenada & nc);
|
||||
|
||||
//Funciones para comprobar la igualdad o desigualdad de dos coordenadas
|
||||
bool operator== (const tCoordenada &c1, const tCoordenada &c2);
|
||||
bool operator!= (const tCoordenada &c1, const tCoordenada &c2);
|
||||
|
||||
|
||||
#endif
|
93
Exámenes Resueltos (Segundo Semestre)/Junio2018AB/jardin.cpp
Normal file
93
Exámenes Resueltos (Segundo Semestre)/Junio2018AB/jardin.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
#include "jardin.h"
|
||||
using namespace std;
|
||||
|
||||
bool cargarJardin(tJardin& jardin, ifstream& archivo) {
|
||||
bool carga = false;
|
||||
int F, C;
|
||||
//ifstream archivo;
|
||||
|
||||
//archivo.open(jardin);
|
||||
//if (!archivo.is_open()) {
|
||||
// cout << "No se ha podido cargar el jardin." << endl;
|
||||
//}
|
||||
//else {
|
||||
archivo >> jardin.numF;
|
||||
archivo >> jardin.numC;
|
||||
for (int i = 0; i < jardin.numF; i++){
|
||||
for (int j = 0; j < jardin.numC; j++){
|
||||
archivo >> jardin.parcela[i][j].aguaNecesaria;
|
||||
jardin.parcela[i][j].aguaRegada = 0;
|
||||
}
|
||||
}
|
||||
carga = true;
|
||||
//}
|
||||
//archivo.close();
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
void mostrarJardin(tJardin& jardin) {
|
||||
for (int i = 0; i < jardin.numF; i++){
|
||||
for (int j = 0; j < jardin.numC; j++){
|
||||
cout << jardin.parcela[i][j].aguaNecesaria << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void regar(tJardin& jardin, tCoordenada& coordenada) {
|
||||
tCoordenada nc;
|
||||
|
||||
for (int i = 0; i < 8; i++){
|
||||
calcularCoordenada(coordenada, i, nc);
|
||||
jardin.parcela[nc._fila][nc._columna].aguaRegada++;
|
||||
}
|
||||
}
|
||||
|
||||
int calcularPuntuacion(tJardin& jardin) {
|
||||
int puntos = 0;
|
||||
|
||||
for (int i = 0; i < jardin.numF; i++){
|
||||
for (int j = 0; j < jardin.numC; j++){
|
||||
if (jardin.parcela[i][j].aguaRegada > jardin.parcela[i][j].aguaNecesaria) {
|
||||
puntos += (jardin.parcela[i][j].aguaRegada - jardin.parcela[i][j].aguaNecesaria);
|
||||
}
|
||||
else if (jardin.parcela[i][j].aguaRegada == jardin.parcela[i][j].aguaNecesaria) {
|
||||
puntos += jardin.parcela[i][j].aguaNecesaria;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return puntos;
|
||||
}
|
||||
|
||||
bool plantaCondenada(tJardin& jardin, tCoordenada& coordenada) {
|
||||
bool encontrada = false;
|
||||
int i = -1, j = 0;
|
||||
|
||||
while (!encontrada && i < jardin.numF) {
|
||||
i++;
|
||||
while (!encontrada && j < jardin.numC) {
|
||||
if (jardin.parcela[i][j].aguaNecesaria < jardin.parcela[i][j].aguaRegada) {
|
||||
encontrada = true;
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coordenada = crearCoordenada(i, j);
|
||||
|
||||
return encontrada;
|
||||
}
|
||||
|
||||
bool esLibre(const tJardin& jardin, tCoordenada coordenada) {
|
||||
bool libre = false;
|
||||
|
||||
if (coordenada._fila < jardin.numF && coordenada._columna < jardin.numC && jardin.parcela[coordenada._fila][coordenada._columna].aguaNecesaria == 0) {
|
||||
libre = true;
|
||||
}
|
||||
|
||||
return libre;
|
||||
}
|
33
Exámenes Resueltos (Segundo Semestre)/Junio2018AB/jardin.h
Normal file
33
Exámenes Resueltos (Segundo Semestre)/Junio2018AB/jardin.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef _JARDIN
|
||||
#define _JARDIN
|
||||
|
||||
#include "coordenada.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
//Constantes:
|
||||
const int DIM = 50;
|
||||
|
||||
//Tipos:
|
||||
typedef struct tParcela{
|
||||
int aguaNecesaria;
|
||||
int aguaRegada;
|
||||
};
|
||||
|
||||
typedef struct tJardin {
|
||||
tParcela parcela[DIM][DIM];
|
||||
int numF, numC;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
bool cargarJardin(tJardin& jardin, std::ifstream& archivo);
|
||||
void mostrarJardin(tJardin& jardin);
|
||||
void regar(tJardin& jardin, tCoordenada& coordenada);
|
||||
int calcularPuntuacion(tJardin& jardin);
|
||||
bool plantaCondenada(tJardin& jardin, tCoordenada& coordenada);
|
||||
bool esLibre(const tJardin& jardin, tCoordenada coordenada);
|
||||
|
||||
|
||||
#endif // !_JARDIN
|
@ -0,0 +1,6 @@
|
||||
5 8
|
||||
5 0 0 0 0 0 0 3
|
||||
0 0 0 6 0 0 0 0
|
||||
0 8 0 0 0 1 0 2
|
||||
0 0 0 0 0 0 0 0
|
||||
0 3 0 0 0 5 0 0
|
@ -0,0 +1,5 @@
|
||||
Alberto 8
|
||||
Clara 5
|
||||
Susana 17
|
||||
Tadeo 8
|
||||
Victor 2
|
@ -0,0 +1,50 @@
|
||||
#include "listaCoordenadas.h"
|
||||
using namespace std;
|
||||
|
||||
void crearVacia(tListaCoordenadas& listaCoor) {
|
||||
for (int i = 0; i < MAX_COORDENADAS; i++){
|
||||
listaCoor.coordenada[i]._fila = 0;
|
||||
listaCoor.coordenada[i]._columna = 0;
|
||||
}
|
||||
listaCoor.cont = 0;
|
||||
}
|
||||
|
||||
bool buscar(tListaCoordenadas& listaCoor, tCoordenada& coordenada) {
|
||||
bool encontrada = false;
|
||||
int i = 0;
|
||||
|
||||
while (!encontrada && i < listaCoor.cont) {
|
||||
if (listaCoor.coordenada[i] == coordenada) {
|
||||
encontrada = true;
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return encontrada;
|
||||
}
|
||||
|
||||
bool insertar(tListaCoordenadas& listaCoor, tCoordenada& coor) {
|
||||
bool insertado = false;
|
||||
|
||||
if (!buscar(listaCoor, coor)) {
|
||||
listaCoor.coordenada[listaCoor.cont] = coor;
|
||||
listaCoor.cont++;
|
||||
insertado = true;
|
||||
}
|
||||
|
||||
return insertado;
|
||||
}
|
||||
|
||||
bool sacar(tListaCoordenadas& listaCoor, tCoordenada& coor) {
|
||||
bool sacada = false;
|
||||
|
||||
if (listaCoor.cont > 1) {
|
||||
coor = listaCoor.coordenada[listaCoor.cont];
|
||||
listaCoor.cont--;
|
||||
sacada = true;
|
||||
}
|
||||
|
||||
return sacada;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef _LISTACOORDENADAS
|
||||
#define _LISTACOORDENADAS
|
||||
|
||||
#include "jardin.h"
|
||||
|
||||
//Constantes:
|
||||
const int MAX_COORDENADAS = DIM * DIM;
|
||||
|
||||
//Tipos:
|
||||
typedef struct tListaCoordenadas {
|
||||
tCoordenada coordenada[MAX_COORDENADAS];
|
||||
int cont;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
void crearVacia(tListaCoordenadas& listaCoor);
|
||||
bool buscar(tListaCoordenadas& listaCoor, tCoordenada& coordenada);
|
||||
bool insertar(tListaCoordenadas& listaCoor, tCoordenada& coor);
|
||||
bool sacar(tListaCoordenadas& listaCoor, tCoordenada& coor);
|
||||
|
||||
#endif // !_LISTACOORDENADAS
|
@ -0,0 +1,140 @@
|
||||
#include "listaJugadores.h"
|
||||
using namespace std;
|
||||
|
||||
//Funciones auxiliares:
|
||||
bool buscarBinaria(tListaJugadores& jugadores, std::string nombre, int& ini, int& fin, int& pos);
|
||||
|
||||
void iniciar(tListaJugadores& lista) {
|
||||
lista.cont = 0;
|
||||
lista.capacidad = 10;
|
||||
lista.jugador = new tJugador*[lista.capacidad];
|
||||
}
|
||||
|
||||
bool cargarJugadores(tListaJugadores& lista, ifstream& archivo) {
|
||||
bool carga = false;
|
||||
//ifstream archivo;
|
||||
|
||||
iniciar(lista);
|
||||
|
||||
//archivo.open(nomArchivo);
|
||||
//if (!archivo.is_open()) {
|
||||
// cout << "Error al cargar la lista de jugadores." << endl;
|
||||
//}
|
||||
//else {
|
||||
while (!archivo.fail()) {
|
||||
lista.jugador[lista.cont] = new tJugador;
|
||||
archivo >> lista.jugador[lista.cont]->nombre;
|
||||
archivo >> lista.jugador[lista.cont]->puntos;
|
||||
lista.cont++;
|
||||
}
|
||||
lista.cont--;
|
||||
carga = true;
|
||||
//}
|
||||
//archivo.close();
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
bool guardarJugadores(tListaJugadores& lista, ofstream& archivo) {
|
||||
bool guardado = false;
|
||||
//ofstream archivo;
|
||||
|
||||
//archivo.open(nomArchivo);
|
||||
//if (!archivo.is_open()) {
|
||||
// cout << "No se pueden guardar los jugadores." << endl;
|
||||
//}
|
||||
//else {
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
archivo << lista.jugador[i]->nombre << " "
|
||||
<< lista.jugador[i]->puntos << endl;
|
||||
}
|
||||
//}
|
||||
//archivo.close();
|
||||
|
||||
return guardado;
|
||||
}
|
||||
|
||||
void mostrarJugadores(const tListaJugadores& jugadores) {
|
||||
for (int i = 0; i < jugadores.cont; i++) {
|
||||
cout << right << setw(15) << jugadores.jugador[i]->nombre
|
||||
<< setw(5) << jugadores.jugador[i]->puntos << endl;
|
||||
}
|
||||
system("PAUSE");
|
||||
}
|
||||
|
||||
bool buscar(tListaJugadores& jugadores, std::string nombre, int& pos) {
|
||||
bool encontrado = false;
|
||||
int ini = 0, fin = jugadores.cont - 1;
|
||||
pos = 0;
|
||||
|
||||
encontrado = buscarBinaria(jugadores, nombre, ini, fin, pos);
|
||||
|
||||
return encontrado;
|
||||
}
|
||||
|
||||
bool buscarBinaria(tListaJugadores& jugadores, std::string nombre, int& ini, int& fin, int& pos) {
|
||||
bool encontrado = false;
|
||||
|
||||
if (ini <= fin) {
|
||||
pos = (ini + fin) / 2;
|
||||
if (nombre < jugadores.jugador[pos]->nombre) {
|
||||
fin = pos - 1;
|
||||
encontrado = buscarBinaria(jugadores, nombre, ini, fin, pos);
|
||||
}
|
||||
else if (jugadores.jugador[pos]->nombre < nombre) {
|
||||
ini = pos + 1;
|
||||
encontrado = buscarBinaria(jugadores, nombre, ini, fin, pos);
|
||||
}
|
||||
else {
|
||||
encontrado = true;
|
||||
}
|
||||
}
|
||||
|
||||
return encontrado;
|
||||
}
|
||||
|
||||
void actualizarPuntuacion(tListaJugadores& jugadores, string nombre, int puntos) {
|
||||
int pos = 0;
|
||||
|
||||
if (!buscar(jugadores, nombre, pos)) {
|
||||
for (int i = jugadores.cont; i >= pos; i--) {
|
||||
jugadores.jugador[i] = jugadores.jugador[i - 1];
|
||||
}
|
||||
jugadores.cont++;
|
||||
jugadores.jugador[pos] = new tJugador;
|
||||
}
|
||||
jugadores.jugador[pos]->nombre = nombre;
|
||||
jugadores.jugador[pos]->puntos = puntos;
|
||||
}
|
||||
|
||||
void mostrarPorPuntos(const tListaJugadores& lista) {
|
||||
int cont;
|
||||
tListaJugadores aux;
|
||||
|
||||
aux.cont = lista.cont + 1;
|
||||
aux.capacidad = lista.capacidad;
|
||||
aux.jugador = new tJugador*[aux.capacidad];
|
||||
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
cont = i;
|
||||
aux.jugador[i] = lista.jugador[i];
|
||||
while (cont > 0 && aux.jugador[cont - 1]->puntos < aux.jugador[cont]->puntos) {
|
||||
aux.jugador[aux.cont] = aux.jugador[cont];
|
||||
aux.jugador[cont] = aux.jugador[cont - 1];
|
||||
aux.jugador[cont - 1] = aux.jugador[aux.cont];
|
||||
cont--;
|
||||
}
|
||||
}
|
||||
|
||||
aux.cont = lista.cont;
|
||||
mostrarJugadores(aux);
|
||||
|
||||
delete[] aux.jugador;
|
||||
}
|
||||
|
||||
void liberar(tListaJugadores& jugadores) {
|
||||
for (int i = 0; i < jugadores.cont; i++){
|
||||
delete jugadores.jugador[i];
|
||||
}
|
||||
delete[] jugadores.jugador;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef _LISTAJUGADORES
|
||||
#define _LISTAJUGADORES
|
||||
|
||||
#include "listaCoordenadas.h"
|
||||
|
||||
//Constantes:
|
||||
|
||||
|
||||
//Tipos:
|
||||
typedef struct tJugador {
|
||||
std::string nombre;
|
||||
int puntos;
|
||||
};
|
||||
|
||||
typedef struct tListaJugadores {
|
||||
tJugador **jugador; //Ordenada por nombre y sin nombres repetidos.
|
||||
int cont;
|
||||
int capacidad;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
void iniciar(tListaJugadores& lista);
|
||||
bool cargarJugadores(tListaJugadores& lista, std::ifstream& archivo);
|
||||
bool guardarJugadores(tListaJugadores& lista, std::ofstream& archivo);
|
||||
void mostrarJugadores(const tListaJugadores& jugadores);
|
||||
bool buscar(tListaJugadores& jugadores, std::string nombre, int& pos); //Binaria y recursiva.
|
||||
void actualizarPuntuacion(tListaJugadores& jugadores, std::string nombre, int puntos);
|
||||
void mostrarPorPuntos(const tListaJugadores& jugadores);
|
||||
void liberar(tListaJugadores& jugadores);
|
||||
|
||||
#endif // !_LISTAJUGADORES
|
222
Exámenes Resueltos (Segundo Semestre)/Junio2018AB/main.cpp
Normal file
222
Exámenes Resueltos (Segundo Semestre)/Junio2018AB/main.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
#include "listaCoordenadas.h"
|
||||
#include "listaJugadores.h"
|
||||
#include "jardin.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
void mostrarMenu(); //menu principal
|
||||
void mostrarMenu2(); //menu para mostrar: opcion 2
|
||||
int leerOpcion(int ini, int fin); //entre los valores ini y fin
|
||||
string leerNombreFichero();
|
||||
|
||||
|
||||
void ejecutarJuego(tListaJugadores &js); //ejecutar opcion 1
|
||||
void leerCoordenadas(const tJardin &j, tListaCoordenadas &cs); //leer las coordenadas de los aspersores
|
||||
void regarJardin(tJardin & j, tListaCoordenadas &cs); //regar todo el jardin: consume la lista de coordenadas
|
||||
|
||||
|
||||
void ejecutarMostrarJugadores(const tListaJugadores &js); //ejecutar opcion 2
|
||||
|
||||
void ejecutarPlantaCondenada(); //ejecutar opcion 3
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
||||
|
||||
tListaJugadores js;
|
||||
ifstream ijugadores;
|
||||
//Cargar los jugadores
|
||||
ijugadores.open("jugadores.txt");
|
||||
if (ijugadores.is_open()){
|
||||
cargarJugadores(js, ijugadores);
|
||||
}
|
||||
else { cout << "No se ha podido cargar fichero.";}
|
||||
ijugadores.close();
|
||||
|
||||
int op,op2;
|
||||
|
||||
do{
|
||||
|
||||
mostrarMenu();
|
||||
op = leerOpcion(0,3);
|
||||
switch (op){
|
||||
case 0: cout << "Adios."; system("pause"); break;
|
||||
case 1: ejecutarJuego(js); break;
|
||||
case 2:ejecutarMostrarJugadores(js); break;
|
||||
case 3: ejecutarPlantaCondenada(); break;
|
||||
default: break;
|
||||
}
|
||||
} while (op != 0);
|
||||
|
||||
|
||||
|
||||
|
||||
//Guardar los jugadores
|
||||
ofstream ofjugadores;
|
||||
ofjugadores.open("jugadores.txt");
|
||||
guardarJugadores(js, ofjugadores);
|
||||
ofjugadores.close();
|
||||
|
||||
liberar(js);
|
||||
}
|
||||
|
||||
|
||||
void leerCoordenadas(const tJardin &j, tListaCoordenadas &cs){
|
||||
int fila, columna;
|
||||
tCoordenada c;
|
||||
|
||||
cout << "Introduzca las coordenadas. Para terminar introduzca -1. \n";
|
||||
|
||||
|
||||
crearVacia(cs);
|
||||
|
||||
cout << "Coordenada: ";
|
||||
cin >> fila;
|
||||
while (!cin.fail() && fila != -1)
|
||||
{
|
||||
cin >> columna;
|
||||
c = crearCoordenada(fila, columna);
|
||||
|
||||
if (esLibre(j, c))
|
||||
{
|
||||
if (!insertar(cs, c)) {
|
||||
cout << "Repetida. \n";
|
||||
}
|
||||
}
|
||||
else { cout << "Esa parcela no est<73> libre.\n"; }
|
||||
|
||||
cout << "Coordenada: ";
|
||||
cin >> fila;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void regarJardin(tJardin & j, tListaCoordenadas &cs)
|
||||
{
|
||||
int puntos; tCoordenada c;
|
||||
while (sacar(cs,c))
|
||||
{
|
||||
regar(j, c);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void mostrarMenu()
|
||||
{
|
||||
system("cls");
|
||||
cout << "1. Jugar." << endl;
|
||||
cout << "2. Mostrar jugadores." << endl;
|
||||
cout << "3. Planta condenada?." << endl;
|
||||
cout << "0.Salir." << endl;
|
||||
cout << "Introduce una opcion: ";
|
||||
|
||||
}
|
||||
|
||||
void mostrarMenu2()
|
||||
{
|
||||
system("cls");
|
||||
cout << "1. Mostrar jugadores ordenados por nombre." << endl;
|
||||
cout << "2. Mostrar jugadores ordenados por puntuacion." << endl;
|
||||
cout << "0.Volver." << endl;
|
||||
cout << "Introduce una opcion: ";
|
||||
|
||||
}
|
||||
|
||||
int leerOpcion(int ini, int fin)
|
||||
{
|
||||
int i;
|
||||
cin >> i;
|
||||
while (cin.fail() || i<ini || i>fin)
|
||||
{
|
||||
cin.clear(); cin.sync();
|
||||
cout << "Opcion incorrecta. Introduce una opcion:";
|
||||
cin >> i;
|
||||
};
|
||||
cin.sync();
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
string leerNombreFichero()
|
||||
{
|
||||
string nfichero;
|
||||
cout << "Introduce el nombre del fichero: ";
|
||||
cin >> nfichero;
|
||||
return nfichero;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ejecutarPlantaCondenada()
|
||||
{
|
||||
|
||||
tJardin j; tCoordenada c;
|
||||
string nfichero = leerNombreFichero();
|
||||
ifstream fjardin;
|
||||
fjardin.open(nfichero);
|
||||
if (fjardin.is_open())
|
||||
{
|
||||
cargarJardin(j, fjardin);
|
||||
if (plantaCondenada(j, c)) { cout << "Tiene al menos una planta condenada, en la coordenada: " << fila(c) << " " << columna(c) << endl; }
|
||||
else { cout << "No tiene plantas condenadas.\n"; }
|
||||
}
|
||||
else { cout << "No se ha podido abrir.\n"; }
|
||||
system("pause");
|
||||
}
|
||||
|
||||
|
||||
void ejecutarMostrarJugadores(const tListaJugadores &js)
|
||||
{
|
||||
int op;
|
||||
mostrarMenu2();
|
||||
op = leerOpcion(0, 2);
|
||||
if (op == 1) {
|
||||
mostrarJugadores(js);
|
||||
}
|
||||
else if (op == 2) {
|
||||
mostrarPorPuntos(js);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ejecutarJuego(tListaJugadores &js)
|
||||
{
|
||||
string nombre, njardin;
|
||||
ifstream fjardin;
|
||||
tJardin j;
|
||||
tListaCoordenadas cs;
|
||||
int puntos;
|
||||
|
||||
cout << "Introduzca el nombre del jugador: ";
|
||||
cin >> nombre;
|
||||
njardin = leerNombreFichero();
|
||||
fjardin.open(njardin);
|
||||
if (fjardin.is_open())
|
||||
{
|
||||
cargarJardin(j, fjardin);
|
||||
mostrarJardin(j);
|
||||
leerCoordenadas(j, cs);
|
||||
regarJardin(j, cs);
|
||||
puntos = calcularPuntuacion(j);
|
||||
cout << nombre << ", has conseguido " << puntos << " puntos!.\n";
|
||||
system("pause");
|
||||
actualizarPuntuacion(js, nombre, puntos);
|
||||
}
|
||||
else { cout << "No se ha podido abrir."; }
|
||||
fjardin.close();
|
||||
}
|
||||
|
Reference in New Issue
Block a user