Updated Table's compatability

This commit is contained in:
Kayne Ruse
2013-01-21 03:25:08 +11:00
parent 440b13c413
commit 1a7a7a1f88
2 changed files with 19 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
/* File Name: table.cpp /* File Name: table.cpp
* Author: Kayne Ruse * Author: Kayne Ruse
* Date (dd/mm/yyyy): 09/06/2011 * Date (dd/mm/yyyy): 21/01/2013
* Copyright: (c) Kayne Ruse 2011, 2012 * Copyright: (c) Kayne Ruse 2011, 2012, 2013
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,10 +23,12 @@
* distribution. * distribution.
* *
* Description: * Description:
* Designed for Project Hearts, 4th try. * Hold the cards in play, and determine the winner of a trick.
*/ */
#include "table.h" #include "table.h"
#include <stdexcept>
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
@@ -49,30 +51,29 @@ Card* Table::Pass() {
void Table::Receive(Card* card, int position) { void Table::Receive(Card* card, int position) {
//position is the player's pos //position is the player's pos
if (position < 0 || position > 4) if (position < 0 || position > 3)
return; throw(std::invalid_argument("Unknown player index"));
cards[position] = card; cards[position] = card;
cards[position]->SetPos( cards[position]->SetPos(
cardPositions[position].x, cardPositions[position].x,
cardPositions[position].y cardPositions[position].y
); );
cards[position]->SetFace(Card::UP); cards[position]->SetFaceState(Card::UP);
} }
int Table::CalcWinner(int first) { int Table::CalcWinner(int first) {
if (first < 0 || first > 3) 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 winner = -1;
int highest = -1; int highest = -1;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (cards[i]->Suit() == suit && if (cards[i]->GetSuit() == suit && cards[i]->GetRank() > highest)
cards[i]->Rank() > highest)
{ {
highest = cards[i]->Rank(); highest = cards[i]->GetRank();
winner = i; winner = i;
} }
} }
@@ -82,8 +83,8 @@ int Table::CalcWinner(int first) {
int Table::GetLeadingSuit(int first) { int Table::GetLeadingSuit(int first) {
if (cards[first] == NULL) if (cards[first] == NULL)
return -1; return -1; //this means "No cards yet..." -?
return cards[first]->Suit(); return cards[first]->GetSuit();
} }
//------------------------- //-------------------------
@@ -107,5 +108,5 @@ void Table::Draw(SDL_Surface* dest, int first) {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
if (cards[(i + first) % 4] != NULL) if (cards[(i + first) % 4] != NULL)
cards[(i + first) % 4]->Draw(dest); cards[(i + first) % 4]->DrawTo(dest);
} }

View File

@@ -1,7 +1,7 @@
/* File Name: table.h /* File Name: table.h
* Author: Kayne Ruse * Author: Kayne Ruse
* Date (dd/mm/yyyy): 09/06/2011 * Date (dd/mm/yyyy): 21/01/2013
* Copyright: (c) Kayne Ruse 2011, 2012 * Copyright: (c) Kayne Ruse 2011, 2012, 2013
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,7 +23,7 @@
* distribution. * distribution.
* *
* Description: * Description:
* Designed for Project Hearts, 4th try. * Hold the cards in play, and determine the winner of a trick.
*/ */
#ifndef KR_TABLE_H_ #ifndef KR_TABLE_H_
#define KR_TABLE_H_ #define KR_TABLE_H_