Skip to content

progress #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions app/BlackJack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Collections = require('typescript-collections');
class BlackJack extends CardGame implements Gamble {
private balance: number;
private player: Player;
private playingDeck = new Deck();
private playerHand: Collections.LinkedList<Card>;
private dealerHand: Collections.LinkedList<Card>;
private playerHandSum: number;
private dealerHandSum: number;
private prompts = new BlackJackPrompts();

run() {
let stillRunning = this.prompts.welcomePrompt;
while (stillRunning => true) {

}
}

buildDealerHand() {
this.dealerHand.add(this.playingDeck.pullCardFromDeck());
this.dealerHand.add(this.playingDeck.pullCardFromDeck());
}

buildHand() {
//add two cards to hand initially
this.playerHand.add(this.playingDeck.pullCardFromDeck());
this.playerHand.add(this.playingDeck.pullCardFromDeck());
}
calculateEarnings(wages: number, winnings: number): number {
throw new Error("Method not implemented.");
}

hit() {
if (this.sumDealerCards() <= 18) {
this.dealerHand.add(this.playingDeck.pullCardFromDeck());
}
this.playerHand.add(this.playingDeck.pullCardFromDeck());
}

sumDealerCards() {
let sumCount = 0;
for (let i = 0; i < this.dealerHand.size(); i++) {
sumCount = this.dealerHand.elementAtIndex(i).valueOfRank();
}
return sumCount;
}

sumPlayerCards() {
let sumCount = 0;
for (let i = 0; i < this.playerHand.size(); i++) {
sumCount = this.playerHand.elementAtIndex(i).valueOfRank();
}
return sumCount;
}

checkBust(person: String) {
switch (person) {
case "player": if (this.sumPlayerCards() > 21) { return true; } else { return false; }
case "dealer": if (this.sumDealerCards() > 21) { return true; } else { return false; }
}
}
}
6 changes: 6 additions & 0 deletions app/BlackJackPrompts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class BlackJackPrompts{

welcomePrompt():boolean{
return false;
}
}
50 changes: 50 additions & 0 deletions app/Card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Card{
private rank: String;
private suit: String;

constructor(rank: String, suit: String){
this.rank = rank;
this.suit = suit;
}

getRank(){
return this.rank;
}

getSuit(){
return this.suit;
}

getIntValue(){
return this.rank.valueOf;
}

setSuit(suit: String){
this.suit = suit;
}

toString(){
let output = (this.rank.toString + "of" + this.suit.toString);
return output;
}

valueOfRank(): number{
switch(this.rank){
case "ACE": return 1;
case "TWO": return 2;
case "THREE": return 3;
case "FOUR": return 4;
case "FIVE": return 5;
case "SIX": return 6;
case "SEVEN": return 7;
case "EIGHT": return 8;
case "NINE": return 9;
case "TEN": return 10;
case "JACK": return 11;
case "QUEEN": return 12;
case "KING": return 13;
default: return null;
}
}

}
5 changes: 5 additions & 0 deletions app/CardGame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abstract class CardGame{
protected deck = Deck;

abstract buildHand();
}
43 changes: 43 additions & 0 deletions app/Deck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Deck{
private fullDeck: Card[];
private deckInPlay: Card[];

constructor(){
this.fullDeck = new Card[52];
this.buildDeck();
this.deckInPlay = this.fullDeck;
}

buildDeck(){
let rank = ["ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
"SEVEN", "EIGHT", "NINE", "TEN",
"JACK", "QUEEN", "KING"];
let suit = ["HEARTS", "CLUBS", "SPADES", "DIAMONDS"];
let counter = 0;
for(let i = 0; i < 13; i++){
for(let j = 0; j < 4; j++){
this.fullDeck[counter] = new Card(rank[i], suit[j]);
counter++;
}
}
}

pullCardFromDeck():Card{
let indexOfCard = Math.floor((Math.random() * this.deckInPlay.length) + 1);
let cardToBePulled = this.deckInPlay[indexOfCard];
let bufferdeck = new Card[this.deckInPlay.length-1];
let counterForDeckInPlay = 0;
for(let i = 0; i < bufferdeck.length; i++){
if(i == indexOfCard){
counterForDeckInPlay++;
} else{
bufferdeck[i] = this.deckInPlay[counterForDeckInPlay];
counterForDeckInPlay++;
}
}
this.deckInPlay = bufferdeck;
return cardToBePulled;
}


}
3 changes: 3 additions & 0 deletions app/Gamble.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Gamble{
calculateEarnings(wages: number, winnings: number): number;
}
11 changes: 11 additions & 0 deletions app/GameEngine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
abstract class GameEngine<Game> implements GameEngineInterface<GameTypePlayer, GameType> {
getGame(): GameType {
throw new Error("Method not implemented.");
}
evaluateTurn(player: GameTypePlayer): void {
throw new Error("Method not implemented.");
}
run(): void {
throw new Error("Method not implemented.");
}
}
5 changes: 5 additions & 0 deletions app/GameEngineInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface GameEngineInterface<T extends PlayerInterface, E extends GameInterface<T>>{
getGame(): E;
evaluateTurn(player: T): void;
run(): void;
}
9 changes: 9 additions & 0 deletions app/GameInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface GameInterface<T extends PlayerInterface> {

getPlayers(): T[];
getPlayer(playerId: number): T;
addPlayer(player: T): void;
removePlayer(player: T): void;
contains(player: T): boolean;

}
3 changes: 3 additions & 0 deletions app/GameType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface GameType extends GameInterface<GameTypePlayer>{

}
3 changes: 3 additions & 0 deletions app/GameTypePlayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface GameTypePlayer extends PlayerInterface{

}
4 changes: 4 additions & 0 deletions app/IOHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//will handle all input and output for the whole system
class IOHandler{

}
21 changes: 21 additions & 0 deletions app/Player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Player implements PlayerInterface {
id: number;
name: string;
profile: Profile;
constructor(id: number, name: string, balance: number){
this.name = name;
this.id = id;
this.profile = new Profile(this.id, this.name, balance);
}


getProfile(): Profile {
return this.profile;
}
getName(): String {
return this.name;
}
getId(): number {
return this.id;
}
}
9 changes: 9 additions & 0 deletions app/PlayerInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface PlayerInterface {
id: number;
name: string;
profile: Profile;

getProfile(): Profile;
getName(): String;
getId(): number;
}
22 changes: 22 additions & 0 deletions app/Profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Profile{
id: number = 0;
name: string = "";
balance: number = 0;
constructor(id: number, name: string, balance: number){
this.id = id;
this.name = name;
this.balance = balance;
}

getProfileId(){
return this.id;
}

getUserName(){
return this.name;
}

getBalance(){
return this.balance;
}
}
3 changes: 3 additions & 0 deletions app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class app{

}
3 changes: 3 additions & 0 deletions app/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"code-runner.defaultLanguage": "javascript"
}
22 changes: 22 additions & 0 deletions node_modules/typescript-collections/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/typescript-collections/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading