示例#1
0
 def game_logic(self):
     """
     Creates our game logic objects
     and creates us an empty board
     """
     inputs = self._game_initial_inputs
     self._game_obj = Othello_logic.GameLogic(Othello_logic.new_othello_board(inputs),inputs[2],inputs[4])
     self._game_board = Othello_logic.initial_four_chips(self._game_obj._board,inputs)
示例#2
0
 def game_logic(self):
     """
     Creates our game logic objects
     and creates us an empty board
     """
     inputs = self._game_initial_inputs
     self._game_obj = Othello_logic.GameLogic(
         Othello_logic.new_othello_board(inputs), inputs[2], inputs[4])
     self._game_board = Othello_logic.initial_four_chips(
         self._game_obj._board, inputs)
示例#3
0
def runUserInterface() -> None:
	'''
	Runs user interface
	'''
	print('FULL')
	rows = int(input())
	columns = int(input())
	startingPlayer = input()
	startingOrientation = input()
	wayToWin = input()
	othello = Othello_logic.GameState(rows, columns, 
		startingPlayer, startingOrientation, wayToWin)
	othello.createBoard()
	while True:
		playerTiles = othello.checkNumTiles()
		print('B: {}  W: {}'.format(othello.blackPieces, othello.whitePieces))
		othello.printBoard()
		if othello.turn == 1:
			turn = 'B'
			print('TURN: {}'.format(turn))
		else:
			turn = 'W'
			print('TURN: {}'.format(turn))
		playerMove(othello)
		if othello.isGameOver() == True:
			break
	determineWinner(othello)
示例#4
0
def ui():
    '''Executes the game'''
    []
    BOARD_ROWS = board("rows")
    BOARD_COLUMNS = board("columns")
    FIRST = first_and_default('who should go first')
    DEFAULT = first_and_default(
        'which color piece is in the top left-position in the default')
    WIN = win_method()
    a = Othello_logic.OthelloGameState(BOARD_ROWS, BOARD_COLUMNS, FIRST,
                                       DEFAULT, WIN)
    b = a.new_board()
    d = a.default_board()
    while True:
        display_board(d, BOARD_ROWS, BOARD_COLUMNS)
        print_turn(a.current_move())
        r = move('row', BOARD_ROWS) - 1
        c = move('column', BOARD_COLUMNS) - 1
        try:
            a.place_piece(r, c)
            a.count_pieces()
            print('SCORE:\nBlack:', a._numB, '\nWhite:', a._numW)
            a.change_turn()
            if a.current_move() == a.turn_pass():
                pass
            else:
                if a.current_move() == a.turn_pass():
                    print(a.opposite_turn(), 'has no more moves.',
                          a.opposite_turn(), 'passes.')
                else:
                    if a.victor() == a._BLACK:
                        print('No more moves can be made.\nBLACK WINS!')
                        break
                    elif a.victor() == a._WHITE:
                        print('No more moves can be made.\nWHITE WINS!')
                        break
                    elif a.victor() == '':
                        print("No more moves can be made.\nIt is a TIE.")
                        break
                    else:
                        pass
        except Othello_logic.InvalidMove:
            print('Sorry. That was an invalid move.')
        except Othello_logic.InvalidRowColumn:
            print('Sorry. That row and/or column does not exist')
    display_board(d, BOARD_ROWS, BOARD_COLUMNS)
示例#5
0
    def _on_start_press(self) -> None:
        dialog = GameSpecDialog()
        dialog.run()
        if dialog._was_ok_clicked() == True:
            self._canvas.delete(tkinter.ALL)
            rows = int(dialog._get_num_rows())
            columns = int(dialog._get_num_columns())
            starting_player = dialog._get_starting_player()
            starting_orientation = dialog._get_starting_position()
            win_type = dialog._get_way_to_win()

            self._othello_state = Othello_logic.GameState(
                rows, columns, starting_player, starting_orientation, win_type)
            self._othello_state.createBoard()
            self._draw_board()
            self._show_turn()
            self._show_pieces()
            self._draw_circles()
