mirror of
https://github.com/Ratstail91/Hearts.git
synced 2025-11-29 02:24:28 +11:00
Shoehorned in the button and text interface
This is an attempt to show that I can complete a specified set of features. The code itself is an absolute mess, and I've always wanted to refactor this project. For now though, it'll do as far as the portfolio goes.
This commit is contained in:
@@ -186,7 +186,7 @@ void BaseEngine::RedrawScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseEngine::AdditionalInit() {
|
void BaseEngine::AdditionalInit() {
|
||||||
SDL_WM_SetCaption("KAGE: Kayne's All-purpose Game Engine, By Kayne Ruse",NULL);
|
SDL_WM_SetCaption("Hearts",NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseEngine::TranslateMods(SDL_keysym ks) {
|
int BaseEngine::TranslateMods(SDL_keysym ks) {
|
||||||
|
|||||||
@@ -27,11 +27,18 @@
|
|||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sstream>
|
||||||
#include "hearts_engine.h"
|
#include "hearts_engine.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define CASE break; case
|
#define CASE break; case
|
||||||
|
|
||||||
|
string itos(int i) {
|
||||||
|
ostringstream ostr;
|
||||||
|
ostr << i;
|
||||||
|
return ostr.str();
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -46,8 +53,8 @@ HeartsEngine::HeartsEngine() {
|
|||||||
button.LoadFontSurface("rsc\\pk_white_8.bmp");
|
button.LoadFontSurface("rsc\\pk_white_8.bmp");
|
||||||
font.LoadSurface("rsc\\pk_white_8.bmp");
|
font.LoadSurface("rsc\\pk_white_8.bmp");
|
||||||
|
|
||||||
// button.SetX();
|
button.SetX(300);
|
||||||
// button.SetY();
|
button.SetY(300);
|
||||||
|
|
||||||
player[0] = new PlayerUser();
|
player[0] = new PlayerUser();
|
||||||
player[1] = new PlayerAI();
|
player[1] = new PlayerAI();
|
||||||
@@ -84,8 +91,14 @@ HeartsEngine::~HeartsEngine() {
|
|||||||
//Engine members
|
//Engine members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& button) {
|
void HeartsEngine::MouseMotion(SDL_MouseMotionEvent& motion) {
|
||||||
BaseEngine::MouseButtonDown(button);
|
BaseEngine::MouseMotion(motion);
|
||||||
|
button.MouseMotion(motion);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& butt) {
|
||||||
|
BaseEngine::MouseButtonDown(butt);
|
||||||
|
button.MouseButtonDown(butt);
|
||||||
|
|
||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
CASE SWAP:
|
CASE SWAP:
|
||||||
@@ -96,6 +109,11 @@ void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HeartsEngine::MouseButtonUp(SDL_MouseButtonEvent& butt) {
|
||||||
|
BaseEngine::MouseButtonUp(butt);
|
||||||
|
button.MouseButtonUp(butt);
|
||||||
|
}
|
||||||
|
|
||||||
void HeartsEngine::Process() {
|
void HeartsEngine::Process() {
|
||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
CASE SETUP: SetupPhase();
|
CASE SETUP: SetupPhase();
|
||||||
@@ -113,16 +131,52 @@ void HeartsEngine::Draw() {
|
|||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
case SETUP:
|
case SETUP:
|
||||||
case SWAP:
|
case SWAP:
|
||||||
|
if (player[0]->CheckSwapCards()) {
|
||||||
|
switch(rotation) {
|
||||||
|
case Rotation::LEFT:
|
||||||
|
button.SetText("Pass Left");
|
||||||
|
break;
|
||||||
|
case Rotation::RIGHT:
|
||||||
|
button.SetText("Pass Right");
|
||||||
|
break;
|
||||||
|
case Rotation::ACROSS:
|
||||||
|
button.SetText("Pass Across");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
button.DrawTo(screen);
|
||||||
|
}
|
||||||
case TRICK:
|
case TRICK:
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
player[i]->DrawHand(screen);
|
player[i]->DrawHand(screen);
|
||||||
|
|
||||||
table.Draw(screen,firstPlayer);
|
table.Draw(screen,firstPlayer);
|
||||||
break;
|
break;
|
||||||
case SCORE:
|
case SCORE:
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
player[i]->DrawTricks(screen);
|
player[i]->DrawTricks(screen);
|
||||||
break;
|
button.SetText("Continue");
|
||||||
|
button.DrawTo(screen);
|
||||||
|
|
||||||
|
//I know this sucks
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (winner == i) {
|
||||||
|
font.DrawStringTo(
|
||||||
|
string() + "Player " + itos(i+1) + ": " + itos(player[i]->Score()) + " - " + itos(player[i]->Wins()) + " wins <-- Winner!!",
|
||||||
|
screen,
|
||||||
|
300,
|
||||||
|
200 + font.GetCharH() * i
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
font.DrawStringTo(
|
||||||
|
string() + "Player " + itos(i+1) + ": " + itos(player[i]->Score()) + " - " + itos(player[i]->Wins()) + " wins",
|
||||||
|
screen,
|
||||||
|
300,
|
||||||
|
200 + font.GetCharH() * i
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +220,7 @@ void HeartsEngine::SetupPhase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::SwapPhase() {
|
void HeartsEngine::SwapPhase() {
|
||||||
if (!keyboard[SDLK_F1])
|
if (button.GetState() != Button::State::PRESSED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!player[0]->CheckSwapCards())
|
if (!player[0]->CheckSwapCards())
|
||||||
@@ -210,47 +264,41 @@ void HeartsEngine::TrickPhase() {
|
|||||||
ResetPositions();
|
ResetPositions();
|
||||||
CalcScores();
|
CalcScores();
|
||||||
gamePhase = SCORE;
|
gamePhase = SCORE;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
cout << "Player " << i << ": " << player[i]->Score() << endl;//tmp...
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::ScorePhase() {
|
void HeartsEngine::ScorePhase() {
|
||||||
//end of game; temporary functionality...
|
//end of game; temporary functionality...
|
||||||
if (player[0]->Score() >= 100 ||
|
if ((player[0]->Score() >= 100 ||
|
||||||
player[1]->Score() >= 100 ||
|
player[1]->Score() >= 100 ||
|
||||||
player[2]->Score() >= 100 ||
|
player[2]->Score() >= 100 ||
|
||||||
player[3]->Score() >= 100)
|
player[3]->Score() >= 100) && winner == -1)
|
||||||
{
|
{
|
||||||
cout << "GAME OVER" << endl;
|
winner = 0;
|
||||||
int winner = 0;
|
|
||||||
|
|
||||||
|
//find the winner
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (player[i]->Score() < player[winner]->Score()) {
|
if (player[i]->Score() < player[winner]->Score()) {
|
||||||
winner = i;
|
winner = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << "Winner is: " << winner << endl;
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
|
//award the winner
|
||||||
player[winner]->Wins(1);
|
player[winner]->Wins(1);
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
cout << "Player " << i << " wins: " << player[i]->Wins() << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
//reset all values
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
player[i]->Score( -player[i]->Score() );
|
|
||||||
rotation = NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//10 second delay
|
//wait for input
|
||||||
if (SDL_GetTicks() - timeTick > 10000 || keyboard[SDLK_F1])//button...
|
if (button.GetState() == Button::State::PRESSED) {
|
||||||
gamePhase = CLEANUP;
|
gamePhase = CLEANUP;
|
||||||
|
|
||||||
|
//reset the game
|
||||||
|
if (winner != -1) {
|
||||||
|
winner = -1;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
player[i]->Score( -player[i]->Score() );
|
||||||
|
rotation = NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::CleanupPhase() {
|
void HeartsEngine::CleanupPhase() {
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ public:
|
|||||||
~HeartsEngine();
|
~HeartsEngine();
|
||||||
private:
|
private:
|
||||||
/* Engine members */
|
/* Engine members */
|
||||||
|
void MouseMotion (SDL_MouseMotionEvent& motion);
|
||||||
void MouseButtonDown (SDL_MouseButtonEvent& button);
|
void MouseButtonDown (SDL_MouseButtonEvent& button);
|
||||||
|
void MouseButtonUp (SDL_MouseButtonEvent& button);
|
||||||
void Process ();
|
void Process ();
|
||||||
void Draw ();
|
void Draw ();
|
||||||
|
|
||||||
@@ -88,6 +90,8 @@ private:
|
|||||||
bool heartsBroken;
|
bool heartsBroken;
|
||||||
int timeTick;
|
int timeTick;
|
||||||
|
|
||||||
|
int winner = -1;
|
||||||
|
|
||||||
/* Utility members */
|
/* Utility members */
|
||||||
void ResetPositions();
|
void ResetPositions();
|
||||||
void ResetFaces();
|
void ResetFaces();
|
||||||
|
|||||||
Reference in New Issue
Block a user