Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Coding Academy - WordScramble Help

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
branmask



Joined: Thu Feb 18, 2010 1:19 am
Posts: 14

PostPosted: Wed Mar 03, 2010 11:21 pm    Post subject: Coding Academy - WordScramble Help Reply with quote

Hello all,
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 < Cool{
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;
}
}
}
Back to top
View user's profile Send private message
branmask



Joined: Thu Feb 18, 2010 1:19 am
Posts: 14

PostPosted: Wed Mar 03, 2010 11:29 pm    Post subject: Reply with quote

nevermind! I figured it out. in the " if (!UsedList.Contains(input)){ " line I didn't put the "!" before UsedList.
Thanks anyways...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast