#include #include"console.h" #include /// for key #define BACKGROUND 176 #define TEXTCOLOR 7 using namespace std; typedef char str[31]; str manipulation[5] = { "Login ","Menu", "3","4","5" }; enum MOVE { UP, DOWN, LEFT, RIGHT, ENTER, BACK }; MOVE key(int z) { if (z == 224) { char c; c = _getch(); if (c == 72) { return UP; } if (c == 80) { return DOWN; } if (c == 77) { return RIGHT; } if (c == 75) { return LEFT; } } else if (z == 13) return ENTER; if (z == 8) return BACK; } int menu(str manipulation[5], int n) { int tt = 0; int* color = new int[n]; for (int i = 0; i < n; i++) { color[i] = TEXTCOLOR; } color[0] = BACKGROUND; while (1) { clrscr(); for (int i = 0; i < n; i++) { TextColor(color[i]); cout << i + 1 << "> " << manipulation[i] << endl; } int z = _getch(); MOVE move = key(z); switch (move) { case UP: { if (tt == 0) { tt = n - 1; } else tt--; break; } case DOWN: { if (tt == n - 1) { tt = 0; }else tt++; break; } case ENTER: { return tt; } } } for (int i = 0; i < n; i++) { color[i] = TEXTCOLOR; } color[tt] = BACKGROUND; delete[]color; } int main() { int x = menu(manipulation, 5); switch (x) { case 0: { system("CLS"); cout << "0" << endl; system("PAUSE>NUL"); break; } case 1: { system("CLS"); cout << "1" << endl; system("PAUSE>NUL"); break; }case 2: { system("CLS"); cout << "2" << endl; system("PAUSE>NUL"); break; }case 3: { system("CLS"); cout << "3" << endl; system("PAUSE>NUL"); break; }case 4: { system("CLS"); cout << "4" << endl; system("PAUSE>NUL"); break; } } system("pause"); return 0; }