diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..2698db34 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5309019f..00000000 --- a/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -# Compiled source # -################### -*.com -*.class -*.dll -*.exe -*.o -*.so - -# Packages # -############ -# it's better to unpack these files and commit the raw source -# git has its own built in compression methods -*.7z -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip - -# Logs and databases # -###################### -*.log -*.sql -*.sqlite - -# OS generated files # -###################### -.DS_Store -.DS_Store? -._* -.Spotlight-V100 -.Trashes -ehthumbs.db -Thumbs.db \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..494bc33e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${file}", + "outFiles": [ + "${workspaceFolder}/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..fe88541a --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "typescript", + "tsconfig": "tsconfig.json", + "option": "watch", + "problemMatcher": [ + "$tsc-watch" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/BlackJack.js b/BlackJack.js new file mode 100644 index 00000000..22cc8412 --- /dev/null +++ b/BlackJack.js @@ -0,0 +1,159 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var player_1 = require("./player"); +var CardGame_1 = require("./CardGame"); +var webElement = document.getElementById("display"); +var BlackJack = /** @class */ (function (_super) { + __extends(BlackJack, _super); + function BlackJack() { + return _super.call(this) || this; + } + BlackJack.prototype.turnPrompt = function () { + var answer = "yes"; + switch (answer) { + case 'Hit': + this.hit(); + break; + case 'Stay': + this.stay(); + break; + } + }; + BlackJack.prototype.roundPrompt = function () { + var game = this; + var answer = "Yes"; + switch (answer) { + case 'Yes': + game.newHand(); + game.start(); + break; + case 'No': + console.log('Peace out'); + break; + } + }; + BlackJack.prototype.start = function () { + this.currentPlayer = 1; + this.addNewPlayer("PLAYER_1"); + this.dealCards(2); + this.gameStartState(); + this.evaluateState(); + }; + BlackJack.prototype.quit = function () { + console.log('Goodbye!'); + }; + BlackJack.prototype.hit = function () { + this.draw(); + this.printLastDraw(); + // console.log(`Your hand value is now: ${this.players[this.currentPlayer].handScore}`); + webElement.innerText += "Your hand value is now: " + this.players[this.currentPlayer].handScore; + this.evaluateState(); + }; + BlackJack.prototype.stay = function () { + this.incrementTurn(); + this.evaluateState(); + }; + // fold() { + // console.log("You folded. Better luck next time!"); + // this.players[this.currentPlayer].hand = []; + // this.players[this.currentPlayer].handScore = this.calculateHandValue(this.players[this.currentPlayer].hand); + // this.evaluateState(); + // } + BlackJack.prototype.draw = function () { + _super.prototype.draw.call(this); + this.players[this.currentPlayer].handScore = this.calculateHandScores(this.players[this.currentPlayer].hand); + }; + BlackJack.prototype.evaluateState = function () { + var winner = new player_1.Player("???"), draw = false; + // If turns have gone back around to the dealer + if (this.currentPlayer === 0) { + // The dealer takes his actions + //console.log(`The dealer has ${this.players[0].handToString()}`); + webElement.innerText += "The dealer has " + this.players[0].handToString(); + while (this.players[0].handScore < 16) { + this.draw(); + this.printLastDraw(); + if (this.players[0].handScore > 21) { + console.log('The Dealer busted!'); + webElement.innerText += 'The Dealer busted!'; + this.players[0].handScore = 0; + break; + } + } + // Then check for a winner + this.players.forEach(function (player) { + if (player.handScore > winner.handScore) { + winner = player; + draw = false; + } + else if (player.handScore === winner.handScore) { + draw = true; + } + }); + if (draw) { + console.log("This round was a draw."); + } + else { + console.log(winner.name + " won the round with " + winner.handScore + "."); + } + this.roundPrompt(); + } + else { + if (this.players[this.currentPlayer].handScore === 21) { + console.log('Blackjack!'); + this.currentPlayer++; + this.roundPrompt(); + } + else if (this.players[this.currentPlayer].handScore > 21) { + console.log('Busted! You lost'); + this.players[this.currentPlayer].handScore = 0; + this.currentPlayer++; + this.roundPrompt(); + } + else { + this.turnPrompt(); + } + } + }; + BlackJack.prototype.calculateHandScores = function (cards) { + var value = 0; + cards.forEach(function (card) { + value += card.value; + if (card.rank == 'A' && value > 21) { + value -= 10; + } + }); + return value; + }; + BlackJack.prototype.gameStartState = function () { + this.printDealerState(); + this.printPlayerState(1); + }; + BlackJack.prototype.printDealerState = function () { + //console.log(`The dealer has ${this.players[0].hand[0].cardToString()}`); + webElement.innerText += "The dealer has " + this.players[0].hand[0].cardToString(); + }; + BlackJack.prototype.printPlayerState = function (playerIndex) { + console.log("Your hand is: " + this.players[playerIndex].handToString()); + console.log("Your hand value is now: " + this.players[playerIndex].handScore); + webElement.innerText += "Your hand is: " + this.players[playerIndex].handToString(); + webElement.innerText += "Your hand value is now: " + this.players[playerIndex].handScore; + }; + BlackJack.prototype.printLastDraw = function () { + console.log(this.players[this.currentPlayer].name + " drew " + this.players[this.currentPlayer].hand[this.players[this.currentPlayer].hand.length - 1]); + }; + return BlackJack; +}(CardGame_1.CardGame)); +exports.BlackJack = BlackJack; +var jack = new BlackJack(); +jack.start(); diff --git a/BlackJack.ts b/BlackJack.ts new file mode 100644 index 00000000..f0a9747d --- /dev/null +++ b/BlackJack.ts @@ -0,0 +1,162 @@ +import { Player } from "./player"; +import { Deck } from "./deck"; +import { CardGame } from "./CardGame"; +import { Dealer } from "./dealer"; +import { Card } from "./card"; + +var webElement = document.getElementById("display"); + +export class BlackJack extends CardGame{ + + constructor(){ + super(); + + } + turnPrompt() { + var answer: string = "yes"; + switch(answer){ + case 'Hit': + this.hit(); + break; + case 'Stay': + this.stay(); + break; + } + + } + roundPrompt() { + var game = this; + var answer: string = "Yes"; + + switch(answer){ + case 'Yes': + game.newHand(); + game.start(); + break; + case 'No': + console.log('Peace out'); + break; + } + + } + start() { + this.currentPlayer = 1; + this.addNewPlayer("PLAYER_1"); + this.dealCards(2); + this.gameStartState(); + this.evaluateState(); + + } + + quit() { + console.log('Goodbye!'); + } + + hit() { + this.draw(); + this.printLastDraw(); + // console.log(`Your hand value is now: ${this.players[this.currentPlayer].handScore}`); + webElement.innerText += `Your hand value is now: ${this.players[this.currentPlayer].handScore}`; + this.evaluateState(); + + } + + stay() { + this.incrementTurn(); + this.evaluateState(); + } + + // fold() { + // console.log("You folded. Better luck next time!"); + // this.players[this.currentPlayer].hand = []; + // this.players[this.currentPlayer].handScore = this.calculateHandValue(this.players[this.currentPlayer].hand); + // this.evaluateState(); + // } + + draw() { + super.draw(); + this.players[this.currentPlayer].handScore = this.calculateHandScores(this.players[this.currentPlayer].hand); + } + + + evaluateState() { + var winner = new Player("???"), draw = false; + // If turns have gone back around to the dealer + if (this.currentPlayer === 0) { + // The dealer takes his actions + //console.log(`The dealer has ${this.players[0].handToString()}`); + webElement.innerText += `The dealer has ${this.players[0].handToString()}`; + while (this.players[0].handScore < 16) { + this.draw(); + this.printLastDraw(); + if(this.players[0].handScore > 21) { + console.log('The Dealer busted!'); + webElement.innerText += 'The Dealer busted!'; + this.players[0].handScore = 0; + break; + } + } + // Then check for a winner + this.players.forEach(function(player){ + if (player.handScore > winner.handScore) { + winner = player; + draw = false; + } + else if(player.handScore === winner.handScore) { + draw = true; + } + }); + if(draw) { + console.log(`This round was a draw.`); + } + else { + console.log(`${winner.name} won the round with ${winner.handScore}.`); + } + this.roundPrompt(); + } else { + if (this.players[this.currentPlayer].handScore === 21) { + console.log('Blackjack!'); + this.currentPlayer++; + this.roundPrompt(); + } + else if (this.players[this.currentPlayer].handScore > 21) { + console.log('Busted! You lost'); + this.players[this.currentPlayer].handScore = 0; + this.currentPlayer++; + this.roundPrompt(); + } else { + this.turnPrompt(); + } + } + } + calculateHandScores(cards: Card[]): number { + var value = 0; + cards.forEach(function(card){ + value += card.value; + if(card.rank == 'A' && value > 21) { + value -= 10; + } + }); + return value; + } + gameStartState() { + this.printDealerState(); + this.printPlayerState(1); + } + printDealerState() { + //console.log(`The dealer has ${this.players[0].hand[0].cardToString()}`); + webElement.innerText += `The dealer has ${this.players[0].hand[0].cardToString()}`; + } + printPlayerState(playerIndex:number) { + console.log("Your hand is: " + this.players[playerIndex].handToString()); + console.log(`Your hand value is now: ${this.players[playerIndex].handScore}`); + webElement.innerText += "Your hand is: " + this.players[playerIndex].handToString(); + webElement.innerText += `Your hand value is now: ${this.players[playerIndex].handScore}`; + } + printLastDraw() { + console.log(`${this.players[this.currentPlayer].name} drew ${this.players[this.currentPlayer].hand[this.players[this.currentPlayer].hand.length-1]}`); + } + +} +var jack = new BlackJack(); +jack.start(); diff --git a/CardGame.js b/CardGame.js new file mode 100644 index 00000000..7013d66b --- /dev/null +++ b/CardGame.js @@ -0,0 +1,50 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var player_1 = require("./player"); +var deck_1 = require("./deck"); +var dealer_1 = require("./dealer"); +var CardGame = /** @class */ (function () { + function CardGame() { + this.players = []; + this.currentPlayer = 1; + this.players.push(new dealer_1.Dealer("Dealer")); + this.deck = new deck_1.Deck(); + } + CardGame.prototype.draw = function () { + var card = this.deck.draw(); + this.players[this.currentPlayer].hand.push(card); + }; + CardGame.prototype.incrementTurn = function () { + this.currentPlayer++; + if (this.currentPlayer === this.players.length) { + this.currentPlayer = 0; + } + }; + CardGame.prototype.dealCards = function (numOfCards) { + for (var i = 0; i < (numOfCards || 2); i++) { + for (var player = 0; player < this.players.length; player++) { + this.draw(); + this.incrementTurn(); + } + } + }; + CardGame.prototype.addNewPlayer = function (name) { + this.players.push(new player_1.Player((name || "Player " + (this.players.length + 1)))); + }; + CardGame.prototype.showHands = function () { + this.players.forEach(function (player) { + console.log(player.name + "'s hand:"); + player.hand.forEach(function (card) { + console.log(card.cardToString()); + }); + }); + }; + CardGame.prototype.newHand = function () { + for (var player = 0; player < this.players.length; player++) { + this.players[player].hand = []; + this.players[player].handScore = 0; + } + }; + return CardGame; +}()); +exports.CardGame = CardGame; diff --git a/CardGame.ts b/CardGame.ts new file mode 100644 index 00000000..791d68a5 --- /dev/null +++ b/CardGame.ts @@ -0,0 +1,52 @@ +import { Player } from "./player"; +import { Deck } from "./deck"; +import { Dealer } from "./dealer"; +import { Card } from "./card"; + +export class CardGame{ + players: Player[]; + currentPlayer: number; + deck: Deck; + + constructor(){ + this.players = []; + this.currentPlayer = 1; + this.players.push(new Dealer("Dealer")); + this.deck = new Deck(); + } + draw(){ + var card = this.deck.draw(); + this.players[this.currentPlayer].hand.push(card); + } + incrementTurn() { + this.currentPlayer++; + if (this.currentPlayer === this.players.length) { + this.currentPlayer = 0; + } + } + dealCards(numOfCards?: number){ + for (var i = 0; i < (numOfCards||2); i++){ + for (var player = 0; player < this.players.length; player++){ + this.draw(); + this.incrementTurn(); + } + } + } + addNewPlayer(name?: string){ + this.players.push(new Player((name|| `Player ${this.players.length+1}`))); + } + showHands(){ + this.players.forEach(function(player) { + console.log(`${player.name}'s hand:`); + player.hand.forEach(function(card) { + console.log(card.cardToString()); + }); + }); + } + newHand(){ + for (var player = 0; player < this.players.length; player++){ + this.players[player].hand = []; + this.players[player].handScore = 0; + } + } +} diff --git a/card.js b/card.js new file mode 100644 index 00000000..1d37bdd1 --- /dev/null +++ b/card.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Card = /** @class */ (function () { + function Card(rank, suit) { + this.rank = rank; + this.suit = suit; + switch (rank) { + case 'A': + this.value = 11; + break; + case 'K': + case 'Q': + case 'J': + this.value = 10; + break; + default: + this.value = parseInt(rank); + break; + } + } + Card.prototype.rankToString = function () { + switch (this.rank) { + case 'A': + return "Ace"; + case 'K': + return "King"; + case 'Q': + return "Queen"; + case 'J': + return "Jack"; + default: + return this.value.toString(); + } + }; + Card.prototype.suitToString = function () { + switch (this.suit) { + case '♥': + return "Hearts"; + case '♦': + return "Diamonds"; + case '♣': + return "Clubs"; + case '♠': + return "Spades"; + default: + return this.value.toString(); + } + }; + Card.prototype.cardToString = function () { + return this.rankToString() + " of " + this.suitToString(); + }; + return Card; +}()); +exports.Card = Card; diff --git a/card.ts b/card.ts new file mode 100644 index 00000000..483b15eb --- /dev/null +++ b/card.ts @@ -0,0 +1,54 @@ +export class Card{ + rank: string; + suit: string; + value: number; + + constructor(rank: string, suit: string){ + this.rank = rank; + this.suit = suit; + switch(rank){ + case 'A': + this.value = 11; + break; + case 'K': + case 'Q': + case 'J': + this.value = 10; + break; + default: + this.value = parseInt(rank); + break; + } + } + rankToString(): string { + switch (this.rank){ + case 'A': + return "Ace"; + case 'K': + return "King"; + case 'Q': + return "Queen"; + case 'J': + return "Jack"; + default: + return this.value.toString(); + } + } + suitToString(): string { + switch (this.suit){ + case '♥': + return "Hearts"; + case '♦': + return "Diamonds"; + case '♣': + return "Clubs"; + case '♠': + return "Spades"; + default: + return this.value.toString(); + } + } + cardToString(): string { + return `${this.rankToString()} of ${this.suitToString()}`; + } +} diff --git a/css/style.css b/css/style.css index cc704eef..fda87cec 100644 --- a/css/style.css +++ b/css/style.css @@ -113,7 +113,7 @@ article p { margin-bottom: 20px;} section {margin:10px;} h1 {font-weight: bold; margin-left: 10px;} #main { - + } #display { border: 1px #aaa solid; diff --git a/dealer.js b/dealer.js new file mode 100644 index 00000000..71d5580f --- /dev/null +++ b/dealer.js @@ -0,0 +1,21 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var player_1 = require("./player"); +var Dealer = /** @class */ (function (_super) { + __extends(Dealer, _super); + function Dealer(name) { + return _super.call(this, "Dealer") || this; + } + return Dealer; +}(player_1.Player)); +exports.Dealer = Dealer; diff --git a/dealer.ts b/dealer.ts new file mode 100644 index 00000000..21f1eeab --- /dev/null +++ b/dealer.ts @@ -0,0 +1,9 @@ +import { Player } from "./player"; + +export class Dealer extends Player{ + + constructor(name : string) { + super("Dealer"); + + } +} \ No newline at end of file diff --git a/deck.js b/deck.js new file mode 100644 index 00000000..0ba1da41 --- /dev/null +++ b/deck.js @@ -0,0 +1,38 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var card_1 = require("./card"); +var Deck = /** @class */ (function () { + function Deck() { + this.cards = []; + this.currentCard = 0; + for (var i = 0; i < 13; i++) { + for (var suit = 0; suit < 4; suit++) { + this.cards.push(new card_1.Card(Deck.RANKS[i], Deck.SUITS[suit])); + } + } + this.shuffle(3); + } + Deck.prototype.shuffle = function (times) { + for (var i = 0; i < (times || 1); i++) { + this.cards.sort(function () { + return (0.5 - Math.random()); + }); + } + }; + Deck.prototype.printDeck = function () { + this.cards.forEach(function (card) { + console.log(card.cardToString()); + }); + }; + Deck.prototype.draw = function () { + if (this.currentCard === this.cards.length - 1) { + this.shuffle(); + this.currentCard = 0; + } + return this.cards[this.currentCard++]; + }; + Deck.SUITS = ['♥', '♦', '♠', '♣']; + Deck.RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; + return Deck; +}()); +exports.Deck = Deck; diff --git a/deck.ts b/deck.ts new file mode 100644 index 00000000..7de66f12 --- /dev/null +++ b/deck.ts @@ -0,0 +1,38 @@ +import {Card} from "./card"; + +export class Deck{ + static SUITS = ['♥', '♦', '♠', '♣']; + static RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']; + + cards: Card[]; + currentCard: number; + + constructor(){ + this.cards = []; + this.currentCard = 0; + for (var i = 0; i < 13; i++){ + for (var suit = 0; suit < 4; suit++){ + this.cards.push(new Card(Deck.RANKS[i], Deck.SUITS[suit])); + } + } + this.shuffle(3); + } + shuffle(times?:number) { + for (var i = 0; i < (times||1); i++) { + this.cards.sort(function(){ + return (0.5 - Math.random()); }); + } + } + printDeck(){ + this.cards.forEach(function(card:Card){ + console.log(card.cardToString()); + }); + } + draw(): Card{ + if (this.currentCard === this.cards.length-1){ + this.shuffle(); + this.currentCard = 0; + } + return this.cards[this.currentCard++]; + } +} diff --git a/index.html b/index.html index d2c3c254..c2efae11 100644 --- a/index.html +++ b/index.html @@ -19,13 +19,26 @@

