RPG를 만들려고했습니다. 수업을 선택할 수있는 메뉴에 문제가 있습니다. 화살표 키를 사용하여 방향을 제어 할 수있는 메뉴를 만들려고했습니다. 화살표 키를 사용하여 무언가를 선택하고자 할 때 실제 게임처럼 전경색으로 강조 표시되는 특정 클래스로 방향을 제어 할 수 있습니다. 당신이있는 것은 강조 표시됩니다.화살표 키로 메뉴 제어 및 입력
내 문제는 화살표 키를 누를 때 화살표 키의 위치를 지정할 수 없다는 것입니다. 나만 첫 번째 위치로 갈 수 있고 다른 문제는 rpg 클래스를 강조 표시하여 사용자가 어디에 있는지 보여주고 모든 rpg 클래스가 전경색을 얻는다. 나는 그들을 분리하기 위해 Console.Read
을 사용했다. 그러나 지금 나는 항상 반드시 눌러야한다 색을 바꾸기 위해를 입력해라.
다음은 코드입니다. 나는 코드를 열면 내 문제를 이해할 수있을 것 같아.
감사합니다. Csharpnoob61. 객관식 행동의 이러한 종류의 같은 일반적인 작업을위한 도우미 클래스를 사용하여, 옵션 세트를 전달하고 사용자가 만들 때까지 기다리 대신 손으로 모든 조합을 작성
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Enter_Eingabe
{
class Program
{
static void Main(string[] args)
{
//ints
int char_HP_Current = 20;
int char_HP_Full = 100;
double char_Exp_Current = 10;
double char_Exp_Full = 100;
int char_Level_Current = 1;
int GameOver = 0;
int char_Move_Left_Right = 0;
int char_Move_Up_Down = 8;
int Error = 0;
int Resting_Time = 0;
int Attack_Bonus = 0;
int Speech_Bonus = 0;
int Sneak_Bonus = 0;
int Armor_Bonus = 0;
int Casting_Bonus = 0;
//Strings
string char_Name = "";
string Current_Command;
string char_Status = "";
string char_Class;
string test;
Console.Clear();
Console.SetCursorPosition(0, 8);
do
{
string text = "Guardian";
Console.SetCursorPosition(15, 8);
Console.WriteLine(text);
Console.SetCursorPosition(45, 8);
Console.WriteLine("Paladin");
Console.SetCursorPosition(30, 8);
Console.WriteLine("Outlaw");
ConsoleKeyInfo KeyInfo;
KeyInfo = Console.ReadKey(true);
switch (KeyInfo.Key)
{
//Player Controlls
case ConsoleKey.RightArrow:
Console.SetCursorPosition(0, 8);
if (char_Move_Left_Right < 78)
{
char_Move_Left_Right+=14;
Console.SetCursorPosition(char_Move_Left_Right, char_Move_Up_Down);
Console.WriteLine("_");
Console.SetCursorPosition(char_Move_Left_Right - 1, char_Move_Up_Down);
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("_");
Console.ForegroundColor = ConsoleColor.White;
if (char_Move_Left_Right == 14)
{
if (char_Move_Up_Down == 8)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.SetCursorPosition(15, 8);
Console.WriteLine(text);
Console.Read();
}
Console.ForegroundColor = ConsoleColor.White;
}
}
if (char_Move_Left_Right == 29)
{
if (char_Move_Up_Down == 8)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.SetCursorPosition(30,8);
Console.WriteLine("Outlaw");
Console.Read();
}
Console.ForegroundColor = ConsoleColor.White;
}
if (char_Move_Left_Right == 44)
{
if (char_Move_Up_Down == 8)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.SetCursorPosition(45, 8);
Console.WriteLine("Paladin");
Console.ReadLine();
}
Console.ForegroundColor = ConsoleColor.White;
}
break;
case ConsoleKey.LeftArrow:
if (char_Move_Left_Right > 1)
{
char_Move_Left_Right--;
Console.SetCursorPosition(char_Move_Left_Right, char_Move_Up_Down);
Console.WriteLine("_");
Console.SetCursorPosition(char_Move_Left_Right + 1, char_Move_Up_Down);
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("_");
Console.ForegroundColor = ConsoleColor.White;
}
else { }
break;
case ConsoleKey.UpArrow:
if (char_Move_Up_Down > 3)
{
char_Move_Up_Down--;
Console.SetCursorPosition(char_Move_Left_Right, char_Move_Up_Down);
Console.WriteLine("_");
Console.SetCursorPosition(char_Move_Left_Right, char_Move_Up_Down + 1);
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("_");
Console.ForegroundColor = ConsoleColor.White;
}
else { }
break;
case ConsoleKey.DownArrow:
if (char_Move_Up_Down < 21)
{
char_Move_Up_Down++;
Console.SetCursorPosition(char_Move_Left_Right, char_Move_Up_Down);
Console.WriteLine("_");
Console.SetCursorPosition(char_Move_Left_Right, char_Move_Up_Down - 1);
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("_");
Console.ForegroundColor = ConsoleColor.White;
}
else { }
break;
}
}while (Error == 0);
}
}
}
이것은 매우 재사용이되지 않는 것처럼 보이며 (이미 발생 했으므로) 오류가 발생하기 쉬운 방법입니다. 내가 뭔가를 찾으면 한 번 보겠지 만, 여러 번 사용할 수 있도록 함수에 넣어 두는 것이 좋습니다. –