事情是,我想能夠增加/減少一個變量(整數)通過按向上和向下的箭頭鍵。但是我該如何操作這個變量,所以它從3變爲1,又從1變回3?直到一個特定的數字,並重新開始+倒數
我使用Visual C#express 2010,它是一個Windows控制檯應用程序!抱歉,添麻煩了!
我拼命地試圖進入C#,並與這些基本的東西掙扎。如果有人能幫助我,我會非常感激。我走了這麼遠,這應該成爲其中用戶可以通過三種選項滾動菜單:1-新遊戲// 2 - 載入遊戲和3-退出遊戲
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int iMOP = 0;
ConsoleKeyInfo keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.UpArrow){
}
else if (keyInfo.Key == ConsoleKey.DownArrow){
}
switch (iMOP)
{
case 0:
break;
case 1:
break;
case 2:
break;
}
}
}
}
附加:我會盡力用Console.Clear刷新菜單,但我必須計算計數問題。 我已經將它翻譯成這個了:它現在感謝輸入,他!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.CursorVisible = false;
int iMOP = 1;
Console.WriteLine(" >>New Game");
Console.WriteLine(" Load Game");
Console.WriteLine(" Exit Game");
while (iMOP != 5)
{
{
ConsoleKeyInfo keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.UpArrow)
{
iMOP--;
}
else if (keyInfo.Key == ConsoleKey.DownArrow)
{
iMOP++;
}
}
if (iMOP == 0)
{
iMOP = 3;
}
else if (iMOP == 4)
{
iMOP = 1;
}
switch (iMOP)
{
case 1:
Console.Clear();
Console.WriteLine(" >>New Game");
Console.WriteLine(" Load Game");
Console.WriteLine(" Exit Game");
break;
case 2:
Console.Clear();
Console.WriteLine(" New Game");
Console.WriteLine(" >>Load Game");
Console.WriteLine(" Exit Game");
break;
case 3:
Console.Clear();
Console.WriteLine(" New Game");
Console.WriteLine(" Load Game");
Console.WriteLine(" >>Exit Game");
break;
}
}
}
}
}
目前尚不清楚你的意思......如果你對按鍵有反應,那麼這將決定你是增加還是減少變量。也許如果你發佈了迄今爲止已有的代碼,並解釋了它的作用和你希望做的事情之間的區別,那麼幫助你會更容易。 –
所以你想要數字「包裝」?模運算符('%')在這裏是你的朋友。如果你發佈了你所擁有的東西,幫助起來會更容易。 – BradleyDotNET
當您的問題涉及到任何用戶界面或輸入(即箭頭鍵啓動一個過程)時,您應列出您正在使用的平臺,因爲您會得到不同的答案:WPF,Windows Forms,Web? –