Skip to content

Commit

Permalink
Added UI refinements to the Crossword game to display the meaning eff…
Browse files Browse the repository at this point in the history
…iciently.
  • Loading branch information
AnirbanBanik1998 committed Jul 22, 2018
1 parent 811a34f commit 277ea49
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Game/Games/Crossword/Crossword.py
Expand Up @@ -9,7 +9,6 @@
word2=""
word3=""
word4=""
k=1
def find(w, c, r):
'''
This function helps to find if there is an intersection between the c'th letter of a word and the r'th letter of another word given in the file.
Expand Down Expand Up @@ -44,6 +43,7 @@ def main():
'''
Uses the functions to generate 4 4-letter words for a 4 X 4 crossword.
'''
k=1
while k:
wordlist = []
my_randoms=random.randint(0,len(lines)-1)
Expand Down
57 changes: 47 additions & 10 deletions Game/Games/Crossword/maker1.py
Expand Up @@ -46,6 +46,33 @@ def message(self, msg, color, width, height, font_size, center=False):
else:
self.gameDisplay.blit(screen_text, [width, height])

def multi_line_text(self, surface, text, pos, font_size, color):
'''
Used to display multi_line text.
:param surface: The game display surface or window.
:param text: The single(or multi-line)text to be displayed.
:param pos: The width and height positions of the text, to be entered in tuple format.
:param font_size: The display font_size of the text.
:param color: The color of the text to be displayed on screen.
'''
words = [word.split(' ') for word in text.splitlines()]
font=pygame.font.SysFont(None, font_size)
space = font.size(' ')[0]
max_width, max_height = surface.get_size()
x, y = pos
for line in words:
for word in line:
word_surface=font.render(word,True,color)
word_width, word_height=word_surface.get_size()
if x+word_width >= max_width:
x=pos[0]
y+=word_height
surface.blit(word_surface, (x,y))
x +=word_width+space
x=pos[0]
y+=word_height

def meaning(self, w):
'''
Extracts the meaning out of the line containing the word.
Expand Down Expand Up @@ -96,11 +123,21 @@ def formation(self, w, q):
:return: The updated string if within game-running time, or else returns "END".
'''
self.message(self.n, self.white, 0, self.display_height/4, 30)
string1=""
mean_string="Meaning of the word is :"
f=pygame.font.SysFont(None, 25)
word_surf=f.render(mean_string, True, self.green)
word_wid, word_hei=word_surf.get_size()
self.multi_line_text(self.gameDisplay, mean_string, (0, self.display_height/10), 25, self.green)
pygame.display.update()
self.multi_line_text(self.gameDisplay, self.n, (word_wid, self.display_height/8), 25, self.black)
pygame.display.update()
self.message("Meaning of the word is "+str(self.mean[q]), self.white, 0, self.display_height/4, 30)
for meaning in self.mean[q]:
print(meaning)
string1=string1+meaning+"\n"
self.multi_line_text(self.gameDisplay, string1, (word_wid, self.display_height/8), 25, self.white)
pygame.display.update()
self.n="Meaning of the word is "+str(self.mean[q])
self.n=string1

k=0
str1=""
Expand All @@ -114,11 +151,11 @@ def formation(self, w, q):
else:
string=w
str1=w
self.message(self.m, self.black, self.display_width/3, self.display_height/3, 30, True)
self.message(self.m, self.black, self.display_width/2, self.display_height/3, 30, True)
pygame.display.update()
self.message(str1, self.white, self.display_width/3, self.display_height/3, 30, True)
self.message("Output: "+str1, self.white, self.display_width/2, self.display_height/3, 30, True)
pygame.display.update()
self.m=str1
self.m="Output: "+str1
str1=""
while k<15:
k=k+1
Expand All @@ -143,11 +180,11 @@ def formation(self, w, q):
str1=""
for j in range(0, len(string)):
str1=str1+string[j]+" "
self.message(self.m, self.black, self.display_width/3, self.display_height/3, 30, True)
self.message(self.m, self.black, self.display_width/2, self.display_height/3, 30, True)
pygame.display.update()
self.message(str1, self.white, self.display_width/3, self.display_height/3, 30, True)
self.message("Output: "+str1, self.white, self.display_width/2, self.display_height/3, 30, True)
pygame.display.update()
self.m=str1
self.m="Output: "+str1
if string==q or k==15:
return string
elif int(round(time.time())-self.start)>=180:
Expand Down Expand Up @@ -202,7 +239,7 @@ def main():
gameExit=False
clock=pygame.time.Clock()
while not gameExit:
c.message("Crossword", c.blue, c.display_width/7, c.display_height/7, 50)
c.message("Crossword", c.blue, c.display_width/20, c.display_height/20, 50)
pygame.display.update()
n=0
s=0
Expand Down

0 comments on commit 277ea49

Please sign in to comment.