Code viewer for World: Tic-Tac-Toe (clone by Cbum)

// Cloned by Cbum on 29 Nov 2022 from World "Tic-Tac-Toe" by Scott Brady 
// Please leave this clone trail here.
 
function splashScreen(){return"Welcome to Tic Tac Toe. The aim of the game is to fill a row, diagonal or column with your symbol, X or O. First to do so is the winner."}function errorSplashScreen(){return"The game is full. Please try again later."}let board,p1,p2,turn,currentTurnDiv;AB.world.newRun=function(){AB.socketStart(),AB.runReady=!1},AB.newSplash(splashScreen()),$("#splashbutton").click(function(){AB.removeSplash(),AB.backgroundMusic(MUSICFILE),AB.runReady=!0,AB.socket&&AB.socket.connected&&console.log("SOCKET CONNECTED")}),AB.world.nextStep=function(){};let turnText="";var cnv;let height;var activePlayer,data={};const POP_SOUND="/uploads/mrprice/mixkit-game-ball-tap-2073.wav",MUSICFILE="/uploads/mrprice/elevator_music.mp3";function setup(){height=windowHeight-300,p1=new Player("X"),p2=new Player("O");var t=createCanvas(height,height),e=(windowWidth-width)/2,r=(windowHeight-height)/2;t.position(e,r),currentTurnDiv=createDiv("").size(180,100),board=new Board(p1,p2),activePlayer=p1}function draw(){background(color("yellow")),AB.hideRunHeader(),board.display(),currentTurnDiv.style("font-size","50px"),currentTurnDiv.style("font-family","sans-serif"),currentTurnDiv.style("padding-top","25px"),currentTurnDiv.style("margin","auto"),currentTurnDiv.style("width","100%"),currentTurnDiv.style("height","100%"),currentTurnDiv.style("color","white"),currentTurnDiv.style("text-align","center"),currentTurnDiv.style("background-image","url(/uploads/mrprice/bg.jpg)"),currentTurnDiv.style("background-size","cover"),currentTurnDiv.style("background-position","center"),currentTurnDiv.style("background-repeat","no-repeat"),currentTurnDiv.style("background-attachment","fixed")}function playSound(t){"pop"==t&&new Audio(POP_SOUND).play()}function mousePressed(){mouseX>0&&mouseX<height&&mouseY>0&&mouseY<height&&!0===AB.runReady&&(board.winState?(board.newGame(),AB.socketOut("startOver")):("X"===board.turn?(playSound("pop"),p1.select(board)):"O"===board.turn&&(playSound("pop"),p2.select(board)),board.toggleTurn()))}class Board{constructor(t,e){this.cells=[],this.cellSize=(width-1)/3,this.p1=t,this.p2=e,this.turn=this.p1.symbol,this.winState=!1,this.resultText="",this.newGame()}display(){let t=this.cellSize;if(this.winState){textSize(40),textAlign(CENTER),text(this.resultText,width/2,height/2),text("Click anywhere for a new game",width/2,height-200);var e=color("teal");fill(e)}else this.cells.forEach(function(e){strokeWeight(25),stroke("rgba(0, 80, 80, 0.8)");var r=color("teal");fill(r),rect(e.row*t,e.col*t,t,t),r=color("yellow"),fill(r),strokeWeight(10),stroke("rgba(173, 167, 0, 0.8)"),textSize(168),textAlign(CENTER),text(e.symbol,e.row*t+t/2,e.col*t+t/2+60),strokeWeight(0)})}update(t,e,r){let o=this.turn;this.cells.forEach(function(n){n.row===t&&n.col===e&&0===n.val&&(n.symbol=r,"X"===o?(n.val=1,data.element=n):(n.val=-1,data.element=n))});let n=this.checkResult();"X"===n?(this.winState=!0,this.resultText="X wins!"):"O"===n?(this.winState=!0,this.resultText="O wins!"):"tie"===n&&(this.winState=!0,this.resultText="It's a tie!")}toggleTurn(){this.turn==p1.symbol?(data.currentTurn=p2.symbol,this.turn=p2.symbol,activePlayer=p2,turnText="Turn: "+p2.symbol):(data.currentTurn=p1.symbol,this.turn=p1.symbol,activePlayer=p1,turnText="Turn: "+p1.symbol),data.activePlayer=activePlayer,currentTurnDiv.html(turnText),data.turnText=turnText,AB.socketOut(data)}checkResult(){let t,e=this.p1,r=this.p2,o=new Array(3),n=new Array(3),l=new Array(3),i=9;for(let t=0;t<3;t++)o[t]=0,n[t]=0,l[t]=0;return this.cells.forEach(function(t){o[t.row]+=t.val,n[t.col]+=t.val,i-=abs(t.val),0===abs(t.row-t.col)&&(l[0]+=t.val),(2===abs(t.row-t.col)||1==t.row&&1==t.col)&&(l[1]+=t.val)}),o.forEach(function(o){3===o&&(t=e.symbol,e.win()),-3===o&&(t=r.symbol,r.win())}),n.forEach(function(o){3===o&&(t=e.symbol,e.win()),-3===o&&(t=r.symbol,r.win())}),l.forEach(function(o){3===o&&(t=e.symbol,e.win()),-3===o&&(t=r.symbol,r.win())}),0===i&&(t="tie"),t}newGame(){console.log("p1 score"+p1.score),console.log("p2 score"+p2.score),this.winState=!1,this.turn=this.p1.symbol,currentTurnDiv.html("Turn: "+this.p1.symbol),this.cells=[];for(let t=0;t<3;t++)for(let e=0;e<3;e++)this.cells.push({row:t,col:e,symbol:"",val:0})}}class Player{constructor(t){this.symbol=t,this.score=0}select(t){if(t.turn==this.symbol){console.log(t.turn,this.symbol);let e=int(Math.floor(mouseX/t.cellSize)),r=int(Math.floor(mouseY/t.cellSize));t.update(e,r,this.symbol),data.row=e,data.col=r,data.symbol=this.symbol}}win(){console.log("YO YO"),this.score++}}AB.socketIn=function(t){console.log(t.turnText),currentTurnDiv.html(t.turnText),board.update(t.row,t.col,t.symbol),console.log(t.currentTurn),board.turn=t.currentTurn,activePlayer=t.activePlayer,"startOver"==t&&board.newGame()};