number puzzle

hi, i wanted to write a number puzzle ( 4*4 square that contains numbers from 1 to 15 and a empty space and you should keep swapping the empty space with one of the neighboring numbers until the numbers are ordered in the following way:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15
I know how to program it but i encountered a problem:
How will i take the instructions to swap
I thought of using arrows (up swaps the empty space with the number above and so on) but how will i take the arrows as input? Then i thought of replacing the arrows with (w,a,s,d) but how can i take them directly (without the user having to press enter after each move)?
If there are any solutions for these problems please provide me with solutions
If there arent solutions please provide me with other ideas to do it




Play with this how to take the arrows as input. :)

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

int main()
{
    int key;
    key=getch();
    if(key==224)
    {
        key=getch();
        switch(key)
        {
            case 72: cout<<"UP"<<endl;break;
            case 80: cout<<"DOWN"<<endl;break;
            case 75: cout<<"LEFT"<<endl;break;
            case 77: cout<<"RIGHT"<<endl;break;
        }
    }
    return 0;
}
Thank you very much.
But why did you check for 224 first?
Last edited on
check this out look for the "Extended" Keys
http://www.lagmonster.org/docs/DOS7/v-ansi-keys.html
ok got it, thanks
I hope you get your program to work the way you want ;) have fun :)
Topic archived. No new replies allowed.