1 # Get A Clue (C) 2010 V. Harishankar
2 # Crossword puzzle maker program
3 # Licensed under the GNU GPL v3
5 # Cross puzzle creator class
9 class CrosswordPuzzleCreator
:
10 # ansi color codes for grid display
23 self
.current_file
= None
26 # display the grid with words
27 def print_puzzle (self
, no_words
=False):
28 # if self.puzzle is not none
30 # get row, col and print them (with grid number if set)
31 for col
in range (self
.puzzle
.cols
):
32 # print the first row as column headers
33 print self
.BLUE
+ ' ' + str (col
) + self
.ENDCOL
,
36 for row
in range (self
.puzzle
.rows
):
37 for col
in range (self
.puzzle
.cols
):
39 # if the cell is numbered i.e. start of a word
40 if self
.puzzle
.data
[row
][col
].numbered
!= 0:
41 print self
.BRICKRED
+ str(self
.puzzle
.data
[row
][col
].numbered
) + self
.ENDCOL
,
45 # if the character is not a blank or a block
46 if self
.puzzle
.data
[row
][col
].char
<> "." and self
.puzzle
.data
[row
][col
].char
<> "#":
47 # if words are to be shown regardless of hidden/revealed state
49 print self
.BOLD
+ self
.puzzle
.data
[row
][col
].char
+ self
.ENDCOL
,
51 # display only revealed
52 if self
.puzzle
.data
[row
][col
].revealed
is True:
53 print self
.BOLD
+ self
.puzzle
.data
[row
][col
].char
+ self
.ENDCOL
,
56 print self
.GREY
+ '.' + self
.ENDCOL
,
58 print self
.GREY
+ self
.puzzle
.data
[row
][col
].char
+ self
.ENDCOL
,
60 print ' ' + self
.BLUE
+ str(row
) + self
.ENDCOL
61 raw_input (self
.GREY
+ "Press <return> to continue" + self
.ENDCOL
)
64 def do_puzzle_loop (self
):
65 # there is a current file
67 if self
.current_file
and self
.puzzle
:
68 print self
.BOLD
+ "-----------------------------------"
69 print "Puzzle: " + self
.current_file
70 print "-----------------------------------" + self
.ENDCOL
71 print self
.BLUE
+ "1. Display grid"
72 print "2. Add across word"
73 print "3. Add down word"
74 print "4. Freeze grid"
75 print "5. Unfreeze grid"
76 print "6. Save puzzle"
77 print "X. Exit to main menu" + self
.ENDCOL
78 ch
= raw_input (self
.BRICKRED
+ "Your choice: " + self
.ENDCOL
)
81 elif ch
== "X" or ch
== "x":
84 # when user chooses new puzzle
85 def on_new_puzzle (self
):
86 self
.current_file
= raw_input ("New puzzle file name: ")
87 srows
= raw_input ("Number of rows: ")
88 scols
= raw_input ("Number of cols: ")
93 print "Invalid number of rows/columns"
95 self
.puzzle
= crosswordpuzzle
.CrosswordPuzzle (rows
, cols
)
96 self
.do_puzzle_loop ()
98 # Main application loop
99 def do_main_loop (self
):
103 print self
.BOLD
+ "-----------------------------------"
104 print "Get A Clue - Crossword Puzzle Maker"
105 print "-----------------------------------" + self
.ENDCOL
106 print self
.BLUE
+ "1. Start a new puzzle"
107 print "2. Open an existing puzzle"
108 print "X. Exit" + self
.ENDCOL
109 ch
= raw_input (self
.BRICKRED
+ "Your choice: " + self
.ENDCOL
)
111 self
.on_new_puzzle ()
112 if ch
== 'x' or ch
== 'X':