File tree Expand file tree Collapse file tree 11 files changed +241
-7
lines changed Expand file tree Collapse file tree 11 files changed +241
-7
lines changed Original file line number Diff line number Diff line change
1
+ # depslib dependency file v1.0
2
+ 1447377486 source:c:\users\v�ctor\documents\github\getstartedwithc-\blackjack\main.cpp
3
+ <iostream>
4
+ "MontonCartas.h"
5
+ "Player.h"
6
+
7
+ 1447376182 c:\users\v�ctor\documents\github\getstartedwithc-\blackjack\montoncartas.h
8
+ <iostream>
9
+ <ctime>
10
+ <cstdlib>
11
+ "Carta.h"
12
+
13
+ 1447377515 source:c:\users\v�ctor\documents\github\getstartedwithc-\blackjack\montoncartas.cpp
14
+ "MontonCartas.h"
15
+
16
+ 1447376398 c:\users\v�ctor\documents\github\getstartedwithc-\blackjack\player.h
17
+ <iostream>
18
+ <ctime>
19
+ <cstdlib>
20
+ <string>
21
+ "Carta.h"
22
+
23
+ 1447376440 c:\users\v�ctor\documents\github\getstartedwithc-\blackjack\carta.h
24
+ <iostream>
25
+
26
+ 1447376863 source:c:\users\v�ctor\documents\github\getstartedwithc-\blackjack\player.cpp
27
+ "Player.h"
28
+
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ #ifndef Included_Carta_H
6
+ #define Included_Carta_H
7
+
8
+ struct Carta
9
+ {
10
+ char palo;
11
+ int num;
12
+ Carta *sig; // this pointer is for iterate through the whole card stack
13
+ };
14
+
15
+ #endif
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ void MontonCartas::mezclar()
111
111
aux = p;
112
112
int tam=0 ;
113
113
for (tam; aux != 0 ; tam++)
114
- aux = (*aux).sig ;
114
+ aux = (*aux).sig ;
115
115
116
116
Carta *aux2;
117
117
@@ -238,6 +238,26 @@ int MontonCartas::sizeMonton() const
238
238
return tam;
239
239
}
240
240
241
+ Carta* MontonCartas::getCarta (int pos)
242
+ {
243
+ Carta* laCarta = p;
244
+
245
+ for (int i=0 ; i<pos; i++)
246
+ laCarta = (*laCarta).sig ;
247
+
248
+ return laCarta;
249
+ }
250
+
251
+
252
+ Carta* MontonCartas::sacarCarta (int pos)
253
+ {
254
+ Carta * laCarta = getCarta (pos);
255
+ eliminarCarta (pos);
256
+ (*laCarta).sig = 0 ;
257
+ return laCarta;
258
+ }
259
+
260
+
241
261
void MontonCartas::printMonton ()
242
262
{
243
263
Carta * aux = p;
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
#include < ctime>
3
3
#include < cstdlib>
4
+ #include " Carta.h"
4
5
5
6
using namespace std ;
6
7
7
- struct Carta {
8
- char palo;
9
- int num;
10
- Carta *sig; // this pointer is for iterate through the whole card stack
11
- };
12
8
13
9
class MontonCartas
14
10
{
@@ -30,4 +26,5 @@ class MontonCartas
30
26
int getNumeroCarta (int pos) const ;
31
27
char getPaloCarta (int pos) const ;
32
28
Carta* getCarta (int pos) ;
29
+ Carta* sacarCarta (int pos) ;
33
30
};
Original file line number Diff line number Diff line change
1
+ #include " Player.h"
2
+
3
+ using namespace std ;
4
+
5
+ Player::Player (int id, string name)
6
+ {
7
+ this ->ID = id;
8
+ this ->nombre = name;
9
+ this ->mPuntos = 0 ;
10
+
11
+ mano = 0 ;
12
+ ultimaCarta = 0 ;
13
+ }
14
+
15
+ Player::~Player ()
16
+ {
17
+ Carta *aux;
18
+
19
+ aux = (*mano).sig ;
20
+ while (aux != 0 )
21
+ {
22
+ delete mano;
23
+ mano = aux;
24
+ aux = (*aux).sig ;
25
+ }
26
+ delete mano;
27
+ }
28
+
29
+ double Player::sumarPuntos (double pts)
30
+ {
31
+ mPuntos += pts ;
32
+ return mPuntos ;
33
+ }
34
+
35
+ int Player::getID () const
36
+ {
37
+ return ID;
38
+ }
39
+
40
+
41
+ void Player::showHand ()
42
+ {
43
+ Carta* aux = mano ;
44
+
45
+ cout << " Mano del jugador " << nombre << endl;
46
+ while (aux != 0 )
47
+ {
48
+ cout << (*aux).num << (*aux).palo << " " ;
49
+ aux = (*aux).sig ;
50
+ }
51
+ cout << endl;
52
+ }
53
+
54
+
55
+ string Player::getNombre () const
56
+ {
57
+ return nombre;
58
+ }
59
+
60
+
61
+ double Player::getPuntos () const
62
+ {
63
+ return mPuntos ;
64
+ }
65
+
66
+
67
+ double Player::addCarta (Carta* carta)
68
+ {
69
+ if (mano == 0 )
70
+ {
71
+ mano = carta;
72
+ ultimaCarta = carta;
73
+ (*mano).sig = 0 ;
74
+ }
75
+ else
76
+ {
77
+ (*ultimaCarta).sig = carta;
78
+ ultimaCarta = (*ultimaCarta).sig ;
79
+ (*ultimaCarta).sig = 0 ;
80
+ }
81
+
82
+ int numero = (*ultimaCarta).num ;
83
+ double pts ;
84
+ if (numero == 10 || numero == 11 || numero == 12 )
85
+ {
86
+ pts = 0.5 ;
87
+ }else
88
+ pts = (double )numero;
89
+
90
+ return sumarPuntos (pts);
91
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < ctime>
3
+ #include < cstdlib>
4
+ #include < string>
5
+ #include " Carta.h"
6
+
7
+ using namespace std ;
8
+
9
+ class Player
10
+ {
11
+ int ID ;
12
+ Carta* mano ;
13
+ Carta* ultimaCarta;
14
+ string nombre ;
15
+ double mPuntos ;
16
+
17
+ double sumarPuntos (double pts);
18
+
19
+ public:
20
+
21
+ Player (int id, string name);
22
+ ~Player ();
23
+
24
+ void showHand () ;
25
+
26
+ int getID () const ;
27
+ string getNombre () const ;
28
+ double getPuntos () const ;
29
+
30
+ /* *
31
+ return Los puntos que tiene el jugador al añadir esa carta.
32
+ */
33
+ double addCarta (Carta* carta);
34
+ };
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
#include " MontonCartas.h"
3
+ #include " Player.h"
3
4
4
5
using namespace std ;
5
6
6
- int main ()
7
+ void on ()
8
+ {
9
+ cout << " \t ******** BLACK JACK ********" << endl << endl;
10
+ cout << " \t 1 - Play" <<endl;
11
+ cout << " \t 2 - Rules" << endl;
12
+ cout << " \t 3 - Exit" <<endl;
13
+ }
14
+
15
+ void test1 ()
16
+ {
17
+ MontonCartas monton (1 );
18
+
19
+ monton.printMonton ();
20
+
21
+ cout << endl << " Sacamos una carta: " ;
22
+ Carta* carta = monton.sacarCarta (12 );
23
+
24
+ cout << (*carta).num << (*carta).palo << endl << endl;
25
+ if ((*carta).sig != 0 )
26
+ cout << " Apunta a otra carta" << endl << endl;
27
+ else
28
+ cout << " No apunta a ninguna carta" << endl << endl;
29
+
30
+
31
+ monton.printMonton ();
32
+ }
33
+
34
+ void test2 ()
7
35
{
8
36
MontonCartas monton (1 );
37
+ // monton.mezclar();
38
+
39
+ cout << " Mostramos el monton barajado" << endl << endl;
9
40
monton.printMonton ();
41
+
42
+ cout << endl << " Sacamos una carta: " ;
43
+ Carta *unaCarta = monton.sacarCarta (0 );
44
+ cout << (*unaCarta).num << (*unaCarta).palo << endl << " Y se la damos al jugador" << endl;
45
+
46
+
47
+ Player player (1 ," Alfonso" );
48
+ player.addCarta (unaCarta);
49
+
50
+ cout<< endl << " Ahora mostramos la mano del jugador" << endl;
51
+ player.showHand ();
52
+
53
+
54
+ }
55
+
56
+ int main ()
57
+ {
58
+ test2 ();
10
59
}
You can’t perform that action at this time.
0 commit comments