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
9 changes: 9 additions & 0 deletions PallaviVerma026/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ttt/.vs/

ttt/packages/

ttt/ttt/bin/

ttt/ttt/obj/

ttt/ttt/scripts/
19 changes: 19 additions & 0 deletions PallaviVerma026/db.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create database ttt;

create table tictacto (
PID int primary key,
username varchar(20),
points int );


insert into tictacto values(
1,
'Pallavi',
0);

insert into tictacto values(
2,
'Vishal',
0);

select * from tictacto;
85 changes: 85 additions & 0 deletions PallaviVerma026/ttt.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
table {
position: absolute;
top:20%;
left: 35%;
width: 50%;
border-collapse: collapse;
border: 1px;
height: 30%;
}

td {
width: 10%;
border: 6px solid #222;
text-align: center;
}

#canc
{
position: absolute;
left:9%;
padding: 12px;
margin: 6px;
background-color: forestgreen;
cursor: pointer;
width: 10%;
box-shadow: 20px;
text-align: center;
display: inline-block;
font-size: 12px;
transition-duration: 0.4s;
color: white;
border-radius: 3;
}


#canc:hover
{
background-color: darkgreen;
color: white;
}

td:after {
content: '';
display: block;
margin-top: 40%;
}

button
{
padding: 16px;
margin: 8px;
width: 50%;
text-align: center;
font-size: 16px;
background-color: white;
box-shadow: 20px;
cursor: pointer;
}

input
{
text-align: center;
width:10%;
}


td:first-of-type {
border-left-color: transparent;
border-top-color: transparent;
}

td:nth-of-type(2) {
border-top-color: transparent;
}
td:nth-of-type(3) {
border-right-color: transparent;
border-top-color: transparent;
}
tr:nth-of-type(3) td {
border-bottom-color: transparent;
}

body{
background-color: aliceblue;
}
265 changes: 265 additions & 0 deletions PallaviVerma026/ttt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
<!DOCTYPE html>
<html>
<head>
<title> Tic Tac Toe </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="ttt.css">

<script type="text/javascript"
src="http://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous">

</script>

</head>

<body>
<b><h1>TIC TAC TOE</h1></b>

<b>Player 1</b>
<input type="text" required id="p_id1" placeholder="ID">
<input type="text" required id="pname1" placeholder="Name"> <br>
<b> Score:</b><div id="sc1"><b></b></div>

<b> Player 2</b>
<input type="text" required id="p_id2" placeholder="ID">
<input type="text" required id="pname2" placeholder="Name"> <br>
<b>Score:</b> <div id="sc2"> <b> </b> </div><br>

<!-- <button type="button" class="cancel" id="canc"> Cancel </button> <br>-->
<button type="submit" class="login" onclick="GetScore()" id="canc">Log In </button><br>



<!--
<br>
Score of Player 1 = GetScore();
<br>
Score of player 2 = GetScore();
-->

<table id="board">

<tr>
<td><button onclick="valfun(this.id)" id="one" value="1">@</button></td>
<td><button onclick="valfun(this.id)" id="two"value="2">@</button></td>
<td><button onclick="valfun(this.id)" id="three" value="3">@</button></td>
</tr>
<tr>
<td><button onclick="valfun(this.id)" id="four"value="4">@</button></td>
<td><button onclick="valfun(this.id)" id="five" value="5">@</button></td>
<td><button onclick="valfun(this.id)" id="six"value="6">@</button></td>
</tr>
<tr>
<td><button onclick="valfun(this.id)" id="seven"value="7">@</button></td>
<td><button onclick="valfun(this.id)" id="eight"value="8">@</button></td>
<td><button onclick="valfun(this.id)" id="nine"value="9">@</button></td>
</tr>

</table>
</body>


<script>
alert("Log in before playing");
var score1;
var score2;
var ctr=0;

// winning cond : [0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]


function DisplayScore()
{
document.getElementById("sc1").innerHTML=score1;
document.getElementById("sc2").innerHTML=score2;
}

