Skip to content

attempted the challenge using jQuery and CSS3 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ __conda_version__.txt

ui/node_modules/
ui/static/
ui
backend
environment.yml
run.py
9 changes: 0 additions & 9 deletions backend/templates/index.html

This file was deleted.

65 changes: 65 additions & 0 deletions tic-tac-toe/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
html {
background-color: #F7F3EF;
color: ##006989;
line-height: 1.4;
font-size: 15px;
}

body {
text-align: center;
font-family: 'Shadows Into Light Two', cursive;
}

header {
margin-top: 3em;
}

h1 {
font-size: 4em;
color: #006989;
}

#alert {
font-size: 25px;
}

table {
margin: 2em auto;
}

table.board {
border-collapse: collapse;
font-size: 50px;
}

.board td {
width: 100px;
height: 100px;
text-align: center;
border: 5px solid black;
cursor: pointer;
}

.board tr td:first-child {
border-left: none;
}

.board tr td:last-child {
border-right: none;
}

.board tr:first-child td {
border-top: none;
}

.board tr:last-child td {
border-bottom: none;
}

#reset-btn {
border-radius: 5px;
padding: 10px;
margin-bottom: 8em;
font-size: 10px;
background-color: #F7F5FB;
}
44 changes: 44 additions & 0 deletions tic-tac-toe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Continuum UI Coding Challenge</title>

<link href="https://fonts.googleapis.com/css?family=Shadows+Into+Light+Two" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css" media="screen" charset="utf-8">
</head>
<body>
<header>
<h1>Tic Tac Toe</h1>
<h2>Current Player: <span id="playerNumber"></span></h2>
</header>

<div id="alert"></div>

<table class="board">
<tbody>
<tr>
<td id="1" class="box"></td>
<td id="2" class="box"></td>
<td id="3" class="box"></td>
</tr>
<tr>
<td id="4" class="box"></td>
<td id="5" class="box"></td>
<td id="6" class="box"></td>
</tr>
<tr>
<td id="7" class="box"></td>
<td id="8" class="box"></td>
<td id="9" class="box"></td>
</tr>
</tbody>
</table>


<button id="reset-btn" type="button" name="Reset">Reset Board</button>

<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>

<script src="js/main.js" charset="utf-8"></script>
</body>
</html
67 changes: 67 additions & 0 deletions tic-tac-toe/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
console.log('Connected');

$(function() {

// DOM has loaded

var playerOne = 'X', playerTwo = 'O';
var currentPlayer = playerOne;
var turns = 0, maxTurns = 9;

$('#playerNumber').text(currentPlayer);

$('.box').on('click', function() {
// Set the current player's marker
$(this).text(currentPlayer);


// Increment the number of turns taken
turns++;

// Check if the user is a winner
if (isWinner('#1', '#2', '#3') || // row 1
isWinner('#4', '#5', '#6') || // row 2
isWinner('#7', '#8', '#9') || // row 3
isWinner('#1', '#4', '#7') || // col 1
isWinner('#2', '#5', '#8') || // col 2
isWinner('#3', '#6', '#9') || // col 3
isWinner('#1', '#5', '#9') || // diagonal 1
isWinner('#3', '#5', '#7')) { // diagonal 2
$('#alert').append("Winner!");
} else {
// Did we reach the maximum number of tries
if (turns >= maxTurns) {
$('#alert').append("We have a Cat's Game!");
return;
}

// Switch to the other player
switchPlayer();
}

// Removes the event handler so they can't click it again
$(this).off('click');
});

function isWinner(square1, square2, square3) {
return $(square1).text() && $(square1).text() === $(square2).text() && $(square2).text() === $(square3).text();
}

function switchPlayer() {
if (currentPlayer === playerOne) {
currentPlayer = playerTwo;
$('#playerNumber').text(currentPlayer);

} else {
currentPlayer = playerOne;
$('#playerNumber').text(currentPlayer);
}
}

// Reload page
$('#reset-btn').on('click', function(){
window.location.reload(true);
// $('#board')location.reload(true);
});

}); // End of dom
6 changes: 0 additions & 6 deletions ui/src/index.scss

This file was deleted.

8 changes: 0 additions & 8 deletions ui/src/main.js

This file was deleted.