18.move

#include <bits/stdc++.h>
#include <conio.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second
int way; // 0 -> up  1 -> down  2 -> left  3 -> right
int dx[] = {0 , 0 , -1 , 1} , dy[] = {-1 , 1 , 0 , 0};
int main(){
    int ch , ch2;
    pii point;
    point.F = 0;
    point.S = 0;
    while(1){
        ch = getch();
        if(ch == 224){
            ch2 = getch();
            switch(ch2){
                case 72 :
                    cout << "UP" << endl;
                    way = 0;
                    break;
                case 80 :
                    cout << "DOWN" << endl;
                    way = 1;
                    break;
                case 75 :
                    cout << "LEFT" << endl;
                    way = 2;
                    break;
                case 77 :
                    cout << "RIGTH" << endl;
                    way = 3;
                    break;
            }
        }
        point.F += dx[way];
        point.S += dy[way];
        gotoxy(point.F , point.S);
        cout << "*";
    }
    return 0;
}

results matching ""

    No results matching ""