X-Git-Url: https://harishankar.org/repos/?p=getaclue.git;a=blobdiff_plain;f=crosswordpuzzlecreator.py;h=4ffffb345a1d260711870eeb0506be4fe9893158;hp=1e62315ecd42f6fc4fb71ca8962e412a55e39455;hb=8178235fb21779eed3615e502f2c4fdebd42150e;hpb=5f68ccac12372c5271c21e9045558d2d03e92a41 diff --git a/crosswordpuzzlecreator.py b/crosswordpuzzlecreator.py index 1e62315..4ffffb3 100644 --- a/crosswordpuzzlecreator.py +++ b/crosswordpuzzlecreator.py @@ -3,6 +3,7 @@ # Licensed under the GNU GPL v3 # Cross puzzle creator class + import sys import cPickle import readline @@ -161,6 +162,48 @@ class CrosswordPuzzleCreator: 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 @@ -262,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":