Skip to content
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
44 changes: 44 additions & 0 deletions NikhilTayal INT005/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Comfortaa|Hammersmith+One|IBM+Plex+Mono|Niramit" rel="stylesheet">
<script
src="http://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>

<title>Document</title>
</head>
<body onLoad="newGame();">
<div class="container">
<table class="container">
<h2>THE TIC TAC TOE GAME</h2>
<p id="Message">Message Here</p>
<tr>
<td class="cell1" id="box1" onClick="nextTurn(this)"></td>
<td class="cell1" id="box2" onClick="nextTurn(this)"></td>
<td class="cell1" id="box3" onClick="nextTurn(this)"></td>
</tr>
<tr>
<td class="cell1" id="box4" onClick="nextTurn(this)"></td>
<td class="cell1" id="box5" onClick="nextTurn(this)"></td>
<td class="cell1" id="box6" onClick="nextTurn(this)"></td>
</tr>
<tr>
<td class="cell1" id="box7" onClick="nextTurn(this)"></td>
<td class="cell1" id="box8" onClick="nextTurn(this)"></td>
<td class="cell1" id="box9" onClick="nextTurn(this)"></td>
</tr>
</table>
<!-- <input type="submit" value="New Game" onclick="restart()">-->
<a href="javascript: newGame();">New Game</a>
<input type="submit" onclick="SubmitData()" value="Submit Progress">
</div>


</body>
<script src="index.js"></script>

</html>
96 changes: 96 additions & 0 deletions NikhilTayal INT005/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
var XPoints=0;
var YPoints=0;
function newGame(){
for (var i=1; i <= 9 ; i++){
restart(i);
}

var x=prompt("which player do you want?");
document.turn=x.toUpperCase();
messageToShow(document.turn+ " \'s Move");
document.winner=null;
}
function nextTurn(cell1){
if(document.winner!=null){
messageToShow("Can't make a move,Because " + document.turn + " WON")
}
else if(cell1.innerHTML==""){
cell1.innerText=document.turn;
newUserTurn();
}
else{
messageToShow("please choose different column");
}
}
function newUserTurn(){

if(checkForWinner(document.turn)){
messageToShow("Congrats " + document.turn + " Win" )
document.winner=document.turn;
if(document.winner=="X"){
XPoints+=10;
YPoints-=5;
}else{
YPoints+=10;
XPoints-=5;
}
console.log(document.winner + " Wins and points is" + "\nX Points: " + XPoints +" \nO Points: " +YPoints);
}
else if(document.turn=="X"){
document.turn="O";
messageToShow("O' s Move");
}
else{
document.turn="X";
messageToShow("X' s Move");
}
}
function checkForWinner(move){
var result=false;
if(checkRow(1,2,3,move) ||
checkRow(4,5,6,move) ||
checkRow(7,8,9,move) ||
checkRow(1,4,7,move) ||
checkRow(2,5,8,move) ||
checkRow(3,6,9,move) ||
checkRow(1,5,9,move) ||
checkRow(3,5,7,move)){
result= true;
}
return result;
}
function messageToShow(msg){
document.getElementById("Message").innerHTML=msg;
}
function checkRow(a,b,c,move){
var result=false;
if(getBox(a)== move && getBox(b)==move && getBox(c)==move){
result = true;
}
return result;
}
function getBox(number){
return document.getElementById("box"+number).innerHTML;
}
function restart(number){

document.getElementById("box"+number).innerText="";
}
function SubmitData(){
var dataToSend={
"id": "4",
"XPoints": XPoints,
"OPoints": YPoints
}
$.ajax({
url:"http://localhost:59264/api/Scores",
data: dataToSend,
type:'post',
dataType:'json',
success:function(res){
console.log(res);
alert("scord submitted");
}

});
}
60 changes: 60 additions & 0 deletions NikhilTayal INT005/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
td{
height: 150px;
width: 150px;
background-color: red;
border: 2px solid black;
border-collapse: collapse;
text-align: center;
font-size: 500%;
font-family: 'Niramit', sans-serif;
}
body{
width: 1000px;
margin: 20px auto;
}
.container{
margin: 20px auto;

}
h2{
text-align: center;
font-size: 50px;
font-family: 'Comfortaa', cursive;
/* font-family: 'IBM Plex Mono', monospace;*/
/* font-family: 'Hammersmith One', sans-serif;*/
}
a{
position: relative;
top: 50%;
left: 50%;
height: 64px;
width: 233px;
border-radius: 20px;
outline: none;
font-size: 42px;
display: block;
text-decoration: none;
border: 3px solid grey;
text-align: center;
padding-top: 4px;
color: black;
background-color: grey;
font-family: 'IBM Plex Mono', monospace;
margin-bottom: 20px;
}
input{
position: relative;
top: 50%;
left: 50%;
height: 80px;
width: 240px;
border-radius: 20px;
outline: none;
font-size: 25px;
display: block;
}
p{
text-align: center;
font-size: 30px;
font-family: 'Hammersmith One', sans-serif;
}
Loading