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