Basics for card game

*MAIN*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
************************************
* @Author: Shah Nami
* @Created: 11 december 2012
* @Title: main.cpp
************************************
*/

#include "O9O1.h"


int main() {
	Hand hand1("Player 1");
	Hand hand2("Player 2");
	Hand hand3("Player 3");
	Hand hand4("Player 4");
	Deck deck1;

	deck1.shuffle();

	/* Splitting cards in 4 */

	for(int i=0;i<52/4;i++){
		hand1.addCard(deck1.get_card(i));
	}
	for(int i=52/4;i<52/2;i++){
		hand2.addCard(deck1.get_card(i));
	}
	for(int i=52/2;i<(52/2 + 52/4);i++){
		hand3.addCard(deck1.get_card(i));
	}
	for(int i=(52/2 + 52/4);i<52;i++){
		hand4.addCard(deck1.get_card(i));
	}
	std::cout << std::endl;
	std::cout << "========================================================================" << std::endl;
	std::cout << hand1.getPlayer() << std::endl;
	hand1.printh();
	std::cout << hand2.getPlayer() << std::endl;
	hand2.printh();
	std::cout << hand3.getPlayer() << std::endl;
	hand3.printh();
	std::cout << hand4.getPlayer() << std::endl;
	hand4.printh();
	std::cout << "========================================================================" << std::endl;
	std::cout << std::endl;
}


*OS*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
************************************
* @Author: Nami Shah
* @Created: 11 december 2012
* @Title: os.h
************************************
*/

#ifndef INC_OS_H
	
	#define INC_OS_H

	#include "O9O1.h"

	#ifdef _WIN32
	   	//define something for Windows
		const char character(soort type) {
			return ((char) type);
		}
	#else
	  	//define it for a Unix machine
		#include<string>
		using std::string;
		string character(soort type) {
			switch (type) {
				// Info: http://www.fileformat.info/info/unicode/char/2665/index.htm
				case hart:     return "\xe2\x99\xa5"; //L'\u2665' 
				case ruit:     return "\xe2\x99\xa6"; //L'\u2666'
				case klaver:   return "\xe2\x99\xa3"; //L'\u2663'
				case schoppen: return "\xe2\x99\xa0"; //L'\u2660'
			};
			return NULL;
		}
	#endif

#endif 


*SOURCE FILE*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
************************************
* @Author: Shah Nami
* @Created: 11 december 2012
* @Title: O9O1.cpp
************************************
*/

#include "os.h"

using namespace std;

Card::Card(kaart k, soort t){
	nummer = k;
	type = t;
}

Card::Card(){
	nummer;
	type;
}

Deck::Deck(){
	for (int n=2;n<15;n++) { //13 cards
		for (int m=0;m<4;m++) { //4 suits
			cards[(n-2)*4+m].set(kaart(n), soort(m));
		}
	}
}

Card Deck::get_card(int i){
    return cards[i];
}

kaart Card::getCard() {
	return Card::nummer;
}

soort Card::getSuit() {
	return Card::type;
}

ostream &operator<<(ostream& os, const Card& card){
	switch(card.nummer){
		case aas:
			os << character(card.type) << " A" << " ";
			break;
		case koning:
			os << character(card.type) << " K" << " ";
			break;
		case dame:
			os << character(card.type) << " D" << " ";
			break;
		case boer:
			os << character(card.type) << " B" << " ";
			break;
		default:
			os << character(card.type) << " " << card.nummer << " ";
			break;
	}
	return os;
}

ostream& operator<<(ostream &os, const Deck &card) {
	for (int n=0;n<52;n++) {
		//for (int m=0;m<n;m++) {
		//os << " ";
		//}       
		os << card.cards[n] << " ";
	}
	return os;
}

void Card::set(kaart k, soort t){
	nummer = k;
	type = t;
}

void Deck::shuffle(){
	for (int i=0;i<100;i++) {
		Card tmp;
		int n = rand()%51; // Kies random n van 52 kaarten (begin 0)
		int m = rand()%51; // Kies random m
		tmp.set(cards[n].getCard(),cards[n].getSuit()); //Random card number, random card suit
		cards[n] = cards[m]; //swappen
		cards[m] = tmp; //kaart m = nieuwe kaart
	}
}

Hand::Hand(){
	pname;
}

Hand::Hand(string player){
	pname = player;
}

string Hand::getPlayer(){
	return pname;
}

void Hand::addCard(Card c){
	vcards.insert(vcards.begin(),c);
}

void Hand::printh(){
	vector<Card>::iterator it;
	for(it=vcards.begin();it!=vcards.end();it++){
		cout << *it << " ";
	}
	cout << endl;
	cout << endl;
}


int Hand::count_cards(){

}


*HEADER FILE*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
************************************
* @Author: Shah Nami
* @Created: 11 december 2012
* @Title: O9O1.h
************************************
*/

#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <vector>
#include <string>


	enum kaart {twee=2, drie, vier, vijf, zes, zeven, acht, negen, tien, boer, dame, koning, aas};
	enum soort {hart, ruit, klaver, schoppen};

	class Card {
		private:
			kaart nummer;
			soort type;
		public:

			Card();
			Card(kaart, soort);
			void print();
			void set(kaart, soort);
			kaart getCard();
			soort getSuit(); 
			friend std::ostream& operator<<(std::ostream&, const Card&);
	};


	class hearts: public Card {
		public:	
			hearts(kaart nummer): Card(nummer, hart){};
			friend std::ostream& operator<<(std::ostream&, const hearts&);
	};

	class diamonds: public Card {
		public:	
			diamonds(kaart nummer): Card(nummer, ruit){};
			friend std::ostream& operator<<(std::ostream&, const diamonds&);
	};

	class clubs: public Card {
		public:	
			clubs(kaart nummer): Card(nummer, klaver){};
			friend std::ostream& operator<<(std::ostream&, const clubs&);
	};

	class spades: public Card {
		public:	
			spades(kaart nummer): Card(nummer, schoppen){};
			friend std::ostream& operator<<(std::ostream&, const spades&);
	};


	class Deck {
		private:
			Card cards[52];
		public: 
			
			Deck();
			Card get_card(int);
			void shuffle(); 
			friend std::ostream& operator<<(std::ostream&, const Deck&);
	};

	class Hand {
		private:
			std::string pname;
			std::vector<Card> vcards;
		public:
			Hand();
			Hand(std::string);
			void printh();
			void addCard(Card);
			std::string getPlayer();
			int count_cards();
			friend std::ostream& operator<<(std::ostream&, const Hand&);
	};



Notice I'm not using my derived classes, if someone could help out with that, I would appreciate.
*Makefile*

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
all: O9O1

O9O1: O9O1.o main.o
	g++ O9O1.o main.o -o O9O1
	./O9O1
	
O9O1.o: O9O1.cpp
	g++ -c --pedantic O9O1.cpp

main.o: main.cpp
	g++ -c --pedantic main.cpp

clean:
	rm -f *.o O9O1 O9O1.exe

tgz:    clean
	rm -f tarball.tgz
	tar -cvzf tarball.tgz *
	chmod 644 tarball.tgz
Topic archived. No new replies allowed.