From 1a7a7a1f88ab45d3b5d93c8cb6a335f1b62748f9 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 21 Jan 2013 03:25:08 +1100 Subject: [PATCH] Updated Table's compatability --- Hearts/table.cpp | 31 ++++++++++++++++--------------- Hearts/table.h | 6 +++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Hearts/table.cpp b/Hearts/table.cpp index a873a10..da45d0d 100644 --- a/Hearts/table.cpp +++ b/Hearts/table.cpp @@ -1,7 +1,7 @@ /* File Name: table.cpp * Author: Kayne Ruse - * Date (dd/mm/yyyy): 09/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 + * Date (dd/mm/yyyy): 21/01/2013 + * Copyright: (c) Kayne Ruse 2011, 2012, 2013 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -23,10 +23,12 @@ * distribution. * * Description: - * Designed for Project Hearts, 4th try. + * Hold the cards in play, and determine the winner of a trick. */ #include "table.h" +#include + //------------------------- //Public access members //------------------------- @@ -47,32 +49,31 @@ Card* Table::Pass() { return cList.PassSlab(0,4); } -void Table::Receive(Card* card,int position) { +void Table::Receive(Card* card, int position) { //position is the player's pos - if (position < 0 || position > 4) - return; + if (position < 0 || position > 3) + throw(std::invalid_argument("Unknown player index")); cards[position] = card; cards[position]->SetPos( cardPositions[position].x, cardPositions[position].y ); - cards[position]->SetFace(Card::UP); + cards[position]->SetFaceState(Card::UP); } int Table::CalcWinner(int first) { if (first < 0 || first > 3) - return -1; + throw(std::invalid_argument("Unknown player index")); - int suit = cards[first]->Suit(); + int suit = cards[first]->GetSuit(); int winner = -1; int highest = -1; for (int i = 0; i < 4; i++) { - if (cards[i]->Suit() == suit && - cards[i]->Rank() > highest) + if (cards[i]->GetSuit() == suit && cards[i]->GetRank() > highest) { - highest = cards[i]->Rank(); + highest = cards[i]->GetRank(); winner = i; } } @@ -82,8 +83,8 @@ int Table::CalcWinner(int first) { int Table::GetLeadingSuit(int first) { if (cards[first] == NULL) - return -1; - return cards[first]->Suit(); + return -1; //this means "No cards yet..." -? + return cards[first]->GetSuit(); } //------------------------- @@ -107,5 +108,5 @@ void Table::Draw(SDL_Surface* dest, int first) { for (int i = 0; i < 4; i++) if (cards[(i + first) % 4] != NULL) - cards[(i + first) % 4]->Draw(dest); + cards[(i + first) % 4]->DrawTo(dest); } diff --git a/Hearts/table.h b/Hearts/table.h index 17628e5..26137a4 100644 --- a/Hearts/table.h +++ b/Hearts/table.h @@ -1,7 +1,7 @@ /* File Name: table.h * Author: Kayne Ruse - * Date (dd/mm/yyyy): 09/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 + * Date (dd/mm/yyyy): 21/01/2013 + * Copyright: (c) Kayne Ruse 2011, 2012, 2013 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -23,7 +23,7 @@ * distribution. * * Description: - * Designed for Project Hearts, 4th try. + * Hold the cards in play, and determine the winner of a trick. */ #ifndef KR_TABLE_H_ #define KR_TABLE_H_