Last active
December 13, 2015 23:08
-
-
Save saltavenger/4988962 to your computer and use it in GitHub Desktop.
Javascript Checkers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//establish whose turn it is & how many points | |
var whosTurn = 1; | |
var redPoint = 0; | |
var blackPoint = 0; | |
console.log("Player 1 is red, It's your turn!"); | |
//create board game | |
function createRow(numCols, className, hasCheckers, checkerColor){ | |
for(var col= 1; col <= numCols; col++){ | |
document.getElementById("checkers").innerHTML += "<div class='"+className+"'></div>"; | |
if(hasCheckers){ | |
if(className == "odd" && col%2 == 0){ | |
$("#checkers > div").last().append("<div class='checker " + checkerColor + "'></div>"); | |
} | |
else if(className == "even" && col%2 == 1){ | |
$("#checkers > div").last().append("<div class='checker " + checkerColor + "'></div>"); | |
} | |
} | |
} | |
} | |
//create checkers | |
for(var row= 1; row <= 8; row++){ | |
var hasCheckers = row < 4 || row > 5; | |
var checkerColor = row < 4 ? 'redChecker': 'blackChecker'; | |
if(row%2 == 1){ | |
createRow(8,"odd", hasCheckers, checkerColor); | |
} | |
else{ | |
createRow(8, "even", hasCheckers, checkerColor); | |
} | |
} | |
//checker selection | |
$(".checker").click(function(e){ | |
e.stopPropagation(); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1 && ($(this).hasClass("redChecker") || $(this).hasClass("redKing"))){ | |
$(this).toggleClass("selected"); | |
} | |
else if(whosTurn == 2 && ($(this).hasClass("blackChecker") || $(this).hasClass("blackKing"))){ | |
$(this).toggleClass("selected"); | |
} | |
}); | |
//move checkers | |
$("#checkers > div").click(function(e){ | |
var sel=$(".selected"); | |
if(sel.length!=0){ | |
//checker rules | |
var selIndex = $(".selected").parent().index() | |
var check1 = selIndex >=1 && selIndex <=6 || selIndex >=9 && selIndex <=14 || | |
selIndex >=17 && selIndex <=22 || selIndex >=25 && selIndex <=30 || | |
selIndex >=33 && selIndex <=38 || selIndex >=41 && selIndex <=46 || | |
selIndex >=49 && selIndex <=54 || selIndex >=57 && selIndex <=62 ? true: false; | |
var check2 = selIndex == 0 || selIndex == 8 || selIndex == 16 || selIndex == 24 || selIndex == 32 || | |
selIndex == 40 ||selIndex == 48 || selIndex == 56 ? true: false; | |
var check3 = selIndex == 7 || selIndex == 15 || selIndex == 23 || selIndex == 31 || selIndex == 39 || | |
selIndex == 47 || selIndex == 55 || selIndex == 63 ? true: false; | |
//moving red kings in the middle | |
if((check1 && sel.hasClass("redKing"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var blackPos1 = selIndex+7; | |
var blackPos2 = selIndex+8; | |
var blackPos3 = selIndex+9; | |
var blackPos4 = selIndex+1; | |
var blackPos5 = selIndex-1; | |
var blackPos6 = selIndex-7; | |
var blackPos7 = selIndex-8; | |
var blackPos8 = selIndex-9; | |
var newMove = $(this).index() == selIndex-2 || $(this).index() == selIndex-14 || $(this).index() == selIndex-16 || $(this).index() == selIndex-18 || | |
$(this).index() == selIndex+2 || $(this).index() == selIndex+14 || $(this).index() == selIndex+16 || $(this).index() == selIndex+18 ? true: false; | |
var jump = $("#checkers >div").eq(blackPos1).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos2).children().hasClass("blackChecker") || | |
$("#checkers >div").eq(blackPos3).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos4).children().hasClass("blackChecker") | |
|| $("#checkers >div").eq(blackPos5).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos6).children().hasClass("blackChecker") | |
|| $("#checkers >div").eq(blackPos7).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos8).children().hasClass("blackChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+14) && ($("#checkers >div").eq(blackPos1).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(blackPos2).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+18) && ($("#checkers >div").eq(blackPos3).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+2) && ($("#checkers >div").eq(blackPos4).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos4).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-2) && ($("#checkers >div").eq(blackPos5).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos5).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-14) && ($("#checkers >div").eq(blackPos6).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos6).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-16) && ($("#checkers >div").eq(blackPos7).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos7).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-18) && ($("#checkers >div").eq(blackPos8).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos8).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
//if there's not a jump | |
else if($(this).index() == selIndex+7 || $(this).index() == selIndex+8 || $(this).index() == selIndex+9 || $(this).index() == selIndex+1 || $(this).index() == selIndex-1 | |
|| $(this).index() == selIndex-9 || $(this).index() == selIndex-8 || $(this).index() == selIndex-7){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//moving red kings on the left | |
if((check2 && sel.hasClass("redKing"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var blackPos1 = selIndex+9; | |
var blackPos2 = selIndex+8; | |
var blackPos3 = selIndex+1; | |
var blackPos4 = selIndex-7; | |
var blackPos5 = selIndex-8; | |
var newMove = $(this).index() == selIndex+2 || $(this).index() == selIndex-14 || $(this).index() == selIndex-16 || | |
$(this).index() == selIndex+16 || $(this).index() == selIndex+18 ? true: false; | |
var jump = $("#checkers >div").eq(blackPos1).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos2).children().hasClass("blackChecker") || | |
$("#checkers >div").eq(blackPos3).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos4).children().hasClass("blackChecker") | |
|| $("#checkers >div").eq(blackPos5).children().hasClass("blackChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+18) && ($("#checkers >div").eq(blackPos1).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(blackPos2).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+2) && ($("#checkers >div").eq(blackPos3).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-14) && ($("#checkers >div").eq(blackPos4).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos4).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-16) && ($("#checkers >div").eq(blackPos5).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos5).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
//if there's not a jump | |
else if($(this).index() == selIndex-7 || $(this).index() == selIndex-8 || $(this).index() == selIndex+1 || | |
$(this).index() == selIndex+9 || $(this).index() == selIndex+8){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//moving red kings on the right | |
if((check3 && sel.hasClass("redKing"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var blackPos1 = selIndex+8; | |
var blackPos2 = selIndex+7; | |
var blackPos3 = selIndex-1; | |
var blackPos4 = selIndex-8; | |
var blackPos5 = selIndex-9; | |
var newMove = $(this).index() == selIndex-2 || $(this).index() == selIndex+14 || $(this).index() == selIndex+16 || | |
$(this).index() == selIndex-16 || $(this).index() == selIndex-18 ? true: false; | |
var jump = $("#checkers >div").eq(blackPos1).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos2).children().hasClass("blackChecker") || | |
$("#checkers >div").eq(blackPos3).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos4).children().hasClass("blackChecker") | |
|| $("#checkers >div").eq(blackPos5).children().hasClass("blackChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(blackPos1).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+14) && ($("#checkers >div").eq(blackPos2).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-2) && ($("#checkers >div").eq(blackPos3).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-16) && ($("#checkers >div").eq(blackPos4).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos4).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-18) && ($("#checkers >div").eq(blackPos5).children().hasClass("blackChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(blackPos5).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
//if there's not a jump | |
else if($(this).index() == selIndex+7 || $(this).index() == selIndex+8 || $(this).index() == selIndex-1 || | |
$(this).index() == selIndex-9 || $(this).index() == selIndex-8){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//moving red checkers in the middle | |
if((check1 && sel.hasClass("redChecker"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var blackPos1 = selIndex+7 | |
var blackPos2 = selIndex+8 | |
var blackPos3 = selIndex+9 | |
var newMove = $(this).index() == selIndex+14 || $(this).index() == selIndex+16 || $(this).index() == selIndex+18 ? true: false; | |
var jump = $("#checkers >div").eq(blackPos1).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos2).children().hasClass("blackChecker") || | |
$("#checkers >div").eq(blackPos3).children().hasClass("blackChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+14) && ($("#checkers >div").eq(blackPos1).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+7; | |
var blackJumpPos2 = jumpIndex+8; | |
var blackJumpPos3 = jumpIndex+9; | |
var blackJumpPos4 = jumpIndex+14; | |
var blackJumpPos5 = jumpIndex+16; | |
var blackJumpPos6 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos5).children(".checker").length; | |
var jumpPos3 = $("#checkers >div").eq(blackJumpPos6).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) || | |
(($("#checkers >div").eq(blackJumpPos3).children().hasClass("blackChecker")== true) && jumpPos3 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 2; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(blackPos2).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+7; | |
var blackJumpPos2 = jumpIndex+8; | |
var blackJumpPos3 = jumpIndex+9; | |
var blackJumpPos4 = jumpIndex+14; | |
var blackJumpPos5 = jumpIndex+16; | |
var blackJumpPos6 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos5).children(".checker").length; | |
var jumpPos3 = $("#checkers >div").eq(blackJumpPos6).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) || | |
(($("#checkers >div").eq(blackJumpPos3).children().hasClass("blackChecker")== true) && jumpPos3 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 2; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if(($(this).index() == selIndex+18) && ($("#checkers >div").eq(blackPos3).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+7; | |
var blackJumpPos2 = jumpIndex+8; | |
var blackJumpPos3 = jumpIndex+9; | |
var blackJumpPos4 = jumpIndex+14; | |
var blackJumpPos5 = jumpIndex+16; | |
var blackJumpPos6 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos5).children(".checker").length; | |
var jumpPos3 = $("#checkers >div").eq(blackJumpPos6).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) || | |
(($("#checkers >div").eq(blackJumpPos3).children().hasClass("blackChecker")== true) && jumpPos3 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 2; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//if there's not a jump | |
else{ | |
//if there's a king | |
if(($(this).index() == selIndex+7 || $(this).index() == selIndex+8 || $(this).index() == selIndex+9) && ($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).append($(".selected")); | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else if($(this).index() == selIndex+7 || $(this).index() == selIndex+8 || $(this).index() == selIndex+9){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
} | |
//moving left side red checkers | |
if((check2 && sel.hasClass("redChecker"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var blackPos1 = selIndex+8 | |
var blackPos2 = selIndex+9 | |
var newMove = $(this).index() == selIndex+16 || $(this).index() == selIndex+18 ? true: false; | |
var jump = $("#checkers >div").eq(blackPos1).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos2).children().hasClass("blackChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if((newMove == ($(this).index() == selIndex+16)) && ($("#checkers >div").eq(blackPos1).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+8; | |
var blackJumpPos2 = jumpIndex+9; | |
var blackJumpPos3 = jumpIndex+16; | |
var blackJumpPos4 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 2; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if((newMove == ($(this).index() == selIndex+18)) && ($("#checkers >div").eq(blackPos2).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+8; | |
var blackJumpPos2 = jumpIndex+9; | |
var blackJumpPos3 = jumpIndex+16; | |
var blackJumpPos4 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//if there's not a jump | |
else{ | |
//if there's a king | |
if(($(this).index() == selIndex+8 || $(this).index() == selIndex+9) && ($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).append($(".selected")); | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else if($(this).index() == selIndex+8 || $(this).index() == selIndex+9){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
} | |
//moving right side red checkers | |
if((check3 && sel.hasClass("redChecker"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var blackPos1 = selIndex+7; | |
var blackPos2 = selIndex+8; | |
var newMove = $(this).index() == selIndex+14 || $(this).index() == selIndex+16 ? true: false; | |
var jump = $("#checkers >div").eq(blackPos1).children().hasClass("blackChecker") || $("#checkers >div").eq(blackPos2).children().hasClass("blackChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if((newMove == ($(this).index() == selIndex+14)) && ($("#checkers >div").eq(blackPos1).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+7; | |
var blackJumpPos2 = jumpIndex+8; | |
var blackJumpPos3 = jumpIndex+16; | |
var blackJumpPos4 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 2; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if((newMove == ($(this).index() == selIndex+16)) && ($("#checkers >div").eq(blackPos2).children().hasClass("blackChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var blackJumpPos1 = jumpIndex+7; | |
var blackJumpPos2 = jumpIndex+8; | |
var blackJumpPos3 = jumpIndex+16; | |
var blackJumpPos4 = jumpIndex+18; | |
var jumpPos1 = $("#checkers >div").eq(blackJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(blackJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(blackJumpPos1).children().hasClass("blackChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(blackJumpPos2).children().hasClass("blackChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(blackPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
redPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 1, you have a double jump-- DO IT"); | |
whosTurn = 1; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 2; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//if there's not a jump | |
else{ | |
//if there's a king | |
if(($(this).index() == selIndex+7 || $(this).index() == selIndex+8) && ($(this).index() >= 56) && ($(this).index() <= 63)){ | |
$(this).append($(".selected")); | |
$(this).children().removeClass("redChecker").addClass("redKing"); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Red has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else if($(this).index() == selIndex+7 || $(this).index() == selIndex+8){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
} | |
//moving black kings in the middle | |
if((check1 && sel.hasClass("blackKing"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var redPos1 = selIndex+7; | |
var redPos2 = selIndex+8; | |
var redPos3 = selIndex+9; | |
var redPos4 = selIndex+1; | |
var redPos5 = selIndex-1; | |
var redPos6 = selIndex-7; | |
var redPos7 = selIndex-8; | |
var redPos8 = selIndex-9; | |
var newMove = $(this).index() == selIndex-2 || $(this).index() == selIndex-14 || $(this).index() == selIndex-16 || $(this).index() == selIndex-18 || | |
$(this).index() == selIndex+2 || $(this).index() == selIndex+14 || $(this).index() == selIndex+16 || $(this).index() == selIndex+18 ? true: false; | |
var jump = $("#checkers >div").eq(redPos1).children().hasClass("redChecker") || $("#checkers >div").eq(redPos2).children().hasClass("redChecker") || | |
$("#checkers >div").eq(redPos3).children().hasClass("redChecker") || $("#checkers >div").eq(redPos4).children().hasClass("redChecker") | |
|| $("#checkers >div").eq(redPos5).children().hasClass("redChecker") || $("#checkers >div").eq(redPos6).children().hasClass("redChecker") | |
|| $("#checkers >div").eq(redPos7).children().hasClass("redChecker") || $("#checkers >div").eq(redPos8).children().hasClass("redChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+14) && ($("#checkers >div").eq(redPos1).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(redPos2).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+18) && ($("#checkers >div").eq(redPos3).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+2) && ($("#checkers >div").eq(redPos4).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos4).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-2) && ($("#checkers >div").eq(redPos5).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos5).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-14) && ($("#checkers >div").eq(redPos6).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos6).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-16) && ($("#checkers >div").eq(redPos7).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos7).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-18) && ($("#checkers >div").eq(redPos8).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos8).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
//if there's not a jump | |
else if($(this).index() == selIndex+7 || $(this).index() == selIndex+8 || $(this).index() == selIndex+9 || $(this).index() == selIndex+1 || $(this).index() == selIndex-1 | |
|| $(this).index() == selIndex-9 || $(this).index() == selIndex-8 || $(this).index() == selIndex-7){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//moving black kings on the left | |
if((check2 && sel.hasClass("blackKing"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var redPos1 = selIndex+9; | |
var redPos2 = selIndex+8; | |
var redPos3 = selIndex+1; | |
var redPos4 = selIndex-7; | |
var redPos5 = selIndex-8; | |
var newMove = $(this).index() == selIndex+2 || $(this).index() == selIndex-14 || $(this).index() == selIndex-16 || | |
$(this).index() == selIndex+16 || $(this).index() == selIndex+18 ? true: false; | |
var jump = $("#checkers >div").eq(redPos1).children().hasClass("redChecker") || $("#checkers >div").eq(redPos2).children().hasClass("redChecker") || | |
$("#checkers >div").eq(redPos3).children().hasClass("redChecker") || $("#checkers >div").eq(redPos4).children().hasClass("redChecker") | |
|| $("#checkers >div").eq(redPos5).children().hasClass("redChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+18) && ($("#checkers >div").eq(redPos1).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(redPos2).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+2) && ($("#checkers >div").eq(redPos3).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-14) && ($("#checkers >div").eq(redPos4).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos4).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
if(($(this).index() == selIndex-16) && ($("#checkers >div").eq(redPos5).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos5).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
//if there's not a jump | |
else if($(this).index() == selIndex-7 || $(this).index() == selIndex-8 || $(this).index() == selIndex+1 || | |
$(this).index() == selIndex+9 || $(this).index() == selIndex+8){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//moving black kings on the right | |
if((check3 && sel.hasClass("blackKing"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var redPos1 = selIndex+8; | |
var redPos2 = selIndex+7; | |
var redPos3 = selIndex-1; | |
var redPos4 = selIndex-8; | |
var redPos5 = selIndex-9; | |
var newMove = $(this).index() == selIndex-2 || $(this).index() == selIndex+14 || $(this).index() == selIndex+16 || | |
$(this).index() == selIndex-16 || $(this).index() == selIndex-18 ? true: false; | |
var jump = $("#checkers >div").eq(redPos1).children().hasClass("redChecker") || $("#checkers >div").eq(redPos2).children().hasClass("redChecker") || | |
$("#checkers >div").eq(redPos3).children().hasClass("redChecker") || $("#checkers >div").eq(redPos4).children().hasClass("redChecker") | |
|| $("#checkers >div").eq(redPos5).children().hasClass("redChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if(($(this).index() == selIndex+16) && ($("#checkers >div").eq(redPos1).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex+14) && ($("#checkers >div").eq(redPos2).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-2) && ($("#checkers >div").eq(redPos3).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
else if(($(this).index() == selIndex-16) && ($("#checkers >div").eq(redPos4).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos4).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
if(($(this).index() == selIndex-18) && ($("#checkers >div").eq(redPos5).children().hasClass("redChecker"))){ | |
$(this).append($(".selected")); | |
$("#checkers >div").eq(redPos5).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
//if there's not a jump | |
else if($(this).index() == selIndex+7 || $(this).index() == selIndex+8 || $(this).index() == selIndex-1 || | |
$(this).index() == selIndex-9 || $(this).index() == selIndex-8){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//moving black checkers in the middle | |
if((check1 && sel.hasClass("blackChecker"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var redPos1 = selIndex-7 | |
var redPos2 = selIndex-8 | |
var redPos3 = selIndex-9 | |
var newMove = $(this).index() == selIndex-14 || $(this).index() == selIndex-16 || $(this).index() == selIndex-18 ? true: false; | |
var jump = $("#checkers >div").eq(redPos1).children().hasClass("redChecker") || $("#checkers >div").eq(redPos2).children().hasClass("redChecker") || | |
$("#checkers >div").eq(redPos3).children().hasClass("redChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if((newMove == ($(this).index() == selIndex-14)) && ($("#checkers >div").eq(redPos1).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-7; | |
var redJumpPos2 = jumpIndex-8; | |
var redJumpPos3 = jumpIndex-9; | |
var redJumpPos4 = jumpIndex-14; | |
var redJumpPos5 = jumpIndex-16; | |
var redJumpPos6 = jumpIndex-18; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos5).children(".checker").length; | |
var jumpPos3 = $("#checkers >div").eq(redJumpPos6).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) || | |
(($("#checkers >div").eq(redJumpPos3).children().hasClass("redChecker")== true) && jumpPos3 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if((newMove == ($(this).index() == selIndex-16)) && ($("#checkers >div").eq(redPos2).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-7; | |
var redJumpPos2 = jumpIndex-8; | |
var redJumpPos3 = jumpIndex-9; | |
var redJumpPos4 = jumpIndex-14; | |
var redJumpPos5 = jumpIndex-16; | |
var redJumpPos6 = jumpIndex-18; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos5).children(".checker").length; | |
var jumpPos3 = $("#checkers >div").eq(redJumpPos6).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) || | |
(($("#checkers >div").eq(redJumpPos3).children().hasClass("redChecker")== true) && jumpPos3 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if((newMove == ($(this).index() == selIndex-18)) && ($("#checkers >div").eq(redPos3).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-7; | |
var redJumpPos2 = jumpIndex-8; | |
var redJumpPos3 = jumpIndex-9; | |
var redJumpPos4 = jumpIndex-14; | |
var redJumpPos5 = jumpIndex-16; | |
var redJumpPos6 = jumpIndex-18; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos5).children(".checker").length; | |
var jumpPos3 = $("#checkers >div").eq(redJumpPos6).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) || | |
(($("#checkers >div").eq(redJumpPos3).children().hasClass("redChecker")== true) && jumpPos3 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos3).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//if there's not a jump | |
else{ | |
//if there's a king | |
if(($(this).index() == selIndex-7 || $(this).index() == selIndex-8 || $(this).index() == selIndex-9) && ($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).append($(".selected")); | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else if($(this).index() == selIndex-7 || $(this).index() == selIndex-8 || $(this).index() == selIndex-9){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
} | |
//moving left side black checkers | |
if((check2 && sel.hasClass("blackChecker"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var redPos1 = selIndex-7 | |
var redPos2 = selIndex-8 | |
var newMove = $(this).index() == selIndex-14 || $(this).index() == selIndex-16 ? true: false; | |
var jump = $("#checkers >div").eq(redPos1).children().hasClass("redChecker") || $("#checkers >div").eq(redPos2).children().hasClass("redChecker") || | |
$("#checkers >div").eq(redPos3).children().hasClass("redChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if((newMove == ($(this).index() == selIndex-14)) && ($("#checkers >div").eq(redPos1).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-7; | |
var redJumpPos2 = jumpIndex-8; | |
var redJumpPos3 = jumpIndex-14; | |
var redJumpPos4 = jumpIndex-16; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if((newMove == ($(this).index() == selIndex-16)) && ($("#checkers >div").eq(redPos2).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-7; | |
var redJumpPos2 = jumpIndex-8; | |
var redJumpPos3 = jumpIndex-14; | |
var redJumpPos4 = jumpIndex-16; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//if there's not a jump | |
else{ | |
//if there's a king | |
if(($(this).index() == selIndex-7 || $(this).index() == selIndex-8) && ($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).append($(".selected")); | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not king | |
else if($(this).index() == selIndex-7 || $(this).index() == selIndex-8){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
} | |
//moving right side black checkers | |
if((check3 && sel.hasClass("blackChecker"))){ | |
if($(".selected").length > 0 && $(this).children(".checker").length==0){ | |
var redPos1 = selIndex-8 | |
var redPos2 = selIndex-9 | |
var newMove = $(this).index() == selIndex-16 || $(this).index() == selIndex-18 ? true: false; | |
var jump = $("#checkers >div").eq(redPos1).children().hasClass("redChecker") || $("#checkers >div").eq(redPos2).children().hasClass("redChecker") ? true: false; | |
//if there's a jump | |
if(newMove == true && jump == true){ | |
if((newMove == ($(this).index() == selIndex-16)) && ($("#checkers >div").eq(redPos1).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-8; | |
var redJumpPos2 = jumpIndex-9; | |
var redJumpPos3 = jumpIndex-16; | |
var redJumpPos4 = jumpIndex-18; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos1).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
else if((newMove == ($(this).index() == selIndex-18)) && ($("#checkers >div").eq(redPos2).children().hasClass("redChecker"))){ | |
$(".selected").addClass("jumped"); | |
$(this).append($(".selected")); | |
var jumpIndex = $(".jumped").parent().index(); | |
var hasJump = $(".checker").hasClass("jumped"); | |
var redJumpPos1 = jumpIndex-8; | |
var redJumpPos2 = jumpIndex-9; | |
var redJumpPos3 = jumpIndex-16; | |
var redJumpPos4 = jumpIndex-18; | |
var jumpPos1 = $("#checkers >div").eq(redJumpPos3).children(".checker").length; | |
var jumpPos2 = $("#checkers >div").eq(redJumpPos4).children(".checker").length; | |
var placeToJump = (($("#checkers >div").eq(redJumpPos1).children().hasClass("redChecker") == true) && jumpPos1 == 0) || | |
(($("#checkers >div").eq(redJumpPos2).children().hasClass("redChecker") == true) && jumpPos2 == 0) ? true: false; | |
//if there's a king | |
if(($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not a king | |
else{ | |
$("#checkers >div").eq(redPos2).children().remove(); | |
$(".selected").removeClass("selected"); | |
blackPoint++ | |
if(hasJump && placeToJump){ | |
$(".checker").removeClass("jumped"); | |
console.log("Player 2, you have a double jump-- DO IT"); | |
whosTurn = 2; | |
} | |
else{ | |
$(".checker").removeClass("jumped"); | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
//if there's not a jump | |
else{ | |
//if there's a king | |
if(($(this).index() == selIndex-8 || $(this).index() == selIndex-9) && ($(this).index() >= 0) && ($(this).index() <= 7)){ | |
$(this).append($(".selected")); | |
$(this).children().removeClass("blackChecker").addClass("blackKing"); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("Black has been Kinged! The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
//if there's not king | |
else if($(this).index() == selIndex-8 || $(this).index() == selIndex-9){ | |
$(this).append($(".selected")); | |
$(".selected").removeClass("selected"); | |
if(whosTurn == 1){ | |
whosTurn = 2; | |
} | |
else{ | |
whosTurn = 1; | |
} | |
console.log("The score is Red " + redPoint + " & Black " + blackPoint + ". Player " + whosTurn + " go!"); | |
} | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment