Hi Ram--
This line:
[code]static string lines;[/code]
was me declaring the string 'lines' prior to the main body of the program. If I don't put it in there I get this error message:
[code]"The name `lines' does not exist in the current context (CS0103)"[/code]
in reference to the last line of code:
[code]foreach(string word in lines){ [/code]
You asked about this snippet:
[code]{
if (args.Length > 12){
string[] lines = File.ReadAllLines(args[1]);
}[/code]
Well, I assumed that the argument "./wordscramble" would be 12 letters (not counting the ./). I also assumed that "args[1]" would refer to the second [i]element[/i] of the array "args" ie. the file name entered by the user. (Yeah, I know what happens when I assume!)
You also wrote:
[quote]mywordlist would then be stored in (args[0])[/quote]
So, the command "./wordscramble" isn't considered part of the "args" array? OK, I'll work with that, and see what happens.
Anyway, here is the full "WordScramble" code (note that I have a comment with the error message next to the line that MonoDevelop doesn't like):
[code]
using System; //created by Chris Adams 6/16/10
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 Random Rand = new Random();
static string PromptLetters;
static string lines;
public static void Main (string[] args)
{
if (args.Length > 0){
string[] lines = File.ReadAllLines(args[1]);
}
else{
string[] lines = File.ReadAllLines("wordlist");
}
foreach(string word in lines){ //Error Msg. -> Cannot convert type `char' to `string' (CS0030)
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("");
var score = 0;
GetLetters(); //goes to GetLetters subroutine
Console.WriteLine(PromptLetters);
bool running = true;
while (running){
string input = Console.ReadLine(); //get player input
switch (input){ //look for !quit, !next, !letters commands
case "!quit":
running = false;
break;
case "!next":
GetLetters();
Console.WriteLine(PromptLetters);
Console.WriteLine("Score = " + score);
break;
case "!letters":
Console.WriteLine(PromptLetters);
break;
default: //check to be sure word exists, & hasn't been used already
if (!UsedList.Contains(input)){
if (WordIsPossible(input)){
if (WordList.Contains(input)){
UsedList.Add(input);
var WordScore = WordValue(input);
score = score + WordScore;
Console.WriteLine("Good! Score = " + score);
} 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 used that word already!");
}
break;
}
}
}
static void GetLetters(){ //GetLetters subroutine
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;
}
static int WordValue(string input) {
var wvalue = 0;
foreach (char letter in input){
wvalue++;
}
return wvalue;
}
}
}
[/code]
Thanks for your time, Ram.
chriswadams