<script type="text/javascript" language="javascript">
var userBingoValues = new Array(1, 10, 25, 2, 3, 5, 11, 12, 19, 17, 16, 21, 7, 8, 24, 14, 18, 13, 4, 6, 9, 15, 20, 22, 23);
var temp = userBingoValues;
var systemClickValues = GetRandomValue(temp);
var bingoCount = 0;
var systemClickCount = 0;
var systemBingoValues = new Array();
$(document).ready(function() {
userBingoValues = GetRandomValue(userBingoValues);
$("#divGame input:button").each(function(n) {
var clickedButton = $(this);
$(this).attr("value", userBingoValues[n]);
$(this).click(function() {
$("#divSystemBingo input:button[value=" + clickedButton.attr("value") + "]").attr("disabled", "disabled");
$("#divUserBingoedValues center").append("<span>" + clickedButton.attr("value") + "</span>");
$("#divUserBingoedValues span[innerHTML=" + clickedButton.attr("value") + "]").fadeIn("slow");
$("#divUserBingoedValues span[innerHTML=" + clickedButton.attr("value") + "]").css("display", "inline");
CheckForSystemStrike();
$(this).attr("disabled", "disabled");
CheckForStrike();
systemClickValues.splice($.inArray(parseInt(clickedButton.attr("value")), systemClickValues), 1);
if (bingoCount != 5 && systemBingoCount != 5) {
$("#divSystemBingo input:button[value=" + systemClickValues[systemClickCount++] + "]").trigger('click');
}
});
});
systemBingoValues = GetRandomValue(temp);
$("#divSystemBingo input:button").each(function(n) {
var clickedButton = $(this);
$(this).attr("value", systemBingoValues[n]);
$(this).click(function() {
$("#divGame input:button[value=" + clickedButton.attr("value") + "]").attr("disabled", "disabled");
$("#divSystemBingoedValues center").append("<span style='background-color:Lime;color: Black;'>" + clickedButton.attr("value") + "</span>");
$("#divSystemBingoedValues span[innerHTML=" + clickedButton.attr("value") + "]").fadeIn("slow");
$("#divSystemBingoedValues span[innerHTML=" + clickedButton.attr("value") + "]").css("display", "inline");
CheckForStrike();
$(this).attr("disabled", "disabled");
CheckForSystemStrike();
systemClickValues.splice($.inArray(parseInt(clickedButton.attr("value")), systemClickValues), 1);
});
});
});
var bingoCount = 0;
var bingoArray = new Array(6);
for (var i = 0; i < 6; i++) {
bingoArray[i] = new Array(0, 0, 0, 0, 0, 0, 0);
}
function GetRandomValue(array) {
for (var j, x, i = array.length; i; j = parseInt(Math.random() * i), x = array[--i], array[i] = array[j], array[j] = x);
return array;
}
function CheckForStrike() {
$("#divGame input:button:disabled").each(function() {
var currentButton = $(this);
bingoArray[parseInt(currentButton.attr("rindex")) + 1][parseInt(currentButton.attr("cindex")) + 1] = "B";
});
for (var i = 0; i < 6; i++) {
if (bingoArray[i][0] != "C") {
var isRowBingo = true;
for (var j = 1; j < 6; j++) {
if (bingoArray[i][j] != "B") {
isRowBingo = false;
break;
}
}
if (isRowBingo) {
bingoArray[i][0] = "C";
$("#divGame input:button[rindex=" + (i - 1) + "]").css("border-color", "lightgreen");
bingoCount++;
}
}
}
for (var i = 0; i < 6; i++) {
if (bingoArray[0][i] != "C") {
var isColBingo = true;
for (var j = 1; j < 6; j++) {
if (bingoArray[j][i] != "B") {
isColBingo = false;
break;
}
}
if (isColBingo) {
bingoArray[0][i] = "C";
$("#divGame input:button[cindex=" + (i - 1) + "]").css("border-color", "lightgreen");
bingoCount++;
}
}
}
var isNormBingo = true;
if (bingoArray[0][0] != "C") {
for (var i = 1; i < 6; i++) {
if (bingoArray[i][i] != "B") {
isNormBingo = false;
break;
}
}
if (isNormBingo) {
bingoCount++;
bingoArray[0][0] = "C";
for (var i = 0; i < 5; i++) {
$("#divGame input:button[rindex=" + i + "][cindex=" + i + "]").css("border-color", "lightgreen");
}
isNormBingo = null;
}
}
if (bingoArray[0][6] != "C") {
isNormBingo = true;
for (var i = 5, j = 1; i > 0; i--, j++) {
if (bingoArray[i][j] != "B") {
isNormBingo = false;
break;
}
}
if (isNormBingo) {
bingoCount++;
bingoArray[0][6] = "C";
for (var i = 4, j = 0; i >= 0; i--, j++) {
$("#divGame input:button[rindex=" + i + "][cindex=" + j + "]").css("border-color", "lightgreen");
}
isNormBingo = null;
}
}
if (bingoCount == 5) {
DisableGameBoards();
AnimateBingo('divUserBingoedValues');
$("#divSystemBingo").fadeIn("slow");
}
if (systemBingoCount == 5) {
DisableGameBoards();
AnimateBingo('divSystemBingoedValues');
$("#divSystemBingo").fadeIn("slow");
}
}
var systemBingoCount = 0;
var systemBingoArray = new Array(6);
for (var i = 0; i < 6; i++) {
systemBingoArray[i] = new Array(0, 0, 0, 0, 0, 0, 0);
}
function CheckForSystemStrike() {
$("#divSystemBingo input:button:disabled").each(function() {
var currentButton = $(this);
systemBingoArray[parseInt(currentButton.attr("rindex")) + 1][parseInt(currentButton.attr("cindex")) + 1] = "B";
});
for (var i = 0; i < 6; i++) {
if (systemBingoArray[i][0] != "C") {
var isRowBingo = true;
for (var j = 1; j < 6; j++) {
if (systemBingoArray[i][j] != "B") {
isRowBingo = false;
break;
}
}
if (isRowBingo) {
systemBingoArray[i][0] = "C";
$("#divSystemBingo input:button[rindex=" + (i - 1) + "]").css("border-color", "lightgreen");
systemBingoCount++;
}
}
}
for (var i = 0; i < 6; i++) {
if (systemBingoArray[0][i] != "C") {
var isColBingo = true;
for (var j = 1; j < 6; j++) {
if (systemBingoArray[j][i] != "B") {
isColBingo = false;
break;
}
}
if (isColBingo) {
systemBingoArray[0][i] = "C";
$("#divSystemBingo input:button[cindex=" + (i - 1) + "]").css("border-color", "lightgreen");
systemBingoCount++;
}
}
}
var isNormBingo = true;
if (systemBingoArray[0][0] != "C") {
for (var i = 1; i < 6; i++) {
if (systemBingoArray[i][i] != "B") {
isNormBingo = false;
break;
}
}
if (isNormBingo) {
systemBingoCount++;
systemBingoArray[0][0] = "C";
for (var i = 0; i < 5; i++) {
$("#divSystemBingo input:button[rindex=" + i + "][cindex=" + i + "]").css("border-color", "lightgreen");
}
isNormBingo = null;
}
}
if (systemBingoArray[0][6] != "C") {
isNormBingo = true;
for (var i = 5, j = 1; i > 0; i--, j++) {
if (systemBingoArray[i][j] != "B") {
isNormBingo = false;
break;
}
}
if (isNormBingo) {
systemBingoCount++;
systemBingoArray[0][6] = "C";
for (var i = 4, j = 0; i >= 0; i--, j++) {
$("#divSystemBingo input:button[rindex=" + i + "][cindex=" + j + "]").css("border-color", "lightgreen");
}
isNormBingo = null;
}
}
if (systemBingoCount == 5) {
DisableGameBoards();
AnimateBingo('divSystemBingoedValues');
$("#divSystemBingo").fadeIn("slow");
}
if (bingoCount == 5) {
DisableGameBoards();
AnimateBingo('divUserBingoedValues');
$("#divSystemBingo").fadeIn("slow");
}
}
function AnimateBingo(id) {
$("#" + id + " center").empty().append("<span>BINGOOOOO!!!</span>");
$("#" + id + " center span").fadeToggle("fast", function() {
$("#" + id + " center span").fadeToggle("fast", function() {
$("#" + id + " center span").fadeToggle("fast");
});
});
}
function DisableGameBoards() {
$("#divSystemBingo,#divGame").attr("disabled", "disabled");
}
</script>
span
{
width: 20px;
height: 20px;
border-style: outset;
background-color: Black;
font-family: Comic Sans MS;
font-size: 2em;
vertical-align: middle;
text-align: center;
color: Lime;
display: none;
}
modified 2-Mar-12 5:37am.
|