function valfun(ide)
{

if(ctr%2==0)
{
document.getElementById(ide).innerHTML='X';
document.getElementById(ide).value='1';
console.log("changing to x");

var varone= document.getElementById("one").value;
var vartwo = document.getElementById("two").value;
var varthree = document.getElementById("three").value;
var varfour= document.getElementById("four").value;
var varfive = document.getElementById("five").value;
var varsix = document.getElementById("six").value;
var varseven = document.getElementById("seven").value;
var vareight = document.getElementById("eight").value;
var varnine = document.getElementById("nine").value;


if((varone == varfour && varfour == varseven)||
(varfour == varfive && varfive == varsix)||
(varseven == vareight && vareight == varnine)||
(varone == vartwo && vartwo == varthree)||
(varfive == vartwo && vartwo == vareight)||
(varnine == varfive && varfive == varone)||
(varthree == varsix && varsix == varnine)||
(varseven == varfive && varfive == varthree))
{

alert("Player 1 won");
score1=score1+10;
score2=score2-5;
UpdateScore();


// document.getElementById("sc1").innerHTML=score1;
// document.getElementById("sc2").innerHTML=score2;
// console.log(apoints);//PUT@@@@@@@@@
// break;

}

}
else

{

document.getElementById(ide).innerHTML='0';
document.getElementById(ide).value='2';
console.log("changing to 0");
var varone= document.getElementById("one").value;
var vartwo = document.getElementById("two").value;
var varthree = document.getElementById("three").value;
var varfour= document.getElementById("four").value;
var varfive = document.getElementById("five").value;
var varsix = document.getElementById("six").value;
var varseven = document.getElementById("seven").value;
var vareight = document.getElementById("eight").value;
var varnine = document.getElementById("nine").value;

if((varone == varfour && varfour == varseven)||
(varfour == varfive && varfive == varsix)||
(varseven == vareight && vareight == varnine)||
(varone == vartwo && vartwo == varthree)||
(varfive == vartwo && vartwo == vareight)||
(varnine == varfive && varfive == varone)||
(varthree == varsix && varsix == varnine)||
(varseven == varfive && varfive == varthree))
{

alert("Player 2 won");
score2=score2+10;
score1=score1-5;
UpdateScore();


// break;

}

}
ctr++;
}


function GetScore()
{
alert("Users suucessfully logged in");
ide1=document.getElementById("p_id1").value;
Url='http://localhost:64445/api/tictactoes/';
Url1=Url+''+ide1;
$.ajax({
url: Url1,
type: 'GET',
dataType: 'json',
success: function(res){
console.log(res);
score1=res["points"];
console.log(score1);
DisplayScore();
}
});

ide2=document.getElementById("p_id2").value;
Url='http://localhost:64445/api/tictactoes/';
Url2=Url+ide2;
$.ajax({
url: Url2,
type: 'GET',
dataType: 'json',
success: function(res){
console.log(res);
score2=res["points"];
console.log(score2);
DisplayScore();
}
});
// function InitialScore()
console.log(score2);


}



function UpdateScore()
{
var Id1 = document.getElementById("p_id1").value; // var , form
var Name1 = document.getElementById("pname1").value;


var Id2 = document.getElementById("p_id2").value; // var , form
var Name2 = document.getElementById("pname2").value;


var dataToSend1= {
"PID": Id1, //db:var
"username":Name1,
"points":score1
};

ide1=document.getElementById("p_id1").value;
Url='http://localhost:64445/api/tictactoes/';
Url1=Url+ide1;

$.ajax({
url:Url1,
type: 'PUT',
dataType: 'json',
data: dataToSend1,
success: function(data){
alert("Score of Player 1 Updated");
DisplayScore();
// console.log(data);

}
});

ide2=document.getElementById("p_id2").value;
Url='http://localhost:64445/api/tictactoes/';
Url2=Url+ide2;

var dataToSend2= {
"PID": Id2, //db:var
"username":Name2,
"points":score2
};

$.ajax({
url:Url2,
type: 'PUT',
dataType: 'json',
data: dataToSend2,
success: function(data){
alert("Score of Player 2 Updated");
DisplayScore();
// console.log(data);

}
});
};


</script>

</html>
Loading