Курсовая работа по предмету МиТП на тему создания программы для игры в слова. Курсовая работа. Составляем слова
Скачать 1.43 Mb.
|
controller.show_frame("Play_Computer")], activebackground='#a7ccdf', font=("Helvetica", 14, tkfont.BOLD, tkfont.ITALIC), height=2, width=20) button_2.pack() button_3 = tk.Button(self, text="Я", command=lambda: [main_text_Computer.insert(1.0, 'Первый ход делаете Вы'), controller.show_frame("Play_Computer")], activebackground='#a7ccdf', font=("Helvetica", 14, tkfont.BOLD, tkfont.ITALIC), height=2, width=20) button_3.pack() class TwoPlayers(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.controller = controller label = tk.Label(self, text="Выберите кто будет ходить первым", font=("Helvetica", 14, tkfont.BOLD, tkfont.ITALIC)) label.pack(side="top", fill="x", pady=10) button_1 = tk.Button(self, text="Случайный выбор", command=lambda: [random_move_TwoPlayers(), controller.show_frame("Play_TwoPlayers")], activebackground='#a7ccdf', font=("Helvetica", 14, tkfont.BOLD, tkfont.ITALIC), height=2, width=20) button_1.pack() button_2 = tk.Button(self, text="Игрок 1", command=lambda: [main_text_TwoPlayers.insert(1.0, 'Первый ход делает Игрок 1'), controller.show_frame("Play_TwoPlayers")], activebackground='#a7ccdf', font=("Helvetica", 14, tkfont.BOLD, tkfont.ITALIC), height=2, width=20) button_2.pack() button_3 = tk.Button(self, text="Игрок 2", command=lambda: [main_text_TwoPlayers.insert(1.0, 'Первый ход делает Игрок 2'), controller.show_frame("Play_TwoPlayers")], activebackground='#a7ccdf', font=("Helvetica", 14, tkfont.BOLD, tkfont.ITALIC), height=2, width=20) button_3.pack() class Play_TwoPlayers(tk.Frame): def word_entred(self): global used_words, player, score_Player_1, score_Player_2 main_text_TwoPlayers.configure(state='normal') ent_word = label_word_TwoPlayers.cget("text").strip('Введенное слово: ') new_word = entry_new_word_TwoPlayers.get() words = possible_words(input_list, ent_word) for word in words: if new_word == word: main_text_TwoPlayers.insert(tk.END, "\nИгрок" + player + " ввел слово: " + new_word + "\n") used_words.append(new_word) if player == "1": score_Player_1 += 1 player = "2" else: score_Player_2 += 1 player = "1" label_score_TwoPlayers['text'] = "Игрок1 :" + str(score_Player_1) + " Игрок2: " + str( score_Player_2) main_text_TwoPlayers.insert(tk.END, "\nХодит Игрок" + player) main_text_TwoPlayers.see(tk.END) main_text_TwoPlayers.configure(state='disabled') break for i in range(len(used_words)): if new_word == used_words[i]: main_text_TwoPlayers.insert(tk.END, "\nДанное слово уже было использовано. Попробуйте ввести другое") main_text_TwoPlayers.see(tk.END) main_text_TwoPlayers.configure(state='disabled') break else: main_text_TwoPlayers.insert(tk.END, "\nИгрок" + player + " ввел неправильное слово") main_text_TwoPlayers.see(tk.END) main_text_TwoPlayers.configure(state='disabled') def first_Launch(self): global player, used_words main_text_TwoPlayers.configure(state='disabled') create_word(label_word_TwoPlayers) used_words = list() player = '1' def __init__(self, parent, controller): global label_word_TwoPlayers, main_text_TwoPlayers, entry_new_word_TwoPlayers, new_word, label_score_TwoPlayers tk.Frame.__init__(self, parent) self.controller = controller label_word_TwoPlayers = tk.Label(self, font=controller.title_font) label_word_TwoPlayers.pack(side="top", fill="x", pady=10) main_text_TwoPlayers = tk.Text(self, font=controller.title_font, height=10) main_text_TwoPlayers.pack(side="top", fill="x") main_text_TwoPlayers.pack_propagate(0) main_text_TwoPlayers_scrollbar = tk.Scrollbar(main_text_TwoPlayers, orient=tk.VERTICAL, command=main_text_TwoPlayers.yview) main_text_TwoPlayers.config(yscrollcommand=main_text_TwoPlayers_scrollbar.set) main_text_TwoPlayers_scrollbar.pack(side="right", fill="y", pady=10) label_score_TwoPlayers = tk.Label(self, font=controller.title_font, text='Игрок1: 0 Игрок2: 0') label_score_TwoPlayers.pack(side="top", fill="x", pady=10) entry_new_word_TwoPlayers = tk.Entry(self, font=controller.title_font) entry_new_word_TwoPlayers.pack(side="top", fill="x", pady=10) button_new_word_TwoPlayers = tk.Button(self, font=controller.title_font, text='Ввести слово', command=self.word_entred) button_new_word_TwoPlayers.pack(side="top", fill="x") button_surrender_TwoPlayers = tk.Button(self, font=controller.title_font, text='Сдаться', command=surrender_TwoPlayers) button_surrender_TwoPlayers.pack(side="top", fill="x") class Play_Computer(tk.Frame): def get_word_Computer(self): global used_words, score_Computer ent_word = label_word_Computer.cget("text").strip('Введенное слово: ') get_words = list() get_words = possible_words(input_list, ent_word) if get_words == list(): surrender_Computer_Computer() new_word = random.choice(get_words) used_words.append(new_word) main_text_Computer.configure(state='normal') main_text_Computer.insert(tk.END, "\nКомпьютер ввел слово: " + new_word + "\n") main_text_Computer.insert(tk.END, "\nХод переходит Игроку") main_text_Computer.see(tk.END) main_text_Computer.configure(state='disabled') score_Computer += 1 label_score_Computer['text'] = "Игрок: " + str(score_Player) + " Компьютер: " + str(score_Computer) def word_entred(self): global used_words, score_Player main_text_Computer.configure(state='normal') ent_word = label_word_Computer.cget("text").strip('Введенное слово: ') new_word = entry_new_word_Computer.get() words = possible_words(input_list, ent_word) for word in words: if new_word == word: main_text_Computer.insert(tk.END, "\nВы ввели слово: " + new_word + "\n") used_words.append(new_word) score_Player += 1 label_score_Computer['text'] = "Игрок: " + str(score_Player) + " Компьютер: " + str( score_Computer) main_text_Computer.insert(tk.END, "\nХод переходит компьютеру") main_text_Computer.see(tk.END) main_text_Computer.configure(state='disabled') self.get_word_Computer() break for i in range(len(used_words)): if new_word == used_words[i]: main_text_Computer.insert(tk.END, "\nДанное слово уже было использовано. Попробуйте ввести другое") main_text_Computer.see(tk.END) main_text_Computer.configure(state='disabled') break else: main_text_Computer.insert(tk.END, "\nВы ввели неправильное слово") main_text_Computer.see(tk.END) main_text_Computer.configure(state='disabled') def first_Launch(self): global used_words create_word(label_word_Computer) used_words = list() main_text_Computer.configure(state='disabled') if main_text_Computer.get("1.0", 'end-1c') == "Первый ход делает компьютер": self.get_word_Computer() def __init__(self, parent, controller): global label_word_Computer, main_text_Computer, used_words, entry_new_word_Computer, label_score_Computer tk.Frame.__init__(self, parent) self.controller = controller label_word_Computer = tk.Label(self, font=controller.title_font) label_word_Computer.pack(side="top", fill="x", pady=10) main_text_Computer = tk.Text(self, font=controller.title_font, height=10) main_text_Computer.pack(side="top", fill="x", pady=10) main_text_Computer.pack_propagate(0) main_text_Computer_scrollbar = tk.Scrollbar(main_text_Computer,orient=tk.VERTICAL, command=main_text_Computer.yview) main_text_Computer.config(yscrollcommand=main_text_Computer_scrollbar.set) main_text_Computer_scrollbar.pack(side="right", fill="y", pady=10) label_score_Computer = tk.Label(self, font=controller.title_font, text="Игрок: 0 Компьютер: 0") label_score_Computer.pack(side="top", fill="x", pady=10) entry_new_word_Computer = tk.Entry(self, font=controller.title_font) entry_new_word_Computer.pack(side="top", fill="x", pady=10) button_new_word_Computer = tk.Button(self, font=controller.title_font, text='Ввести слово', command=self.word_entred) button_new_word_Computer.pack(side="top", fill="x") button_surrender_Computer = tk.Button(self, font=controller.title_font, text='Сдаться', command=surrender_Computer_Player) button_surrender_Computer.pack(side="top", fill="x") if __name__ == '__main__': app = SampleApp() app.mainloop() |