TypeScript Casino

-
+
+

Welcome to the Casino!

+

Would you like to play? Press Start Game

+
- -
+ + + +
+ + + +
- + + + + + diff --git a/main.js b/main.js new file mode 100644 index 00000000..00835552 --- /dev/null +++ b/main.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var BlackJack_1 = require("./BlackJack"); +var button = document.getElementById("submit"); +var userInput = document.getElementById("user_input"); +var button = document.getElementById("submit_button"); +var hitButton = document.getElementById("hit_button"); +var startButton = document.getElementById("start_button"); +var webElement = document.getElementById("display"); +button.addEventListener("click", function (e) { return putToDisplay(userInput.value); }); +var blackJack = new BlackJack_1.BlackJack(); +startButton.addEventListener("click", function (e) { return blackJack.start(); }); +function putToDisplay(text) { + webElement.innerText += text; +} +function playGame() { + webElement.innerText += "damn"; +} diff --git a/main.ts b/main.ts new file mode 100644 index 00000000..134ce648 --- /dev/null +++ b/main.ts @@ -0,0 +1,18 @@ +import { BlackJack } from "./BlackJack"; + +var button = document.getElementById("submit"); +var userInput: HTMLInputElement = document.getElementById("user_input"); +var button = document.getElementById("submit_button"); +var hitButton = document.getElementById("hit_button"); +var startButton = document.getElementById("start_button"); +var webElement = document.getElementById("display"); +button.addEventListener("click", (e:Event)=> putToDisplay(userInput.value)); +var blackJack: BlackJack = new BlackJack(); +startButton.addEventListener("click", (e:Event)=> blackJack.start()); + +function putToDisplay(text: string){ + webElement.innerText += text; +} +function playGame(){ + webElement.innerText += "damn"; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..58d705be --- /dev/null +++ b/package-lock.json @@ -0,0 +1,229 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "ansi-escapes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz", + "integrity": "sha512-UgAb8H9D41AQnu/PbWlCofQVcnV4Gs2bBJi9eZPxfU/hgglFh3SMDMENRIqdr7H6XFnXdoknctFByVsCOotTVw==" + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "1.9.1" + } + }, + "chalk": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.2.tgz", + "integrity": "sha512-ZM4j2/ld/YZDc3Ma8PgN7gyAk+kHMMMyzLNryCPGhWrsfAuDVeuid5bpRFTDgMH9JBK2lA4dyyAkkZYF/WcqDQ==", + "requires": { + "ansi-styles": "3.2.1", + "escape-string-regexp": "1.0.5", + "supports-color": "5.3.0" + } + }, + "chardet": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", + "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=" + }, + "cli-cursor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", + "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "requires": { + "restore-cursor": "2.0.0" + } + }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=" + }, + "color-convert": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", + "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "external-editor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.1.0.tgz", + "integrity": "sha512-E44iT5QVOUJBKij4IIV3uvxuNlbKS38Tw1HiupxEIHPv9qtC2PrDYohbXV5U+1jnfIXttny8gUhj+oZvflFlzA==", + "requires": { + "chardet": "0.4.2", + "iconv-lite": "0.4.19", + "tmp": "0.0.33" + } + }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "requires": { + "escape-string-regexp": "1.0.5" + } + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "inquirer": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-5.1.0.tgz", + "integrity": "sha512-kn7N70US1MSZHZHSGJLiZ7iCwwncc7b0gc68YtlX29OjI3Mp0tSVV+snVXpZ1G+ONS3Ac9zd1m6hve2ibLDYfA==", + "requires": { + "ansi-escapes": "3.1.0", + "chalk": "2.3.2", + "cli-cursor": "2.1.0", + "cli-width": "2.2.0", + "external-editor": "2.1.0", + "figures": "2.0.0", + "lodash": "4.17.5", + "mute-stream": "0.0.7", + "run-async": "2.3.0", + "rxjs": "5.5.7", + "string-width": "2.1.1", + "strip-ansi": "4.0.0", + "through": "2.3.8" + } + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" + }, + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + }, + "mimic-fn": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==" + }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=" + }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "requires": { + "mimic-fn": "1.2.0" + } + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, + "restore-cursor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", + "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "requires": { + "onetime": "2.0.1", + "signal-exit": "3.0.2" + } + }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "requires": { + "is-promise": "2.1.0" + } + }, + "rxjs": { + "version": "5.5.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.7.tgz", + "integrity": "sha512-Hxo2ac8gRQjwjtKgukMIwBRbq5+KAeEV5hXM4obYBOAghev41bDQWgFH4svYiU9UnQ5kNww2LgfyBdevCd2HXA==", + "requires": { + "symbol-observable": "1.0.1" + } + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "2.0.0", + "strip-ansi": "4.0.0" + } + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "requires": { + "ansi-regex": "3.0.0" + } + }, + "supports-color": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz", + "integrity": "sha512-0aP01LLIskjKs3lq52EC0aGBAJhLq7B2Rd8HC/DR/PtNNpcLilNmHC12O+hu0usQpo7wtHNRqtrhBwtDb0+dNg==", + "requires": { + "has-flag": "3.0.0" + } + }, + "symbol-observable": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.1.tgz", + "integrity": "sha1-g0D8RwLDEi310iKI+IKD9RPT/dQ=" + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + }, + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "requires": { + "os-tmpdir": "1.0.2" + } + } + } +} diff --git a/player.js b/player.js new file mode 100644 index 00000000..387a7dce --- /dev/null +++ b/player.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Player = /** @class */ (function () { + function Player(name) { + this.name = name; + this.hand = []; + this.handScore = 0; + this.money = 1000; + } + Player.prototype.playerNameToString = function () { + return this.name; + }; + Player.prototype.handToString = function () { + var handString = ""; + for (var i = 0; i < this.hand.length; i++) { + handString += this.hand[i].cardToString() + " "; + } + return handString; + }; + return Player; +}()); +exports.Player = Player; diff --git a/player.ts b/player.ts new file mode 100644 index 00000000..4955d3dc --- /dev/null +++ b/player.ts @@ -0,0 +1,25 @@ +import { Card } from "./card"; + +export class Player { + name: string; + hand: Card[]; + handScore: number; + money: number; + + constructor(name: string){ + this.name = name; + this.hand = []; + this.handScore = 0; + this.money = 1000; + } + playerNameToString(): string{ + return this.name; + } + handToString(): string{ + var handString = ""; + for (var i = 0; i < this.hand.length; i++){ + handString += this.hand[i].cardToString() + " "; + } + return handString; + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..65abb6d3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,57 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + //"strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + //"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + } +} \ No newline at end of file