Example #1
0
	def addWord(self, obj_word, obj_letter):
		dictionary = Dictionary()
		# find out who's turn it is
		playerId = self.getCurrentPlayerId()
		word = self.getWord(obj_word)
		# Check if word is in Dictionary
		if not dictionary.isWordValid(word):
			return Game.State.ERR_UNKNOWN_WORD
		# Check if word is not used yet
		elif  word in self.usedWords:
			return Game.State.ERR_ALREADY_USED
		# Check if word contains new added letter and allowed on the field
		elif  self.isWordNotValid(obj_word, obj_letter):
			return Game.State.ERR_WORD_IS_NOT_ON_FIELD
		# if word is valid
		else:
			self.passedMovement = 0
			self.players[playerId].words.append(word)
			self.gameField[obj_letter.posLine][obj_letter.posColumn] = obj_letter.letter
			# Increase score
			self.players[playerId].score += len(word)
			self.usedWords.append(word)
			self.lastWord = obj_word
			# Verify if there is no free spots in game field, end up the game
			if self.isGameFieldComplit():
				self.endGame()
				return Game.State.END_OF_GAME
			else:
				# Pass turn to next player
				self.setCurrentPlayer(self.getNextPlayerId())
				return Game.State.SUCCESS
Example #2
0
	def setFirstWord(self):
		dictionary = Dictionary()
		# length of word is same as field size
		word = dictionary.getWord(self.dimension)
		# this word cant be used again in the game
		self.usedWords.append(word)
		wordAsList = list(word)
		line = self.dimension/2
		# put it in the middle of gamefield
		for col in range(0, self.dimension):
			self.gameField[line][col] = word[col]