Ejemplo n.º 1
0
    def key_down(self, event):
        key = repr(event.char)
        if key in self.commands:
            self.matrix, changed, score = self.commands[repr(event.char)](
                self.matrix)
            if changed:
                logic.add_new_2(self.matrix)
                self.update_grid_cells()
                changed = False

        elif key == c.KEY_AI:
            while logic.get_current_state(self.matrix) == 'GAME NOT OVER':
                self.matrix, valid_game = ai_logic.ai_move(self.matrix, 45, 35)
                if valid_game:
                    self.matrix = logic.add_new_2(self.matrix)
                    self.update_grid_cells()

        self.update_grid_cells()
        time.sleep(3)

        if logic.get_current_state(self.matrix) == 'WON':
            self.grid_cells[1][1].configure(text="You",
                                            bg=c.BACKGROUND_COLOR_CELL_EMPTY)
            self.grid_cells[1][2].configure(text="Win!",
                                            bg=c.BACKGROUND_COLOR_CELL_EMPTY)

        elif logic.get_current_state(self.matrix) == 'LOST':
            self.grid_cells[1][1].configure(text="You",
                                            bg=c.BACKGROUND_COLOR_CELL_EMPTY)
            self.grid_cells[1][2].configure(text="Lose!",
                                            bg=c.BACKGROUND_COLOR_CELL_EMPTY)
Ejemplo n.º 2
0
	def key_down(self, event):
		key = repr(event.char)

		if key in self.commands:
			self.matrix, changed = self.commands[repr(event.char)](self.matrix)

			if changed:

				logic.add_new_2(self.matrix)
				self.update_grid_cells()
				changed = False

				if logic.get_current_state(self.matrix) == "Congratulations, you won the game.":
					self.grid_cells[1][1].configure(text='You', bg=c.BACKGROUND_COLOR_CELL_EMPTY)
					self.grid_cells[1][2].configure(text='Win', bg=c.BACKGROUND_COLOR_CELL_EMPTY)

				if logic.get_current_state(self.matrix) == 'Lost':
					self.grid_cells[1][1].configure(text='You', bg=c.BACKGROUND_COLOR_CELL_EMPTY)
					self.grid_cells[1][2].configure(text='Lose', bg=c.BACKGROUND_COLOR_CELL_EMPTY)
Ejemplo n.º 3
0
    mat = logic.start_game()

while (True):

    # taking the user input
    # for next step
    x = input("Press the command : ")

    # we have to move up
    if (x == 'W' or x == 'w'):

        # call the move_up funtion
        mat, flag = logic.move_up(mat)

        # get the current state and print it
        status = logic.get_current_state(mat)
        print(status)

        # if game not ove then continue
        # and add a new two
        if (status == 'GAME NOT OVER'):
            logic.add_new_2(mat)

        # else break the loop
        else:
            break

    # the above process will be followed
    # in case of each type of move
    # below