@@ -25,6 +25,9 @@ export class CardDataService {
2525 userScore = 0 ;
2626 dealerScore = 0 ;
2727 availableCards = [ ] ;
28+ gameResult = "" ;
29+ wallet = 1000 ;
30+ bet = 10 ;
2831
2932 reset ( ) {
3033 this . availableCards = this . allCards . slice ( ) ;
@@ -33,10 +36,51 @@ export class CardDataService {
3336 this . dealerCards = [ ] ;
3437 this . userScore = 0 ;
3538 this . dealerScore = 0 ;
36- this . availableCards = [ ] ;
39+ this . gameResult = "" ;
3740 }
3841
3942 constructor ( ) {
4043 this . availableCards = this . allCards . slice ( ) ;
4144 }
45+
46+ getRandomCard ( identity ) {
47+ let randomCard = this . availableCards . splice ( Math . floor ( Math . random ( ) * this . availableCards . length ) , 1 ) [ 0 ] ;
48+ let cardScore :number = this . getCardScore ( randomCard , identity ) ;
49+ if ( identity === 'dealer' ) {
50+ this . dealerCards . push ( randomCard ) ;
51+ this . dealerScore += cardScore ;
52+ }
53+ else {
54+ this . userCards . push ( randomCard ) ;
55+ this . userScore += cardScore ;
56+ }
57+
58+ }
59+
60+ getCardScore ( cardID , identity ) {
61+ let score = 0 ;
62+ let cardValue = 0 ;
63+ if ( identity === 'dealer' ) {
64+ score = this . dealerScore ;
65+ }
66+ else {
67+ score = this . userScore ;
68+ }
69+ let royalCards = [ 'JC' , 'JD' , 'JH' , 'JS' ,
70+ 'QC' , 'QD' , 'QH' , 'QS' ,
71+ 'KC' , 'KD' , 'KH' , 'KS' ,
72+ 'AC' , 'AD' , 'AH' , 'AS' ] ;
73+ if ( royalCards . includes ( cardID ) ) {
74+ cardValue = 10 ;
75+ if ( score + cardValue > 21 && [ 'AC' , 'AD' , 'AH' , 'AS' ] . includes ( cardID ) ) {
76+ cardValue = 1 ;
77+ }
78+ }
79+ else {
80+ console . log ( cardID ) ;
81+ cardValue = parseInt ( cardID . substring ( 0 , cardID . length - 1 ) ) ;
82+ }
83+ //score = score + cardValue;
84+ return cardValue ;
85+ }
4286}
0 commit comments