Example #1
0
	def __createGameOnClick(self):
		from backend import Callback

		# TODO validate ipt length
		gameId = self.__createGameIpt.text()
		logging.info("Creating game: %s", gameId)
		cb = Callback()
		cb.onAction = lambda success: self.__onCreateGame(success)
		self.__backend.createGame(gameId, cb)
		self.__interfaceEnabled(False)
Example #2
0
	def __init__(self, backend):
		from backend import Callback

		super(ConnectDialog, self).__init__()
		self.__backend = backend
		self.__setupGui()

		cb = Callback()
		cb.onAction = lambda servers: self.__onUpdateServers(servers)
		self.__onUpdateServers(self.__backend.registerUdpDiscoveryCallback(cb))
Example #3
0
	def __joinGameOnClick(self):
		from backend import Callback

		if self.__gamesWidget.count() > 0:
			gameId = self.__gamesWidget.currentItem().text().split(":")[0]
			cb = Callback()
			cb.onAction = lambda success: self.__onJoinGame(success)
			self.__backend.joinGame(gameId, cb)
			self.__interfaceEnabled(False)
		else:
			self.__showMessageBox("No game available", "There is is game to join.")
Example #4
0
	def __leaveGame(self):
		from backend import Callback

		if self.__leaveGameBtn.text().replace('&', '') == "Capitulate":
			self.__showMessageBox("Capitulation", "You capitulated.")
			cb = Callback()
			cb.onAction = lambda: self.__onCapitulate()
			self.__backend.capitulate(cb)
		elif self.__leaveGameBtn.text().replace('&', '') == "New Game":
			self.__resetClient()
		else:
			self.__showMessageBox("Game aborted", "Game aborted. You can now join or create another one.")
			self.__backend.leaveGame()
Example #5
0
	def __init__(self, backend):
		from backend import Callback

		self.__backend = backend
		self.__gamesListCb = Callback()
		self.__gamesListCb.onAction = lambda: self.__onUpdateGamesList()
		players, games = self.__backend.registerLobbyUpdateGamesCallback(self.__gamesListCb)

		super(LobbyDialog, self).__init__()
		self.__setupGui()
		self.__onUpdateGamesList()
Example #6
0
	def __onUpdateClientStatus(self):
		from backend import ClientStatus

		status = self.__backend.clientStatus
		if status is ClientStatus.NOTCONNECTED:
			self.__statusLbl.setText("Please connect to a server.")
			self.__setup()
			self.__onRepaint()
		elif status is ClientStatus.NOGAMERUNNING:
			self.__onRepaint()
			self.__statusLbl.setText("No game running, please use the lobby to connect to a game.")
			self.__playersLbl.setText("Nickname: %s" % self.__backend.lobby.nickname)
			self.__lobbyBtn.setEnabled(True)
			self.__connectBtn.setText("Disconnect")
			self.__connectBtn.setEnabled(True)
			self.__leaveGameBtn.setEnabled(False)
			self.__viewModel.reset()
		elif status is ClientStatus.WAITINGFOROPPONENT:
			self.__statusLbl.setText("Waiting for opponent now.")
			self.__placeShipBtn.setEnabled(False)
			self.__connectBtn.setEnabled(False)
			self.__lobbyBtn.setEnabled(False)
			self.__leaveGameBtn.setEnabled(True)
		elif status is ClientStatus.PREPARATIONS:
			from backend import Callback

			self.__statusLbl.setText("Please place your ships.")
			self.__placeShipBtn.setEnabled(True)
			self.__updatePlayersLbl()

			cb = Callback()
			cb.onAction = lambda shipId: self.__onUpdateShipList(shipId)
			self.__backend.registerShipUpdateCallback(cb)
			self.__leaveGameBtn.setEnabled(True)
		elif status is ClientStatus.OWNTURN:
			self.__statusLbl.setText("It is your turn.")
			self.__enableGamePlayButtons()

			logging.debug("WTFFFF " + self.__leaveGameBtn.text())
			if self.__leaveGameBtn.text().replace('&', '') == "Leave Game":
				self.__leaveGameBtn.setText("Capitulate")

		elif status is ClientStatus.OPPONENTSTURN:
			self.__statusLbl.setText("Please wait for your opponent.")
			self.__disableGamePlayButtons()
		elif status is ClientStatus.YOUWIN:
			self.__statusLbl.setText("You win!")
			self.__disableGamePlayButtons()

			self.__leaveGameBtn.setText("New Game")
			self.__leaveGameBtn.setEnabled(True)
			self.__connectBtn.setEnabled(True)
			self.__lobbyBtn.setEnabled(True)
		elif status is ClientStatus.YOULOSE:
			self.__statusLbl.setText("You lose!")
			self.__disableGamePlayButtons()

			self.__leaveGameBtn.setText("New Game")
			self.__leaveGameBtn.setEnabled(True)
			self.__connectBtn.setEnabled(True)
			self.__lobbyBtn.setEnabled(True)
Example #7
0
	def __init__(self, backend, fieldLength, devmode):
		import os
		from backend import Callback

		self.__backend = backend
		self.__fieldLength = fieldLength
		self.devmode = devmode

		self.__viewModel = ViewModel(self)
		self.__fieldLength = fieldLength
		self.__connectDialogAlreadyOpen = False
		self.__lobbyAlreadyOpen = False

		super(MainForm, self).__init__()
		self.__setupGui()
		self.__setup()

		clientStatusCb = Callback()
		clientStatusCb.onAction = lambda: self.__onUpdateClientStatus()
		self.__backend.registerClientStatusCallback(clientStatusCb)
		self.__onUpdateClientStatus()

		repaintCb = Callback()
		repaintCb.onAction = lambda: self.__onRepaint()
		self.__backend.registerRepaintCallback(repaintCb)

		chatCb = Callback()
		chatCb.onAction = lambda authorId, timestamp, message: self.__onIncomingChatMessage(authorId, timestamp,
																							message)
		self.__backend.registerChatCallback(chatCb)

		errorCb = Callback()
		errorCb.onAction = lambda error: self.__onError(error)
		self.__backend.registerErrorCallback(errorCb)

		opponentJoinedCb = Callback()
		opponentJoinedCb.onAction = lambda: self.__updatePlayersLbl()
		self.__backend.registerOpponentJoinedGameCallback(opponentJoinedCb)

		specialAttackCb = Callback()
		specialAttackCb.onAction = lambda: self.__onSpecialAttack()
		self.__backend.registerSpecialAttackCallback(specialAttackCb)

		leaveGameCb = Callback()
		leaveGameCb.onAction = lambda: self.__onLeaveGame()
		self.__backend.registerLeaveGameCallback(leaveGameCb)

		soundCb = Callback()
		soundCb.onAction = lambda type: self.__onPlaySound(type)
		self.__backend.registerPlaySoundCallback(soundCb)