4/1/2022
66
Javascript Blackjack Github Rating: 8,8/10 8393 reviews
JavascriptJavascript Blackjack Github

Blackjack (card game oftentimes referred to as twenty-one or pontoon) - duo project with Kevin Xu. Written in Java, constructed on the Android Studio application - created as a mobile application. A javascript class representing a game of Blackjack - blackjack.js. Analytics cookies. We use analytics cookies to understand how you use our websites so we can make them better, e.g. They're used to gather information about the pages you visit and how many clicks you need to accomplish a task. Javascript library to make blackjack engines. Contribute to kedoska/engine-blackjack development by creating an account on GitHub. GitHub Wordpress Twitter. Day24 JS: javascript blackjack game 26 Mar 2019. 寫javascript時,我們常使用Google Chrome網頁瀏覽器進行測試。.

Javascript github api
Blackjack
/*Object Oriented Blackjack
A Game has: Players
Dealer
Deck
A Player / Dealer has: Score
Cards
A Score has: Game Logic
Current Score
A Deck has: Cards
*/
function Game() {
this.currentTurnIndex = 0;
this.deck = new Deck();
}
function Deck() {
this.cards = [];
this.cardsDrawn = 0;
var suits = ['spades', 'diamonds', 'hearts', 'clubs'];
var names = ['ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'jack', 'queen', 'king'];
for (var suit in suits) {
for (var name in names) {
this.cards.push(new Card(names[name], suits[suit]));
}
}
}
Deck.prototype.getCard = function () {
if (this.cards.length this.cardsDrawn) {
return null;
} //case: check if all cards drawn
var random = Math.floor(Math.random() * (this.cards.length - this.cardsDrawn));
var temp = this.cards[random];
//swap chosen card with card last in array
this.cards[random] = this.cards[this.cards.length - this.cardsDrawn - 1];
this.cards[this.cards.length - this.cardsDrawn - 1] = temp;
this.cardsDrawn++;
return temp;
};
function Card(name, suit) {
this.name = name;
this.suit = suit;
}
Card.prototype.image = function () {
return 'http://www.jonarnaldo.com/sandbox/deck_images/' + name + '_of_' + suit + '.png';
};
Card.prototype.value = function () {
if (this.name 'jack' 'queen' 'king') {
return [10];
} else if (this.name 'ace') {
return [1, 11];
} else {
return parseInt(this.name, 10);
}
};
function Player() {
//this.name;
this.cards = [];
}
Player.prototype.addCard = function () {
this.cards.push(deck.getCard());
};
Player.prototype.score = function () {
var score = 0;
var aces = [];
for (var i = 0; i < this.cards.length; i++) {
var value = this.cards[i].value() // value array ex.[10]
if (value.length 1) {
score += value[0];
} else {
aces.push(value);
}
}
for (var j = 0; j < aces.length; j++) {
if (score + aces[j].value[1] <= 21) {
score + aces[j].value[1];
} else {
score + aces[j].value[0];
}
}
return score;
};
var deck = new Deck();
var player1 = new Player();
$('#getCard').click(function () {
player1.addCard();
var cardName = player1.cards[player1.cards.length-1].name;
var cardSuit = player1.cards[player1.cards.length-1].suit;
$('#table').append(cardName + cardSuit);
});
Javascript

commented Jun 13, 2017

Blackjack

My coding bootcamp is making me code a Blackjack Hand Calculator. I have to turn it in soon. I'm failing. JavaScipt is fking me.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Github Javascript Examples

RouletteGame.java

Github Javascript Project

importjava.util.Random;
importjava.util.Scanner;
publicclassRouletteGame
{
publicstaticvoidmain(String[] args)
{
Scanner keyboard =newScanner(System.in);
Random generator =newRandom();
double total =500;
double amount;
int choice, win =0, lose =0, spin =0;
int number;
int rouletteNum;
int result;
char response ='y';
int resultArr[] =newint[36];
while (response 'y' response 'Y'&& total <=0)
{
System.out.print('Enter your bet amount: ');
amount = keyboard.nextDouble();
System.out.print('0 - Evenn1 - Oddn2 - Numbern');
choice =-1;
while (choice <0 choice >2)
{
System.out.print('Place your bet on: ');
choice = keyboard.nextInt();
}
number =0;
if (choice 2)
{
while (number <1 number >36)
{
System.out.print('Place your bet on number(1-36): ');
number = keyboard.nextInt();
}
}
rouletteNum = generator.nextInt(37);
spin++;
System.out.println('Roulette number: '+ rouletteNum);
if (choice 2)
{
if (rouletteNum number)
result =35;
else
result =0;
}
else
{
if (rouletteNum 0 rouletteNum %2!= choice)
result =0;
else
result =1;
}
//Print out game result, win/lose amount
if (result >0)
{
System.out.println('Congratulatons!!! You win!');
System.out.printf('You have won $%.2f n', result * amount);
System.out.printf('Here's your money back: $%.2f n',
(result +1) * amount);
total = (result +1) * amount + total;
win ++;
resultArr[rouletteNum]++;
}
else
{
System.out.println('You lose. Better luck next time!');
System.out.printf('You have lost $%.2f n',
(result +1) * amount);
total = total - (result +1) * (amount);
lose ++;
resultArr[rouletteNum]++;
if (total <=0) {
break;
}
}
//Ask for another game
for (int totals=1; totals<36; totals++) {
if( resultArr[totals] >0 ) {
System.out.println('The number '+ totals +' won '+ resultArr[totals] +' times.');
}
}
System.out.println('You hayve $'+ total +' remaining.' );
System.out.println('You have won '+ win +' games.');
System.out.println('You have lost '+ lose +' games.');
System.out.println('The wheel has been spun '+ spin +' times.');
System.out.print('nWould you like to play another game? (y/n) ');
response = keyboard.next().charAt(0);
}
}
}

Javascript Blackjack Github Interview

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment