mendoza_franco

TP08 - RUEDA DE LA FORTUNA

Sep 7th, 2023
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h> 
  3. #include <conio.h> 
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "funciones.h"
  7.  
  8. using namespace std;
  9.  
  10.     struct nodo {
  11.         int numero;
  12.         char nombre[20];
  13.         bool libre;
  14.         nodo *siguiente;
  15.         nodo *anterior;
  16.     };
  17.     nodo *primero = NULL;
  18.     nodo *ultimo = NULL;
  19.  
  20. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  21.     void crearLugares(int lugar){
  22.         nodo *nuevo = new nodo();
  23.                 nuevo->numero = lugar;  //NUMERACION;
  24.                 strcpy(nuevo->nombre,"LIBRE");//nombres[0]     
  25.                 nuevo->libre = true;
  26.                
  27.             if(primero == NULL){
  28.                 primero = nuevo;
  29.                 primero->siguiente = primero;
  30.                 primero->anterior = ultimo;
  31.                 ultimo = primero;
  32.             }  
  33.             else{
  34.                 ultimo->siguiente = nuevo;
  35.                 nuevo->siguiente = primero;
  36.                 nuevo->anterior = ultimo;
  37.                 ultimo = nuevo;
  38.             }
  39.     }
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41.     void visualizar(){//char tipoVista
  42.         nodo *mostrar = new nodo();
  43.         int linea = 0;
  44.             mostrar = primero;
  45.                     colors(14); posicionar(62,3);   cout<<"- DISTRIBUCION:  ";
  46.                 do{        
  47.                         if( mostrar->libre == true  )   colors(2);
  48.                         if( mostrar->libre == false )   colors(4);
  49.                        
  50.                             posicionar(62,4+linea); cout<<(char)219;    cout<<" LUGAR #"<<mostrar->numero<<":\t"<<mostrar->nombre;
  51.                         mostrar = mostrar->siguiente;  
  52.                     linea++;
  53.                 }while(mostrar != primero);
  54.     }
  55. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56.     int girar(){
  57.         int opcion, mover;
  58.         colors(14);
  59.         posicionar(6,12);   cout<<" > MENU: SUBIR."<<endl;
  60.         posicionar(6,14);   cout<<"   1. GIRAR HACIA LA DERECHA.";
  61.         posicionar(6,15);   cout<<"   2. GIRAR HACIA LA IZQUIERDA.";
  62.             opcion = takeOptionGotoxy(" - OPCION:\t",1,2,9,17);
  63.              //mover = takeInt(" - CUANTAS POSICIONES: ");
  64.                 do{
  65.                     fflush(stdin);
  66.                     mover = takeOptionGotoxy("   - CUANTAS POSICIONES [1-30]:\t",1,30,6,19);
  67.                     switch(opcion){
  68.                         case 1:
  69.                                 if (mover > 0  && mover <= 10){ return mover;   }
  70.                                 if (mover > 10 && mover <= 20){ mover = mover - 10; return mover;   }
  71.                                 if (mover > 20 && mover <= 30){ mover = mover - 20; return mover;   }
  72.                                
  73.                             break;
  74.                         case 2:
  75.                                 if (mover > 0  && mover <= 9){  mover = 10 - mover; return mover;   }
  76.                                 if (mover == 10 )            {  mover = 1;          return mover;   }
  77.                                 if (mover > 10 && mover <= 20){ mover = 20 - mover; return mover;   }
  78.                                 if (mover > 20 && mover <= 30){ mover = 30 - mover; return mover;   }
  79.                             break;
  80.                     }
  81.                 }while(true);
  82.     }
  83. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  84.     void subirPasajero(int posicion){
  85.         nodo *recorrer = new nodo();
  86.         int aux;
  87.         char vNombre[20];
  88.             recorrer = primero;
  89.                 do{
  90.                     aux = recorrer->numero;
  91.                     if(aux == posicion && recorrer->libre == true){
  92.                         recorrer->numero = posicion;
  93.                                 colors(10);
  94.                                 posicionar(62,18);  cout<<" - SUBIR PASAJERO:";
  95.                                 posicionar(62,19);  cout<<"   > LUGAR:\t"<<recorrer->numero;
  96.                                 posicionar(62,20);  cout<<"   > INGRESE EL NOMBRE:\t";
  97.                             fflush(stdin);
  98.                                 cin.getline(vNombre,20,'\n');
  99.                                     strupr(vNombre);    //MAYUSCULA
  100.                         strcpy(recorrer->nombre,vNombre);
  101.                         recorrer->libre = false;
  102.                         break;
  103.                     }
  104.                     if(aux == posicion && recorrer->libre == false){
  105.                         recorrer->numero = posicion;
  106.                                 colors(12);
  107.                                 posicionar(62,18);  cout<<" - ¡ADVERTENCIA!: ASIENTO OCUPADO.";
  108.                         break;
  109.                     }
  110.                     recorrer = recorrer->siguiente;
  111.                 }while(recorrer != primero);
  112.     }
  113. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  114.     void bajarPasajero(){
  115.         nodo *recorrer = new nodo();
  116.         recorrer = primero;
  117.         int aux, posicion = 0;
  118.        
  119.         posicionar(6,12);         cout<<" - MENU: BAJAR."<<endl;
  120.             posicion = takeOptionGotoxy("   > BAJAR AL PASAJERO DE LA POSICION [1-10]: ",1,10,6,14);
  121.                 do{
  122.                     aux = recorrer->numero;
  123.                     if(aux == posicion && recorrer->libre == false){
  124.                         recorrer->numero = posicion;
  125.                             colors(12);
  126.                             strcpy(recorrer->nombre,"LIBRE");
  127.                             recorrer->libre = true;
  128.                                 posicionar(62,18);  cout<<" - BAJAR PASAJERO:";
  129.                                 posicionar(62,19);  cout<<"   > LUGAR:\t"<<recorrer->numero;
  130.                                 posicionar(62,20);  cout<<"   > PASAJERO:\t"<<recorrer->nombre;
  131.                         break;
  132.                     }
  133.                     else{
  134.                         if(posicion == aux &&  recorrer->libre == true ){
  135.                             colors(12);
  136.                             posicionar(62,18);  cout<<" - HACIENTO:";   colors(10);  cout<<"LIBRE";
  137.                         }
  138.                     }
  139.                     recorrer = recorrer->siguiente;
  140.                 }while(recorrer != primero);
  141.     }
  142. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  143.     int main(void){
  144.         int menu = 0, posicion = 0;
  145.         {//GENERADOR
  146.         crearLugares(1);
  147.         crearLugares(2);
  148.         crearLugares(3);
  149.         crearLugares(4);
  150.         crearLugares(5);
  151.         crearLugares(6);
  152.         crearLugares(7);
  153.         crearLugares(8);
  154.         crearLugares(9);
  155.         crearLugares(10);
  156.         }
  157.         do{
  158.             visualizar();
  159.                 colors(14);
  160.             posicionar(3,3);    cout<<" - MENU RUEDA FORTUNA: ";
  161.             posicionar(3,5);    cout<<"   1. SUBIR PASAJERO.";
  162.             posicionar(3,6);    cout<<"   2. BAJAR PASAJERO.";
  163.             posicionar(3,7);    cout<<"   3. FINALIZAR.";
  164.                
  165.                 menu = takeOptionGotoxy(" - OPCION:\t",1,3,3,9);
  166.                
  167.                     switch(menu){  
  168.                         case 1:     posicion = girar();
  169.                                         subirPasajero(posicion);
  170.                             break;
  171.                         case 2:     bajarPasajero();
  172.                             break;
  173.                         case 3:     cout<<"GRACIAS POR JUGAR";
  174.                             break;
  175.                     }
  176.             colors(14);
  177.             posicionar(3,28);   system("pause");    system("cls");
  178.         }while(menu != 3);
  179.     return 0;}//END GENERAL;
Add Comment
Please, Sign In to add comment