Beispiel #1
0
    def init_game(self, mode):
        game = Game()
        controller = Controller(game)

        ai = AI(game)
        first_player = Player(PieceColor.WHITE, controller,
                              ai if mode == GameMode.AI_VS_HUMAN else None)
        second_player = Player(PieceColor.BLACK, controller,
                               ai if mode == GameMode.HUMAN_VS_AI else None)

        players = [first_player, second_player]

        game_board = GameBoardWidget(game)
        for player in players:
            if player.type == PlayerType.HUMAN:
                game_board.move_receive_from_ui.append(
                    player.move_receive_from_ui_handler)

        if first_player.type == PlayerType.AI:
            first_player.move_complete_event(PieceColor.BLACK)

        Clock.schedule_interval(lambda delta_time: game_board.update(), 0.03)

        self.clear_widgets()

        game_widget = GameWidget(game)
        size = (game_board.width, game_board.height + 50)
        game_widget.size = size
        Window.size = size
        game_widget.set_game_board(game_board)
        self.add_widget(game_widget)
Beispiel #2
0
class mainwindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(mainwindow,self).__init__()
        '''TODO:view文件构建qt的布局。
        contro函数中的py文件,负责构造具体内容、按钮样式、生成图片等
        所有的触发公共接口都留到main.py中,后期根据具体需求考虑多线程。 '''
        self.view=Ui_MainWindow()
        self.view.setupUi(self)
        self.load_windows()
        '''TODO:调整背景
        self.setAutoFillBackground(True) # 设置背景颜色
        self.setStyleSheet("background-color:black;")
        self.setBackgroundRole(QtGui.QPalette.Midlight)
        '''

    def load_windows(self):
        self.page = historywindow()
        self.widget = informationwindow()
        self.page_2 = analysiswindow()
        self.page_3 = Player(sys.argv[1:])

        self.page.setObjectName("page")
        self.view.stackedWidget.addWidget(self.page)
    
        self.widget.setObjectName("widget")
        self.view.gridLayout.addWidget(self.widget, 0, 1, 4, 1)

        
        self.page_2.setObjectName("page_2")
        self.view.stackedWidget.addWidget(self.page_2)     
        
        self.page_3.setObjectName("page_3")
        self.view.stackedWidget.addWidget(self.page_3)

        '''按钮触发'''
        self.view.pushButton.clicked.connect(self.changed_history)
        self.view.pushButton_2.clicked.connect(self.changed_analysis)
        self.view.pushButton_3.clicked.connect(self.changed_video)

    def update_information():
        '''TODO:把history.py的函数调用中的数据接口部分放到main中,
            目的是:用户在选取MapId后,数据库的操作放到main中'''
        pass

    def upadte_history():
        pass

    '''按钮触发对应函数'''  
    def changed_history(self):
        self.view.stackedWidget.setCurrentIndex(0)
    def changed_analysis(self):
        self.view.stackedWidget.setCurrentIndex(1)
    def changed_video(self):
        self.view.stackedWidget.setCurrentIndex(2)
    def __movePlayerPosition(self, player: Player, rolledVal: int):

        x, y = player.getPlayerPosition()
        newposition = SnakeLadderGame._getNextPosition(x, y, rolledVal)
        x1, y1 = self.__checkSymbol(newposition)
        size = self.snakeLadderBoard.getSize() - 1

        if x1 == size:
            print("Move not possible, try in next turn")
        else:
            player.setPlayerPosition((x1, y1))
            print(f"Player moved from ${x} {y} to position ${x1} {y1}")

        if x1 == size - 1 and y1 == size - 1:
            print(f"Player {player.getName()} won")
            self.__setWinner(player)
            self.__setGameStatus(GameStatus.Completed)
    def __playGame(self, player: Player):

        #roll the dice
        rolledVal = player.playMove(dice)

        if rolledVal == -1:
            return

        #check if rolled value is greater
        self.__movePlayerPosition(player, rolledVal)
Beispiel #5
0
  def playMove(self, dice: DiceService):
    retry = HumanPlayer.RETRIES
    while val!=1 and retry > 0:
      print(f"Hi {self.name}, Please enter 1 to roll the dice")
      val = int(input())
      retry -= 1

    if val == 1:
      return Player.playMove(self.id)
    else :
      print("Try on next turn!")
      return -1
Beispiel #6
0
    def load_windows(self):
        self.page = historywindow()
        self.widget = informationwindow()
        self.page_2 = analysiswindow()
        self.page_3 = Player(sys.argv[1:])

        self.page.setObjectName("page")
        self.view.stackedWidget.addWidget(self.page)
    
        self.widget.setObjectName("widget")
        self.view.gridLayout.addWidget(self.widget, 0, 1, 4, 1)

        
        self.page_2.setObjectName("page_2")
        self.view.stackedWidget.addWidget(self.page_2)     
        
        self.page_3.setObjectName("page_3")
        self.view.stackedWidget.addWidget(self.page_3)

        '''按钮触发'''
        self.view.pushButton.clicked.connect(self.changed_history)
        self.view.pushButton_2.clicked.connect(self.changed_analysis)
        self.view.pushButton_3.clicked.connect(self.changed_video)
Beispiel #7
0
 def playMove(self, dice: DiceService):
   return Player.playMove(dice)
Beispiel #8
0
from controller.player import Player
from controller.diceservice import DiceService

class ComputerPlayer(Player):

  def __init__(self, id, name)
    Player.__init__(self, id, name, True)

  def playMove(self, dice: DiceService):
    return Player.playMove(dice)
Beispiel #9
0
from controller.player import Player
from controller.diceservice import DiceService

class HumanPlayer(Player):

  RETRIES = 3

  def __init__(self, id, name)
    Player.__init__(self, id, name, False)

  def playMove(self, dice: DiceService):
    retry = HumanPlayer.RETRIES
    while val!=1 and retry > 0:
      print(f"Hi {self.name}, Please enter 1 to roll the dice")
      val = int(input())
      retry -= 1

    if val == 1:
      return Player.playMove(self.id)
    else :
      print("Try on next turn!")
      return -1