Commit 856b3887 authored by Chingiz's avatar Chingiz 💻

Application.ts has been created.

parent 188100be
import * as readlineSync from 'readline-sync';
import {Deck} from "./Deck";
import {Hand} from "./Hand";
import {Checker} from "./Checker";
export class Application {
private _hand: Hand = new Hand()
private _deck: Deck = new Deck()
startGame() {
console.log('==============================');
console.log('Let the Game begin!')
console.log('==============================\n\n');
let isEnd: boolean = true;
while (isEnd){
const answer = readlineSync.question(`
Choose one of the options:
1) Shuffle the deck
2) Take five cards${
this._hand.holdingCards.join()
?
'\n 3) Show my cards\n 4) Change the cards\n 5) Show my points'
:
''
}
6) Start new game
7) End this game
`)
switch (answer) {
case '1':
this._deck.shuffleDeck()
break;
case'2':
this.spreadOut5Cards()
break;
case '3':
this._hand.showCards();
break;
case '4':
this.changeTheCards()
break;
case'5':
this.checkPoints()
break;
case'6':
this._hand.holdingCards = [];
break;
case'7':
isEnd = false;
break;
default:
console.log("Choose correct option!")
}
}
}
spreadOut5Cards(){
for (let i = 1; i < 6; i++){
let cardFromDeck = this._deck.takeACardFromDeck();
if (cardFromDeck) this._hand.receiveCard(cardFromDeck);
}
}
changeTheCards(){
const answer = readlineSync.question("Choose which cards you want to change?")
const arrAnswer = Array.from(answer);
for (let i = 0; i < arrAnswer.length; i++) {
let cardFromDeck = this._deck.takeACardFromDeck();
if (cardFromDeck) this._hand.changeCard(cardFromDeck, parseInt(arrAnswer[i]));
}
}
checkPoints(){
const checker = new Checker(this._hand.holdingCards)
checker.checkCombination()
}
}
\ 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