Code viewer for World: X and O (clone by John Lasis)

// Cloned by John Lasis on 5 Dec 2022 from World "X and O" by Genesis 
// Please leave this clone trail here.
 
function InfoScreen(){return"Welcome to X and O. To win the game you have to get 3 rows with either X or O. This is a 2 player Game. You can play On 2 different browsers or you can play on the same browser"}let table,p1,p2,turn,divbox;AB.world.newRun=function(){AB.socketStart(),AB.runReady=!1},AB.newSplash(InfoScreen()),$("#splash").click(function(){AB.removeSplash(),AB.backgroundMusic(music),AB.runReady=!0}),AB.world.nextStep=function(){};let TText="";var ready,info={};const soundaffect="/uploads/destinyjames/mixkit-game-click-1114.wav",music="/uploads/destinyjames/the-incident-soundroll-main-version-16775-01-32.mp3";let height;var canvas;function setup(){height=windowHeight-300,p1=new Player("X"),p2=new Player("O");var t=createCanvas(height,height),e=(windowWidth-width)/2,s=(windowHeight-height)/2;t.position(e,s),divbox=createDiv("").size(100,100),table=new Board(p1,p2),ready=p1}function draw(){background(color("brown")),AB.hideRunHeader(),table.display(),divbox.style("font-size","50px"),divbox.style("font-family","sans-serif"),divbox.style("padding-top","25px"),divbox.style("width","100%"),divbox.style("height","100%"),divbox.style("text-align","center"),divbox.style("margin","auto"),divbox.style("color","black"),divbox.style("background-repeat","no-repeat"),divbox.style("background-image","url(/uploads/destinyjames/1669759381.png)"),divbox.style("background-position","center"),divbox.style("background-attachment","fixed"),divbox.style("background-size","cover")}function Sound(t){"click"==t&&new Audio(soundaffect).play()}function mousePressed(){mouseX>0&&mouseX<500&&mouseY>0&&mouseY<500&&!0===AB.runReady&&(table.winState?(table.newGame(),AB.socketOut("Start")):("X"===table.turn?(Sound("click"),p1.select(table)):"O"===table.turn&&(Sound("click"),p2.select(table)),table.toggleTurn()))}class Board{constructor(t,e){this.cells=[],this.cellSize=(width-1)/3,this.p1=t,this.p2=e,this.turn=this.p1.s,this.winState=!1,this.resultText="",this.newGame()}display(){let t=this.cellSize;if(this.winState){textSize(20),textAlign(CENTER),text(this.resultText,width/2,height/2),text("Click anywhere for a new game",width/2,height/2+30);var e=color("black");fill(e)}else this.cells.forEach(function(e){strokeWeight(20),stroke("rgba(0, 5, 0, 0.8)");var s=color("brown");fill(s),rect(e.r*t,e.c*t,t,t),s=color("black"),fill(s),strokeWeight(10),stroke("black)"),textSize(100),textAlign(CENTER),text(e.s,e.r*t+t/2,e.c*t+t/2+35),strokeWeight(0)})}update(t,e,s){let i=this.turn;this.cells.forEach(function(o){o.r===t&&o.c===e&&0===o.val&&(o.s=s,"X"===i?(o.val=1,info.element=o):(o.val=-1,info.element=o))});let o=this.checkResult();"X"===o?(this.winState=!0,this.resultText="X wins!"):"O"===o?(this.winState=!0,this.resultText="O wins!"):"tie"===o&&(this.winState=!0,this.resultText="Its a draw!")}toggleTurn(){this.turn==p1.s?(info.Whosturn=p2.s,this.turn=p2.s,ready=p2,TText="Turn: "+p2.s):(info.Whosturn=p1.s,this.turn=p1.s,ready=p1,TText="Turn: "+p1.s),info.ready=ready,divbox.html(TText),info.TText=TText,AB.socketOut(info)}checkResult(){let t,e=this.p1,s=this.p2,i=new Array(3),o=new Array(3),n=new Array(3),l=9;for(let t=0;t<3;t++)i[t]=0,o[t]=0,n[t]=0;return this.cells.forEach(function(t){i[t.r]+=t.val,o[t.col]+=t.val,l-=abs(t.val),0===abs(t.r-t.c)&&(n[0]+=t.val),(2===abs(t.r-t.c)||1==t.r&&1==t.c)&&(n[1]+=t.val)}),i.forEach(function(i){3===i&&(t=e.s,e.win()),-3===i&&(t=s.s,s.win())}),o.forEach(function(i){3===i&&(t=e.s,e.win()),-3===i&&(t=s.s,s.win())}),n.forEach(function(i){3===i&&(t=e.s,e.win()),-3===i&&(t=s.s,s.win())}),0===l&&(t="tie"),t}newGame(){console.log("p1 score"+p1.score),console.log("p2 score"+p2.score),this.winState=!1,this.turn=this.p1.s,divbox.html("Turn: "+this.p1.s),this.cells=[];for(let t=0;t<3;t++)for(let e=0;e<3;e++)this.cells.push({r:t,c:e,s:"",val:0})}}class Player{constructor(t){this.s=t,this.score=0}select(t){if(t.turn==this.s){console.log(t.turn,this.s);let e=int(Math.floor(mouseX/t.cellSize)),s=int(Math.floor(mouseY/t.cellSize));t.update(e,s,this.s),info.r=e,info.c=s,info.s=this.s}}win(){console.log("yes"),this.score++}}AB.socketIn=function(t){console.log(t.TText),divbox.html(t.TText),table.update(t.r,t.c,t.s),console.log(t.Whosturn),table.turn=t.Whosturn,ready=t.ready,"start"==t&&table.newGame()};