Advertisement
webmanix

Matrix menu

Nov 9th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.78 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <windows.h>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. struct _pilha{
  9.        int mem[50];
  10.        int topo;
  11.        };
  12. _pilha p;
  13.  
  14. void gotoxy(int x, int y)
  15. {
  16.   COORD coord;
  17.   coord.X = x;
  18.   coord.Y = y;
  19.   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  20. }
  21.  
  22. //principal
  23. char um[] = "1 Adicionar valor a pilha", dois[] = "2 Remover valor da pilha", tres[] = "3 Mostrar pilha", quatro[] = "4 Sair";
  24. //adicionar valor
  25. char adcv[]= "Digite o valor";
  26.  
  27. int sinal = 0, mainm = 0;
  28.  
  29.  
  30.  
  31. void animarmenu1()
  32. {
  33.      srand(time(NULL));    
  34.      for(int x=0;x<strlen(um);x++)
  35.         {
  36.              while(sinal)Sleep(rand()&3);
  37.              if(mainm==0)ExitThread(1);
  38.              sinal^=1;
  39.              gotoxy(2,x+1);
  40.              printf("%c",um[x]);
  41.              Sleep(rand() & 0x3f);
  42.              sinal^=1;
  43.              Sleep(rand()&3);
  44.          }
  45.  }
  46.  
  47. void animarmenu2()
  48. {
  49.      srand(time(NULL));
  50.      
  51.      for(int x=0;x<strlen(dois);x++)
  52.         {
  53.              
  54.              while(sinal)Sleep(rand()&3);
  55.              if(mainm==0)ExitThread(1);
  56.              sinal^=1;
  57.              gotoxy(5,x+1);
  58.              printf("%c",dois[x]);
  59.              Sleep(rand() & 0x3f);
  60.              sinal^=1;
  61.              Sleep(rand()&3);
  62.          }
  63.  }
  64.  
  65. void animarmenu3()
  66. {
  67.      srand(time(NULL));
  68.      
  69.      for(int x=0;x<strlen(tres);x++)
  70.         {
  71.              while(sinal)Sleep(rand()&3);
  72.              if(mainm==0)ExitThread(1);
  73.              sinal^=1;
  74.              gotoxy(8,x+1);
  75.              printf("%c",tres[x]);
  76.              Sleep(rand() & 0x3f);
  77.              sinal^=1;
  78.              Sleep(rand()&3);
  79.          }
  80.  }
  81.  
  82. void animarmenu4()
  83. {
  84.      srand(time(NULL));
  85.      
  86.      for(int x=0;x<strlen(quatro);x++)
  87.         {
  88.              while(sinal)Sleep(rand()&3);
  89.              if(mainm==0)ExitThread(1);
  90.              sinal^=1;
  91.              gotoxy(11,x+1);
  92.              printf("%c",quatro[x]);
  93.              Sleep(rand() & 0x3f);
  94.              sinal^=1;
  95.              Sleep(rand()&3);
  96.          }
  97.  }
  98.  
  99. void animarmenuadc()
  100. {
  101.      srand(time(NULL));
  102.      
  103.      for(int x=0;x<strlen(adcv);x++)
  104.         {
  105.              gotoxy(1,x+1);
  106.              printf("%c",adcv[x]);
  107.              gotoxy(0,strlen(adcv)+2);
  108.              Sleep((rand() & 0x3f)+50);
  109.          }
  110.  }
  111.  
  112. void push(int x)
  113. {
  114.      p.mem[p.topo++]=x;
  115.  }
  116.  
  117. int pop()
  118. {
  119.      int x = p.mem[p.topo];
  120.      p.topo--;
  121.      return x;
  122.  }
  123.  
  124. int queue()
  125. {
  126.     return p.mem[p.topo];
  127. }
  128.  
  129. void zprintf(char x[])
  130. {
  131.      for(int y=0;y<strlen(x);y++,Sleep(rand()&0xf))
  132.         printf("%c",x[y]);
  133.  }
  134.  
  135. void ( __stdcall *_x)(int,int,int,int,int,int);
  136. void menu()
  137. {  
  138.    system("CLS");
  139.    mainm=1;
  140.    sinal=0;
  141.    _x(0,0,(DWORD)&animarmenu1,0,0,0);
  142.    _x(0,0,(DWORD)&animarmenu2,0,0,0);
  143.    _x(0,0,(DWORD)&animarmenu3,0,0,0);
  144.    _x(0,0,(DWORD)&animarmenu4,0,0,0);
  145.  }
  146.  
  147. int adicionarvalor()
  148. {
  149.    system("CLS");
  150.    mainm=0;
  151.    Sleep(50);
  152.    _x(0,0,(DWORD)&animarmenuadc,0,0,0);
  153.    int buffer;
  154.    fflush(stdin);
  155.    scanf("%d",&buffer);
  156.    return buffer;  
  157.  }
  158.  
  159. void mostrar()
  160. {
  161.      system("CLS");
  162.      
  163.      for(int x=0;x<p.topo;x++)
  164.      {
  165.              char buf[100];
  166.              sprintf(buf,"\n %d: %d",x+1,p.mem[x]);
  167.              zprintf(buf);
  168.              }
  169.      getch();
  170.  }
  171.  
  172. int main(int argc, char *argv[])
  173. {
  174.    
  175.     p.topo=0;
  176.    
  177.     *(DWORD*)(&_x) = (DWORD)&CreateThread;
  178.     system("COLOR 0A");
  179.     int opt=0;
  180.     while(opt!='4'){
  181.     menu();
  182.     opt = getch();
  183.     mainm=0;
  184.     Sleep(90);
  185.     switch(opt){
  186.                 case '1': push(adicionarvalor()); break;
  187.                 case '2': pop(); break;
  188.                 case '3': mostrar();
  189.                
  190.                      }
  191.     }
  192.     return EXIT_SUCCESS;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement