Esempio n. 1
0
def _move():
    flag = 0
    for enemy in people.Enemy.enemies:
        x = enemy.x
        y = enemy.y

        if Board.board[enemy.x + 1][enemy.y] == '-':
            Board.board[enemy.x][enemy.y] = ' '
            for en in people.Enemy.enemies:
                if en.x == enemy.x and en.y == enemy.y:
                    people.Enemy.enemies.remove(en)

        elif (Board.board[x][y - 1] in people.obstacles
              or Board.board[x + 1][y - 1] == '-'):
            enemy.hit += 1

        elif (Board.board[x][y + 1] in people.obstacles
              or Board.board[x + 1][y + 1] == '-'):
            enemy.hit += 1

        elif (Board.board[x][y - 1] == 'T' and Board.board[x][y + 1] == 'T'):
            flag = 1

    for enemy in people.Enemy.enemies:
        if (enemy.hit % 2 == 1 and flag == 0):
            if people.Enemy._move_forward(enemy) == "exit":
                return "exit"
        elif (enemy.hit % 2 == 0 and flag == 0):
            if people.Enemy._move_backward(enemy) == "exit":
                return "exit"

    os.system('clear')
    init_board(Board.prev_i, Board.prev_j, Board.prev_k)
Esempio n. 2
0
    def go_up(self):
        """jump up for mario"""
        self.x, self.y = Mario._get_coordinates(Board.prev_i, Board.prev_j,
                                                Board.prev_k)
        Mario._pass(self.x, self.y)
        temp = self.x
        flag = 0
        while (temp >= self.x - 8):
            if (Board.board[temp][self.y] in obstacles):
                flag = 1
                temp_x = temp + 1
                break
            temp = temp - 1

        if (not flag):
            temp_x = self.x - 8

        if Board.board[temp_x - 1][self.y] == 'B':
            new = self.y
            for i in range(new - 4, new + 5):
                if Board.board[temp_x - 1][i] == 'B':
                    Board.board[temp_x - 1][i] = 'T'
            Mario.bonus += 50
            if self.y == 229 or self.y == 230 or self.y == 231:
                Board.board[23][230] = 'P'

        Board.board[temp_x][self.y] = 'M'
        os.system('clear')
        init_board(Board.prev_i, Board.prev_j, Board.prev_k)
Esempio n. 3
0
    def _move_backward(self):
        self.x, self.y = Mario._get_coordinates(Board.prev_i, Board.prev_j,
                                                Board.prev_k)
        if (self.y > Board.prev_j):
            self.y = self.y - 1
            if Board.board[self.x][self.y] == '0':
                Mario._pass(self.x, self.y + 1)
                Mario.score += 1
                Board.board[self.x][self.y] = 'M'

            if Board.board[self.x][self.y] == '@':
                Mario._pass(self.x, self.y + 1)
                Mario.lives -= 1
                call(["aplay", "-q", "smb_mariodie.wav"])
                if Mario.lives <= 0:
                    call(["aplay", "-q", "smb_gameover.wav"])
                    return
                os.system('clear')
                print(
                    "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tNumber of Mario left",
                    Mario.lives)
                Mario.respawn(self.x, self.y)
                time.sleep(2)
                init_board(Board.prev_i, Board.prev_j, Board.prev_k)

            elif Board.board[self.x][self.y] == 'P':
                Mario.lives += 1
                Mario._pass(self.x, self.y + 1)
                Board.board[self.x][self.y] = 'M'
                call(["aplay", "-q", "smb_1-up.wav"])

            elif Board.board[self.x][self.y] == 'A':
                Mario._pass(self.x, self.y + 1)
                Board.board[self.x][self.y] = 'M'
                Mario.attack = 1
                call(["aplay", "-q", "smb_powerup.wav"])

            elif (Board.board[self.x][self.y] == '/'):
                Mario._pass(self.x, self.y + 1)
                Board.board[self.x - 1][self.y] = 'M'

            elif (Board.board[self.x][self.y] in obstacles):
                Mario._pass(self.x, self.y + 1)
                Board.board[self.x][self.y + 1] = 'M'

            elif ((Board.board[self.x + 1][self.y + 1] == '/'
                   or Board.board[self.x + 1][self.y + 1] == 'T')
                  and Board.board[self.x + 1][self.y] == ' '):
                Mario._pass(self.x, self.y + 1)
                Board.board[self.x][self.y - 1] = 'M'
                Mario.go_down(self)
            else:
                Mario._pass(self.x, self.y + 1)
                Board.board[self.x][self.y] = 'M'

        os.system('clear')
        init_board(Board.prev_i, Board.prev_j, Board.prev_k)
Esempio n. 4
0
def main():
    # Handles command line args
    if len(sys.argv) != 3:
        print("Incorrect amount of args")
        return
    
    args = sys.argv[1:]
    try:
        int(args[0])
        float(args[1])
    except ValueError:
        print("Incorrect arg types")
        return
    

    if(int(args[0]) != 1 and float(args[1]) != 2):
        print("Turn arg must be 1 or 2")
        return

    # Initializes board
    board = init_board()
    turn = int(args[0])
    print("Initial board:")
    utils.print_board(board)

    # Loops until someone wins
    while len(utils.get_next_board_states(board, turn)) > 0:
        board = montecarlo(board, turn, float(args[1]))
        print(f"{turn} goes")
        utils.print_board(board)
        turn = utils.next_turn(turn)
    
    print(f"{utils.next_turn(turn)} wins!")
Esempio n. 5
0
def main():
    print "Hello, start game"
    windows = get_window()
    if len(windows) != 1:
        print "Cannot find window"
        exit()
    window = windows[0]

    board = [[0 for x in range(8)] for y in range(8)]
    board2 = [[0 for x in range(8)] for y in range(8)]
    Matrix = Board.find_matrix(window)
    Board.init_board(Matrix)
    while True:
        Board.fill_table(window, Matrix, board)
        Strategy.print_board(board)
        moveboard = Strategy.check_move(board)
        #        Strategy.print_board(board)
        do_move(window, Matrix, moveboard)
        time.sleep(0.5)
Esempio n. 6
0
def boss_round():
    os.system('clear')
    print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tBOSS ROUND")
    Board.prev_j = 400
    Board.prev_k = 500

    for i in range(6, 36):
        for j in range(Board.prev_j, 650):
            Board.board[i][j] = ' '

    people.Mario.bullets = []

    Board.board[6:, 498:500] = 'X'
    Board.board[35][Board.prev_j + 10] = 'M'
    people.Boss.attack = 1
    people.Boss.health = 100

    boss = people.Boss()

    time.sleep(3)
    init_board(38, Board.prev_j, Board.prev_k)
Esempio n. 7
0
def run_game():
    not_quit = True
    p1_turn = False  # This will make sense below for who goes first
    p1_x = game.start_game()

    while not_quit:

        # Clear the display
        clear_display()

        # Initialize the game
        game_board = board.init_board()

        status = game.get_status(game_board, game.get_marker(p1_turn, p1_x))

        # Take turns until game is won or lost or quit
        while status == "ongoing":

            # Change whose turn it is
            p1_turn = not p1_turn

            # Set current marker
            marker = game.get_marker(p1_turn, p1_x)

            # Get choice positions and valid positions and move
            print("\n----------------")
            print("\nOpen Options Board:")
            move_choice = game.move(*board.get_open_pos(game_board), p1_turn)

            # Update the board
            game_board = board.update_game_board(game_board, move_choice,
                                                 marker)

            # Clear the display
            clear_display()

            # Display the Board
            print("\nGame Board:")
            board.display_board(game_board)

            # Check if game is won or stalemate
            status = game.get_status(game_board, marker)
            if status != "ongoing":
                break

            t_sleep(1)

        # See if they want to play again
        not_quit = game.set_replay(status, p1_turn)

    print("\nSorry to see you go, but I'll enjoy watching you walk away :)")
