C# Hjälp med en liten for sats!
Hej!
Jag har fastnat på en mindre detalj och behöver nu förslag från er!
Jag har skrivit ett "typing game" där man ska hindra ord att komma till andra sidan av skärmen. Vill nu föra in ett meddelande när man har klarat av att skriva in alla ord innan de når andra sidan. Men jag kommer inte på vart eller hur jag ska lösa detta.
Min idé är att man kör ett for loop genom alla orden på listan och om alla = " " så skrivs det meddelande. Men jag, som sagt inte hur eller vart jag ska placera detta och hur koden kan se ut.
Hjälp!
Det jag har skrivit är följande:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
List<string> wordList = new List<string>();
wordList.Add("THIS");
wordList.Add("IS");
wordList.Add("THE");
wordList.Add("MATRIX");
wordList.Add("AND");
wordList.Add("YOU");
wordList.Add("PICKED");
wordList.Add("THE");
wordList.Add("RED");
wordList.Add("PILL");
string spacer = "";
int counter = 0;
string input = "";
while (true)
{
spacer += " ";
counter++;
if (counter == Console.WindowWidth)
{
Console.Write("Dead...");
break;
}
if (Console.KeyAvailable)
{
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Key == ConsoleKey.Enter)
{
for (int i = 0; i < wordList.Count; i++)
{
if (input.ToUpper() == wordList[i])
{
wordList.Remove(input.ToUpper());
wordList.Insert(i, " ");
input = "";
break;
}
}
input = "";
}
else
input += info.KeyChar;
}
for (int i = 0; i < wordList.Count; i++)
{
Console.WriteLine(spacer + wordList[i]);
}
Console.WriteLine("Hints: Type and Enter. \nInput: " + input);
Thread.Sleep(150);
Console.Clear();
}
Console.ReadKey();
}
}
}