-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ucfai/demo-ui
Demo UI
- Loading branch information
Showing
6 changed files
with
476 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ Flask-Cors==3.0.10 | |
Flask==2.1.1 | ||
gunicorn==20.1.0 | ||
numpy==1.22.2 | ||
simple-websocket===0.5.2 | ||
Flask-SocketIO===5.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,66 @@ | ||
env = 'http://127.0.0.1:5000' | ||
var n = 7 | ||
var m = 7 | ||
env = "https://team-game-bot.herokuapp.com/"; | ||
var m = 7; | ||
var n = 3; | ||
var k = 3; | ||
|
||
main(); | ||
|
||
async function main() { | ||
board = await getEmptyBoard(env, n, m) | ||
displayBoard(board) | ||
board = await getEmptyBoard(env, m, n); | ||
displayBoard(board); | ||
|
||
// Just testing this | ||
await postBoard(board) | ||
// Just testing this | ||
await postBoard(board); | ||
} | ||
|
||
async function postBoard(board) { | ||
await fetch(`${env}/play`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(board) | ||
}) | ||
await fetch(`${env}/play`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(board), | ||
}); | ||
} | ||
|
||
async function getRandomBoard(env, n, m) { | ||
return (await fetch(`${env}/board/random/${n}x${m}/`).then(response => { return response.json() })).board | ||
async function getRandomBoard(env, m, n) { | ||
return ( | ||
await fetch(`${env}/board/random/${m}x${n}/`).then((response) => { | ||
return response.json(); | ||
}) | ||
).board; | ||
} | ||
|
||
async function getEmptyBoard(env, n, m) { | ||
return (await fetch(`${env}/board/empty/${n}x${m}/`).then(response => { return response.json() })).board | ||
async function getEmptyBoard(env, m, n) { | ||
return ( | ||
await fetch(`${env}/board/empty/${m}x${n}/`).then((response) => { | ||
return response.json(); | ||
}) | ||
).board; | ||
} | ||
|
||
function displayBoard(board) { | ||
var m = board.length; | ||
var n = board[0].length; | ||
|
||
var n = board.length | ||
var m = board[0].length | ||
let cellSize = 100 - Math.min((Math.max(m, n) - 3) * 8, 50); | ||
document.documentElement.style.setProperty("--cell-size", `${cellSize}px`); | ||
|
||
let cellSize = 100 - Math.min(((Math.max(n, m) - 3) * 8), 50) | ||
document.documentElement.style.setProperty("--cell-size", `${cellSize}px`) | ||
boardHtml = document.getElementById("board"); | ||
|
||
boardHtml = document.getElementById('board') | ||
boardHtml.style.setProperty("grid-template-columns", `repeat(${n}, 1fr)`); | ||
|
||
boardHtml.style.setProperty("grid-template-columns", `repeat(${m}, 1fr)`) | ||
boardHtml.style.setProperty("height", `${m} * var(--cell-size) + ${m - 1} * var(--gap-size)`); | ||
boardHtml.style.setProperty("width", `${n} * var(--cell-size) + ${n - 1} * var(--gap-size)`); | ||
|
||
boardHtml.style.setProperty("width", `${m} * var(--cell-size) + ${m-1} * var(--gap-size)`) | ||
boardHtml.style.setProperty("height", `${n} * var(--cell-size) + ${n-1} * var(--gap-size)`) | ||
let cellType = [" O", "", " X"]; | ||
let display = ""; | ||
|
||
let cellType = [" O", "", " X"] | ||
let display = "" | ||
for (var i = 0; i < m; i++) | ||
for (var j = 0; j < n; j++) | ||
display += `<div id="${i}, ${j}" class="cell${ | ||
cellType[board[i][j] + 1] | ||
}" data-cell></div>`; | ||
|
||
for (var i = 0; i < n; i++) | ||
for (var j = 0; j < m; j++) | ||
display += `<div class="cell${cellType[board[i][j] + 1]}" data-cell></div>` | ||
|
||
boardHtml.innerHTML = display | ||
} | ||
boardHtml.innerHTML = display; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<!-- Add Bootstrap --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> | ||
<link rel="stylesheet" type="text/css" href="style.css" /> | ||
<script | ||
src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" | ||
integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" | ||
crossorigin="anonymous" | ||
></script> | ||
<script type="text/javascript" charset="utf-8"> | ||
var socket = io(); | ||
socket.on("connect", function () { | ||
socket.emit("connection", { route: location }); | ||
}); | ||
</script> | ||
<script type="text/javascript" src="display-board.js" defer></script> | ||
<script type="text/javascript" src="script.js" defer></script> | ||
<title>Tic-Tac-Toe</title> | ||
</head> | ||
|
||
<head> | ||
<meta charset='utf-8'> | ||
<meta name='viewport' content='width=device-width, initial-scale=1'> | ||
<link rel='stylesheet' type='text/css' href='style.css'> | ||
<script type='text/javascript' src='display-board.js' defer></script> | ||
<script type='text/javascript' src='script.js' defer></script> | ||
<title>Tic-Tac-Toe</title> | ||
</head> | ||
<body> | ||
<!-- Add padding to new game with bootstrap --> | ||
<div class="New Game" style="padding: 20px;"> | ||
|
||
<h2><div class="Size"><img src="https://svgur.com/i/gXX.svg" class="ucfai" alt="Sgv Image">: MNK Game</h2></div> | ||
<!-- User input for M x N x K Game --> | ||
<div class="input-mnk"> | ||
<div class="Size" style="display: flex; flex-direction: row; align-items: center;"> | ||
<div class="input-group" style="width: 5.5em; margin-right: 1.2em;"> | ||
<div class="input-group-prepend"> | ||
<span class="input-group-text font-weight-bold" id="basic-addon1">M</span> | ||
<input type="number" class="rounded-right" id="m" placeholder="m" min="1" value="7" style="width: 3em; margin-right: 0.5em;" /> | ||
</div> | ||
</div> | ||
<div class="input-group" style="width: 5.5em; margin-right: 1.2em;"> | ||
<div class="input-group-prepend"> | ||
<span class="input-group-text font-weight-bold" id="basic-addon1">N</span> | ||
<input type="number" class="rounded-right" id="n" placeholder="n" min="1" value="3" style="width: 3em; margin-right: 0.5em;" /> | ||
</div> | ||
</div> | ||
<div class="input-group" style="width: 5.5em; margin-right: 1.2em;"> | ||
<div class="input-group-prepend"> | ||
<span class="input-group-text font-weight-bold" id="basic-addon1">K</span> | ||
<input type="number" class="rounded-right" id="k" placeholder="k" min="1" value="3" style="width: 3em; margin-right: 0.5em;" /> | ||
</div> | ||
</div> | ||
|
||
<body> | ||
TODO: Win detection | ||
<div class='board X' id='board'></div> | ||
</div> | ||
<button id="start" class="btn btn-info mt-3">Start</button> | ||
</div> | ||
</div> | ||
<!-- <button class="newGameButton">New Game</button> --> | ||
</div> | ||
|
||
<div class='winningMessage'> | ||
<div class='winningMessageText'></div> | ||
<button class='newGameButton'>New Game</button> | ||
</div> | ||
</body> | ||
<div class="board X" id="board"></div> | ||
|
||
<div class="winningMessage"> | ||
<div class="winningMessageText"></div> | ||
<button class="newGameButton">New Game</button> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.