mirror of
https://github.com/Ratstail91/Hearts.git
synced 2025-11-29 02:24:28 +11:00
Updated some function calls for compatability
Seems to be stable right now.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* File Name: card.cpp
|
/* File Name: card.cpp
|
||||||
* Author: Kayne Ruse
|
* Author: Kayne Ruse
|
||||||
* Date (dd/mm/yyyy): 21/01/2013
|
* Date (dd/mm/yyyy): 22/01/2013
|
||||||
* Copyright: (c) Kayne Ruse 2011, 2012, 2013
|
* 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
|
||||||
@@ -41,11 +41,13 @@ Card::Card(int s, int r, SDL_Surface* faceSurface, SDL_Surface* backSurface):
|
|||||||
face.SetSurface(faceSurface);
|
face.SetSurface(faceSurface);
|
||||||
back.SetSurface(backSurface);
|
back.SetSurface(backSurface);
|
||||||
|
|
||||||
//set the face's clip
|
//set the face's clip (static values based on the card files)
|
||||||
face.SetClipX((rank - 1) * 73);
|
face.SetClipX((rank - 1) * 73);
|
||||||
face.SetClipY((suit - 1) * 98);
|
face.SetClipY((suit - 1) * 98);
|
||||||
face.SetClipW(73);
|
face.SetClipW(73);
|
||||||
face.SetClipH(98);
|
face.SetClipH(98);
|
||||||
|
face.SetClipW(73);
|
||||||
|
face.SetClipH(98);
|
||||||
|
|
||||||
SetFaceState(UP);
|
SetFaceState(UP);
|
||||||
|
|
||||||
@@ -124,6 +126,14 @@ Sint16 Card::GetY() {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sint16 Card::GetWidth() {
|
||||||
|
return face.GetClipW();
|
||||||
|
}
|
||||||
|
|
||||||
|
Sint16 Card::GetHeight() {
|
||||||
|
return face.GetClipH();
|
||||||
|
}
|
||||||
|
|
||||||
void Card::DrawTo(SDL_Surface* const dest) {
|
void Card::DrawTo(SDL_Surface* const dest) {
|
||||||
if (faceState == UP)
|
if (faceState == UP)
|
||||||
face.DrawTo(dest, x, y);
|
face.DrawTo(dest, x, y);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* File Name: card.h
|
/* File Name: card.h
|
||||||
* Author: Kayne Ruse
|
* Author: Kayne Ruse
|
||||||
* Date (dd/mm/yyyy): 21/01/2013
|
* Date (dd/mm/yyyy): 22/01/2013
|
||||||
* Copyright: (c) Kayne Ruse 2011, 2012, 2013
|
* 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
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
#define ISCARD(CARD,RANK,SUIT) (CARD->Suit() == Card::SUIT && CARD->Rank() == Card::RANK)
|
#define ISCARD(CARD,RANK,SUIT) (CARD->GetSuit() == Card::SUIT && CARD->GetRank() == Card::RANK)
|
||||||
|
|
||||||
class Card {
|
class Card {
|
||||||
public:
|
public:
|
||||||
@@ -59,6 +59,9 @@ public:
|
|||||||
Sint16 GetX();
|
Sint16 GetX();
|
||||||
Sint16 GetY();
|
Sint16 GetY();
|
||||||
|
|
||||||
|
Sint16 GetWidth();
|
||||||
|
Sint16 GetHeight();
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const);
|
void DrawTo(SDL_Surface* const);
|
||||||
|
|
||||||
/* Macros */
|
/* Macros */
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
* Designed for Project Hearts, 4th try.
|
* Designed for Project Hearts, 4th try.
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <time.h>
|
||||||
#include "hearts_engine.h"
|
#include "hearts_engine.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -36,7 +37,8 @@ using namespace std;
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
HeartsEngine::HeartsEngine() {
|
HeartsEngine::HeartsEngine() {
|
||||||
mImage.Add("heart","rsc\\heart.bmp",32,32,64,64);
|
heartSprite.LoadSurface("rsc\\heart.bmp");
|
||||||
|
heartSprite.SetClipW(64);
|
||||||
|
|
||||||
mAudio.Init(0,MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,1,1024);
|
mAudio.Init(0,MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,1,1024);
|
||||||
mAudio.Add("knock","rsc\\knock.wav");
|
mAudio.Add("knock","rsc\\knock.wav");
|
||||||
@@ -60,6 +62,10 @@ HeartsEngine::HeartsEngine() {
|
|||||||
player[1]->SetPositions(0, ScreenHeight()/2 - 169, 0,20);
|
player[1]->SetPositions(0, ScreenHeight()/2 - 169, 0,20);
|
||||||
player[2]->SetPositions(ScreenWidth()/2-156, 0, 20,0);
|
player[2]->SetPositions(ScreenWidth()/2-156, 0, 20,0);
|
||||||
player[3]->SetPositions(ScreenWidth()-73, ScreenHeight()/2 - 169, 0,20);
|
player[3]->SetPositions(ScreenWidth()-73, ScreenHeight()/2 - 169, 0,20);
|
||||||
|
|
||||||
|
//randomization
|
||||||
|
srand(time(NULL));
|
||||||
|
rand(); rand(); rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
HeartsEngine::~HeartsEngine() {
|
HeartsEngine::~HeartsEngine() {
|
||||||
@@ -67,6 +73,8 @@ HeartsEngine::~HeartsEngine() {
|
|||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
delete player[i];
|
delete player[i];
|
||||||
|
|
||||||
|
heartSprite.UnloadSurface();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -97,7 +105,7 @@ void HeartsEngine::Process() {
|
|||||||
|
|
||||||
void HeartsEngine::Draw() {
|
void HeartsEngine::Draw() {
|
||||||
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,128,0));
|
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,128,0));
|
||||||
mImage.DrawAll(screen);
|
heartSprite.DrawTo(screen, 32, 32);
|
||||||
|
|
||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
case SETUP:
|
case SETUP:
|
||||||
@@ -140,7 +148,7 @@ void HeartsEngine::SetupPhase() {
|
|||||||
firstPlayer = -1;
|
firstPlayer = -1;
|
||||||
trickCount = 0;
|
trickCount = 0;
|
||||||
heartsBroken = false;
|
heartsBroken = false;
|
||||||
mImage["heart"]->SetClipX(0);
|
heartSprite.SetClipX(0);
|
||||||
|
|
||||||
if (rotation == NONE) {
|
if (rotation == NONE) {
|
||||||
CalcFirst();
|
CalcFirst();
|
||||||
@@ -271,7 +279,7 @@ void HeartsEngine::PlayBeforePhase() {
|
|||||||
cerr << "Player index: " << i << endl;
|
cerr << "Player index: " << i << endl;
|
||||||
}
|
}
|
||||||
if (heartSound != heartsBroken) {
|
if (heartSound != heartsBroken) {
|
||||||
mImage["heart"]->SetClipX(64);
|
heartSprite.SetClipX(64);
|
||||||
mAudio.Play("glass");
|
mAudio.Play("glass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +296,7 @@ void HeartsEngine::PlayPlayerPhase() {
|
|||||||
playPhase = AFTER;
|
playPhase = AFTER;
|
||||||
}
|
}
|
||||||
if (heartSound != heartsBroken) {
|
if (heartSound != heartsBroken) {
|
||||||
mImage["heart"]->SetClipX(64);
|
heartSprite.SetClipX(64);
|
||||||
mAudio.Play("glass");
|
mAudio.Play("glass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,7 +317,7 @@ void HeartsEngine::PlayAfterPhase() {
|
|||||||
cerr << "Player index: " << i << endl;
|
cerr << "Player index: " << i << endl;
|
||||||
}
|
}
|
||||||
if (heartSound != heartsBroken) {
|
if (heartSound != heartsBroken) {
|
||||||
mImage["heart"]->SetClipX(64);
|
heartSprite.SetClipX(64);
|
||||||
mAudio.Play("glass");
|
mAudio.Play("glass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,7 +380,7 @@ void HeartsEngine::CalcScores() {
|
|||||||
if (card == NULL)
|
if (card == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (card->Suit() == Card::HEARTS)
|
if (card->GetSuit() == Card::HEARTS)
|
||||||
tally++;
|
tally++;
|
||||||
|
|
||||||
if (ISCARD(card,QUEEN,SPADES))
|
if (ISCARD(card,QUEEN,SPADES))
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#ifndef KR_HEARTSENGINE_H_
|
#ifndef KR_HEARTSENGINE_H_
|
||||||
#define KR_HEARTSENGINE_H_
|
#define KR_HEARTSENGINE_H_
|
||||||
#include "base_engine.h"
|
#include "base_engine.h"
|
||||||
#include "image_manager.h"
|
#include "image.h"
|
||||||
#include "audio_manager.h"
|
#include "audio_manager.h"
|
||||||
#include "deck.h"
|
#include "deck.h"
|
||||||
#include "player_ai.h"
|
#include "player_ai.h"
|
||||||
@@ -47,7 +47,7 @@ private:
|
|||||||
void Draw ();
|
void Draw ();
|
||||||
|
|
||||||
/* KAGE Managers */
|
/* KAGE Managers */
|
||||||
KAGE::ImageManager mImage;
|
Image heartSprite;
|
||||||
KAGE::AudioManager mAudio;
|
KAGE::AudioManager mAudio;
|
||||||
|
|
||||||
/* Game phase members */ //TODO: "phases"
|
/* Game phase members */ //TODO: "phases"
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ void Player::ShiftCard(int index, int dirX, int dirY) {
|
|||||||
|
|
||||||
void Player::SetFaces(int face) {
|
void Player::SetFaces(int face) {
|
||||||
for (CardList::iterator it = hand.Head(); it != NULL; it = it->GetNext())
|
for (CardList::iterator it = hand.Head(); it != NULL; it = it->GetNext())
|
||||||
it->SetFace(face);
|
it->SetFaceState(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::SetPositions(int _posX, int _posY, int _dirX, int _dirY) {
|
void Player::SetPositions(int _posX, int _posY, int _dirX, int _dirY) {
|
||||||
@@ -131,7 +131,7 @@ void Player::SetTrickPositions() {
|
|||||||
tricks.Sort();
|
tricks.Sort();
|
||||||
|
|
||||||
for (int i = 0; i < tricks.Size(); i++) {
|
for (int i = 0; i < tricks.Size(); i++) {
|
||||||
if (tricks.Read(i)->Suit() != Card::HEARTS && !ISCARD(tricks.Read(i),QUEEN,SPADES))
|
if (tricks.Read(i)->GetSuit() != Card::HEARTS && !ISCARD(tricks.Read(i),QUEEN,SPADES))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tricks.Read(i)->SetPos(x,y);
|
tricks.Read(i)->SetPos(x,y);
|
||||||
@@ -141,7 +141,7 @@ void Player::SetTrickPositions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::DrawHand(SDL_Surface* dest) {
|
void Player::DrawHand(SDL_Surface* dest) {
|
||||||
Hand()->DrawAll(dest);
|
Hand()->DrawTo(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::DrawTricks(SDL_Surface* dest) {
|
void Player::DrawTricks(SDL_Surface* dest) {
|
||||||
@@ -149,9 +149,9 @@ void Player::DrawTricks(SDL_Surface* dest) {
|
|||||||
tricks.Sort();
|
tricks.Sort();
|
||||||
|
|
||||||
for (int i = 0; i < tricks.Size(); i++) {
|
for (int i = 0; i < tricks.Size(); i++) {
|
||||||
if (tricks.Read(i)->Suit() != Card::HEARTS && !ISCARD(tricks.Read(i),QUEEN,SPADES))
|
if (tricks.Read(i)->GetSuit() != Card::HEARTS && !ISCARD(tricks.Read(i),QUEEN,SPADES))
|
||||||
continue;
|
continue;
|
||||||
tricks.Read(i)->Draw(dest);
|
tricks.Read(i)->DrawTo(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ void PlayerAI::SelectSwapCards(int dirX, int dirY) {
|
|||||||
int card = -1;
|
int card = -1;
|
||||||
|
|
||||||
for (int i = Hand()->Size() - 1; i >= 0; i--) {
|
for (int i = Hand()->Size() - 1; i >= 0; i--) {
|
||||||
if (Hand()->Read(i)->Rank() > Hand()->Read(card)->Rank() && !CheckSwapCards(i) ) {
|
if (Hand()->Read(i)->GetRank() > Hand()->Read(card)->GetRank() && !CheckSwapCards(i) ) {
|
||||||
card = i;
|
card = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ Card* PlayerAI::PassPlayFirstTrick(int leadingSuit) {
|
|||||||
|
|
||||||
//follow suit
|
//follow suit
|
||||||
for(int i = 0; i < Hand()->Size()-1; i++)
|
for(int i = 0; i < Hand()->Size()-1; i++)
|
||||||
if (Hand()->Read(i)->Suit() == leadingSuit)
|
if (Hand()->Read(i)->GetSuit() == leadingSuit)
|
||||||
return Hand()->Pass(i);
|
return Hand()->Pass(i);
|
||||||
|
|
||||||
/* bug: it's possible that if every penalty card is initially dealt the the AI, it'll break
|
/* bug: it's possible that if every penalty card is initially dealt the the AI, it'll break
|
||||||
@@ -88,7 +88,7 @@ Card* PlayerAI::PassPlayFirstTrick(int leadingSuit) {
|
|||||||
|
|
||||||
for (int i = Hand()->Size() -1; i >= 0; i--) {//backwards, to choose the highest rank
|
for (int i = Hand()->Size() -1; i >= 0; i--) {//backwards, to choose the highest rank
|
||||||
c = Hand()->Read(i);
|
c = Hand()->Read(i);
|
||||||
if (c->Suit() != Card::HEARTS && !ISCARD(c,QUEEN,SPADES) ) {
|
if (c->GetSuit() != Card::HEARTS && !ISCARD(c,QUEEN,SPADES) ) {
|
||||||
c = Hand()->Pass(i);
|
c = Hand()->Pass(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ Card* PlayerAI::PassPlayFollowSuit(int leadingSuit, bool heartsBroken) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (int i = 0; i < Hand()->Size() -1; i++) {
|
for (int i = 0; i < Hand()->Size() -1; i++) {
|
||||||
if (Hand()->Read(i)->Suit() != Card::HEARTS) {
|
if (Hand()->Read(i)->GetSuit() != Card::HEARTS) {
|
||||||
c = Hand()->Pass(i);
|
c = Hand()->Pass(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ Card* PlayerAI::PassPlayFollowSuit(int leadingSuit, bool heartsBroken) {
|
|||||||
|
|
||||||
//play the lowest card of the suit
|
//play the lowest card of the suit
|
||||||
for (int i = 0; i < Hand()->Size()-1; i++)
|
for (int i = 0; i < Hand()->Size()-1; i++)
|
||||||
if (Hand()->Read(i)->Suit() == leadingSuit)
|
if (Hand()->Read(i)->GetSuit() == leadingSuit)
|
||||||
return Hand()->Pass(i);
|
return Hand()->Pass(i);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -135,7 +135,7 @@ Card* PlayerAI::PassPlayBreakSuit(bool& heartsBroken) {
|
|||||||
return Hand()->Pass(i);
|
return Hand()->Pass(i);
|
||||||
|
|
||||||
//if I have a heart
|
//if I have a heart
|
||||||
if (Hand()->Read( Hand()->Size()-1 )->Suit() == Card::HEARTS) {
|
if (Hand()->Read( Hand()->Size()-1 )->GetSuit() == Card::HEARTS) {
|
||||||
heartsBroken = true;
|
heartsBroken = true;
|
||||||
return Hand()->Pass( Hand()->Size()-1 );
|
return Hand()->Pass( Hand()->Size()-1 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,16 +99,16 @@ Card* PlayerUser::PassPlayFirstTrick(int card, int leadingSuit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//follow suit
|
//follow suit
|
||||||
if (Hand()->Read(card)->Suit() == leadingSuit) //if I've selected the correct suit
|
if (Hand()->Read(card)->GetSuit() == leadingSuit) //if I've selected the correct suit
|
||||||
return Hand()->Pass(card);
|
return Hand()->Pass(card);
|
||||||
|
|
||||||
//if I haven't selected the correct suit
|
//if I haven't selected the correct suit
|
||||||
for (int i = 0; i < Hand()->Size() -1; i++)
|
for (int i = 0; i < Hand()->Size() -1; i++)
|
||||||
if (Hand()->Read(i)->Suit() == leadingSuit) //The correct suit is in my hand
|
if (Hand()->Read(i)->GetSuit() == leadingSuit) //The correct suit is in my hand
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
//can't follow suit, no penalty cards
|
//can't follow suit, no penalty cards
|
||||||
if (Hand()->Read(card)->Suit() != Card::HEARTS && !ISCARD(Hand()->Read(card),QUEEN,SPADES))
|
if (Hand()->Read(card)->GetSuit() != Card::HEARTS && !ISCARD(Hand()->Read(card),QUEEN,SPADES))
|
||||||
return Hand()->Pass(card);
|
return Hand()->Pass(card);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -121,7 +121,7 @@ Card* PlayerUser::PassPlayFollowSuit(int card, int leadingSuit, bool heartsBroke
|
|||||||
if (heartsBroken)
|
if (heartsBroken)
|
||||||
return Hand()->Pass(card);
|
return Hand()->Pass(card);
|
||||||
else {
|
else {
|
||||||
if (Hand()->Read(card)->Suit() != Card::HEARTS)
|
if (Hand()->Read(card)->GetSuit() != Card::HEARTS)
|
||||||
return Hand()->Pass(card);
|
return Hand()->Pass(card);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -129,7 +129,7 @@ Card* PlayerUser::PassPlayFollowSuit(int card, int leadingSuit, bool heartsBroke
|
|||||||
}
|
}
|
||||||
|
|
||||||
//if the player is following suit
|
//if the player is following suit
|
||||||
if (Hand()->Read(card)->Suit() == leadingSuit)
|
if (Hand()->Read(card)->GetSuit() == leadingSuit)
|
||||||
return Hand()->Pass(card);
|
return Hand()->Pass(card);
|
||||||
|
|
||||||
//when the card does not follow suit
|
//when the card does not follow suit
|
||||||
@@ -139,10 +139,10 @@ Card* PlayerUser::PassPlayFollowSuit(int card, int leadingSuit, bool heartsBroke
|
|||||||
Card* PlayerUser::PassPlayBreakSuit(int card, int leadingSuit, bool& heartsBroken) {
|
Card* PlayerUser::PassPlayBreakSuit(int card, int leadingSuit, bool& heartsBroken) {
|
||||||
//if the player CAN still follow suit
|
//if the player CAN still follow suit
|
||||||
for (int i = 0; i < Hand()->Size() -1; i++)
|
for (int i = 0; i < Hand()->Size() -1; i++)
|
||||||
if (Hand()->Read(i)->Suit() == leadingSuit)
|
if (Hand()->Read(i)->GetSuit() == leadingSuit)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (Hand()->Read(card)->Suit() == Card::HEARTS)
|
if (Hand()->Read(card)->GetSuit() == Card::HEARTS)
|
||||||
heartsBroken = true;
|
heartsBroken = true;
|
||||||
return Hand()->Pass(card);
|
return Hand()->Pass(card);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,3 @@
|
|||||||
|
|
||||||
~~~~~
|
~~~~~
|
||||||
|
|
||||||
* ~~Move the random setup~~ Add random seed to the scene
|
|
||||||
|
|||||||
Reference in New Issue
Block a user