Skip to content

Commit

Permalink
Separate classes into headers
Browse files Browse the repository at this point in the history
  • Loading branch information
hrmorley34 committed Jul 16, 2023
1 parent 9bd626a commit b502f1e
Show file tree
Hide file tree
Showing 30 changed files with 1,016 additions and 895 deletions.
4 changes: 2 additions & 2 deletions images/scripts/imagedata.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "../imageclasses.hpp"
#include "../card.hpp"

#ifndef IMAGEDATA_H
#define IMAGEDATA_H
#ifndef GEN_IMAGEDATA_H
#define GEN_IMAGEDATA_H

#pragma region IMAGEDATA
const Image CardImage;
Expand Down
14 changes: 4 additions & 10 deletions src/card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum Colour : uint8_t
Black = 1
};

Colour GetSuitColour(const Suit suit)
inline Colour GetSuitColour(const Suit suit)
{
return (Colour)(suit >> 1);
}
Expand All @@ -30,17 +30,11 @@ struct Card
private:
uint8_t ivalue; // 0bssrrrr for suit (0-3), rank (1-13)

void SetInternal(const Suit suit, const Rank rank)
{
ivalue = (uint8_t)suit << 4 | (uint8_t)rank;
}

public:
Card() : ivalue(0) {}
Card()
: ivalue(0) {}
Card(const Suit suit, const Rank rank)
{
SetInternal(suit, rank);
}
: ivalue((uint8_t)suit << 4 | (uint8_t)rank) {}

bool operator==(const Card c) const
{
Expand Down
4 changes: 4 additions & 0 deletions src/cardclasses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "card.hpp"
#include "cardcolumn.c.hpp"
#include "cardll.c.hpp"
#include "cardllpointer.hpp"
95 changes: 95 additions & 0 deletions src/cardcolumn.c.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "cardcolumn.hpp"

CardColumn::CardColumn() {}

void CardColumn::PushLeft(const Card card)
{
revealed.PushLeft(card);
}

void CardColumn::PushUnrevealed(const Card card)
{
unrevealed.PushLeft(card);
}

void CardColumn::Reveal()
{
if (!revealed.empty())
return;
if (unrevealed.empty())
return;
revealed.PushRight(unrevealed.PopLeft());
}

void CardColumn::MoveMany(int count, CardColumn *dest)
{
revealed.MoveMany(count, &(dest->revealed));
Reveal();
}
// void CardColumn::MoveMany(int count, CardLL *dest)
// {
// revealed.MoveMany(count, dest);
// Reveal();
// }
// void CardColumn::MoveManyFrom(int count, CardLL *src)
// {
// src->MoveMany(count, &revealed);
// }

Card CardColumn::PopLeft()
{
if (revealed.empty())
Reveal();
Card c = revealed.PopLeft();
Reveal();
return c;
}

Card CardColumn::Peek() const
{
// if (revealed.empty())
// Reveal();
return revealed.Peek();
}

Card CardColumn::PeekAt(const int index) const
{
// if (revealed.empty())
// Reveal();
return revealed.PeekAt(index);
}

int CardColumn::revealedlength() const
{
return revealed.length();
}

int CardColumn::unrevealedlength() const
{
return unrevealed.length();
}

bool CardColumn::empty() const
{
return revealed.empty() && unrevealed.empty();
}

int CardColumn::WriteToArray(SaveData *const arr) const
{
int length = unrevealed.WriteToArray(arr);
length += revealed.WriteToArray(arr + length);
return length;
}

int CardColumn::GetWriteLength() const
{
return unrevealed.GetWriteLength() +
revealed.GetWriteLength();
}

int CardColumn::ReadFromArray(const SaveData *const arr)
{
int length = unrevealed.ReadFromArray(arr);
length += revealed.ReadFromArray(arr + length);
return length;
}
104 changes: 16 additions & 88 deletions src/cardcolumn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,99 +12,27 @@ class CardColumn
CardLL unrevealed;

public:
CardColumn() {}
CardColumn();

void PushLeft(const Card card)
{
revealed.PushLeft(card);
}
void PushLeft(const Card card);
void PushUnrevealed(const Card card);
void Reveal();

void PushUnrevealed(const Card card)
{
unrevealed.PushLeft(card);
}
void MoveMany(int count, CardColumn *dest);
// void MoveMany(int count, CardLL *dest);
// void MoveManyFrom(int count, CardLL *src);

void Reveal()
{
if (!revealed.empty())
return;
if (unrevealed.empty())
return;
revealed.PushRight(unrevealed.PopLeft());
}
Card PopLeft();
Card Peek() const;
Card PeekAt(const int index) const;

void MoveMany(int count, CardColumn *dest)
{
revealed.MoveMany(count, &(dest->revealed));
Reveal();
}
// void MoveMany(int count, CardLL *dest)
// {
// revealed.MoveMany(count, dest);
// Reveal();
// }
// void MoveManyFrom(int count, CardLL *src)
// {
// src->MoveMany(count, &revealed);
// }
int revealedlength() const;
int unrevealedlength() const;
bool empty() const;

Card PopLeft()
{
if (revealed.empty())
Reveal();
Card c = revealed.PopLeft();
Reveal();
return c;
}

Card Peek() const
{
// if (revealed.empty())
// Reveal();
return revealed.Peek();
}

Card PeekAt(const int index) const
{
// if (revealed.empty())
// Reveal();
return revealed.PeekAt(index);
}

int revealedlength() const
{
return revealed.length();
}

int unrevealedlength() const
{
return unrevealed.length();
}

bool empty() const
{
return revealed.empty() && unrevealed.empty();
}

int WriteToArray(SaveData *const arr) const
{
int length = unrevealed.WriteToArray(arr);
length += revealed.WriteToArray(arr + length);
return length;
}

int GetWriteLength() const
{
return unrevealed.GetWriteLength() +
revealed.GetWriteLength();
}

int ReadFromArray(const SaveData *const arr)
{
int length = unrevealed.ReadFromArray(arr);
length += revealed.ReadFromArray(arr + length);
return length;
}
int WriteToArray(SaveData *const arr) const;
int GetWriteLength() const;
int ReadFromArray(const SaveData *const arr);
};

#endif
Loading

0 comments on commit b502f1e

Please sign in to comment.