示例#6
0
def start_game():
    choices1 = starting_inputs()
    game_board = Othello_logic.new_othello_board(choices1)
    Othello_logic.initial_four_chips(game_board, choices1)
    Othello_logic.count_of_chips(game_board)
    Othello_logic.visual_othello_board(game_board)
    current_turn = choices1[2]
    print("Turn:", current_turn)
    while True:
        if Othello_logic.full_board(game_board) == True:
            choices = insert_input()
            game_logic = Othello_logic.GameLogic(game_board, current_turn, choices1[4])
            if (
                game_logic.check_validity(choices[0], choices[1], current_turn, choices) == True
                and game_logic.insert_check(choices) == True
            ):
                if game_logic.check_both_players(choices) == True:
                    print("Valid")
                    game_logic.flip_vertical(choices)
                    game_logic.flip_horizontal(choices)
                    game_logic.flip_diagonal(choices)
                    current_turn = game_logic.player_turn(current_turn)
                    Othello_logic.count_of_chips(game_board)
                    Othello_logic.visual_othello_board(game_board)
                    print("Turn:", current_turn)
                else:
                    Othello_logic.winner(game_board, choices1[4])
                    break
            else:
                print("Invalid")
        else:
            Othello_logic.winner(game_board, choices1[4])
            break
    def __init__(self, row: int, col: int, first: str, default: str, win: str):
        self._root_window = tkinter.Tk()

        self._logic = Othello_logic.OthelloGameState(row, col, first, default, win)
        self._new_game = self._logic.new_board()
        self._game_time = self._logic.default_board()

        self._columns = col
        self._rows = row
        self._first = first
        self._default = default
        self._win = win

        self._root_window.title('Othello')

        self._frame = tkinter.Frame(master = self._root_window, background = '#F50C0C')

        self._frame.grid(
            row = 0, columnspan = 3, padx = 5, pady = (5, 0),
            sticky = tkinter.NSEW)
        
        self._canvas = tkinter.Canvas(
            master = self._root_window,
            width = 500, height = 500,
            background = '#187330')

        self._black_count = tkinter.Label(master = self._frame, text = ('Black: ' + str(self._logic._numB)), font = ('Helvetica', 16), background = '#F50C0C')
        self._black_count.grid(row = 0, column = 0, padx = 5, pady = 5, sticky = tkinter.NSEW)
        self._white_count = tkinter.Label(master = self._frame, text = ('White: ' + str(self._logic._numW)), font = ('Helvetica', 16), background = '#F50C0C')
        self._white_count.grid(row = 0, column = 2, padx = 5, pady = 5, sticky =  tkinter.NSEW)

        self._color = ''

        self._black_turn = "Black's turn"
        self._white_turn = "White's turn"

        if self._first == 'B':
            self._color = 'black'
            self._turn = tkinter.Label(master = self._frame, text = self._black_turn, font = ('Helvetica', 16), background = '#F50C0C')
            self._turn.grid(row = 0, column = 1, padx = 5, pady = 5, sticky = tkinter.N + tkinter.S)
        else:
            self._color = 'white'
            self._turn = tkinter.Label(master = self._frame, text = self._white_turn, font = ('Helvetica', 16), background = '#F50C0C')
            self._turn.grid(row = 0, column = 1, padx = 5, pady = 5, sticky = tkinter.N + tkinter.S)

        self._canvas.grid(
            row = 1, column = 0, padx = 3, pady = 5,
            sticky = tkinter.NSEW)

        self._frame.rowconfigure(0, weight = 1)
        self._frame.columnconfigure(0, weight = 1)
        self._frame.columnconfigure(1, weight = 1)
        self._frame.columnconfigure(2, weight = 1)
        
        self._canvas.bind('<Configure>', self._on_canvas_resized)
        self._canvas.bind('<Button-1>', self._on_canvas_clicked)


        self._root_window.rowconfigure(0, weight = 1)
        self._root_window.rowconfigure(1, weight = 8)
        self._root_window.columnconfigure(0, weight = 1)

        self._col_width = 0
        self._row_height = 0
示例#8
0
#Python 3.3
import Othello_ui
import Othello_logic

a = Othello_logic.OthelloGameState(Othello_ui.BOARD_ROWS,
                                   Othello_ui.BOARD_COLUMNS, Othello_ui.FIRST,
                                   Othello_ui.DEFAULT)
b = a.new_board()
c = a.default_board()
a._board


def display_board(board: [[str]], rows: int, columns: int) -> None:
    '''Creates and displays the game board'''
    s = '   '
    for i in range(1, columns + 1):
        if i > 9:
            s += str(i) + ' '
        else:
            s += str(i) + '  '
    s += '\n'

    for row in range(rows):
        if row > 9:
            s += str(row + 1) + ' '
        else:
            s += str(row + 1) + '  '
        for col in range(columns):
            if board[row][col] == ' ':
                s += '.  '
            else:
示例#9
0
def start_game():
    choices1 = starting_inputs()
    game_board = Othello_logic.new_othello_board(choices1)
    Othello_logic.initial_four_chips(game_board,choices1)
    Othello_logic.count_of_chips(game_board)
    Othello_logic.visual_othello_board(game_board)
    current_turn = choices1[2]
    print("Turn:",current_turn)
    while True:
        if Othello_logic.full_board(game_board) == True:
            choices = insert_input()
            game_logic = Othello_logic.GameLogic(game_board,current_turn,choices1[4])
            if game_logic.check_validity(choices[0],choices[1],current_turn,choices) == True and game_logic.insert_check(choices) == True:
                if game_logic.check_both_players(choices) == True:
                    print("Valid")
                    game_logic.flip_vertical(choices)
                    game_logic.flip_horizontal(choices)
                    game_logic.flip_diagonal(choices)
                    current_turn = game_logic.player_turn(current_turn)
                    Othello_logic.count_of_chips(game_board)
                    Othello_logic.visual_othello_board(game_board)
                    print("Turn:",current_turn)
                else:
                    Othello_logic.winner(game_board,choices1[4])
                    break
            else:
                print("Invalid")
        else:
            Othello_logic.winner(game_board,choices1[4])
            break