Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#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;