mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:57:34 +00:00
Solitaire: Move cards functionality into LibCards
This commit is contained in:
parent
9440a3c280
commit
3e47eec862
9 changed files with 32 additions and 23 deletions
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
@ -1,12 +1,10 @@
|
||||||
compile_gml(Solitaire.gml SolitaireGML.h solitaire_gml)
|
compile_gml(Solitaire.gml SolitaireGML.h solitaire_gml)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
Card.cpp
|
|
||||||
CardStack.cpp
|
|
||||||
Game.cpp
|
Game.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
SolitaireGML.h
|
SolitaireGML.h
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_app(Solitaire ICON app-solitaire)
|
serenity_app(Solitaire ICON app-solitaire)
|
||||||
target_link_libraries(Solitaire LibGUI LibGfx LibCore)
|
target_link_libraries(Solitaire LibCards LibGUI LibGfx LibCore)
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CardStack.h"
|
#include <LibCards/CardStack.h>
|
||||||
#include <LibGUI/Frame.h>
|
#include <LibGUI/Frame.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
|
|
||||||
|
using Cards::Card;
|
||||||
|
using Cards::CardStack;
|
||||||
|
|
||||||
namespace Solitaire {
|
namespace Solitaire {
|
||||||
|
|
||||||
enum class Mode : u8 {
|
enum class Mode : u8 {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
add_subdirectory(LibArchive)
|
add_subdirectory(LibArchive)
|
||||||
add_subdirectory(LibAudio)
|
add_subdirectory(LibAudio)
|
||||||
add_subdirectory(LibC)
|
add_subdirectory(LibC)
|
||||||
|
add_subdirectory(LibCards)
|
||||||
add_subdirectory(LibChess)
|
add_subdirectory(LibChess)
|
||||||
add_subdirectory(LibCompress)
|
add_subdirectory(LibCompress)
|
||||||
add_subdirectory(LibCore)
|
add_subdirectory(LibCore)
|
||||||
|
|
7
Userland/Libraries/LibCards/CMakeLists.txt
Normal file
7
Userland/Libraries/LibCards/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
set(SOURCES
|
||||||
|
Card.cpp
|
||||||
|
CardStack.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
serenity_lib(LibCards cards)
|
||||||
|
target_link_libraries(LibCards LibC LibCore)
|
|
@ -9,7 +9,7 @@
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/FontDatabase.h>
|
#include <LibGfx/FontDatabase.h>
|
||||||
|
|
||||||
namespace Solitaire {
|
namespace Cards {
|
||||||
|
|
||||||
static const NonnullRefPtr<Gfx::CharacterBitmap> s_diamond = Gfx::CharacterBitmap::create_from_ascii(
|
static const NonnullRefPtr<Gfx::CharacterBitmap> s_diamond = Gfx::CharacterBitmap::create_from_ascii(
|
||||||
" # "
|
" # "
|
||||||
|
@ -75,7 +75,7 @@ Card::Card(Type type, uint8_t value)
|
||||||
Gfx::Painter bg_painter(*s_background);
|
Gfx::Painter bg_painter(*s_background);
|
||||||
|
|
||||||
s_background->fill(Color::White);
|
s_background->fill(Color::White);
|
||||||
auto image = Gfx::Bitmap::load_from_file("/res/icons/solitaire/buggie-deck.png");
|
auto image = Gfx::Bitmap::load_from_file("/res/icons/cards/buggie-deck.png");
|
||||||
VERIFY(!image.is_null());
|
VERIFY(!image.is_null());
|
||||||
|
|
||||||
float aspect_ratio = image->width() / static_cast<float>(image->height());
|
float aspect_ratio = image->width() / static_cast<float>(image->height());
|
|
@ -15,7 +15,7 @@
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
namespace Solitaire {
|
namespace Cards {
|
||||||
|
|
||||||
class Card final : public Core::Object {
|
class Card final : public Core::Object {
|
||||||
C_OBJECT(Card)
|
C_OBJECT(Card)
|
||||||
|
@ -74,28 +74,28 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Solitaire::Card> : Formatter<FormatString> {
|
struct AK::Formatter<Cards::Card> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, const Solitaire::Card& card)
|
void format(FormatBuilder& builder, const Cards::Card& card)
|
||||||
{
|
{
|
||||||
StringView type;
|
StringView type;
|
||||||
|
|
||||||
switch (card.type()) {
|
switch (card.type()) {
|
||||||
case Solitaire::Card::Type::Clubs:
|
case Cards::Card::Type::Clubs:
|
||||||
type = "C"sv;
|
type = "C"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::Card::Type::Diamonds:
|
case Cards::Card::Type::Diamonds:
|
||||||
type = "D"sv;
|
type = "D"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::Card::Type::Hearts:
|
case Cards::Card::Type::Hearts:
|
||||||
type = "H"sv;
|
type = "H"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::Card::Type::Spades:
|
case Cards::Card::Type::Spades:
|
||||||
type = "S"sv;
|
type = "S"sv;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Formatter<FormatString>::format(builder, "{:>2}{}", Solitaire::Card::labels[card.value()], type);
|
Formatter<FormatString>::format(builder, "{:>2}{}", Cards::Card::labels[card.value()], type);
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "CardStack.h"
|
#include "CardStack.h"
|
||||||
|
|
||||||
namespace Solitaire {
|
namespace Cards {
|
||||||
|
|
||||||
CardStack::CardStack()
|
CardStack::CardStack()
|
||||||
: m_position({ 0, 0 })
|
: m_position({ 0, 0 })
|
|
@ -10,7 +10,7 @@
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
namespace Solitaire {
|
namespace Cards {
|
||||||
|
|
||||||
class CardStack final {
|
class CardStack final {
|
||||||
public:
|
public:
|
||||||
|
@ -88,25 +88,25 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<Solitaire::CardStack> : Formatter<FormatString> {
|
struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> {
|
||||||
void format(FormatBuilder& builder, const Solitaire::CardStack& stack)
|
void format(FormatBuilder& builder, const Cards::CardStack& stack)
|
||||||
{
|
{
|
||||||
StringView type;
|
StringView type;
|
||||||
|
|
||||||
switch (stack.type()) {
|
switch (stack.type()) {
|
||||||
case Solitaire::CardStack::Type::Stock:
|
case Cards::CardStack::Type::Stock:
|
||||||
type = "Stock"sv;
|
type = "Stock"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::CardStack::Type::Normal:
|
case Cards::CardStack::Type::Normal:
|
||||||
type = "Normal"sv;
|
type = "Normal"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::CardStack::Type::Foundation:
|
case Cards::CardStack::Type::Foundation:
|
||||||
type = "Foundation"sv;
|
type = "Foundation"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::CardStack::Type::Waste:
|
case Cards::CardStack::Type::Waste:
|
||||||
type = "Waste"sv;
|
type = "Waste"sv;
|
||||||
break;
|
break;
|
||||||
case Solitaire::CardStack::Type::Play:
|
case Cards::CardStack::Type::Play:
|
||||||
type = "Play"sv;
|
type = "Play"sv;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
Loading…
Add table
Add a link
Reference in a new issue