awacke1 commited on
Commit
bc09212
·
1 Parent(s): 250e43d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -30
app.py CHANGED
@@ -54,7 +54,7 @@ def validate_word(word, board):
54
  return True
55
  return False
56
 
57
- def boggle(size, time_limit):
58
  """Main function for playing the Boggle game"""
59
  st.title("Boggle Game")
60
  st.write("Find as many words as possible by connecting adjacent letters on the board.")
@@ -78,44 +78,63 @@ def boggle(size, time_limit):
78
  st.write("Here are your words:")
79
  st.write(words)
80
 
81
- def boggle_old(size, time_limit):
82
- """Main function for playing the Boggle game"""
83
  st.title("Boggle Game")
84
- st.write("Find as many words as possible by connecting adjacent letters on the board within the time limit.")
85
  st.write("Words must be at least three letters long and can only be used once.")
86
  board = generate_board(size)
87
  board_df = pd.DataFrame(board)
88
  st.write(board_df)
89
  words = set()
90
- start_time = time.time()
91
- form_id = 0
92
 
93
- with st.form(key=f"new_word_{form_id}"):
94
  new_word = st.text_input("Enter a new word:")
95
-
96
- if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
97
- words.add(new_word)
98
-
99
- st.write(f"Added {new_word} to the list of words!")
100
- st.form_submit_button(label='Submit')
101
- form_id += 1
102
-
103
- #while time.time() - start_time < time_limit:
104
- # st.markdown(""".
105
- # """)
106
  st.write("Here are your words:")
107
  st.write(words)
108
 
109
- # while time.time() - start_time < time_limit:
110
- # with st.form(key=f"new_word_{form_id}"):
111
- # new_word = st.text_input("Enter a new word:")
112
- # if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
113
- # words.add(new_word)
114
- # st.write(f"Added {new_word} to the list of words!")
115
- # st.form_submit_button(label='Submit')
116
- # form_id += 1
117
- #st.write("Time's up! Here are your words:")
118
- #st.write(words)
119
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  if __name__ == "__main__":
121
- boggle(7, 60)
 
 
 
 
 
54
  return True
55
  return False
56
 
57
+ def boggle_1(size, time_limit):
58
  """Main function for playing the Boggle game"""
59
  st.title("Boggle Game")
60
  st.write("Find as many words as possible by connecting adjacent letters on the board.")
 
78
  st.write("Here are your words:")
79
  st.write(words)
80
 
81
+ def boggle(size):
82
+ """Function for setting up the Boggle game"""
83
  st.title("Boggle Game")
84
+ st.write("Find as many words as possible by connecting adjacent letters on the board.")
85
  st.write("Words must be at least three letters long and can only be used once.")
86
  board = generate_board(size)
87
  board_df = pd.DataFrame(board)
88
  st.write(board_df)
89
  words = set()
 
 
90
 
91
+ with st.form(key="new_word"):
92
  new_word = st.text_input("Enter a new word:")
93
+ if st.form_submit_button("Submit"):
94
+ if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
95
+ words.add(new_word)
96
+ st.write(f"Added {new_word} to the list of words!")
97
+ elif new_word in words:
98
+ st.write("Word already used!")
99
+ else:
100
+ st.write("Invalid word. Try again.")
101
+
 
 
102
  st.write("Here are your words:")
103
  st.write(words)
104
 
105
+ return board, words
106
+
107
+
108
+ def play_boggle(board, words, time_limit):
109
+ """Function for playing the Boggle game"""
110
+ start_time = time.time()
111
+ remaining_time = time_limit
112
+
113
+ while remaining_time > 0:
114
+ with st.form(key="new_word"):
115
+ new_word = st.text_input("Enter a new word:")
116
+ if st.form_submit_button("Submit"):
117
+ if len(new_word) >= 3 and new_word not in words and validate_word(new_word.upper(), board):
118
+ words.add(new_word)
119
+ st.write(f"Added {new_word} to the list of words!")
120
+ elif new_word in words:
121
+ st.write("Word already used!")
122
+ else:
123
+ st.write("Invalid word. Try again.")
124
+
125
+ st.write("Here are your words:")
126
+ st.write(words)
127
+ st.write("Time remaining:", remaining_time)
128
+ time.sleep(1)
129
+ remaining_time = int(time_limit - (time.time() - start_time))
130
+
131
+ st.write("Time's up! Here are your final words:")
132
+ st.write(words)
133
+
134
+
135
  if __name__ == "__main__":
136
+ board, words = boggle(7)
137
+ play_boggle(board, words, 60)
138
+
139
+ #if __name__ == "__main__":
140
+ # boggle(7, 60)