Commit be83115b authored by Chingiz's avatar Chingiz 💻

Class Hand has been created and some changes has been made in the Card class

parent 6117d857
...@@ -6,7 +6,7 @@ export class Card { ...@@ -6,7 +6,7 @@ export class Card {
this._rank = rank; this._rank = rank;
this._suite = suit; this._suite = suit;
} }
show(){ show(i:number){
return(` _____\n| ${this._rank} ${this._suite} |\n -----`) return(` _____\n${i} | ${this._rank} ${this._suite} |\n -----`)
} }
} }
\ No newline at end of file
import {Card} from "./Card"; import {Card} from "./Card";
class Hand { export class Hand {
private limit: number = 5; private _limit: number = 5;
private holdingCards: Card[] = []; private _holdingCards: Card[] = [];
private _changeCounter: number = 5;
receiveCard(card: Card) { receiveCard(card: Card) {
if (this.holdingCards.length <= this.limit) { if (this._holdingCards.length < this._limit) {
this.holdingCards.push(card) this._holdingCards.push(card)
} else { } else {
console.log("Hand is full!") console.log("Hand is full!")
} }
} }
showCards(){ showCards(){
for (let i = 0; i < this.holdingCards.length; i++){ for (let i = 0; i < this._holdingCards.length; i++){
console.log(`Card# ${i}) `) console.log(this._holdingCards[i].show(i+1))
this.holdingCards[i].show(); console.log("==============")
} }
} }
changeCard(newCard: Card, i: number){ changeCard(newCard: Card, i: number){
this.holdingCards[i] = newCard; 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;
console.log("Card has been changed!")
this._changeCounter--
}else{
console.log("You've already changed 5 times.")
}
} }
} }
\ 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