Keys not working

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <ctype.h>

using namespace std;

int gameOn(){
#define UP 72
#define LEFT 75
#define RIGHT 77
#define DOWN 80
system("CLS");
int tileOneX = 1;
int tileOneY = 1;
int tileTwoX = 2;
int tileTwoY = 1;
int tileThreeX = 3;
int tileThreeY = 1;
int tileFourX = 4;
int tileFourY = 1;
int tileFiveX = 1;
int tileFiveY = 2;
int tileSixX = 2;
int tileSixY = 2;
int tileSevenX = 3;
int tileSevenY = 2;
int tileEightX = 4;
int tileEightY = 2;
int tileNineX = 1;
int tileNineY = 3;
int tileTenX = 2;
int tileTenY = 3;
int tileElevenX = 3;
int tileElevenY = 3;
int tileTwelveX = 4;
int tileTwelveY = 3;
int tileThirteenX = 1;
int tileThirteenY = 4;
int tileFourteenX = 2;
int tileFourteenY = 4;
int tileFifteenX = 3;
int tileFifteenY = 4;
int tileSixteenX = 4;
int tileSixteenY = 4;
int playerX = 1;
int playerY = 1;
int keys = _getch();
switch(keys)
{
case UP:
{
cout<<"Hello World";
}
case LEFT:
{

}
case RIGHT:
{

}
case DOWN:
{

}


}
system("PAUSE");
return 0;
}
int gameOff(){

system("PAUSE");
return 0;






}
int main(int argc, char** argv) {
int choice;

cout<<"-------------------------------------\n";
cout<<"Welcome to the game of the enemy tile\n";
cout<<"-------------------------------------\n\n\n";
cout<<"[1] - Play\n\n\n";
cout<<"[2] - Exit\n\n\n";
cout<<"Enter here:";
cin>> choice;
if (choice == 1){
gameOn();

}
if(choice == 2){
gameOff();
}

system("PAUSE");
return 0;
}
When I press the up key it will not display anything. Suggestions
Please use code tags:
http://www.cplusplus.com/articles/jEywvCM9/

Conio.h is a non-standard deprecated header, don't use it:
https://en.wikipedia.org/wiki/Conio.h

The console is a bad medium for games:
http://www.cplusplus.com/articles/G13hAqkS/

If you don't want to use a graphics library, I recommend typing characters like 'u', 'd', 'l', 'r' instead.
Last edited on
Just for fun

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
    int key;
    cout<<"Press an arrow key"<<endl;
    key=getch();
    if(key==224)
    {
        key=getch();
        switch(key)
        {
            case 72: cout<<"Hello world"<<endl;break;
            case 80: cout<<"DOWN"<<endl;break;
            case 75: cout<<"LEFT"<<endl;break;
            case 77: cout<<"RIGHT"<<endl;break;
        }
    }
    else
    cout<<"Not an arrow key"<<endl;
    return 0;
}
Topic archived. No new replies allowed.