Skip to content

Draft: Afegir joc escambrit #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ add_executable(
src/games/truc/print.cpp
src/games/truc/statistics.cpp
)

add_executable(
escambrit
src/games/escambrit/escambrit.cpp
src/games/escambrit/card.cpp
src/games/escambrit/banca.cpp
src/games/escambrit/deck.cpp
src/games/escambrit/game.cpp
src/games/escambrit/human.cpp
src/games/escambrit/player.cpp
src/games/escambrit/print.cpp
src/games/escambrit/statistics.cpp
)
14 changes: 14 additions & 0 deletions src/games/escambrit/banca.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "headers/banca.h"
#include <iostream>


// Prints first card revealed and second card hidden
void Banca::printFirstCard(){
std::cout<<"\n";
std::cout<<".------..------."<<"\n";
std::cout<<"|"<<hand[0].getPrintNumber()<<".--. || .--. |"<<"\n";
hand[0].printCardL1(); std::cout<<"| // |"<<"\n";
hand[0].printCardL2(); std::cout<<"| // |"<<"\n";
std::cout<<"| '--'"<<hand[0].getPrintNumber()<<"|| '--' |"<<"\n";
std::cout<<"`------'`------'"<<"\n";
}
66 changes: 66 additions & 0 deletions src/games/escambrit/card.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "headers/card.h"
#include <iostream>

Card::Card(){
number = 0;
suit = '\0';
block = false;
}

Card::Card(int no, char s){
number = no;
suit = s;
block = false;
}

int Card::getNumber(){
return number;
}

char Card::getSuit(){
return suit;
}
bool Card::getBlock(){
return block;
}

void Card::setNumber(int no){
number = no;
}
void Card::setSuit(char c){
suit = c;
}
void Card::setBlock(bool b){
block = b;
}

char Card::getPrintNumber(){
switch(number){
case 1: return 'A';
case 10: return 'X';
case 11: return 'J';
case 12: return 'Q';
case 13: return 'K';
default: char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
return digits[number];
}
}
void Card::printCardL1(){
switch(suit){
case 'C': std::cout<<"| :(): |"; break;
case 'H': std::cout<<"| (\\/) |"; break;
case 'D':
case 'S': std::cout<<"| :/\\: |"; break;
default : std::cout<<"| // |";
}
}

void Card::printCardL2(){
switch(suit){
case 'C': std::cout<<"| ()() |"; break;
case 'H':
case 'D': std::cout<<"| :\\/: |"; break;
case 'S': std::cout<<"| (__) |"; break;
default : std::cout<<"| // |";
}
}
56 changes: 56 additions & 0 deletions src/games/escambrit/deck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "headers/deck.h"
#include <iostream>
#include <algorithm>
#include <assert.h>

// Shuffles a deck
void Deck::shuffleDeck() {
std::random_shuffle(deck.begin(), deck.end());
}

// Constructs a Deck
/*
* O: Oros;
* E: Espases;
* B: Bastos;
* C: Copes;
*/
void Deck::initializeDeck(){
deck.clear();
char suits[4] = {'O','E','B','C'};
for(int i=0;i<4;i++){
for(int j=0;j<12;j++){
Card c(j+1,suits[i]);
deck.push_back(c);
}
}
shuffleDeck();
}

// Getter Function for size of deck
int Deck::getSize(){
return deck.size();
}

// Deals by returning one card from the deck
Card Deck::deal(){
int val = (rand()%(deck.size())); // TODO: Why shuffle again if the deck is initialized and shuffled? Can you choose any card at your will?
Card t = deck[val];
deck.erase(deck.begin()+val);
return t;
}

// Pick a number of cards (default is 1) from the deck (the first one)
Card* Deck::pick(short number=1){
short val = number;
Card cards[number-1];

// Test that the number is 1 or more
assert(number>=1);
for(short i=0;i<number;i++){
Card card = deck[0];
cards[i] = card;
deck.erase(deck.begin()+val);
}
return cards;
}
14 changes: 14 additions & 0 deletions src/games/escambrit/escambrit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "headers/escambrit.h"
#include <iostream>
#include <time.h>

int main(){

srand(time(NULL)); // To seed rand() function across all files

Game game; // Constructs object GAME
game.beginMenu(false, ""); // Begins with the interface

return 0; // Return integer value at end of main()

}
Loading