I have the code done for wordscramble(not including the homework), but for some reason all it prints in the terminal is: You've had that word already!
Even when I know I've typed a good word. ie:
cassandre
case
You've had that word already!
read
You've had that word already!
I'm thinking something is out of place or incorrect in my code, but I can't seem to find it. If anyone can see where I went wrong, help would be appreciated. Thanks. Here's my code:
using System;
using System.Collections.Generic;
using System.IO;
namespace WordScramble
{
class MainClass
{
static List<string> WordList = new List<string>();
static List<string> UsedList = new List<string>();
static string PromptLetters;
static Random Rand=new Random();
public static void Main(string[] args)
{
string[]lines = File.ReadAllLines("wordlist");
foreach(string word in lines){
if(word.Length < 3) continue;
if(word.Contains("'"))continue;
WordList.Add(word.ToLower());
}
Console.WriteLine("");
Console.WriteLine("Welcome to WordScramble!");
Console.WriteLine("Type !quit to exit, !letters for a reminder, or !next for a new word.");
Console.WriteLine("");
GetLetters();
Console.WriteLine(PromptLetters);
bool running = true;
while (running){
string input = Console.ReadLine();
switch (input){
case "!quit":
running=false;
break;
case "!next":
GetLetters();
Console.WriteLine(PromptLetters);
break;
case "!letters":
Console.WriteLine(PromptLetters);
break;
default:
if(UsedList.Contains(input)){
if(WordIsPossible(input)){
if(WordList.Contains(input)){
UsedList.Add(input);
Console.WriteLine("Good!");
}else{
Console.WriteLine("That word doesn't exist!");
}
}else{
Console.WriteLine("Did you forget your letters or something?");
Console.WriteLine("Reminder:"+PromptLetters);
}
}else{
Console.WriteLine("You've had that word already!");
}
break;
}
}
}
static void GetLetters(){
PromptLetters="";
UsedList.Clear();
string word ="";
while (word.Length <

word = WordList[Rand.Next(WordList.Count)];
}
foreach (char letter in word){
PromptLetters = PromptLetters + letter +"";
}
}
static bool WordIsPossible(string word){
string letters = PromptLetters;
foreach(char letter in word){
int pos = letters.IndexOf(letter);
if (pos !=-1){
letters = letters.Remove(pos, 1);
}else{
return false;
}
}
return true;
}
}
}