/// <summary> /// Load the serialized game file. An optional parameter indicating the file name can be used on the /// command prompt. /// </summary> public void Load() { if (state!=READY) { return; } string filename = (commands.Length>=2)?commands[1]:DefaultGameFileName; Stream stream; IFormatter formatter; try { stream = new FileStream(filename, FileMode.Open); formatter = new BinaryFormatter(); grid = (WordSearchGrid) formatter.Deserialize(stream); grid.ResetColorPoints(); state += GAME_LOADED; } catch(IOException ex) { Console.WriteLine(ex.Message); } catch(SerializationException ex) { Console.WriteLine(ex.Message); } catch(Exception ex) { Console.WriteLine(ex.Message); } finally { stream.Close(); } }
public void WordSearchGridTestSetup() { TestWords = new ArrayList(); FillTestWords(); WordTests = new WordLine[2]; Test1 = new WordSearchGrid(TestWords); WordTests[0] = new WordLine(new Point(1,2), new Point(1,0), (string)TestWords[0]); WordTests[1] = new WordLine(new Point(3,1), new Point(0,1), (string)TestWords[1]); }
/// <summary> /// Generates an playable WordSearchGrid filling it with the words specified in the file 'words.txt', /// or if an argument was provided along with the command, the words will be read from the file /// with the name specified on that argument. A third argument can be provided to specify the Tolerance /// of the generator. /// </summary> public void Generate() { Console.WriteLine (Lang.Generating[lang]); Stopwatch timer = new Stopwatch(); state = BUSY; bool load_default_words = (commands.Length>1 && commands[1]=="--default"); string filename = (commands.Length>1)?commands[1]:DefaultFileName; ArrayList word_list = (load_default_words)?default_word_list:ReadSourceFile(filename); // Reads the specified source file grid = new WordSearchGrid(word_list); Random r = new Random(); Point direction, invalid_direction = new Point(0,0); int word_placing_attempts; if ((state&WITH_ERRORS) == WITH_ERRORS) { state += READY - BUSY; return; } timer.Reset(); timer.Start(); while (grid.UnplacedWords.Count > 0) { do { direction = new Point(r.Next(3)-1,r.Next(3)-1); }while(direction==invalid_direction); word_placing_attempts = 0; while(!grid.PlaceWord(new Point(r.Next(grid.GridSize),r.Next(grid.GridSize)), direction)) { if (++word_placing_attempts >= tolerance) { grid.ReportFailedWord(); break; } } } grid.FillHoles(); timer.Stop(); FailedList(); Console.WriteLine(Lang.GenerationTime[lang],timer.ElapsedMilliseconds/1000.0d,grid.NotFoundWords.Count,grid.GridSize); state += READY + WRITABLE - BUSY; }