Commit ef3e76f4 authored by Chingiz's avatar Chingiz 💻

Fixed showing style.

parent acc87532
......@@ -2,9 +2,11 @@ export class Card {
get rank(): string {
return this._rank;
}
get suite(): string {
return this._suite;
}
private _rank: string;
private _suite: string;
......@@ -12,7 +14,8 @@ export class Card {
this._rank = rank;
this._suite = suit;
}
show(i:number){
return(` _____\n${i} | ${this._rank} ${this._suite} |\n -----`)
show(i: number) {
return (` _____\n${i} | ${this._rank} ${this._suite} |\n -----`)
}
}
\ No newline at end of file
......@@ -7,7 +7,19 @@ export class Checker {
private _checkMethods: ({
message: string,
check: (sameRanks: { [key: string]: number }) => boolean
})[] = [{ message: "You've got Four of a Kind! 8 points", check: this.isFourOfKind }, {message: "You've got Full House! 7 points", check: this.isFullHouse}, {message: "You've got Street! 5 points", check: this.isStreet}, {message: "You've got Royal Three of a Kind! 4 points", check: this.isThreeOfKind}, {message: "You've got Two Pare! 3 points", check: this.isTwoPare}, {message: "You've got Pare! 2 points", check: this.isPare}]
})[] = [{
message: "You've got Four of a Kind! 8 points",
check: this.isFourOfKind
}, {message: "You've got Full House! 7 points", check: this.isFullHouse}, {
message: "You've got Street! 5 points",
check: this.isStreet
}, {
message: "You've got Royal Three of a Kind! 4 points",
check: this.isThreeOfKind
}, {message: "You've got Two Pare! 3 points", check: this.isTwoPare}, {
message: "You've got Pare! 2 points",
check: this.isPare
}]
constructor(cards: Card[]) {
for (const card of cards) {
......@@ -18,7 +30,7 @@ export class Checker {
}
sortSameRanks() {
if (this._cards){
if (this._cards) {
this._sameRanks = this._cards.reduce((acc: { [key: string]: number }, card: {
rank: string,
suite: string
......@@ -32,7 +44,7 @@ export class Checker {
}
sortSameSuites() {
if (this._cards){
if (this._cards) {
this._sameSuites = this._cards.reduce((acc: { [key: string]: number }, card: {
rank: string,
suite: string
......@@ -40,7 +52,7 @@ export class Checker {
acc[card.suite] = (acc[card.suite]++ || 0) + 1;
return acc;
}, {});
}else {
} else {
console.log("NO cards!")
}
}
......@@ -146,15 +158,25 @@ export class Checker {
}
checkCombination() {
if (this.isRoyalFlush(this._sameRanks, this._sameSuites)) return console.log("You've got Royal Flash! 10 point!");
if (this.isFlush(this._sameSuites)) return console.log("You've got Flash! 6 point!");
if (this.isRoyalFlush(this._sameRanks, this._sameSuites)) return this.congratMessage("You've got Royal Flash! 10 point!");
if (this.isFlush(this._sameSuites)) return this.congratMessage("You've got Flash! 6 point!");
for (const combination of this._checkMethods) {
if (combination.check(this._sameRanks)) {
return console.log(combination.message);
return this.congratMessage(combination.message);
}
}
return console.log("You've got High Card! 1 point!")
return this.congratMessage("You've got High Card! 1 point!");
}
congratMessage(message: string) {
return console.log(`
==================================================
* *
* ${message}!!!
* *
===================================================
`)
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ export class Deck {
private RANKS: string[] = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
private SUITS: string[] = ["♠", "♥", "♦", "♣"]
private _cards: Card[] = [];
private tookCardIndexes: number[] =[];
private tookCardIndexes: number[] = [];
constructor() {
for (let i = 0; i < this.RANKS.length; i++) {
......@@ -13,6 +13,7 @@ export class Deck {
this._cards.push(new Card(this.RANKS[i], this.SUITS[j]))
}
}
console.log("New deck has been created.")
}
shuffleDeck() {
......@@ -20,12 +21,15 @@ export class Deck {
const j = Math.floor(Math.random() * (i + 1));
[this._cards[i], this._cards[j]] = [this._cards[j], this._cards[i]];
}
console.log("The deck has been shuffled!")
}
takeACardFromDeck(){
takeACardFromDeck() {
const ranNum: number = getRandomNumber(0, this._cards.length + 1);
if(!this.tookCardIndexes.includes(ranNum)){
if (!this.tookCardIndexes.includes(ranNum)) {
return this._cards[ranNum];
this.tookCardIndexes.push(ranNum);
console.log(`You took ${this.tookCardIndexes.length} from the deck`)
}
this.takeACardFromDeck();
}
......
import {Card} from "./Card";
export class Hand {
set holdingCards(value: Card[]) {
this._holdingCards = value;
}
get holdingCards(): Card[] {
return this._holdingCards;
}
private _limit: number = 5;
private _holdingCards: Card[] = [];
private _changeCounter: number = 5;
......@@ -11,23 +16,26 @@ export class Hand {
receiveCard(card: Card) {
if (this._holdingCards.length < this._limit) {
this._holdingCards.push(card)
console.log(`You received ${this._holdingCards.length} cards.`)
} else {
console.log("Hand is full!")
}
}
showCards(){
for (let i = 0; i < this._holdingCards.length; i++){
console.log(this._holdingCards[i].show(i+1))
showCards() {
for (let i = 0; i < this._holdingCards.length; i++) {
console.log(this._holdingCards[i].show(i + 1))
console.log("==============")
}
}
changeCard(newCard: Card, i: number){
changeCard(newCard: Card, i: number) {
if (i > 6 && i > 0) return console.log("Card number can not be more then 5 and less then 1")
if (this._changeCounter){
this._holdingCards[i-1] = newCard;
if (this._changeCounter) {
this._holdingCards[i - 1] = newCard;
console.log("Card has been changed!")
this._changeCounter--
}else{
} else {
console.log("You've already changed 5 times.")
}
}
......
import {Deck} from "./Modules/Deck";
import {Card} from "./Modules/Card";
const deck = new Deck();
deck.shuffleDeck();
let card: Card | undefined;
card = deck.takeACard()
console.log(card ? card.show() : card)
import {Application} from "./Modules/Application";
const game = new Application();
game.startGame()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment