Arrow Driven Menu - CLR

I have been trying to figure out the best way to get a menu working with the arrow keys. For example:

--> Start Game
......Options
......End Game
I want the user to be able to move the arrow using the up and down arrows keys. I have been messing around some algorithms...but I think I am looking at it from a wrong perspective. If someone could push me in the right way of thinking of how to approach this problem, I will be grateful.

Here is the code I have so far (It is broken):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <string>

using namespace System;
using namespace std;

#pragma comment(lib, "user32.lib")

int main()
{
	string Menu[] = 
	{
		"Start",
		"Options",
		"End Game",
	};
	int left = 5;
	int top = 5;
	int temp = top;
	for(int i = 0; i < 3; ++i)
	{

		Console::SetCursorPosition(5, temp++);

		cout << Menu[i] << endl;

		cout << temp;
	}

	Console::SetCursorPosition(left-3, top);
	cout << "==>";
	int i = 1;
	temp = top;

	while(!GetAsyncKeyState(VK_RETURN))
	{
		if(GetAsyncKeyState(VK_DOWN))
		{
			Console::SetCursorPosition(left-3, top);
			cout << "   ";
			Console::SetCursorPosition(left-3, top+=1);
			cout << "==>";

			
		}
		if(top > 7)
			{
				top = 4;
			}
		Sleep(100);
	}


	getchar();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.