Esempio n. 8
0
def reset_game(p1_turn):
    """
    Reset the game_board and who goes first (opposite of who went first last time).

    Parameters
    ----------
    p1_turn : bool
        Whether or not it is player 1's turn

    Returns
    -------
    game_board : list
        Reset game_board to initial status

    p1_turn : bool
        Whether or not it is player 1's turn
    """

    return board.init_board(), not p1_turn
Esempio n. 9
0
from threading import Thread
"""
Done by:
1003158 Lim Thian Yew
1004879 Gao Fancheng
1005013 Joseph Low
1005351 Janani Sureshkumar
"""

input = get_input.get_input

# https://docs.python.org/3/library/threading.html
# https://benedictwilkinsai.github.io/post/tkinter-mp/

# create GUI window
gui_board = board.init_board(start=False)
# attach write event hook to wrapper board object
game.on_board_update = gui_board.set_board
game.on_board_reset = gui_board.reset_board
multiplayer.on_board_update = gui_board.set_board
multiplayer.on_board_reset = gui_board.reset_board
game_func = None

while game_func is None:
    use_multiplayer = input('multiplayer? (y/n) ')
    use_multiplayer = use_multiplayer.strip()

    if use_multiplayer == 'n':
        game_func = game.game
    elif use_multiplayer == 'y':
        game_func = multiplayer.main
Esempio n. 10
0
import board
from play import play

if __name__ == '__main__':
    board.init_board()
    board.show_board()
    play()
Esempio n. 11
0
    def go_down(self):
        """coming down for mario"""
        self.x, self.y = Mario._get_coordinates(Board.prev_i, Board.prev_j,
                                                Board.prev_k)
        if (Board.board[self.x + 1][self.y] == '@'):
            Mario.bonus += 100
            Board.board[self.x + 1][self.y] = 'M'
            call(["aplay", "-q", "smb_stomp.wav"])

            for en in Enemy.enemies:
                if en.x == self.x + 1 and en.y == self.y:
                    Enemy.enemies.remove(en)
            Mario._pass(self.x, self.y)

        elif Board.board[self.x +
                         1][self.y] == 'S' or Board.board[self.x +
                                                          1][self.y] == 'E':
            Mario._pass(self.x, self.y)
            Board.board[self.x - 25][self.y] = 'M'

        elif Board.board[self.x + 1][self.y] == 'P':
            Mario.lives += 1
            Mario._pass(self.x, self.y)
            Board.board[self.x + 1][self.y] = 'M'
            call(["aplay", "-q", "smb_1-up.wav"])

        elif Board.board[self.x + 1][self.y] == 'A':
            Mario.attack = 1
            Board.board[self.x][self.y] = ' '
            Board.board[self.x + 1][self.y] = 'M'
            call(["aplay", "-q", "smb_powerup.wav"])

        elif Board.board[self.x + 1][self.y] == '-':
            Mario._pass(self.x, self.y)
            Mario.lives -= 1
            call(["aplay", "-q", "smb_mariodie.wav"])
            if Mario.lives <= 0:
                call(["aplay", "-q", "smb_gameover.wav"])
                return "exit"
            minimum = 500
            os.system('clear')
            Board.board[self.x][self.y] = ' '
            print(
                "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tNumber of Mario left:",
                Mario.lives)
            for gaps in Board.gap:
                if self.y - gaps >= 0:
                    if self.y - gaps < minimum:
                        minimum = self.y - gaps
                        temp_space = gaps

            Board.board[35][temp_space - 3] = 'M'
            time.sleep(2)

        elif Board.board[self.x + 1][self.y] == '0':
            Mario._pass(self.x, self.y)
            Mario.score += 1
            Board.board[self.x + 1][self.y] = 'M'

        elif Board.board[self.x +
                         1][self.y] == '/' or Board.board[self.x +
                                                          1][self.y] == '<':
            Board.board[self.x][self.y] = 'M'

        elif Board.board[self.x + 1][self.y] not in obstacles:
            Mario._pass(self.x, self.y)
            Board.board[self.x + 1][self.y] = 'M'

        os.system('clear')
        init_board(Board.prev_i, Board.prev_j, Board.prev_k)
