Began working on the player application
[getaclue.git] / crosswordpuzzlecreator.py
index 5a0ae11..4ffffb3 100644 (file)
@@ -3,6 +3,7 @@
 # Licensed under the GNU GPL v3
 
 # Cross puzzle creator class
+
 import sys
 import cPickle
 import readline
@@ -146,9 +147,8 @@ class CrosswordPuzzleCreator:
                        aword, arow, acol, alen = self.puzzle.get_word_across (row, col)
                        sys.stdout.write (self.BLUE + "Across word at position: " + aword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for across word: " + self.ENDCOL)
-                       if clue:
-                               self.puzzle.data[arow][acol].clue_across = clue
-                               sys.stdout.write (self.BLUE + "Set clue: \n" + self.puzzle.data[arow][acol].clue_across)
+                       self.puzzle.data[arow][acol].clue_across = clue
+                       sys.stdout.write (self.BLUE + "Set the clue: \n" + self.puzzle.data[arow][acol].clue_across)
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No across word found at that position\n")
 
@@ -157,12 +157,53 @@ class CrosswordPuzzleCreator:
                        dword, drow, dcol, dlen = self.puzzle.get_word_down (row, col)
                        sys.stdout.write (self.BLUE + "Down word at position: " + dword + "\n" + self.ENDCOL)
                        clue = raw_input (self.BRICKRED + "Clue for down word: " + self.ENDCOL)
-                       if clue:
-                               self.puzzle.data[drow][dcol].clue_down = clue
-                               sys.stdout.write (self.BLUE + "Set clue: \n" + self.puzzle.data[drow][dcol].clue_down)
+                       self.puzzle.data[drow][dcol].clue_down = clue
+                       sys.stdout.write (self.BLUE + "Set the clue: \n" + self.puzzle.data[drow][dcol].clue_down)
+               except crosswordpuzzle.NoWordException:
+                       sys.stderr.write ("No down word found at that position\n")
+
+       # remove a down word
+       def on_remove_down (self):
+               self.print_puzzle ()
+
+               srow = raw_input (self.BRICKRED + "At row: " + self.ENDCOL)
+               scol = raw_input (self.BRICKRED + "At col: " + self.ENDCOL)
+               try:
+                       row = int (srow)
+                       col = int (scol)
+               except ValueError:
+                       sys.stderr.write ("Invalid row or column\n")
+                       return
+
+               try:
+                       self.puzzle.remove_word_down (row, col)
+                       sys.stdout.write (self.BLUE + "Down word removed\n" + self.ENDCOL)
+               except crosswordpuzzle.FrozenGridException:
+                       sys.stderr.write ("Word cannot be removed from a frozen puzzle\n")
                except crosswordpuzzle.NoWordException:
                        sys.stderr.write ("No down word found at that position\n")
 
+       # remove an across word
+       def on_remove_across (self):
+               self.print_puzzle ()
+
+               srow = raw_input (self.BRICKRED + "At row: " + self.ENDCOL)
+               scol = raw_input (self.BRICKRED + "At col: " + self.ENDCOL)
+               try:
+                       row = int (srow)
+                       col = int (scol)
+               except ValueError:
+                       sys.stderr.write ("Invalid row or column\n")
+                       return
+
+               try:
+                       self.puzzle.remove_word_across (row, col)
+                       sys.stdout.write (self.BLUE + "Across word removed\n" + self.ENDCOL)
+               except crosswordpuzzle.FrozenGridException:
+                       sys.stderr.write ("Word cannot be removed from a frozen puzzle\n")
+               except crosswordpuzzle.NoWordException:
+                       sys.stderr.write ("No across word found at that position\n")
+
        # add a word to the puzzle
        def on_add_word (self, across=True):
                # first display the grid
@@ -251,6 +292,7 @@ class CrosswordPuzzleCreator:
                                sys.stdout.write ("7. Unfreeze grid\n")
                                sys.stdout.write ("8. Set clue for word\n")
                                sys.stdout.write ("9. Display clues\n")
+                               sys.stdout.write ("R. Reset grid\n")
                                sys.stdout.write ("S. Save puzzle\n")
                                sys.stdout.write ("E. Export to AcrossLite(TM) format\n")
                                sys.stdout.write ("H. Export puzzle as image/HTML\n")
@@ -263,6 +305,10 @@ class CrosswordPuzzleCreator:
                                        self.on_add_word ()
                                elif ch == "3":
                                        self.on_add_word (False)
+                               elif ch == "4":
+                                       self.on_remove_across ()
+                               elif ch == "5":
+                                       self.on_remove_down ()
                                elif ch == "6":
                                        self.puzzle.freeze_grid ()
                                elif ch == "7":
@@ -271,6 +317,8 @@ class CrosswordPuzzleCreator:
                                        self.on_set_clue ()
                                elif ch == "9":
                                        self.on_display_clues ()
+                               elif ch == "R" or ch == "r":
+                                       self.on_reset_grid ()
                                elif ch == "S" or ch == "s":
                                        self.save_puzzle ()
                                elif ch == "E" or ch == "e":
@@ -304,6 +352,15 @@ class CrosswordPuzzleCreator:
                self.load_puzzle ()
                self.do_puzzle_loop ()
 
+       # when user chooses to reset grid
+       def on_reset_grid (self):
+               ans = raw_input (self.BRICKRED +
+                       "This will clear the entire grid! Are you sure (Y/N)? " + self.ENDCOL)
+               if ans == "y" or ans == "Y":
+                       self.puzzle.reset_grid ()
+                       sys.stdout.write (self.BLUE + "Grid has been cleared of all data!"
+                                               + self.ENDCOL + "\n")
+
        # Main application loop
        def do_main_loop (self):
                # display the menu