diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..34a653a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,81 @@ +cmake_minimum_required(VERSION 3.5) + +project(Blackjack VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets LinguistTools) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools) + +#set(TS_FILES languages/Blackjack_en_GB.ts) + +set(PROJECT_SOURCES + main.cpp + mainwindow.cpp + mainwindow.hpp + mainwindow.ui + playwindow.cpp + playwindow.hpp + playwindow.ui + images.qrc + ${TS_FILES} +) + +add_subdirectory(blackjack) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(Blackjack + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET Blackjack APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation + + qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) +else() + if(ANDROID) + add_library(Blackjack SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(Blackjack + ${PROJECT_SOURCES} + ) + endif() + + qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) +endif() + +target_compile_options(Blackjack PRIVATE $<$: + -Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion + >) + +target_include_directories(Blackjack PUBLIC blackjack) +target_link_libraries(Blackjack PRIVATE Qt${QT_VERSION_MAJOR}::Widgets blackjack) + +set_target_properties(Blackjack PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +install(TARGETS Blackjack + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(Blackjack) +endif() diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000..5127849 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,422 @@ + + + + + + EnvironmentId + {48575134-1fc3-4253-940c-17c134c3fd80} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 4 + + /home/sanderspeetjens/git/blackjack/Blackjack/CMakeLists.txt + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.5.0 GCC 64bit + Desktop Qt 6.5.0 GCC 64bit + qt.qt6.650.gcc_64_kit + 4 + 0 + 0 + + Release + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /home/sanderspeetjens/git/blackjack/build-Blackjack-Desktop_Qt_6_5_0_GCC_64bit-Release + + + + + all + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /home/sanderspeetjens/git/blackjack/build-Blackjack-Desktop_Qt_6_5_0_GCC_64bit-RelWithDebInfo + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + /home/sanderspeetjens/git/blackjack/build-Blackjack-Desktop_Qt_6_5_0_GCC_64bit-Profile + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /home/sanderspeetjens/git/blackjack/build-Blackjack-Desktop_Qt_6_5_0_GCC_64bit-MinSizeRel + + + + + all + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + + Debug + 2 + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + /home/sanderspeetjens/git/build-Blackjack-Desktop_Qt_6_5_0_GCC_64bit-Debug + + + + + all + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + true + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Blackjack + CMakeProjectManager.CMakeRunConfiguration.Blackjack + Blackjack + false + true + true + false + true + /home/sanderspeetjens/git/build-Blackjack-Desktop_Qt_6_5_0_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/images.qrc b/images.qrc new file mode 100644 index 0000000..a780086 --- /dev/null +++ b/images.qrc @@ -0,0 +1,62 @@ + + + images/bg.jpg + images/blackjack_table.png + images/draw.png + images/lose.png + images/win.png + images/cards/2C.png + images/cards/2D.png + images/cards/2H.png + images/cards/2S.png + images/cards/3C.png + images/cards/3D.png + images/cards/3H.png + images/cards/3S.png + images/cards/4C.png + images/cards/4D.png + images/cards/4H.png + images/cards/4S.png + images/cards/5C.png + images/cards/5D.png + images/cards/5H.png + images/cards/5S.png + images/cards/6C.png + images/cards/6D.png + images/cards/6H.png + images/cards/6S.png + images/cards/7C.png + images/cards/7D.png + images/cards/7H.png + images/cards/7S.png + images/cards/8C.png + images/cards/8D.png + images/cards/8H.png + images/cards/8S.png + images/cards/9C.png + images/cards/9D.png + images/cards/9H.png + images/cards/9S.png + images/cards/10C.png + images/cards/10D.png + images/cards/10H.png + images/cards/10S.png + images/cards/AC.png + images/cards/AD.png + images/cards/AH.png + images/cards/AS.png + images/cards/AS2.png + images/cards/JC.png + images/cards/JD.png + images/cards/JH.png + images/cards/JS.png + images/cards/KC.png + images/cards/KD.png + images/cards/KH.png + images/cards/KS.png + images/cards/QC.png + images/cards/QD.png + images/cards/QH.png + images/cards/QS.png + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..9be5da5 --- /dev/null +++ b/main.cpp @@ -0,0 +1,23 @@ +#include "mainwindow.hpp" + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QTranslator translator; + const QStringList uiLanguages = QLocale::system().uiLanguages(); + for (const QString &locale : uiLanguages) { + const QString baseName = "Blackjack_" + QLocale(locale).name(); + if (translator.load(":/i18n/" + baseName)) { + a.installTranslator(&translator); + break; + } + } + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..cf1c1ba --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,19 @@ +#include "mainwindow.hpp" +#include "./ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) + , playwindow(new playWindow) +{ + ui->setupUi(this); + connect(ui->playButton, &QPushButton::clicked, this, [=]{ + playwindow->show(); + this->hide();}); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + diff --git a/mainwindow.hpp b/mainwindow.hpp new file mode 100644 index 0000000..4a1c4ae --- /dev/null +++ b/mainwindow.hpp @@ -0,0 +1,23 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "playwindow.hpp" + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + playWindow *playwindow; +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..f0e7b15 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,69 @@ + + + MainWindow + + + + 0 + 0 + 467 + 377 + + + + false + + + BlackJack C++ by Sani7 + + + true + + + #centralWidget { +border-image: url(:/images/bg.jpg) 0 0 0 0 stretch stretch; +} + + + + false + + + + + + + 0 + 0 + + + + Play Game + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Quit + + + + + + + diff --git a/playwindow.cpp b/playwindow.cpp new file mode 100644 index 0000000..67c9929 --- /dev/null +++ b/playwindow.cpp @@ -0,0 +1,230 @@ +#include "playwindow.hpp" +#include "ui_playwindow.h" + +#define QD qDebug() << "File:" << __FILE__ << "Function:" << __PRETTY_FUNCTION__ << "Line:" << __LINE__ << "=>" + +playWindow::playWindow(QWidget *parent) : QMainWindow(parent), + ui(new Ui::playWindow) +{ + ui->setupUi(this); + + cardToImg = { + {Card(Card::Rank::ACE, Card::Suit::CLUBS), "AC"}, + {Card(Card::Rank::TWO, Card::Suit::CLUBS), "2C"}, + {Card(Card::Rank::THREE, Card::Suit::CLUBS), "3C"}, + {Card(Card::Rank::FOUR, Card::Suit::CLUBS), "4C"}, + {Card(Card::Rank::FIVE, Card::Suit::CLUBS), "5C"}, + {Card(Card::Rank::SIX, Card::Suit::CLUBS), "6C"}, + {Card(Card::Rank::SEVEN, Card::Suit::CLUBS), "7C"}, + {Card(Card::Rank::EIGHT, Card::Suit::CLUBS), "8C"}, + {Card(Card::Rank::NINE, Card::Suit::CLUBS), "9C"}, + {Card(Card::Rank::TEN, Card::Suit::CLUBS), "10C"}, + {Card(Card::Rank::JACK, Card::Suit::CLUBS), "JC"}, + {Card(Card::Rank::QUEEN, Card::Suit::CLUBS), "QC"}, + {Card(Card::Rank::KING, Card::Suit::CLUBS), "KC"}, + {Card(Card::Rank::ACE, Card::Suit::DIAMONDS), "AD"}, + {Card(Card::Rank::TWO, Card::Suit::DIAMONDS), "2D"}, + {Card(Card::Rank::THREE, Card::Suit::DIAMONDS), "3D"}, + {Card(Card::Rank::FOUR, Card::Suit::DIAMONDS), "4D"}, + {Card(Card::Rank::FIVE, Card::Suit::DIAMONDS), "5D"}, + {Card(Card::Rank::SIX, Card::Suit::DIAMONDS), "6D"}, + {Card(Card::Rank::SEVEN, Card::Suit::DIAMONDS), "7D"}, + {Card(Card::Rank::EIGHT, Card::Suit::DIAMONDS), "8D"}, + {Card(Card::Rank::NINE, Card::Suit::DIAMONDS), "9D"}, + {Card(Card::Rank::TEN, Card::Suit::DIAMONDS), "10D"}, + {Card(Card::Rank::JACK, Card::Suit::DIAMONDS), "JD"}, + {Card(Card::Rank::QUEEN, Card::Suit::DIAMONDS), "QD"}, + {Card(Card::Rank::KING, Card::Suit::DIAMONDS), "KD"}, + {Card(Card::Rank::ACE, Card::Suit::HEARTS), "AH"}, + {Card(Card::Rank::TWO, Card::Suit::HEARTS), "2H"}, + {Card(Card::Rank::THREE, Card::Suit::HEARTS), "3H"}, + {Card(Card::Rank::FOUR, Card::Suit::HEARTS), "4H"}, + {Card(Card::Rank::FIVE, Card::Suit::HEARTS), "5H"}, + {Card(Card::Rank::SIX, Card::Suit::HEARTS), "6H"}, + {Card(Card::Rank::SEVEN, Card::Suit::HEARTS), "7H"}, + {Card(Card::Rank::EIGHT, Card::Suit::HEARTS), "8H"}, + {Card(Card::Rank::NINE, Card::Suit::HEARTS), "9H"}, + {Card(Card::Rank::TEN, Card::Suit::HEARTS), "10H"}, + {Card(Card::Rank::JACK, Card::Suit::HEARTS), "JH"}, + {Card(Card::Rank::QUEEN, Card::Suit::HEARTS), "QH"}, + {Card(Card::Rank::KING, Card::Suit::HEARTS), "KH"}, + {Card(Card::Rank::ACE, Card::Suit::SPADES), "AS"}, + {Card(Card::Rank::TWO, Card::Suit::SPADES), "2S"}, + {Card(Card::Rank::THREE, Card::Suit::SPADES), "3S"}, + {Card(Card::Rank::FOUR, Card::Suit::SPADES), "4S"}, + {Card(Card::Rank::FIVE, Card::Suit::SPADES), "5S"}, + {Card(Card::Rank::SIX, Card::Suit::SPADES), "6S"}, + {Card(Card::Rank::SEVEN, Card::Suit::SPADES), "7S"}, + {Card(Card::Rank::EIGHT, Card::Suit::SPADES), "8S"}, + {Card(Card::Rank::NINE, Card::Suit::SPADES), "9S"}, + {Card(Card::Rank::TEN, Card::Suit::SPADES), "10S"}, + {Card(Card::Rank::JACK, Card::Suit::SPADES), "JS"}, + {Card(Card::Rank::QUEEN, Card::Suit::SPADES), "QS"}, + {Card(Card::Rank::KING, Card::Suit::SPADES), "KS"}}; + + countToPlayerLabel = { + ui->card1Label, ui->card2Label, ui->card3Label, ui->card4Label, ui->card5Label, ui->card6Label, ui->card7Label, ui->card8Label, ui->card9Label, ui->card10Label + }; + + countToDealerLabel = { + ui->card10Label_2, ui->card9Label_2, ui->card8Label_2, ui->card7Label_2, ui->card6Label_2, ui->card5Label_2, ui->card4Label_2, ui->card3Label_2, ui->card2Label_2, ui->card1Label_2 + }; + + deck = std::make_unique(); + player = std::make_unique(); + dealer = std::make_unique(); + + deck->shuffledeck(); + + connect(ui->twistButton, &QPushButton::clicked, this, [=] + { playerTurn(); }); + connect(ui->stickButton, &QPushButton::clicked, this, [=] + { + // To prevent users from activating function before the function ending. + this->setEnabled(false); + ui->statusLabel->setText("Stick"); + ui->playagainButton->setEnabled(true); + ui->twistButton->setEnabled(false); + ui->stickButton->setEnabled(false); + + //Generating Computer score + computerTurn(); + }); + + connect(ui->playagainButton, &QPushButton::clicked, this, [=]{reset();}); + + turnCount = 0; + computerTurnCount = 0; + player_wins = 0; + computer_wins = 0; +} + +void playWindow::playerTurn(void) +{ + if (turnCount > 9) + return; + player->addCard(deck->drawCard()); + + QPixmap img = QPixmap(":/images/cards/" + cardToImg[player->getLastCard()] + ".png"); + + img = img.scaled(ui->card10Label->size().width(), ui->card10Label->size().height(), Qt::KeepAspectRatio); + + countToPlayerLabel[turnCount]->setPixmap(img); + + ui->playertotalLabel->setText("Total: " + QString::number(player->getHandValue())); + + turnCount++; + + // if player bust + if (player->getHandValue() > 21) + { + ui->statusLabel->setText("Bust!"); + ui->twistButton->setEnabled(false); + + // Generating Computer score + computerTurn(); + return; + } + if (player->getHandValue() > 15) + { + ui->stickButton->setEnabled(true); + return; + } + if (player->getHandValue() <= 15) + { + ui->stickButton->setEnabled(false); + ui->playagainButton->setEnabled(true); + } +} + +void playWindow::computerTurn(void) +{ + QPixmap win(":/images/win.png"); + QPixmap lose(":/images/lose.png"); + QPixmap draw(":/images/draw.png"); + + while (dealer->getHandValue() < 16){ + dealer->addCard(deck->drawCard()); + QPixmap img = QPixmap(":/images/cards/" + cardToImg[dealer->getLastCard()] + ".png"); + img = img.scaled(ui->card10Label->size().width(), ui->card10Label->size().height(), Qt::KeepAspectRatio); + + ui->computerScoreLabel->setText("Computer: " + QString::number(dealer->getHandValue())); + + countToDealerLabel[computerTurnCount]->setPixmap(img); + + computerTurnCount++; + } + + //if computer is bust + ui->computerStatusLabel->setText(dealer->getHandValue() > 21 ? "Bust!" : "Stick"); + + // if same score or both bust + if ((dealer->getHandValue() == player->getHandValue()) || ((dealer->getHandValue() > 21) && (player->getHandValue() > 21))){ + ui->outcomeLabel->setPixmap(draw); + } + // if both players are not bust AND computer is larger than player + else if ( + ((dealer->getHandValue() < 22) && (player->getHandValue() < 22) + && (dealer->getHandValue() > player->getHandValue())) + || ((player->getHandValue() > 21) && dealer->getHandValue() < 22 )){ + ui->outcomeLabel->setPixmap(lose);; + computer_wins++; + } + // else, player wins + else{ + ui->outcomeLabel->setPixmap(win); + player_wins++; + } + ui->statusbar->showMessage("Player " + QString::number(player_wins) + " - Gamescore - " + "Computer " + QString::number(computer_wins)); + this->setEnabled(true); +} + +void playWindow::reset(void) +{ + deck.reset(new Deck()); + player.reset(new Player()); + dealer.reset(new Player()); + + deck->shuffledeck(); + + //Clear Labels and Variables + turnCount = 0; + computerTurnCount = 0; + + ui->playertotalLabel->setText("Total: " + QString::number(0)); + + ui->twistButton->setEnabled(true); + ui->playagainButton->setEnabled(false); + ui->stickButton->setEnabled(false); + ui->outcomeLabel->clear(); + ui->computerStatusLabel->setText(""); + ui->statusLabel->setText(""); + ui->computerScoreLabel->setText("Computer: " + QString::number(0)); + + // Clear Cards from player table + ui->card1Label->clear(); + ui->card2Label->clear(); + ui->card3Label->clear(); + ui->card4Label->clear(); + ui->card5Label->clear(); + ui->card6Label->clear(); + ui->card8Label->clear(); + ui->card9Label->clear(); + ui->card10Label->clear(); + + ui->card10Label_2->clear(); + ui->card9Label_2->clear(); + ui->card8Label_2->clear(); + ui->card7Label_2->clear(); + ui->card6Label_2->clear(); + ui->card5Label_2->clear(); + ui->card4Label_2->clear(); + ui->card3Label_2->clear(); + ui->card2Label_2->clear(); + ui->card1Label_2->clear(); +} + +playWindow::~playWindow() +{ + delete ui; +} diff --git a/playwindow.hpp b/playwindow.hpp new file mode 100644 index 0000000..1a1b740 --- /dev/null +++ b/playwindow.hpp @@ -0,0 +1,61 @@ +#ifndef PLAYWINDOW_HPP +#define PLAYWINDOW_HPP + +#include +#include +#include +#include + +#include "Deck.hpp" +#include "Player.hpp" + +namespace Ui +{ + class playWindow; +} + + template <> + struct std::hash + { + std::size_t operator()(const Card& k) const + { + using std::size_t; + using std::hash; + using std::string; + + // Compute individual hash values for first, + // second and third and combine them using XOR + // and bit shifting: + + return ((hash()((int)k.getRank()) + ^ (hash()((int)k.getSuit()) << 1)) >> 1); + } + }; + +class playWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit playWindow(QWidget *parent = nullptr); + ~playWindow(); + void playerTurn(void); + void computerTurn(void); + void reset(void); +private: + Ui::playWindow *ui; + + std::unordered_map cardToImg; + QList countToPlayerLabel; + QList countToDealerLabel; + + std::unique_ptr deck; + std::unique_ptr dealer; + std::unique_ptr player; + uint8_t turnCount; + uint8_t computerTurnCount; + int player_wins; + int computer_wins; +}; + +#endif // PLAYWINDOW_HPP diff --git a/playwindow.ui b/playwindow.ui new file mode 100644 index 0000000..226cc62 --- /dev/null +++ b/playwindow.ui @@ -0,0 +1,870 @@ + + + playWindow + + + + 0 + 0 + 1169 + 546 + + + + BlackJack C++ by Sani7 + + + true + + + #centralWidget { +border-image:url(:/images/blackjack_table.png) 0 0 0 0 stretch stretch; +} + + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + + 16 + true + + + + You + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + + 16 + true + + + + Computer + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 40 + + + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + + + + + + + + + + + + 0 + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + 0 + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + 1 + 1 + + + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 40 + + + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + Total: 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + + Computer: + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 40 + + + + + + + + + 800 + 500 + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Play Again + + + + + + + Twist + + + + + + + Stick + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + +