Skip to content

Commit ea98d07

Browse files
committed
Black Jack v1
1 parent 19ce189 commit ea98d07

File tree

11 files changed

+241
-7
lines changed

11 files changed

+241
-7
lines changed

BlackJack/BlackJack.depend

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+

BlackJack/Carta.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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

BlackJack/MontonCartas.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void MontonCartas::mezclar()
111111
aux = p;
112112
int tam=0;
113113
for(tam; aux != 0; tam++)
114-
aux = (*aux).sig;
114+
aux = (*aux).sig;
115115

116116
Carta *aux2;
117117

@@ -238,6 +238,26 @@ int MontonCartas::sizeMonton() const
238238
return tam;
239239
}
240240

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+
241261
void MontonCartas::printMonton()
242262
{
243263
Carta * aux = p;

BlackJack/MontonCartas.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#include <iostream>
22
#include <ctime>
33
#include <cstdlib>
4+
#include "Carta.h"
45

56
using namespace std;
67

7-
struct Carta {
8-
char palo;
9-
int num;
10-
Carta *sig; // this pointer is for iterate through the whole card stack
11-
};
128

139
class MontonCartas
1410
{
@@ -30,4 +26,5 @@ class MontonCartas
3026
int getNumeroCarta (int pos) const;
3127
char getPaloCarta (int pos) const;
3228
Carta* getCarta (int pos) ;
29+
Carta* sacarCarta (int pos) ;
3330
};

BlackJack/Player.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

BlackJack/Player.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
};

BlackJack/bin/Debug/BlackJack.exe

44.4 KB
Binary file not shown.

BlackJack/main.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,59 @@
11
#include <iostream>
22
#include "MontonCartas.h"
3+
#include "Player.h"
34

45
using namespace std;
56

6-
int main()
7+
void on ()
8+
{
9+
cout << "\t******** BLACK JACK ********" << endl << endl;
10+
cout << "\t1 - Play" <<endl;
11+
cout << "\t2 - Rules" << endl;
12+
cout << "\t3 - 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 ()
735
{
836
MontonCartas monton (1);
37+
// monton.mezclar();
38+
39+
cout << "Mostramos el monton barajado" << endl << endl;
940
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();
1059
}

BlackJack/obj/Debug/MontonCartas.o

1011 Bytes
Binary file not shown.

BlackJack/obj/Debug/Player.o

30.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)