This repository has been archived by the owner on Dec 14, 2024. It is now read-only.
forked from NM-TAFE/github-group-activity-team-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (70 loc) · 2.41 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from flask import Flask, render_template, request, redirect, url_for
import game_play as gp
from score import get_scores, update_scores
app = Flask(__name__)
# Initialise game board and current player
# board = [' '] * 9
# current_player = 'X'
BOARD_WIDTH = 3
WINNING_LINE = 3
game = gp.Game_Play(BOARD_WIDTH, WINNING_LINE)
# NOTE: you cannot use this answer in Portfolio Part 2
# def check_winner():
# # Winning combinations
# return None
# def check_draw():
# return ' ' not in board
# @app.route('/')
# def index():
# winner = check_winner()
# draw = check_draw()
# return render_template('index.html', board=board, current_player=current_player, winner=winner, draw=draw)
@app.route('/')
def index():
winner = game.check_winner()
draw = game.check_draw()
current_player = game.current_player.mark
board = game.setting.board
scores = {'Player 1': game.player1.score, 'Player 2': game.player2.score}
return render_template('index.html',
board=board,
current_player=current_player,
winner=winner,
draw=draw,
scores=scores)
# @app.route('/play/<int:cell>')
# def play(cell):
# # breakpoint()
# global current_player
# if board[cell] == ' ':
# board[cell] = current_player
# if not check_winner():
# current_player = 'O' if current_player == 'X' else 'X'
# return redirect(url_for('index'))
@app.route('/play/<int:cell>')
def play(cell):
# breakpoint()
if game.do_continue() == False:
return redirect(url_for('index'))
if game.setting.board[cell] == ' ':
game.setting.board[cell] = game.current_player.mark
game.current_player.make_choice(cell, game.setting.board_width)
game.current_player = game.player1 if game.current_player == game.player2 else game.player2
return redirect(url_for('index'))
# @app.route('/reset')
# def reset():
# global board, current_player
# board = [' '] * 9
# current_player = 'X'
# return redirect(url_for('index'))
@app.route('/reset')
def reset():
game.setting.board = [' '] * 9
game.current_player = game.player1
game.put_counter = 0
game.player1.choices = []
game.player2.choices = []
game.is_there_winner = False
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True)