Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Bazoonkas_Tamagotchi/Interface.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
106 lines (84 sloc)
2.69 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
#include <windows.h> | |
#include <conio.h> | |
#include <stdlib.h> | |
using namespace std; | |
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); | |
class Main_Menu | |
{ | |
public: | |
int counter = 0; | |
bool confirmation_state = false; | |
const char *confirmation_name; | |
const char *choices[4] = {"FEEDING", "WARDROBE", "SHOP", "EXIT"}; | |
void moving_and_selection() | |
{ | |
#define key_up 72 | |
#define key_down 80 | |
#define enter 13 | |
char key = getch(); | |
int key_code = key; | |
switch(getch()) | |
{ | |
case key_up: | |
if (counter == 0) counter = sizeof(choices) / sizeof(choices[0]) - 1; | |
else if (counter > 0) counter -= 1; | |
break; | |
case key_down: | |
if (counter == sizeof(choices) / sizeof(choices[0]) - 1) counter = 0; | |
else if (counter < sizeof(choices) / sizeof(choices[0]) - 1) counter += 1; | |
break; | |
case enter: | |
confirmation_name = choices[counter]; | |
confirmation_state = true; | |
break; | |
} | |
} | |
void go_to_coord(int x, int y) | |
{ | |
COORD coord; | |
coord.X = x; | |
coord.Y = y; | |
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); | |
} | |
void run() | |
{ | |
do { | |
system("CLS"); | |
for (int i = 0; i <= sizeof(choices) / sizeof(choices[0]) - 1; i++) | |
{ | |
if (i == counter) | |
SetConsoleTextAttribute(hConsole, 1); | |
go_to_coord(55, 20 + 1 * i); | |
cout << choices[i] << endl; | |
SetConsoleTextAttribute(hConsole, 15); | |
} | |
moving_and_selection(); | |
} while(confirmation_state != true); | |
if (confirmation_name == "FEEDING") | |
{ | |
system("CLS"); | |
cout << "YOU SELECTED FEEDING..." << endl; | |
Sleep(1000); | |
} | |
if (confirmation_name == "WARDROBE") | |
{ | |
system("CLS"); | |
cout << "YOU SELECTED THE WARDROBE..." << endl; | |
Sleep(1000); | |
} | |
if (confirmation_name == "EXIT") | |
{ | |
system("CLS"); | |
cout << "YOU SELECTED THE SHOP..." << endl; | |
Sleep(1000); | |
} | |
if (confirmation_name == "EXIT") | |
{ | |
system("CLS"); | |
cout << "CLOSING THE GAME..." << endl; | |
Sleep(1000); | |
} | |
} | |
} main_menu; |