Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <string>
- #include <iostream>
- using namespace std;
- typedef struct Pilha{
- int Elementos[5];
- int Topo;
- }Pilha;
- bool Vazia(Pilha &P){
- if(P.Topo == -1)
- return true;
- return false;
- }
- bool Cheia(Pilha &P){
- if(P.Topo == 4)
- return true;
- return false;
- }
- void Cria(Pilha &P){
- P.Topo = -1;
- }
- void Empilha(Pilha &P, int X, bool &DeuCerto){
- if(Cheia(P))
- DeuCerto = false;
- else{
- P.Topo++;
- P.Elementos[P.Topo] = X;
- DeuCerto = true;
- }
- }
- void Desempilha(Pilha &P, int &X, bool &DeuCerto){
- if(Vazia(P))
- DeuCerto = false;
- else{
- X = P.Elementos[P.Topo];
- P.Topo--;
- DeuCerto = true;
- }
- }
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(1219,794), "Jogo Daora");
- sf::Texture textura[5];
- if(!textura[0].loadFromFile("fotos/pilhacanto/chip.png"))
- std::cout << "Error could not load 1 image" << std::endl;
- if(!textura[1].loadFromFile("fotos/pilhacanto/cooler.png"))
- std::cout << "Error could not load 2 image" << std::endl;
- if(!textura[2].loadFromFile("fotos/pilhacanto/imac.png"))
- std::cout << "Error could not load 3 image" << std::endl;
- if(!textura[3].loadFromFile("fotos/pilhacanto/motherboard.png"))
- std::cout << "Error could not load 4 image" << std::endl;
- if(!textura[4].loadFromFile("fotos/pilhacanto/mouse-4.png"))
- cout << "Erro" << endl;
- sf::Sprite imagens[5];
- imagens[0].setTexture(textura[0]);
- imagens[1].setTexture(textura[1]);
- imagens[2].setTexture(textura[2]);
- imagens[3].setTexture(textura[3]);
- imagens[4].setTexture(textura[4]);
- imagens[0].setScale(0.1, 0.1);
- imagens[1].setScale(0.1, 0.1);
- imagens[2].setScale(0.1, 0.1);
- imagens[3].setScale(0.1, 0.1);
- imagens[4].setScale(0.1, 0.1);
- Pilha pilhaFixa, pilhaCriando, pilhaAuxiliar;
- bool DeuCerto;
- int valor, indice=0;
- Cria(pilhaFixa);
- Cria(pilhaCriando);
- Cria(pilhaAuxiliar);
- for(int i = 0; i < 5; i++)
- {
- Empilha(pilhaFixa, i, DeuCerto);
- }
- Empilha(pilhaCriando, 2, DeuCerto);
- Empilha(pilhaCriando, 4, DeuCerto);
- Empilha(pilhaCriando, 1, DeuCerto);
- while(!Vazia(pilhaCriando))
- {
- Desempilha(pilhaCriando, valor, DeuCerto);
- Empilha(pilhaAuxiliar, valor, DeuCerto);
- }
- while(window.isOpen())
- {
- sf::Event event;
- //botão fechar
- while(window.pollEvent(event)){
- if(event.type == sf::Event::Closed){
- window.close();
- }
- }
- window.clear();
- while(!Vazia(pilhaAuxiliar))
- {
- Desempilha(pilhaAuxiliar, valor, DeuCerto);
- Empilha(pilhaCriando, valor, DeuCerto);
- switch(valor)
- {
- case 0:
- cout << "Empilhou um chip" << endl;
- imagens[0].setPosition(100, 100*indice);
- window.draw(imagens[0]);
- break;
- case 1:
- cout << "Empilhou um cooler" << endl;
- imagens[1].setPosition(100, 100*indice);
- window.draw(imagens[1]);
- break;
- case 2:
- cout << "Empilhou um imac" << endl;
- imagens[2].setPosition(100, 100*indice);
- window.draw(imagens[2]);
- break;
- case 3:
- cout << "Empilhou um motherboard" << endl;
- imagens[3].setPosition(100, 100*indice);
- window.draw(imagens[3]);
- break;
- case 4:
- cout << "Empilhou um mouse" << endl;
- imagens[4].setPosition(100, 100*indice);
- window.draw(imagens[4]);
- break;
- }
- indice++;
- }
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement