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?
D1/CoordinateTrack.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
66 lines (52 sloc)
1.35 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 <conio.h> | |
#include <iostream> | |
using namespace std; | |
#define KEY_UP 72 | |
#define KEY_DOWN 80 | |
#define KEY_LEFT 75 | |
#define KEY_RIGHT 77 | |
#define KEY_ENTER 13 | |
int main() | |
{ | |
int c = 0; | |
int xCord = 50; | |
int yCord = 50; | |
cout << "X=" << xCord << " Y=" << yCord << '\r' ; | |
while(1) | |
{ | |
c = 0; | |
switch((c=getch())) { | |
case KEY_UP: | |
if (yCord<99){ | |
yCord++; | |
} | |
cout << "X=" << xCord << " Y=" << yCord << '\r' ;//key up | |
break; | |
case KEY_DOWN: | |
if (yCord>10){ | |
yCord--; | |
} | |
cout << "X=" << xCord << " Y=" << yCord << '\r'; // key down | |
break; | |
case KEY_LEFT: | |
if (xCord>10){ | |
xCord--; | |
} | |
cout << "X=" << xCord << " Y=" << yCord << '\r'; // key left | |
break; | |
case KEY_RIGHT: | |
if (xCord<99){ | |
xCord++; | |
} | |
cout << "X=" << xCord << " Y=" << yCord << '\r'; // key right | |
break; | |
//default: | |
//cout << endl << "null" << endl; // not arrow | |
//break; | |
case KEY_ENTER: | |
cout<< endl << "You pressed enter. ok"; // exit | |
break; | |
} | |
} | |
return 0; | |
} |