示例#1
0
	def drawInterface():
		guesses = settings["guesses"]
		colourNo = settings["colours"]
		pegNo = settings["pegs"]
		colourList = settings["colourList"]
		
		# Draw interface frame layout
		#================================================
		frame = GUI.Frame(gameScr, relief=GUI.RAISED, borderwidth=1, bg="white")
		frame.pack(fill=GUI.BOTH, expand=1)
		
		# Draw game board
		#================================================
		hintWidth = 8 + int((pegNo + 1) / 2) * 12
		gridWidth = 50 * pegNo + hintWidth
		cvsGrid = GUI.Canvas(frame, width=gridWidth, height=((guesses + 1) * 50 + guesses), bg="white")
		cvsGrid.pack(side=GUI.RIGHT)
		gridPegs = []
		hintPegs = []
		row = 0
		while row < guesses + 1:
			gridPegs.append([])
			hintPegs.append([])
			col = 0
			while col < pegNo:
			
				# Draw rows of pegs
				#================================================
				xPos = 50 * col + 3
				yPos = 50 * row + row + 3
				gridPegs[row].append(cvsGrid.create_oval(xPos, yPos, xPos + 44, yPos + 44, fill="black"))
				
				# Draw hint pegs
				#================================================
				if row < guesses:
					hintX = 50 * pegNo + 6 + int(col / 2) * 12
					if col % 2 == 0:
						hintY = 50 * row + 15 + row
					else:
						hintY = 50 * row + 27 + row
					hintPegs[row].append(cvsGrid.create_oval(hintX, hintY, hintX + 8, hintY + 8, fill="black"))
					
				# Separate rows with lines
				#================================================
				if row != 0:
					cvsGrid.create_line(0, yPos - 3, gridWidth, yPos - 3)
				col += 1
			row += 1
		
		# Draw common interface buttons
		#================================================
		btnQuit = GUI.Button(gameScr, text="Quit Game", fg="red", command=quitGame)
		btnQuit.pack(side=GUI.RIGHT)
		btnMenu = GUI.Button(gameScr, text="Back to Menu", command=openMenu)
		btnMenu.pack(side=GUI.RIGHT)
		btnRestart = GUI.Button(gameScr, text="Restart Game", command=restartGame)
		btnRestart.pack(side=GUI.RIGHT)
		btnNew = GUI.Button(gameScr, text="New Game", command=newGame)
		btnNew.pack(side=GUI.RIGHT)
		
		# Draw human codebreaker buttons
		#================================================
		if settings["mode"] == 1:
			for i in range(0, colourNo):
				btnColour = GUI.Button(frame, text=colourList[i], bg=colourList[i], width=12, height=5, command=lambda a=colourList[i]: selectPeg(a))
				btnColour.pack(anchor=GUI.W)
			btnDel = GUI.Button(frame, text="Undo", width=12, command=undo)
			btnDel.pack(anchor=GUI.W)
			btnSave = GUI.Button(gameScr, text="Save Game", command=lambda a=settings, b=gameEnded: file.saveGame(a, b))
			btnSave.pack(side=GUI.RIGHT)
		
		# Draw CPU codebreaker buttons
		#================================================
		if settings["mode"] == 2:
			btnAI = GUI.Button(gameScr, text="Start AI", fg="blue", command=lambda a=settings, b=GUI, c=gameScr, d=gameEnded, e=selectPeg: AI.startAI(a, b, c, d, e))
			btnAI.pack(side=GUI.RIGHT)
		
		# Set up canvas objects for manipulation
		#================================================
		settings["grid"] = gridPegs
		settings["hints"] = hintPegs
		settings["canvas"] = cvsGrid
		
		# Resume a loaded game
		#================================================
		if load == True:
			loadGrid = loadData[0]
			loadHints = loadData[1]
			for row in range(0, settings["guesses"]):
				for col in range(0, settings["pegs"]):
					settings["canvas"].itemconfig(settings["grid"][row][col], fill=loadGrid[row][col])
					settings["canvas"].itemconfig(settings["hints"][row][col], fill=loadHints[row][col])