aboutsummaryrefslogtreecommitdiff
path: root/index.html
diff options
context:
space:
mode:
authoramelia <[email protected]>2022-05-11 08:31:14 -0500
committeramelia <[email protected]>2022-05-11 08:31:14 -0500
commitd1570705868034cace48249fa62d02573d4e906d (patch)
tree61c005aeac5ef8e80f5263b885bd0d32aeac2cab /index.html
parentd45ad14c2e2f47b2c7a253aa9dda10115e1cdb07 (diff)
peer to pee fully working & added exe
Diffstat (limited to 'index.html')
-rw-r--r--index.html167
1 files changed, 103 insertions, 64 deletions
diff --git a/index.html b/index.html
index acc9e5a..49df165 100644
--- a/index.html
+++ b/index.html
@@ -2,7 +2,7 @@
<head>
<title>chessn't</title>
<link rel="icon" href="icon.png">
- <script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script> <!-- thank you to these kind people :D -->
+ <script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script> <!-- thank you to these kind people :D --> <!--nvm i spent 6 hours trying to make it work, i take the thanks back-->
<style>
html,
body {
@@ -75,6 +75,11 @@ body::-webkit-scrollbar {
}
}
+input {
+ padding: 0.2em;
+ box-sizing: border-box;
+ width: 100%
+}
</style>
</head>
<body>
@@ -82,20 +87,49 @@ body::-webkit-scrollbar {
</div>
<script>
-var peer = new Peer();
+ var boardMain =
+ [
+ [{},{},{},{},{'piece':'bridger','icon':'br+','color':'white','loc':{'z':0}},{},{},{'piece':'rook','icon':'r','color':'white','loc':{'z':0}},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ ]
+ //board
+ //boardUnder
+ var boardUnder =
+ [
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ ]
+ //boardUnder
+ //boardOver
+ var boardOver =
+ [
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ [{},{},{},{},{},{},{},{},{}],
+ ]
+ //boardOver
+ var peer = new Peer();
var conn = null
-peer.on('connection', function(con) {
- conn = con
- con.on('data', function(data){
- data=JSON.parse(data)
- if(data.type=='move'){
- //do the move
- } else if(data.type=='err'){
- console.log(data)
- }
-
- });
-});
function ihate(con,hops){
if(con.peerConnection.connectionState=='connected'){
return(true)
@@ -104,8 +138,18 @@ function ihate(con,hops){
}
window.setTimeout( () => { ihate(con,hops-1); }, 100);
}
+function lonelyMf(){
+ //HAHA NO FRIENDS OR BITCHES
+ //no maidnes
+ conn = 'dontwannatalkaboutit'
+ //mf has a negative snapscore
+ let elem = document.getElementsByClassName('join-online')[0]
+ elem.style.display='none'
+ //he probably covers his mouth when he laughs
+ //doesnt even use ctrl-shift-a
-async function peerCon(id){
+}
+function peerCon(id){
conn = peer.connect(id)
console.log(conn)
setTimeout(() => {
@@ -116,14 +160,43 @@ async function peerCon(id){
console.log(conn.peerConnection.connectionState)
let elem = document.getElementsByClassName('join-online')[0]
- elem.innerHTML='your key is </br><b>'+peer.id+'<\/b></br> or, enter someone else\'s </br><form id="join"onsubmit="peerCon(this.children[1].value);return false" onsubmit=""></br><input type="text" id="peer.id" name="peer.id"><input type="submit" style="display: none" /></form>'
+ elem.innerHTML='your key is </br><b>'+peer.id+'<\/b></br> or, enter someone else\'s </br><form id="join"onsubmit="peerCon(this.children[1].value);return false" onsubmit=""></br><input type="text" id="peer.id" name="peer.id"><input type="submit" style="display: none" /></br></form><button onclick="lonelyMf()"> or play by yourself</button>'
} else {
let elem = document.getElementsByClassName('join-online')[0]
elem.style.display='none'
+ conn.send(JSON.stringify({'type':'con','id':peer.id}))
}
-}, 1000);
+}, 5000);
}
+function setb(m,o,u){
+ boardMain=m
+ boardOver=o
+ boardUnder=u
+ loadb()
+}
+peer.on('connection', function(con) {
+ console.log(con)
+ con.send({'type':'err'})
+ con.on('data', function(data){
+
+ data=JSON.parse(data)
+ console.log(data)
+ if(data.type=='move'){
+ //move(data.fromR,data.fromC,data.toR,data.toC,data.z,data.toz,con,false)
+ setb(data.main,data.over,board.under)
+
+ //do the move
+ } else if(data.type=='err'){
+ console.log(data)
+ } else if(data.type=='con'){
+ peerCon(data.id)
+ //console.log('connect')
+ }
+
+ });
+});
+peer.on('disconnected', function(con) {console.log(true)})
function foo(){
console.log(peer.id)
if(peer.id==null){
@@ -133,8 +206,8 @@ function foo(){
},1000);
} else {
let elem = document.getElementsByClassName('join-online')[0]
- elem.innerHTML='your key is </br><b>'+peer.id+'<\/b></br> or, enter someone else\'s </br><form id="join"onsubmit="peerCon(this.children[1].value);return false" onsubmit=""></br><input type="text" id="peer.id" name="peer.id"><input type="submit" style="display: none" /></form>'
-}
+ elem.innerHTML='your key is </br><b>'+peer.id+'<\/b></br> or, enter someone else\'s </br><form id="join"onsubmit="peerCon(this.children[1].value);return false" onsubmit=""></br><input type="text" id="peer.id" name="peer.id"><input type="submit" style="display: none" /></br></form><button onclick="lonelyMf()"> or play by yourself</button>'
+ }
}
foo()
@@ -173,47 +246,7 @@ document.write('<div class="join-online"></div>')
}
//functions
//board
- var boardMain =
- [
- [{},{},{},{},{'piece':'bridger','icon':'br+','color':'white','loc':{'z':0}},{},{},{'piece':'rook','icon':'r','color':'white','loc':{'z':0}},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- ]
- //board
- //boardUnder
- var boardUnder =
- [
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- ]
- //boardUnder
- //boardOver
- var boardOver =
- [
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- [{},{},{},{},{},{},{},{},{}],
- ]
- //boardOver
+
//popup func
document.write('<div id="modal"class="modal"></div>')
function popup(msg,timeUp){
@@ -243,9 +276,9 @@ document.write('<div class="join-online"></div>')
}
//del temp
//move
- function move(fromR,fromC,toR,toC,z,toz){
- console.log('move')
-
+ function move(fromR,fromC,toR,toC,z,toz,con = conn,shouldi = true){
+ if(conn=='dontwannatalkaboutit'||conn.open){
+
if(z==1){
//boardOver
} else if(z==-1) {
@@ -264,8 +297,14 @@ document.write('<div class="join-online"></div>')
}
}
+ if(conn!='dontwannatalkaboutit'){
+ if(shouldi){
+ //conn.send(JSON.stringify({'type':'move','fromR':fromR,'fromC':fromC,'toR':toR,'toC':toC,'z':z,'toz':toz}))
+ conn.send(JSON.stringify({'type':'move','main':boardMain,'over':boardOver,'under':boardUnder}))
-
+ }}//console.log(conn)
+
+ }
}
//move
//show moves