- Messages
- 178
- Reaction score
- 0
- Points
- 26
View attachment 1059259
tanong ko lang po kung pano ko po mapapagalaw yung arrow sa start instruction at about. kailangan ko po kasi makagawa ng arrow selection menu. thanks in advance po. devc++ nga po pala gamit ko. pero c file lang po.
tried this in c#, mejo hawig naman sa c++. pede mong i-incorporate yung mga user-defined functions na ngawa ko. ang pproblemahin mo na lang eh, kung paano malalaman ng program mo yung up/down arrow key pag ni-press ng user sa console (konting kalikot sa main() function). hopefully, masearch mo sa internet kung paano. PM me kung interested ka sa sample program (.exe) para maforward ko sayo.
Code:
void Main()
{
//Show the banner load the UI with the Start Option selected
ShowBanner();
//handle what option is currently selected
int selectedOption = StartIsSelected(); //selectedOption = 1
//declaration to handle what key is pressed in the console
ConsoleKeyInfo keyInfo = Console.ReadKey(true); //Console.ReadKey(true) means that the input will not display on the console screen
//infinite loop
while (true)
{
//when the Up-Arrow key is pressed on the keyboard
if (keyInfo.Key == ConsoleKey.UpArrow)
{
//clear the console screen
Console.Clear();
//show the banner
ShowBanner();
if (selectedOption == 1)
{
selectedOption = NextSelection(selectedOption, true); //selectedOption will be 3
}
else if (selectedOption == 2)
{
selectedOption = NextSelection(selectedOption, true); //selectedOption will be 2
}
else
{
selectedOption = NextSelection(selectedOption, true); //selectedOption will be 1
}
}
//when the Down-Arrow key is pressed on the keyboard
else if (keyInfo.Key == ConsoleKey.DownArrow)
{
//clear the console screen
Console.Clear();
//show the banner
ShowBanner();
if (selectedOption == 1)
{
selectedOption = NextSelection(selectedOption, false); //selectedOption will be 2
}
else if (selectedOption == 2)
{
selectedOption = NextSelection(selectedOption, false); //selectedOption will be 3
}
else
{
selectedOption = NextSelection(selectedOption, false); //selectedOption will be 1
}
}
//when the Enter key is pressed on the keyboard
else if (keyInfo.Key == ConsoleKey.Enter)
{
switch(selectedOption)
{
case 1:
Console.WriteLine("\n\nThe Start option is selected");
break;
case 2:
Console.WriteLine("\n\nThe Instruction option is selected");
break;
case 3:
Console.WriteLine("\n\nThe About option is selected");
break;
}
//wait until the user press a key
Console.Write("\n\nPress any key to exit...");
Console.ReadKey(true);
//quit the while loop and end the program
break;
}
//store what key is pressed on the console
keyInfo = Console.ReadKey(true);
}
}
/*
*
* UI
*
*/
void ShowBanner()
{
Console.WriteLine("Edit this for your own banner \n");
}
int StartIsSelected()
{
Console.WriteLine("> Start");
Console.WriteLine(" Instruction");
Console.WriteLine(" About");
return 1;
}
int InstructionIsSelected()
{
Console.WriteLine(" Start");
Console.WriteLine("> Instruction");
Console.WriteLine(" About");
return 2;
}
int AboutIsSelected()
{
Console.WriteLine(" Start");
Console.WriteLine(" Instruction");
Console.WriteLine("> About");
return 3;
}
/*
*
*/
int NextSelection(int option, bool up)
{
if (up)
{
return NextSelectionUp(option);
}
else
{
return NextSelectionDown(option);
}
}
int NextSelectionUp(int option)
{
switch (option)
{
case 1:
return AboutIsSelected();
case 3:
return InstructionIsSelected();
default:
return StartIsSelected();
}
}
int NextSelectionDown(int option)
{
switch (option)
{
case 1:
return InstructionIsSelected();
case 2:
return AboutIsSelected();
default:
return StartIsSelected();
}
}