Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <conio.h>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. void gotoxy( int column, int line )
  9. {
  10.     COORD coord;
  11.     coord.X = column;
  12.     coord.Y = line;
  13.     SetConsoleCursorPosition(
  14.         GetStdHandle( STD_OUTPUT_HANDLE ),
  15.         coord
  16.     );
  17. }
  18.  
  19. void izrisGlavniMenu()
  20. {
  21.     system("CLS");
  22.  
  23.     cout<<"Navodila [ ]"<<endl;
  24.     cout<<"Igraj    [ ]"<<endl;
  25.     cout<<"Test     [ ]"<<endl;
  26.     cout<<"Izhod    [ ]"<<endl;
  27. }
  28.  
  29. void premikKazalca(int menu_x_poz, int &menu_y_poz)
  30. {
  31.     if(menu_y_poz<0){ menu_y_poz = 3; }
  32.     else if(menu_y_poz>3) { menu_y_poz = 0; }
  33.  
  34.     gotoxy(menu_x_poz, menu_y_poz);
  35.     cout<<"X";
  36. }
  37.  
  38. void pojdiNazaj()
  39. {
  40.     char tipka;
  41.     do
  42.     {
  43.         tipka = _getch();
  44.     }while(tipka!='a' && tipka!=75);
  45. }
  46.  
  47. void menuNavodila()
  48. {
  49.     system("CLS");
  50.     cout<<"Ugani besedo in ne umri.\nVso sreco!"<<endl;
  51.     pojdiNazaj();
  52. }
  53.  
  54. void menuIgraj()
  55. {
  56.     //Tukaj bo igra (morda)
  57.     system("CLS");
  58.     cout<<"Igra v razvoju..."<<endl;
  59.     pojdiNazaj();
  60. }
  61.  
  62. void menuTest()
  63. {
  64.     system("CLS");
  65.     cout<<"Brezvezni test";
  66.     pojdiNazaj();
  67. }
  68.  
  69. void menuIzhod()
  70. {
  71.     exit(1);
  72. }
  73.  
  74. void odpriMenu(int vrstica)
  75. {
  76.     if(vrstica==0)
  77.         menuNavodila();
  78.     else if(vrstica==1)
  79.         menuIgraj();
  80.     else if(vrstica==2)
  81.         menuTest();
  82.     else if(vrstica==3)
  83.         menuIzhod();
  84. }
  85.  
  86. int main()
  87. {
  88.     char tipka;
  89.     const int menu_x_poz = 10;
  90.     int menu_y_poz = 0;
  91.  
  92.  
  93.     izrisGlavniMenu();
  94.     premikKazalca(menu_x_poz, menu_y_poz);
  95.  
  96.     while(true)
  97.     {
  98.         tipka = _getch();
  99.  
  100.         switch(tipka)
  101.         {
  102.         case 80:
  103.         case 's':
  104.             gotoxy(menu_x_poz, menu_y_poz); cout<<" ";
  105.             menu_y_poz++;
  106.             premikKazalca(menu_x_poz, menu_y_poz);
  107.             break;
  108.         case 72:
  109.         case 'w':
  110.             gotoxy(menu_x_poz, menu_y_poz); cout<<" ";
  111.             menu_y_poz--;
  112.             premikKazalca(menu_x_poz, menu_y_poz);
  113.             break;
  114.         case 13:
  115.             odpriMenu(menu_y_poz);
  116.             izrisGlavniMenu();
  117.             premikKazalca(menu_x_poz, menu_y_poz);
  118.         }
  119.  
  120.         gotoxy(0,20);
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement