Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.00 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. typedef struct Pilha{
  10.     int Elementos[5];
  11.     int Topo;
  12. }Pilha;
  13.  
  14. bool Vazia(Pilha &P){
  15.     if(P.Topo == -1)
  16.         return true;
  17.     return false;
  18. }
  19.  
  20. bool Cheia(Pilha &P){
  21.     if(P.Topo == 4)
  22.         return true;
  23.     return false;
  24. }
  25.  
  26. void Cria(Pilha &P){
  27.     P.Topo = -1;
  28. }
  29.  
  30. void Empilha(Pilha &P, int X, bool &DeuCerto){
  31.     if(Cheia(P))
  32.         DeuCerto = false;
  33.     else{
  34.         P.Topo++;
  35.         P.Elementos[P.Topo] = X;
  36.         DeuCerto = true;
  37.     }
  38. }
  39.  
  40. void Desempilha(Pilha &P, int &X, bool &DeuCerto){
  41.     if(Vazia(P))
  42.         DeuCerto = false;
  43.     else{
  44.         X = P.Elementos[P.Topo];
  45.         P.Topo--;
  46.         DeuCerto = true;
  47.     }
  48. }
  49.  
  50.  
  51. int main()
  52. {
  53.     sf::RenderWindow window(sf::VideoMode(1219,794), "Jogo Daora");
  54.     sf::Texture textura[5];
  55.  
  56.     if(!textura[0].loadFromFile("fotos/pilhacanto/chip.png"))
  57.     std::cout << "Error could not load 1 image" << std::endl;
  58.     if(!textura[1].loadFromFile("fotos/pilhacanto/cooler.png"))
  59.         std::cout << "Error could not load 2 image" << std::endl;
  60.     if(!textura[2].loadFromFile("fotos/pilhacanto/imac.png"))
  61.         std::cout << "Error could not load 3 image" << std::endl;
  62.     if(!textura[3].loadFromFile("fotos/pilhacanto/motherboard.png"))
  63.         std::cout << "Error could not load 4 image" << std::endl;
  64.     if(!textura[4].loadFromFile("fotos/pilhacanto/mouse-4.png"))
  65.         cout << "Erro" << endl;
  66.  
  67.     sf::Sprite imagens[5];
  68.     imagens[0].setTexture(textura[0]);
  69.     imagens[1].setTexture(textura[1]);
  70.     imagens[2].setTexture(textura[2]);
  71.     imagens[3].setTexture(textura[3]);
  72.     imagens[4].setTexture(textura[4]);
  73.  
  74.     imagens[0].setScale(0.1, 0.1);
  75.     imagens[1].setScale(0.1, 0.1);
  76.     imagens[2].setScale(0.1, 0.1);
  77.     imagens[3].setScale(0.1, 0.1);
  78.     imagens[4].setScale(0.1, 0.1);
  79.  
  80.     Pilha pilhaFixa, pilhaCriando, pilhaAuxiliar;
  81.     bool DeuCerto;
  82.     int valor, indice=0;
  83.  
  84.     Cria(pilhaFixa);
  85.     Cria(pilhaCriando);
  86.     Cria(pilhaAuxiliar);
  87.     for(int i = 0; i < 5; i++)
  88.     {
  89.         Empilha(pilhaFixa, i, DeuCerto);
  90.     }
  91.  
  92.     Empilha(pilhaCriando, 2, DeuCerto);
  93.     Empilha(pilhaCriando, 4, DeuCerto);
  94.     Empilha(pilhaCriando, 1, DeuCerto);
  95.  
  96.     while(!Vazia(pilhaCriando))
  97.     {
  98.             Desempilha(pilhaCriando, valor, DeuCerto);
  99.             Empilha(pilhaAuxiliar, valor, DeuCerto);
  100.     }
  101.     while(window.isOpen())
  102.     {
  103.  
  104.         sf::Event event;
  105.             //botão fechar
  106.             while(window.pollEvent(event)){
  107.                 if(event.type == sf::Event::Closed){
  108.                     window.close();
  109.                 }
  110.             }
  111.  
  112.         window.clear();
  113.         while(!Vazia(pilhaAuxiliar))
  114.         {
  115.             Desempilha(pilhaAuxiliar, valor, DeuCerto);
  116.             Empilha(pilhaCriando, valor, DeuCerto);
  117.             switch(valor)
  118.             {
  119.             case 0:
  120.                 cout << "Empilhou um chip" << endl;
  121.                 imagens[0].setPosition(100, 100*indice);
  122.                 window.draw(imagens[0]);
  123.                 break;
  124.  
  125.             case 1:
  126.                 cout << "Empilhou um cooler" << endl;
  127.                 imagens[1].setPosition(100, 100*indice);
  128.                 window.draw(imagens[1]);
  129.                 break;
  130.  
  131.             case 2:
  132.                 cout << "Empilhou um imac" << endl;
  133.                 imagens[2].setPosition(100, 100*indice);
  134.                 window.draw(imagens[2]);
  135.                 break;
  136.  
  137.             case 3:
  138.                 cout << "Empilhou um motherboard" << endl;
  139.                 imagens[3].setPosition(100, 100*indice);
  140.                 window.draw(imagens[3]);
  141.                 break;
  142.  
  143.             case 4:
  144.                 cout << "Empilhou um mouse" << endl;
  145.                 imagens[4].setPosition(100, 100*indice);
  146.                 window.draw(imagens[4]);
  147.                 break;
  148.             }
  149.  
  150.             indice++;
  151.         }
  152.  
  153.         window.display();
  154.     }
  155.  
  156.  
  157.     return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement