Console Black Jack
Black Jack in a console
by Taylor Lopez
HTML
<div id="content"></div>
CSS
html, body
{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
/* Background Color */
background-color: black;
}
#content
{
padding: 10px;
font-family:"Lucida Console", "Courier New", "Courier";
/* Console Text Color */
color: #0F0; /* Lime Green */
}
/* console span properties */
.consoleLine
{
}
JavaScript
/* START CONSOLE FUNCTIONALITY -- DON'T TOUCH */
// This function intercepts the console.log() calls and prints the output to the result pane to the right like a standard console instead of the hidden console. Just pretend like this isn't heeeereee. ooooooooooohhh. *spooky*
var _console = document.getElementById("content"); var _body = document.getElementsByTagName("body")[0]; console.log = function (object) { var output = object === undefined ? "" : object.toString(); output = output.replace(/ /g, " "); while (output.search('\n') !== -1) output = output.replace('\n', "<br />"); _console.innerHTML += ("<span class='consoleLine'>" + output + "</span><br />"); window.scrollTo(0, _body.scrollHeight); };
/* END OF CONSOLE FUNCTIONALITY */
/****************************** YOUR CODE START ******************************/
/* CLASSES */
function Card(value, suiteValue)
{
this.value = value;
this.suite = "";
switch (suiteValue)
{
case 0:
this.suite = "C";
break;
case 1:
this.suite = "D";
break;
case 2:
this.suite = "H";
break;
case 3:
this.suite = "S";
break;
}
}
Card.prototype.toString = function()
{
var printValue = "";
switch (this.value)
{
case 1:
printValue = "A";
break;
case 11:
printValue = "J";
break;
case 12:
printValue = "Q";
break;
case 13:
printValue = "K";
break;
default:
printValue = this.value + "";
}
return printValue + this.suite;
};
function Pile()
{
this.cards = [];
}
Pile.prototype.draw = function()
{
if (this.cards.length > 0)
return this.cards.pop();
};
Pile.prototype.addAllCards = function(cardArray)
{
while(cardArray.length > 0)
...