Esempio n. 12
0
    def _move_forward(self):
        """move forward fo mario"""
        self.x, self.y = Mario._get_coordinates(Board.prev_i, Board.prev_j,
                                                Board.prev_k)
        if (self.y <= 798):
            self.y = self.y + 1
            if Board.board[self.x][self.y] == '0':
                Mario.score += 1
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x][self.y] = 'M'

            elif Board.board[self.x][self.y] == 'P':
                Mario.lives += 1
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x][self.y] = 'M'
                call(["aplay", "-q", "smb_1-up.wav"])

            elif Board.board[self.x][self.y] == 'A':
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x][self.y] = 'M'
                Mario.attack = 1
                call(["aplay", "-q", "smb_powerup.wav"])

            elif Board.board[self.x][self.y] == '@':
                Mario._pass(self.x, self.y - 1)
                Mario.lives -= 1
                call(["aplay", "-q", "smb_mariodie.wav"])
                if Mario.lives <= 0:
                    call(["aplay", "-q", "smb_gameover.wav"])
                    return "exit"
                os.system('clear')
                print(
                    "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tNumber of Mario left",
                    Mario.lives)
                Mario.respawn(self.x, self.y)
                time.sleep(2)
                init_board(Board.prev_i, Board.prev_j, Board.prev_k)

            elif (Board.board[self.x][self.y] == '/'):
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x - 1][self.y] = 'M'

            elif Board.board[self.x][self.y] == 'I':
                Mario._pass(self.x, self.y - 1)
                call(["aplay", "-q", "smb_stage_clear.wav"])
                Board.bonus_round()

            elif Board.board[self.x][self.y] == 'K':
                Mario._pass(self.x, self.y - 1)
                call(["aplay", "-q", "smb_stage_clear.wav"])
                enemy.boss_round()

            elif (Board.board[self.x][self.y] in obstacles):
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x][self.y - 1] = 'M'

            elif ((Board.board[self.x + 1][self.y - 1] == '/'
                   or Board.board[self.x + 1][self.y - 1] == 'T')
                  and Board.board[self.x + 1][self.y] == ' '):
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x][self.y + 1] = 'M'
                Mario.go_down(self)
            else:
                Mario._pass(self.x, self.y - 1)
                Board.board[self.x][self.y] = 'M'

        if (self.y - 1 >= ((Board.prev_j + Board.prev_k) / 2)):
            os.system('clear')
            Board.prev_j += 1
            Board.prev_k += 1
            init_board(Board.prev_i, Board.prev_j, Board.prev_k)
        else:
            os.system('clear')
            init_board(Board.prev_i, Board.prev_j, Board.prev_k)
Esempio n. 13
0
import numpy as np
import get, signal, time, random
import os
import people
from board import Board, init_board
import enemy
"""initializing mario"""
mario = people.Mario()
"""initializing enemies"""
enemy.spawn_enemy()

os.system('clear')
init_board(Board.prev_i, Board.prev_j, Board.prev_k)

start = time.time()
start_ = time.time()


def lost():
    os.system('clear')
    print("SCORE:", people.Mario.score)
    print("BONUS:", people.Mario.bonus)
    print(
        "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tGAME OVER\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    )


if __name__ == '__main__':
    while True:
        """game"""
        x, y = people.Mario._get_coordinates(Board.prev_i, Board.prev_j,
Esempio n. 14
0
def init_board():
    """This function initializes boards, by using the init_board function"""
    global HIDDEN_BOARD_P1, VISIBLE_BOARD_P1
    HIDDEN_BOARD_P1 = board.init_board(BOARD_SIZE)
    VISIBLE_BOARD_P1 = board.init_board(BOARD_SIZE)