Question
Please use python 2.7 or 3.5 **Most of the code is given, just need to connect it and call it from other classes.** Project Procedure:
Please use python 2.7 or 3.5
**Most of the code is given, just need to connect it and call it from other classes.**
Project Procedure: Create a single player KenKen game with the following features:
Driver: A driver file should be used to initialize the game and display the game GUI. The filename should be in the following format:
Game operation: The game should allow a player to play one of three games. When game starts, a game board should be presented to player. If player wins game, they should be notified and the game reset to another game board. There should be exactly three 5 x 5 game boards hard-coded into class objects in the application.
Game board class: A class should be designed to hold each game board. This class should hold all data (attributes) associated with the game board (including correct solution) and should provide appropriate methods that facilitate game operation (e.g., is current solution valid, accessors to facilitate game board GUI construction, etc.). A complex data structure should be utilized to store/access the game board objects in the appropriate file.
Game controls: The game should have exactly three controls: WIN? (checks the game board for a winning combination of numbers), RESET (reloads the current game) and QUIT (terminates the game). The player should select a number for each square using the mouse. The game should check for a winning number combination after each player interaction. If the player wins, a new game board should be loaded.
GUI: A GUI class should be implemented that contains all game GUI components and event model implementation. You need to have the following module for writing different parts of your code. Sample modules will be provided with the project specification.
o GUI module: Firstname_lastname_Project_GUI.py
This module is responsible for creating the basic interface of the program,
This should contain a class with the following possible (but not limited to) methods:
__init__()
create_widgets()
check() # checks to see if user wins
reset()
resetnums() #Resets all the current numbers
surrender(): #if user chooses to surrender then show the solution
next() #Reset the number choices and create the next puzzle
exit() #exit the game
This is the given Firstname_Lastname_GUI.py file. Have to make changes in the code below.
from firstname_lastname_Project_CLASS import KenKen from tkinter import *
class TheGUI(Frame): def __init__(self, master): Frame.__init__(self, master)
self.kenken = KenKen() self.puzzles = self.kenken.getpuzzles() self.linelist = self.kenken.getlines()
self.choice = ['','1','2','3','4','5'] #This keeps track of the puzzle number self.counter = 0 self.lblPuz = StringVar(self) self.lblPuz.set("Puzzle "+str(self.counter+1)) self.lbl1 = Label(self, textvariable = self.lblPuz,\ font = "Arial 20 bold").pack() #creating the components on the GUI self.w = Canvas(master, width=502, height=503) self.w.pack() self.tt = StringVar(self) self.sqlist = [] #This keeps track of the values for each block self.movelist =[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] self.numbers = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] #Creates the puzzle depending on the counter self.create_widgets(self.counter) self.w.bind("
def create_widgets(self, counter): pass
def exit(self,event): exit() def check(self,event): #Checks to see if the user wins pass
def change(self, event): #Updates the buttons to the current number row, column = self.kenken.changer(event) self.movelist[row][column] +=1 if self.movelist[row][column] >5: self.movelist[row][column] = 0 self.w.itemconfigure(self.numbers[row][column], \ text = self.choice[self.movelist[row][column]]) #As the user plays, it will continually check if the user wins or not self.check(event)
def resetnums(self): #Resets all the current numbers self.movelist = self.kenken.resetnum(self.movelist)
def reset(self, event): #Recreate the same game self.w.delete('all') self.resetnums() self.buttonlist.append(self.lbl) for i in range(len(self.buttonlist)): self.buttonlist[i].destroy()
self.create_widgets(self.counter) def surrend(self, event): #Shows the solution pass
def next(self, event): #Reset the number choices and create the next puzzle pass
o Class module: Firstname_lastname_Project_CLASS.py
This module is responsible for actual operations of the game.
This should contain a class with the following possible (but not limited to) methods:
__init__(): #Holds a big list that holds 3 puzzles, 3 solutions lists
getpuzzles() #Gives GUI the current puzzle
getlines(self) #Gives the GUI the layout of the puzzle
changer() #Changes the current user selection to another value
checkit() #This puts all the user numbers into a list for comparison with the solution
surrender() #Reveals the answer if player gives up
resetnum() #Reset player's values
This is the Firstname_Lastname_Class.py file code. Have to make changes in the code below.
class KenKen: def __init__(self): #A big list that holds 3 puzzles self.puzzlelist = [['11+','','','','','2/','','5','11+','','5','16x','',\ '20x','','4+','','','','','2/','','1-','','5'],['45x','','','7+','',\ '1-','','5','','3+','','9+','','9+','','2/','','','','','','16x','',\ '11+',''],['11+','','','','9+','15x','','','9+','','','8+','','','','5+',\ '8+','225x','','','','','','','']] #lines of the puzzle self.lines1 = [[100, 0, 100,400],[200,0,200,400],[300,0, 300,200],\ [300,400,300,500],[400,0, 400,400],[200,100,300,100],[100,200,200,200],\ [300,200,500,200],[100,300,400,300],[0,400,100,400],[200,400,300,400],\ [400,400,500,400],[400,400,400,500]] self.lines2 = [[100,0,100,100],[100,200,100,300],[100,400,100,500],\ [200,100,200,400],[300,0,300,100],[300,200,300,300],\ [300,400,300,500],[400,100,400,200],[400,300,400,400],[100,100,500,100],\ [100,200,200,200],[300,200,400,200],[0,300,500,300],[100,400,400,400]] self.lines3 = [[100,0,100,400],[200,100,200,200],[200,400,200,500],\ [300,0,300,400],[400,200,400,300],[400,400,400,500],\ [100,200,200,200],[200,100,500,100],[300,200,400,200],\ [100,300,300,300],[400,300,500,300],[0,400,200,400],[300,400,400,400]]
#Holds all 3 solution lists self.solution = [[[3,5,2,1,4],[4,2,5,3,1],[5,4,1,2,3],[1,3,4,5,2],\ [2,1,3,4,5]],[[5,1,3,2,4],[4,3,5,1,2],[3,5,2,4,1],[1,2,4,5,3],[2,4,1,3,5]],\ [[2,5,3,1,4],[3,1,4,2,5],[5,3,1,4,2],[4,2,5,3,1],[1,4,2,5,3]]]
def getpuzzles(self): #Gives GUI the current puzzle pass def getlines(self): #Gives the GUI the layout of the puzzle lines = [self.lines1, self.lines2, self.lines3] return lines
def changer(self,event): #Changes the current user selection to another value row = int(event.x/100) column = int(event.y/100) return row, column def checkit(self, numberlist, number): pass
def surrender(self, number): #Reveals the answer if player gives up return self.solution[number] def resetnum(self, checklist): pass
Driver module: Firstname_lastname_Project_DRIVER.py
This will initialize the game by creating the root window, set the GUI object and start the event with mainloop().
This is the Firstname_Lastname_Driver.py file. Have to make changes in the code below.
from firstname_lastname_Project_GUI import TheGUI from tkinter import *
#Starts up the game def main(): root = Tk() root.title("KenKen") root.geometry("600x660") TheGUI(root) mainloop()
if __name__ == main: main()
Here is a sample output:
Project sample board: KenKen 2/ 5 4+ 2/ 16x 5 1 20x 5 Puzzle 1 GOOD LUCK! WIN? Next Puzzle Surrender? RESET EXIT Project sample board: KenKen 2/ 5 4+ 2/ 16x 5 1 20x 5 Puzzle 1 GOOD LUCK! WIN? Next Puzzle Surrender? RESET EXITStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started