├── .craft.ini ├── .flatpak-manifest.json ├── .flatpak-manifest.json.license ├── .gitignore ├── .gitlab-ci.yml ├── .kde-ci.yml ├── CMakeLists.txt ├── CMakePresets.json ├── CMakePresets.json.license ├── COPYING ├── COPYING.DOC ├── LICENSES ├── BSD-3-Clause.txt └── GPL-2.0-or-later.txt ├── README.PACKAGERS ├── autotests ├── CMakeLists.txt ├── basic.cpp ├── test_KBlocksGameLogic.cpp ├── test_KBlocksItemGroup.cpp ├── test_KBlocksScene.cpp ├── test_KBlocksWin.cpp └── test_View-Scene.cpp ├── cmake └── InternalMacros.cmake ├── default.conf ├── doc ├── CMakeLists.txt ├── gameboard.png └── index.docbook ├── icons ├── 128-apps-kblocks.png ├── 16-apps-kblocks.png ├── 22-apps-kblocks.png ├── 32-apps-kblocks.png ├── 48-apps-kblocks.png ├── 64-apps-kblocks.png └── CMakeLists.txt ├── kblocks.knsrc ├── logo.png ├── po ├── ar │ └── kblocks.po ├── ast │ └── kblocks.po ├── bg │ └── kblocks.po ├── bs │ └── kblocks.po ├── ca │ ├── docs │ │ └── kblocks │ │ │ ├── gameboard.png │ │ │ └── index.docbook │ └── kblocks.po ├── ca@valencia │ └── kblocks.po ├── cs │ └── kblocks.po ├── da │ └── kblocks.po ├── de │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── el │ └── kblocks.po ├── en_GB │ └── kblocks.po ├── eo │ └── kblocks.po ├── es │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── et │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── eu │ └── kblocks.po ├── fi │ └── kblocks.po ├── fr │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── ga │ └── kblocks.po ├── gl │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── gu │ └── kblocks.po ├── he │ └── kblocks.po ├── hi │ └── kblocks.po ├── hr │ └── kblocks.po ├── hu │ └── kblocks.po ├── ia │ └── kblocks.po ├── id │ └── kblocks.po ├── is │ └── kblocks.po ├── it │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── ja │ └── kblocks.po ├── ka │ └── kblocks.po ├── kk │ └── kblocks.po ├── km │ └── kblocks.po ├── ko │ └── kblocks.po ├── lt │ └── kblocks.po ├── lv │ └── kblocks.po ├── mai │ └── kblocks.po ├── ml │ └── kblocks.po ├── mr │ └── kblocks.po ├── nb │ └── kblocks.po ├── nds │ └── kblocks.po ├── nl │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── nn │ └── kblocks.po ├── pl │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── pt │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── pt_BR │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── ro │ └── kblocks.po ├── ru │ └── kblocks.po ├── sa │ └── kblocks.po ├── sk │ └── kblocks.po ├── sl │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── sq │ └── kblocks.po ├── sr │ └── kblocks.po ├── sr@ijekavian │ └── kblocks.po ├── sr@ijekavianlatin │ └── kblocks.po ├── sr@latin │ └── kblocks.po ├── sv │ ├── docs │ │ └── kblocks │ │ │ └── index.docbook │ └── kblocks.po ├── th │ └── kblocks.po ├── tr │ └── kblocks.po ├── ug │ └── kblocks.po ├── uk │ ├── docs │ │ └── kblocks │ │ │ ├── gameboard.png │ │ │ └── index.docbook │ └── kblocks.po ├── zh_CN │ └── kblocks.po └── zh_TW │ └── kblocks.po ├── snapcraft.yaml ├── sounds ├── CMakeLists.txt ├── block-fall.ogg ├── block-move.ogg └── block-remove.ogg ├── src ├── AI │ ├── EvaluationInterface.h │ ├── KBlocksAIEvaluation.cpp │ ├── KBlocksAIEvaluation.h │ ├── KBlocksAIFeature.cpp │ ├── KBlocksAIFeature.h │ ├── KBlocksAILog.cpp │ ├── KBlocksAILog.h │ ├── KBlocksAIPlanner.cpp │ ├── KBlocksAIPlanner.h │ ├── KBlocksAIPlannerExtend.cpp │ ├── KBlocksAIPlannerExtend.h │ ├── KBlocksAIPlayer.cpp │ ├── KBlocksAIPlayer.h │ ├── KBlocksAITypeDefine.h │ └── PlannerInterface.h ├── CMakeLists.txt ├── FieldInterface.h ├── GameLogicInterface.cpp ├── GameLogicInterface.h ├── GamePlayerInterface.h ├── GraphicsInterface.h ├── KBlocksAnimDrop.cpp ├── KBlocksAnimDrop.h ├── KBlocksAnimFade.cpp ├── KBlocksAnimFade.h ├── KBlocksAnimator.cpp ├── KBlocksAnimator.h ├── KBlocksAppThread.cpp ├── KBlocksAppThread.h ├── KBlocksConfigManager.cpp ├── KBlocksConfigManager.h ├── KBlocksDefine.cpp ├── KBlocksDefine.h ├── KBlocksDisplay.cpp ├── KBlocksDisplay.h ├── KBlocksDummyAI.cpp ├── KBlocksDummyAI.h ├── KBlocksField.cpp ├── KBlocksField.h ├── KBlocksGameLogic.cpp ├── KBlocksGameLogic.h ├── KBlocksGameMessage.cpp ├── KBlocksGameMessage.h ├── KBlocksGameRecorder.cpp ├── KBlocksGameRecorder.h ├── KBlocksGameReplayer.cpp ├── KBlocksGameReplayer.h ├── KBlocksGraphics.cpp ├── KBlocksGraphics.h ├── KBlocksItemGroup.cpp ├── KBlocksItemGroup.h ├── KBlocksKeyboardPlayer.cpp ├── KBlocksKeyboardPlayer.h ├── KBlocksLayout.cpp ├── KBlocksLayout.h ├── KBlocksNetClient.cpp ├── KBlocksNetClient.h ├── KBlocksNetPlayer.cpp ├── KBlocksNetPlayer.h ├── KBlocksNetServer.cpp ├── KBlocksNetServer.h ├── KBlocksPiece.cpp ├── KBlocksPiece.h ├── KBlocksPieceGenerator.cpp ├── KBlocksPieceGenerator.h ├── KBlocksPlayManager.cpp ├── KBlocksPlayManager.h ├── KBlocksPlayNetwork.cpp ├── KBlocksPlayNetwork.h ├── KBlocksRepWin.cpp ├── KBlocksRepWin.h ├── KBlocksScene.cpp ├── KBlocksScene.h ├── KBlocksScore.cpp ├── KBlocksScore.h ├── KBlocksSingleGame.cpp ├── KBlocksSingleGame.h ├── KBlocksSinglePlayer.cpp ├── KBlocksSinglePlayer.h ├── KBlocksSound.cpp ├── KBlocksSound.h ├── KBlocksSvgItem.cpp ├── KBlocksSvgItem.h ├── KBlocksTheme.cpp ├── KBlocksTheme.h ├── KBlocksView.cpp ├── KBlocksView.h ├── KBlocksWin.cpp ├── KBlocksWin.h ├── Messages.sh ├── PieceInterface.h ├── SceneInterface.cpp ├── SceneInterface.h ├── SingleGameInterface.h ├── SoundInterface.h ├── SvgItemInterface.h ├── Testing │ ├── CMakeLists.txt │ ├── MockField.h │ ├── MockGameLogic.h │ ├── MockGraphics.h │ ├── MockPiece.h │ ├── MockScene.h │ ├── MockSingleGame.h │ ├── MockSound.h │ ├── MockSvgItem.h │ ├── TestingKBlocksItemGroup.h │ ├── TestingKBlocksWin.cpp │ └── TestingKBlocksWin.h ├── config │ ├── kblocks.kcfg │ └── settings.kcfgc ├── kblocks.qrc ├── kblocksui.rc ├── main.cpp ├── org.kde.kblocks.appdata.xml ├── org.kde.kblocks.desktop ├── utils.cpp └── utils.h └── themes ├── CMakeLists.txt ├── default.desktop ├── default_block_fall.ogg ├── default_block_move.ogg ├── egyptian.svg ├── egyptian_preview.png ├── oxygen.desktop ├── oxygen.svg └── oxygen_preview.png /.craft.ini: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Laurent Montel 2 | # SPDX-License-Identifier: CC0-1.0 3 | 4 | [BlueprintSettings] 5 | kde/kdegames/klines/klines.packageAppx=True 6 | kde/kdegames.version=master 7 | -------------------------------------------------------------------------------- /.flatpak-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "org.kde.kblocks", 3 | "runtime": "org.kde.Platform", 4 | "runtime-version": "6.8", 5 | "sdk": "org.kde.Sdk", 6 | "command": "kblocks", 7 | "rename-icon": "kblocks", 8 | "finish-args": [ 9 | "--share=ipc", 10 | "--socket=fallback-x11", 11 | "--socket=wayland", 12 | "--socket=pulseaudio", 13 | "--device=dri" 14 | ], 15 | "modules": [ 16 | { 17 | "name": "libkdegames", 18 | "buildsystem": "cmake-ninja", 19 | "sources": [ 20 | { 21 | "type": "git", 22 | "url": "https://invent.kde.org/games/libkdegames", 23 | "branch": "master" 24 | } 25 | ] 26 | }, 27 | { 28 | "name": "kblocks", 29 | "buildsystem": "cmake-ninja", 30 | "sources": [ 31 | { 32 | "type": "dir", 33 | "path": "." 34 | } 35 | ] 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /.flatpak-manifest.json.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: None 2 | # SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: CC0-1.0 2 | # SPDX-FileCopyrightText: none 3 | .kdev4/ 4 | /build*/ 5 | *.kdev4 6 | CMakeLists.txt.user* 7 | .cmake/ 8 | /.clang-format 9 | /compile_commands.json 10 | .clangd 11 | .cache 12 | .idea 13 | /cmake-build* 14 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: None 2 | # SPDX-License-Identifier: CC0-1.0 3 | 4 | include: 5 | - project: sysadmin/ci-utilities 6 | file: 7 | - /gitlab-templates/linux-qt6.yml 8 | - /gitlab-templates/linux-qt6-next.yml 9 | - /gitlab-templates/freebsd-qt6.yml 10 | - /gitlab-templates/windows-qt6.yml 11 | - /gitlab-templates/flatpak.yml 12 | - /gitlab-templates/craft-windows-x86-64-qt6.yml 13 | - /gitlab-templates/craft-windows-appx-qt6.yml 14 | - /gitlab-templates/craft-macos-x86-64-qt6.yml 15 | - /gitlab-templates/craft-macos-arm64-qt6.yml 16 | - /gitlab-templates/xml-lint.yml 17 | - /gitlab-templates/yaml-lint.yml 18 | -------------------------------------------------------------------------------- /.kde-ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: None 2 | # SPDX-License-Identifier: CC0-1.0 3 | 4 | Dependencies: 5 | - 'on': ['Linux', 'FreeBSD', 'Windows', 'Android'] 6 | 'require': 7 | 'frameworks/extra-cmake-modules': '@latest-kf6' 8 | 'frameworks/kconfig': '@latest-kf6' 9 | 'frameworks/kconfigwidgets': '@latest-kf6' 10 | 'frameworks/kcoreaddons': '@latest-kf6' 11 | 'frameworks/kcrash': '@latest-kf6' 12 | 'frameworks/kdoctools': '@latest-kf6' 13 | 'frameworks/kdbusaddons': '@latest-kf6' 14 | 'frameworks/ki18n': '@latest-kf6' 15 | 'frameworks/kwidgetsaddons': '@latest-kf6' 16 | 'frameworks/kxmlgui': '@latest-kf6' 17 | 'frameworks/kiconthemes': '@latest-kf6' 18 | 'games/libkdegames': '@same' 19 | 20 | Options: 21 | require-passing-tests-on: ['@all'] 22 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16 FATAL_ERROR) 2 | 3 | # KDE Application Version, managed by release script 4 | set(RELEASE_SERVICE_VERSION_MAJOR "25") 5 | set(RELEASE_SERVICE_VERSION_MINOR "07") 6 | set(RELEASE_SERVICE_VERSION_MICRO "70") 7 | set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}") 8 | 9 | project(kblocks VERSION ${RELEASE_SERVICE_VERSION}) 10 | 11 | set(QT_MIN_VERSION "6.5.0") 12 | set(KF_MIN_VERSION "6.0.0") 13 | 14 | find_package(ECM ${KF_MIN_VERSION} REQUIRED CONFIG) 15 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ECM_MODULE_PATH}) 16 | 17 | include(KDEInstallDirs) 18 | include(KDECMakeSettings) 19 | include(KDECompilerSettings NO_POLICY_SCOPE) 20 | 21 | include(ECMAddAppIcon) 22 | include(ECMAddTests) 23 | include(ECMQtDeclareLoggingCategory) 24 | include(ECMSetupVersion) 25 | include(ECMInstallIcons) 26 | include(FeatureSummary) 27 | include(InternalMacros) 28 | include(ECMDeprecationSettings) 29 | 30 | find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS 31 | Network 32 | Svg 33 | SvgWidgets 34 | Test 35 | Widgets 36 | ) 37 | 38 | find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS 39 | Config 40 | ConfigWidgets 41 | CoreAddons 42 | Crash 43 | DocTools 44 | DBusAddons 45 | I18n 46 | WidgetsAddons 47 | XmlGui 48 | IconThemes 49 | ) 50 | 51 | find_package(KDEGames6 6.0.0 REQUIRED) 52 | 53 | ecm_set_disabled_deprecation_versions( 54 | QT 6.9.0 55 | KF 6.14.0 56 | KDEGAMES 6.0 57 | ) 58 | 59 | add_subdirectory(icons) 60 | add_subdirectory(themes) 61 | add_subdirectory(sounds) 62 | add_subdirectory(doc) 63 | add_subdirectory(src) 64 | 65 | if(BUILD_TESTING) 66 | add_subdirectory(autotests) 67 | endif() 68 | 69 | ki18n_install(po) 70 | kdoctools_install(po) 71 | 72 | install(FILES kblocks.knsrc DESTINATION ${KDE_INSTALL_DATADIR}/knsrcfiles) 73 | 74 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) 75 | -------------------------------------------------------------------------------- /CMakePresets.json.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Laurent Montel 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without 15 | specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 26 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.PACKAGERS: -------------------------------------------------------------------------------- 1 | EXTENDED 2 | -------------------------------------------------------------------------------- /autotests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ecm_add_test( 2 | basic.cpp 3 | TEST_NAME basic 4 | LINK_LIBRARIES Qt6::Test 5 | NAME_PREFIX "UnitTest-" 6 | ) 7 | 8 | ecm_add_test( 9 | test_KBlocksGameLogic.cpp 10 | TEST_NAME KBlocksGameLogic 11 | LINK_LIBRARIES Qt6::Test KBlocksCore 12 | NAME_PREFIX "UnitTest-" 13 | ) 14 | 15 | ecm_add_test( 16 | test_KBlocksItemGroup.cpp 17 | TEST_NAME KBlocksItemGroup 18 | LINK_LIBRARIES Qt6::Test KBlocksCore 19 | NAME_PREFIX "UnitTest-" 20 | ) 21 | 22 | ecm_add_test( 23 | test_KBlocksScene.cpp 24 | TEST_NAME KBlocksScene 25 | LINK_LIBRARIES Qt6::Test KBlocksCore 26 | NAME_PREFIX "UnitTest-" 27 | ) 28 | 29 | ecm_add_test( 30 | test_KBlocksWin.cpp 31 | TEST_NAME KBlocksWin 32 | LINK_LIBRARIES Qt6::Test KBlocksCore KBlocksTesting 33 | NAME_PREFIX "UnitTest-" 34 | ) 35 | 36 | ecm_add_test( 37 | test_View-Scene.cpp 38 | TEST_NAME View-Scene 39 | LINK_LIBRARIES Qt6::Test KBlocksCore 40 | NAME_PREFIX "IntegrationTest-" 41 | ) 42 | -------------------------------------------------------------------------------- /autotests/basic.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include 8 | 9 | class testBasic : public QObject 10 | { 11 | Q_OBJECT 12 | private Q_SLOTS: 13 | void testAlwaysSuccessful(); 14 | }; 15 | 16 | void testBasic::testAlwaysSuccessful() 17 | { 18 | QVERIFY( true ); 19 | } 20 | 21 | QTEST_MAIN(testBasic) 22 | 23 | #include "basic.moc" 24 | -------------------------------------------------------------------------------- /autotests/test_KBlocksGameLogic.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #include 8 | 9 | #include "KBlocksGameLogic.h" 10 | 11 | class testKBlocksGameLogic : public QObject 12 | { 13 | Q_OBJECT 14 | private Q_SLOTS: 15 | void test_hasSingleGames(); 16 | }; 17 | 18 | void testKBlocksGameLogic::test_hasSingleGames() 19 | { 20 | /** 21 | * KBlocksGameLogic::hasSingleGames() should return true if single 22 | * games have been created and false otherwise. 23 | */ 24 | KBlocksGameLogic gameLogic(1); 25 | QVERIFY(!gameLogic.hasSingleGames()); 26 | gameLogic.startGame(1); 27 | QVERIFY(gameLogic.hasSingleGames()); 28 | gameLogic.deleteSingleGames(); 29 | QVERIFY(!gameLogic.hasSingleGames()); 30 | 31 | gameLogic.startGame(0); 32 | QVERIFY(!gameLogic.hasSingleGames()); 33 | } 34 | 35 | QTEST_MAIN(testKBlocksGameLogic) 36 | 37 | #include "test_KBlocksGameLogic.moc" 38 | -------------------------------------------------------------------------------- /autotests/test_KBlocksScene.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #include 8 | 9 | #include "KBlocksScene.h" 10 | #include "Testing/MockGameLogic.h" 11 | #include "Testing/MockGraphics.h" 12 | #include "Testing/MockSound.h" 13 | 14 | class testKBlocksScene : public QObject 15 | { 16 | Q_OBJECT 17 | private Q_SLOTS: 18 | void redundantCallsToDeleteGameItemGroupsShouldBeAllowed(); 19 | }; 20 | 21 | void testKBlocksScene::redundantCallsToDeleteGameItemGroupsShouldBeAllowed() 22 | { 23 | /** 24 | * The method deleteGameItemGroups() should remove all existing 25 | * KBlocksItemGroup objects as well as the message box. It should 26 | * be valid to call deleteGameItemGroups() multiple times under all 27 | * circumstances. 28 | * 29 | * Currently, this test is only a should-not-crash test. It does not 30 | * verify that the game item groups are indeed deleted. 31 | */ 32 | MockGameLogic gameLogic; 33 | MockGraphics graphics; 34 | MockSound sound; 35 | KBlocksScene scene(&gameLogic, &graphics, &sound); 36 | 37 | scene.deleteGameItemGroups(); 38 | scene.deleteGameItemGroups(); 39 | scene.createGameItemGroups(1); 40 | scene.deleteGameItemGroups(); 41 | scene.deleteGameItemGroups(); 42 | } 43 | 44 | QTEST_MAIN(testKBlocksScene) 45 | 46 | #include "test_KBlocksScene.moc" 47 | -------------------------------------------------------------------------------- /autotests/test_KBlocksWin.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #include 8 | 9 | #include "KBlocksGameLogic.h" 10 | #include "KBlocksWin.h" 11 | #include "Testing/MockGameLogic.h" 12 | #include "Testing/MockGraphics.h" 13 | #include "Testing/MockScene.h" 14 | #include "Testing/MockSound.h" 15 | #include "Testing/TestingKBlocksWin.h" 16 | 17 | class testKBlocksWin : public QObject 18 | { 19 | Q_OBJECT 20 | private Q_SLOTS: 21 | void callStopGameBeforeSingleGamesAreDeleted(); 22 | }; 23 | 24 | void testKBlocksWin::callStopGameBeforeSingleGamesAreDeleted() 25 | { 26 | /** 27 | * The KBlocksItemGroups which are part of KBlocksScene contain a 28 | * pointer to the single game(s). Thus, KBlocksScene should not 29 | * be used after the single games have been deleted. This is in 30 | * particular true for the stopGame() method which processes the 31 | * final game action items. 32 | */ 33 | MockGameLogic logic; 34 | MockGraphics graphics; 35 | MockSound sound; 36 | TestingKBlocksWin win(&logic, &graphics, &sound, nullptr, nullptr, 0, 0); 37 | MockScene *scene = new MockScene(&logic); 38 | win.replaceScene(scene); 39 | win.callStopGame(); 40 | QVERIFY(!scene->singleGameDeletedWhenStopGameCalled); 41 | } 42 | 43 | QTEST_MAIN(testKBlocksWin) 44 | 45 | #include "test_KBlocksWin.moc" 46 | -------------------------------------------------------------------------------- /autotests/test_View-Scene.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #include 8 | 9 | #include "KBlocksScene.h" 10 | #include "KBlocksView.h" 11 | #include "Testing/MockGameLogic.h" 12 | #include "Testing/MockScene.h" 13 | 14 | class testViewScene : public QObject 15 | { 16 | Q_OBJECT 17 | private Q_SLOTS: 18 | void test_settingsShouldBeUpdatedInViewAndScene(); 19 | }; 20 | 21 | void testViewScene::test_settingsShouldBeUpdatedInViewAndScene() 22 | { 23 | /** 24 | * When the settings are updated for the View, the new settings 25 | * should also be read in the scene to make sure the scene fits 26 | * the view exactly. 27 | */ 28 | MockGameLogic gameLogic; 29 | MockScene scene(&gameLogic); 30 | KBlocksView view(&scene); 31 | view.settingsChanged(); 32 | QVERIFY(scene.readSettingsCalled); 33 | } 34 | 35 | QTEST_MAIN(testViewScene) 36 | 37 | #include "test_View-Scene.moc" 38 | -------------------------------------------------------------------------------- /cmake/InternalMacros.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2022 Friedrich W. H. Kossebau 2 | # 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | if(WIN32) 6 | find_package(7z) 7 | set_package_properties(7z PROPERTIES 8 | TYPE REQUIRED 9 | PURPOSE "For installing SVG files as SVGZ" 10 | ) 11 | else() 12 | find_package(gzip) 13 | set_package_properties(gzip PROPERTIES 14 | TYPE REQUIRED 15 | PURPOSE "For installing SVG files as SVGZ" 16 | ) 17 | endif() 18 | 19 | 20 | function(generate_svgz svg_file svgz_file target_prefix) 21 | if (NOT IS_ABSOLUTE ${svg_file}) 22 | set(svg_file "${CMAKE_CURRENT_SOURCE_DIR}/${svg_file}") 23 | endif() 24 | if (NOT EXISTS ${svg_file}) 25 | message(FATAL_ERROR "No such file found: ${svg_file}") 26 | endif() 27 | get_filename_component(_fileName "${svg_file}" NAME) 28 | 29 | if(WIN32) 30 | add_custom_command( 31 | OUTPUT ${svgz_file} 32 | COMMAND 7z::7z 33 | ARGS 34 | a 35 | -tgzip 36 | ${svgz_file} ${svg_file} 37 | DEPENDS ${svg_file} 38 | COMMENT "Gzipping ${_fileName}" 39 | ) 40 | else() 41 | add_custom_command( 42 | OUTPUT ${svgz_file} 43 | COMMAND ${gzip_EXECUTABLE} 44 | ARGS 45 | -9n 46 | -c 47 | ${svg_file} > ${svgz_file} 48 | DEPENDS ${svg_file} 49 | COMMENT "Gzipping ${_fileName}" 50 | ) 51 | endif() 52 | 53 | add_custom_target("${target_prefix}${_fileName}z" ALL DEPENDS ${svgz_file}) 54 | endfunction() 55 | -------------------------------------------------------------------------------- /default.conf: -------------------------------------------------------------------------------- 1 | [Engine] 2 | GameCount=2 3 | SameSequence=true 4 | HasAttack=true 5 | Synchronized=true 6 | HasHuman=false 7 | SendLimit=false 8 | ServerIP=127.0.0.1:10086 9 | 10 | [Gui] 11 | GameCount=2 12 | GamesPerLine=4 13 | UpdateInterval=1000 14 | ServerIP=127.0.0.1:10086 15 | LocalPort=10088 16 | 17 | [Player] 18 | PlayerCount=2 19 | PlayerType1=AI 20 | PlayerName1=DomesticAI1 21 | PlayerType2=AI 22 | PlayerName2=DomesticAI2 23 | PlayerType3=AI 24 | PlayerName3=DomesticAI3 25 | PlayerType4=AI 26 | PlayerName4=DomesticAI4 27 | PlayerType5=AI 28 | PlayerName5=DomesticAI5 29 | PlayerType6=AI 30 | PlayerName6=DomesticAI6 31 | PlayerType7=AI 32 | PlayerName7=DomesticAI7 33 | PlayerType8=AI 34 | PlayerName8=DomesticAI8 35 | ServerIP=127.0.0.1:10086 36 | LocalPort=10090 37 | 38 | [RecordReplay] 39 | GamesPerLine=4 40 | Theme=default.svg 41 | UpdateInterval=10 42 | StepLength=10 43 | #SnapshotFolder=./snapshot/ 44 | #SnapshotFile=kblocks 45 | Record=lastRecord.kbr 46 | Type=Binary 47 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ########### install files ############### 2 | # 3 | # 4 | kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en SUBDIR kblocks) 5 | -------------------------------------------------------------------------------- /doc/gameboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/doc/gameboard.png -------------------------------------------------------------------------------- /icons/128-apps-kblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/icons/128-apps-kblocks.png -------------------------------------------------------------------------------- /icons/16-apps-kblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/icons/16-apps-kblocks.png -------------------------------------------------------------------------------- /icons/22-apps-kblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/icons/22-apps-kblocks.png -------------------------------------------------------------------------------- /icons/32-apps-kblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/icons/32-apps-kblocks.png -------------------------------------------------------------------------------- /icons/48-apps-kblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/icons/48-apps-kblocks.png -------------------------------------------------------------------------------- /icons/64-apps-kblocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/icons/64-apps-kblocks.png -------------------------------------------------------------------------------- /icons/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ecm_install_icons(ICONS 2 | 16-apps-kblocks.png 3 | 22-apps-kblocks.png 4 | 32-apps-kblocks.png 5 | 48-apps-kblocks.png 6 | 64-apps-kblocks.png 7 | 128-apps-kblocks.png 8 | DESTINATION ${KDE_INSTALL_ICONDIR} 9 | THEME hicolor 10 | ) 11 | -------------------------------------------------------------------------------- /kblocks.knsrc: -------------------------------------------------------------------------------- 1 | [KNewStuff3] 2 | ProvidersUrl=https://autoconfig.kde.org/ocs/providers.xml 3 | Categories=KBlocks Themes 4 | TargetDir=kblocks/themes 5 | Uncompress=always 6 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/logo.png -------------------------------------------------------------------------------- /po/ast/kblocks.po: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 This file is copyright: 2 | # This file is distributed under the same license as the kblocks package. 3 | # 4 | # SPDX-FileCopyrightText: 2023 Enol P. 5 | msgid "" 6 | msgstr "" 7 | "Project-Id-Version: kblocks\n" 8 | "Report-Msgid-Bugs-To: https://bugs.kde.org\n" 9 | "POT-Creation-Date: 2024-11-22 00:38+0000\n" 10 | "PO-Revision-Date: 2023-11-07 01:10+0100\n" 11 | "Last-Translator: Enol P. \n" 12 | "Language-Team: \n" 13 | "Language: ast\n" 14 | "MIME-Version: 1.0\n" 15 | "Content-Type: text/plain; charset=UTF-8\n" 16 | "Content-Transfer-Encoding: 8bit\n" 17 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 18 | "X-Generator: Lokalize 23.08.2\n" 19 | 20 | #, kde-format 21 | msgctxt "NAME OF TRANSLATORS" 22 | msgid "Your names" 23 | msgstr "Softastur" 24 | 25 | #, kde-format 26 | msgctxt "EMAIL OF TRANSLATORS" 27 | msgid "Your emails" 28 | msgstr "alministradores@softastur.org" 29 | 30 | #. i18n: ectx: label, entry (Theme), group (General) 31 | #: config/kblocks.kcfg:9 32 | #, kde-format 33 | msgid "The graphical theme to be used." 34 | msgstr "" 35 | 36 | #. i18n: ectx: label, entry (Sounds), group (Preferences) 37 | #: config/kblocks.kcfg:14 38 | #, kde-format 39 | msgid "Whether sound effects should be played." 40 | msgstr "" 41 | 42 | #: KBlocksDisplay.cpp:58 43 | #, kde-format 44 | msgid "Score List : 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0" 45 | msgstr "" 46 | 47 | #: KBlocksDisplay.cpp:120 48 | #, kde-format 49 | msgid "Score List : %1 - %2 - %3 - %4 - %5 - %6 - %7 - %8" 50 | msgstr "" 51 | 52 | #: KBlocksKeyboardPlayer.cpp:76 53 | #, kde-format 54 | msgctxt "@action" 55 | msgid "Rotate Piece Clockwise" 56 | msgstr "" 57 | 58 | #: KBlocksKeyboardPlayer.cpp:82 59 | #, kde-format 60 | msgctxt "@action" 61 | msgid "Rotate Piece Counterclockwise" 62 | msgstr "" 63 | 64 | #: KBlocksKeyboardPlayer.cpp:88 65 | #, kde-format 66 | msgctxt "@action" 67 | msgid "Move Piece Left" 68 | msgstr "" 69 | 70 | #: KBlocksKeyboardPlayer.cpp:94 71 | #, kde-format 72 | msgctxt "@action" 73 | msgid "Move Piece Right" 74 | msgstr "" 75 | 76 | #: KBlocksKeyboardPlayer.cpp:100 77 | #, kde-format 78 | msgctxt "@action" 79 | msgid "Move Piece Down" 80 | msgstr "" 81 | 82 | #: KBlocksKeyboardPlayer.cpp:106 83 | #, kde-format 84 | msgctxt "@action" 85 | msgid "Drop the Piece" 86 | msgstr "" 87 | 88 | #: KBlocksScene.cpp:216 89 | #, kde-format 90 | msgid "Game Resumed!" 91 | msgstr "" 92 | 93 | #: KBlocksScene.cpp:217 94 | #, kde-format 95 | msgid "Game Paused!" 96 | msgstr "" 97 | 98 | #: KBlocksScene.cpp:271 99 | #, kde-format 100 | msgid "Game Start!" 101 | msgstr "" 102 | 103 | #: KBlocksScene.cpp:277 104 | #, kde-format 105 | msgid "Game Over!" 106 | msgstr "" 107 | 108 | #: KBlocksScene.cpp:283 109 | #, kde-format 110 | msgid "You Win!" 111 | msgstr "" 112 | 113 | #: KBlocksScene.cpp:289 114 | #, kde-format 115 | msgid "You Lose!" 116 | msgstr "" 117 | 118 | #. i18n: ectx: ToolBar (mainToolBar) 119 | #: kblocksui.rc:24 120 | #, kde-format 121 | msgid "Main Toolbar" 122 | msgstr "" 123 | 124 | #: KBlocksWin.cpp:145 KBlocksWin.cpp:249 125 | #, kde-format 126 | msgid "Points: %1 - Lines: %2 - Level: %3" 127 | msgstr "" 128 | 129 | #: KBlocksWin.cpp:290 130 | #, kde-format 131 | msgctxt "@action" 132 | msgid "Single Game" 133 | msgstr "" 134 | 135 | #: KBlocksWin.cpp:294 136 | #, kde-format 137 | msgctxt "@action" 138 | msgid "Human vs AI" 139 | msgstr "" 140 | 141 | #: KBlocksWin.cpp:313 142 | #, kde-format 143 | msgctxt "@option:check" 144 | msgid "Play Sounds" 145 | msgstr "" 146 | 147 | #: KBlocksWin.cpp:320 148 | #, kde-format 149 | msgid "Points: 0 - Lines: 0 - Level: 0" 150 | msgstr "" 151 | 152 | #: main.cpp:409 153 | #, kde-format 154 | msgid "KBlocks" 155 | msgstr "" 156 | 157 | #: main.cpp:411 158 | #, kde-format 159 | msgid "A falling blocks game by KDE" 160 | msgstr "" 161 | 162 | #: main.cpp:413 163 | #, kde-format 164 | msgid "(c) 2007, Mauricio Piacentini" 165 | msgstr "" 166 | 167 | #: main.cpp:416 168 | #, kde-format 169 | msgid "Mauricio Piacentini" 170 | msgstr "" 171 | 172 | #: main.cpp:416 173 | #, kde-format 174 | msgid "Author" 175 | msgstr "" 176 | 177 | #: main.cpp:417 178 | #, kde-format 179 | msgid "Dirk Leifeld" 180 | msgstr "" 181 | 182 | #: main.cpp:417 183 | #, kde-format 184 | msgid "Developer" 185 | msgstr "" 186 | 187 | #: main.cpp:418 188 | #, kde-format 189 | msgid "Zhongjie Cai" 190 | msgstr "" 191 | 192 | #: main.cpp:418 193 | #, kde-format 194 | msgid "New design of KBlocks for AI and tetris research platform" 195 | msgstr "" 196 | 197 | #: main.cpp:419 198 | #, kde-format 199 | msgid "Johann Ollivier Lapeyre" 200 | msgstr "" 201 | 202 | #: main.cpp:419 203 | #, kde-format 204 | msgid "Oxygen art for KDE4" 205 | msgstr "" 206 | 207 | #: main.cpp:428 208 | #, kde-format 209 | msgid "" 210 | "Setup kblocks game running mode.\n" 211 | "\t0 = Desktop Mode\t1 = Game Engine Mode\n" 212 | "\t2 = Gui Mode\t3 = Player Mode" 213 | msgstr "" 214 | 215 | #: main.cpp:429 216 | #, kde-format 217 | msgid "" 218 | "Setup the configuration file for tetris researcher mode. Not for desktop " 219 | "users." 220 | msgstr "" 221 | -------------------------------------------------------------------------------- /po/ca/docs/kblocks/gameboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/po/ca/docs/kblocks/gameboard.png -------------------------------------------------------------------------------- /po/hr/kblocks.po: -------------------------------------------------------------------------------- 1 | # Translation of kblocks to Croatian 2 | # 3 | # Andrej Dundovic , 2010. 4 | msgid "" 5 | msgstr "" 6 | "Project-Id-Version: \n" 7 | "Report-Msgid-Bugs-To: https://bugs.kde.org\n" 8 | "POT-Creation-Date: 2024-11-22 00:38+0000\n" 9 | "PO-Revision-Date: 2010-01-24 17:07+0100\n" 10 | "Last-Translator: Andrej Dundovic \n" 11 | "Language-Team: Croatian \n" 12 | "Language: hr\n" 13 | "MIME-Version: 1.0\n" 14 | "Content-Type: text/plain; charset=UTF-8\n" 15 | "Content-Transfer-Encoding: 8bit\n" 16 | "X-Generator: Lokalize 1.0\n" 17 | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" 18 | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 19 | "X-Environment: kde\n" 20 | "X-Accelerator-Marker: &\n" 21 | "X-Text-Markup: kde4\n" 22 | 23 | #, kde-format 24 | msgctxt "NAME OF TRANSLATORS" 25 | msgid "Your names" 26 | msgstr "" 27 | 28 | #, kde-format 29 | msgctxt "EMAIL OF TRANSLATORS" 30 | msgid "Your emails" 31 | msgstr "" 32 | 33 | #. i18n: ectx: label, entry (Theme), group (General) 34 | #: config/kblocks.kcfg:9 35 | #, kde-format 36 | msgid "The graphical theme to be used." 37 | msgstr "" 38 | 39 | #. i18n: ectx: label, entry (Sounds), group (Preferences) 40 | #: config/kblocks.kcfg:14 41 | #, kde-format 42 | msgid "Whether sound effects should be played." 43 | msgstr "" 44 | 45 | #: KBlocksDisplay.cpp:58 46 | #, kde-format 47 | msgid "Score List : 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0" 48 | msgstr "" 49 | 50 | #: KBlocksDisplay.cpp:120 51 | #, kde-format 52 | msgid "Score List : %1 - %2 - %3 - %4 - %5 - %6 - %7 - %8" 53 | msgstr "" 54 | 55 | #: KBlocksKeyboardPlayer.cpp:76 56 | #, kde-format 57 | msgctxt "@action" 58 | msgid "Rotate Piece Clockwise" 59 | msgstr "" 60 | 61 | #: KBlocksKeyboardPlayer.cpp:82 62 | #, kde-format 63 | msgctxt "@action" 64 | msgid "Rotate Piece Counterclockwise" 65 | msgstr "" 66 | 67 | #: KBlocksKeyboardPlayer.cpp:88 68 | #, kde-format 69 | msgctxt "@action" 70 | msgid "Move Piece Left" 71 | msgstr "" 72 | 73 | #: KBlocksKeyboardPlayer.cpp:94 74 | #, kde-format 75 | msgctxt "@action" 76 | msgid "Move Piece Right" 77 | msgstr "" 78 | 79 | #: KBlocksKeyboardPlayer.cpp:100 80 | #, kde-format 81 | msgctxt "@action" 82 | msgid "Move Piece Down" 83 | msgstr "" 84 | 85 | #: KBlocksKeyboardPlayer.cpp:106 86 | #, kde-format 87 | msgctxt "@action" 88 | msgid "Drop the Piece" 89 | msgstr "" 90 | 91 | #: KBlocksScene.cpp:216 92 | #, kde-format 93 | msgid "Game Resumed!" 94 | msgstr "" 95 | 96 | #: KBlocksScene.cpp:217 97 | #, kde-format 98 | msgid "Game Paused!" 99 | msgstr "" 100 | 101 | #: KBlocksScene.cpp:271 102 | #, kde-format 103 | msgid "Game Start!" 104 | msgstr "" 105 | 106 | #: KBlocksScene.cpp:277 107 | #, kde-format 108 | msgid "Game Over!" 109 | msgstr "" 110 | 111 | #: KBlocksScene.cpp:283 112 | #, kde-format 113 | msgid "You Win!" 114 | msgstr "" 115 | 116 | #: KBlocksScene.cpp:289 117 | #, kde-format 118 | msgid "You Lose!" 119 | msgstr "" 120 | 121 | #. i18n: ectx: ToolBar (mainToolBar) 122 | #: kblocksui.rc:24 123 | #, kde-format 124 | msgid "Main Toolbar" 125 | msgstr "" 126 | 127 | #: KBlocksWin.cpp:145 KBlocksWin.cpp:249 128 | #, kde-format 129 | msgid "Points: %1 - Lines: %2 - Level: %3" 130 | msgstr "" 131 | 132 | #: KBlocksWin.cpp:290 133 | #, kde-format 134 | msgctxt "@action" 135 | msgid "Single Game" 136 | msgstr "" 137 | 138 | #: KBlocksWin.cpp:294 139 | #, kde-format 140 | msgctxt "@action" 141 | msgid "Human vs AI" 142 | msgstr "" 143 | 144 | #: KBlocksWin.cpp:313 145 | #, kde-format 146 | msgctxt "@option:check" 147 | msgid "Play Sounds" 148 | msgstr "" 149 | 150 | #: KBlocksWin.cpp:320 151 | #, kde-format 152 | msgid "Points: 0 - Lines: 0 - Level: 0" 153 | msgstr "" 154 | 155 | #: main.cpp:409 156 | #, kde-format 157 | msgid "KBlocks" 158 | msgstr "" 159 | 160 | #: main.cpp:411 161 | #, kde-format 162 | msgid "A falling blocks game by KDE" 163 | msgstr "" 164 | 165 | #: main.cpp:413 166 | #, kde-format 167 | msgid "(c) 2007, Mauricio Piacentini" 168 | msgstr "© 2007 Mauricio Piacentini" 169 | 170 | #: main.cpp:416 171 | #, fuzzy, kde-format 172 | #| msgid "(c) 2007, Mauricio Piacentini" 173 | msgid "Mauricio Piacentini" 174 | msgstr "© 2007 Mauricio Piacentini" 175 | 176 | #: main.cpp:416 177 | #, kde-format 178 | msgid "Author" 179 | msgstr "" 180 | 181 | #: main.cpp:417 182 | #, kde-format 183 | msgid "Dirk Leifeld" 184 | msgstr "" 185 | 186 | #: main.cpp:417 187 | #, kde-format 188 | msgid "Developer" 189 | msgstr "" 190 | 191 | #: main.cpp:418 192 | #, kde-format 193 | msgid "Zhongjie Cai" 194 | msgstr "" 195 | 196 | #: main.cpp:418 197 | #, kde-format 198 | msgid "New design of KBlocks for AI and tetris research platform" 199 | msgstr "" 200 | 201 | #: main.cpp:419 202 | #, kde-format 203 | msgid "Johann Ollivier Lapeyre" 204 | msgstr "" 205 | 206 | #: main.cpp:419 207 | #, kde-format 208 | msgid "Oxygen art for KDE4" 209 | msgstr "" 210 | 211 | #: main.cpp:428 212 | #, kde-format 213 | msgid "" 214 | "Setup kblocks game running mode.\n" 215 | "\t0 = Desktop Mode\t1 = Game Engine Mode\n" 216 | "\t2 = Gui Mode\t3 = Player Mode" 217 | msgstr "" 218 | 219 | #: main.cpp:429 220 | #, kde-format 221 | msgid "" 222 | "Setup the configuration file for tetris researcher mode. Not for desktop " 223 | "users." 224 | msgstr "" 225 | -------------------------------------------------------------------------------- /po/mai/kblocks.po: -------------------------------------------------------------------------------- 1 | # translation of kblocks.po to Maithili 2 | # Copyright (C) YEAR This_file_is_part_of_KDE 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # 5 | # Rajesh Ranjan , 2010. 6 | msgid "" 7 | msgstr "" 8 | "Project-Id-Version: kblocks\n" 9 | "Report-Msgid-Bugs-To: https://bugs.kde.org\n" 10 | "POT-Creation-Date: 2024-11-22 00:38+0000\n" 11 | "PO-Revision-Date: 2010-09-24 16:39+0530\n" 12 | "Last-Translator: Rajesh Ranjan \n" 13 | "Language-Team: Maithili \n" 14 | "Language: mai\n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "X-Generator: KBabel 1.11.4\n" 19 | "Plural-Forms: nplurals=2; plural=(n!=1);\n" 20 | "\n" 21 | 22 | #, kde-format 23 | msgctxt "NAME OF TRANSLATORS" 24 | msgid "Your names" 25 | msgstr "संगीता कुमारी" 26 | 27 | #, kde-format 28 | msgctxt "EMAIL OF TRANSLATORS" 29 | msgid "Your emails" 30 | msgstr "sangeeta09@gmail.com" 31 | 32 | #. i18n: ectx: label, entry (Theme), group (General) 33 | #: config/kblocks.kcfg:9 34 | #, kde-format 35 | msgid "The graphical theme to be used." 36 | msgstr "" 37 | 38 | #. i18n: ectx: label, entry (Sounds), group (Preferences) 39 | #: config/kblocks.kcfg:14 40 | #, kde-format 41 | msgid "Whether sound effects should be played." 42 | msgstr "" 43 | 44 | #: KBlocksDisplay.cpp:58 45 | #, kde-format 46 | msgid "Score List : 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0" 47 | msgstr "" 48 | 49 | #: KBlocksDisplay.cpp:120 50 | #, kde-format 51 | msgid "Score List : %1 - %2 - %3 - %4 - %5 - %6 - %7 - %8" 52 | msgstr "" 53 | 54 | #: KBlocksKeyboardPlayer.cpp:76 55 | #, kde-format 56 | msgctxt "@action" 57 | msgid "Rotate Piece Clockwise" 58 | msgstr "" 59 | 60 | #: KBlocksKeyboardPlayer.cpp:82 61 | #, kde-format 62 | msgctxt "@action" 63 | msgid "Rotate Piece Counterclockwise" 64 | msgstr "" 65 | 66 | #: KBlocksKeyboardPlayer.cpp:88 67 | #, kde-format 68 | msgctxt "@action" 69 | msgid "Move Piece Left" 70 | msgstr "" 71 | 72 | #: KBlocksKeyboardPlayer.cpp:94 73 | #, kde-format 74 | msgctxt "@action" 75 | msgid "Move Piece Right" 76 | msgstr "" 77 | 78 | #: KBlocksKeyboardPlayer.cpp:100 79 | #, kde-format 80 | msgctxt "@action" 81 | msgid "Move Piece Down" 82 | msgstr "" 83 | 84 | #: KBlocksKeyboardPlayer.cpp:106 85 | #, kde-format 86 | msgctxt "@action" 87 | msgid "Drop the Piece" 88 | msgstr "" 89 | 90 | #: KBlocksScene.cpp:216 91 | #, fuzzy, kde-format 92 | #| msgid "Game Over!" 93 | msgid "Game Resumed!" 94 | msgstr "खेल खत्म!" 95 | 96 | #: KBlocksScene.cpp:217 97 | #, fuzzy, kde-format 98 | #| msgid "Game Over!" 99 | msgid "Game Paused!" 100 | msgstr "खेल खत्म!" 101 | 102 | #: KBlocksScene.cpp:271 103 | #, fuzzy, kde-format 104 | #| msgid "Game Over!" 105 | msgid "Game Start!" 106 | msgstr "खेल खत्म!" 107 | 108 | #: KBlocksScene.cpp:277 109 | #, kde-format 110 | msgid "Game Over!" 111 | msgstr "खेल खत्म!" 112 | 113 | #: KBlocksScene.cpp:283 114 | #, kde-format 115 | msgid "You Win!" 116 | msgstr "" 117 | 118 | #: KBlocksScene.cpp:289 119 | #, kde-format 120 | msgid "You Lose!" 121 | msgstr "" 122 | 123 | #. i18n: ectx: ToolBar (mainToolBar) 124 | #: kblocksui.rc:24 125 | #, kde-format 126 | msgid "Main Toolbar" 127 | msgstr "मुख्य अओजार पट्टी" 128 | 129 | #: KBlocksWin.cpp:145 KBlocksWin.cpp:249 130 | #, kde-format 131 | msgid "Points: %1 - Lines: %2 - Level: %3" 132 | msgstr "" 133 | 134 | #: KBlocksWin.cpp:290 135 | #, kde-format 136 | msgctxt "@action" 137 | msgid "Single Game" 138 | msgstr "" 139 | 140 | #: KBlocksWin.cpp:294 141 | #, kde-format 142 | msgctxt "@action" 143 | msgid "Human vs AI" 144 | msgstr "" 145 | 146 | #: KBlocksWin.cpp:313 147 | #, kde-format 148 | msgctxt "@option:check" 149 | msgid "Play Sounds" 150 | msgstr "" 151 | 152 | #: KBlocksWin.cpp:320 153 | #, kde-format 154 | msgid "Points: 0 - Lines: 0 - Level: 0" 155 | msgstr "" 156 | 157 | #: main.cpp:409 158 | #, kde-format 159 | msgid "KBlocks" 160 | msgstr "" 161 | 162 | #: main.cpp:411 163 | #, kde-format 164 | msgid "A falling blocks game by KDE" 165 | msgstr "" 166 | 167 | #: main.cpp:413 168 | #, kde-format 169 | msgid "(c) 2007, Mauricio Piacentini" 170 | msgstr "" 171 | 172 | #: main.cpp:416 173 | #, kde-format 174 | msgid "Mauricio Piacentini" 175 | msgstr "" 176 | 177 | #: main.cpp:416 178 | #, kde-format 179 | msgid "Author" 180 | msgstr "लेखक" 181 | 182 | #: main.cpp:417 183 | #, kde-format 184 | msgid "Dirk Leifeld" 185 | msgstr "" 186 | 187 | #: main.cpp:417 188 | #, kde-format 189 | msgid "Developer" 190 | msgstr "डेवलपर" 191 | 192 | #: main.cpp:418 193 | #, kde-format 194 | msgid "Zhongjie Cai" 195 | msgstr "" 196 | 197 | #: main.cpp:418 198 | #, kde-format 199 | msgid "New design of KBlocks for AI and tetris research platform" 200 | msgstr "" 201 | 202 | #: main.cpp:419 203 | #, kde-format 204 | msgid "Johann Ollivier Lapeyre" 205 | msgstr "" 206 | 207 | #: main.cpp:419 208 | #, kde-format 209 | msgid "Oxygen art for KDE4" 210 | msgstr "" 211 | 212 | #: main.cpp:428 213 | #, kde-format 214 | msgid "" 215 | "Setup kblocks game running mode.\n" 216 | "\t0 = Desktop Mode\t1 = Game Engine Mode\n" 217 | "\t2 = Gui Mode\t3 = Player Mode" 218 | msgstr "" 219 | 220 | #: main.cpp:429 221 | #, kde-format 222 | msgid "" 223 | "Setup the configuration file for tetris researcher mode. Not for desktop " 224 | "users." 225 | msgstr "" 226 | 227 | #~ msgid "Theme" 228 | #~ msgstr "प्रसंग" 229 | -------------------------------------------------------------------------------- /po/uk/docs/kblocks/gameboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/po/uk/docs/kblocks/gameboard.png -------------------------------------------------------------------------------- /snapcraft.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024-2025 Scarlett Moore 2 | # 3 | # SPDX-License-Identifier: CC0-1.0 4 | --- 5 | name: kblocks 6 | confinement: strict 7 | grade: stable 8 | base: core24 9 | adopt-info: kblocks 10 | apps: 11 | kblocks: 12 | extensions: 13 | - kde-neon-6 14 | common-id: org.kde.kblocks.desktop 15 | desktop: usr/share/applications/org.kde.kblocks.desktop 16 | command: usr/bin/kblocks 17 | plugs: 18 | - audio-playback 19 | slots: 20 | session-dbus-interface: 21 | interface: dbus 22 | name: org.kde.kblocks 23 | bus: session 24 | parts: 25 | kblocks: 26 | parse-info: 27 | - usr/share/metainfo/org.kde.kblocks.appdata.xml 28 | plugin: cmake 29 | source: . 30 | source-type: local 31 | cmake-parameters: 32 | - -DCMAKE_INSTALL_PREFIX=/usr 33 | - -DCMAKE_BUILD_TYPE=Release 34 | - -DQT_MAJOR_VERSION=6 35 | - -DBUILD_WITH_QT6=ON 36 | - -DBUILD_TESTING=OFF 37 | - -DCMAKE_INSTALL_SYSCONFDIR=/etc 38 | - -DCMAKE_INSTALL_LOCALSTATEDIR=/var 39 | - -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON 40 | - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF 41 | - -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON 42 | - -DCMAKE_INSTALL_RUNSTATEDIR=/run 43 | - -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON 44 | - -DCMAKE_VERBOSE_MAKEFILE=ON 45 | - -DCMAKE_INSTALL_LIBDIR=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR 46 | - --log-level=STATUS 47 | - -DCMAKE_LIBRARY_PATH=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR 48 | build-environment: &build-environment 49 | - LD_LIBRARY_PATH: > 50 | "/snap/mesa-2404/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR:$CRAFT_STAGE/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR:/snap/kde-qt6-core24-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libproxy:$LD_LIBRARY_PATH" 51 | prime: 52 | - -usr/lib/*/cmake/* 53 | - -usr/include/* 54 | - -usr/share/ECM/* 55 | - -usr/share/man/* 56 | - -usr/bin/X11 57 | - -usr/lib/gcc/$CRAFT_ARCH_TRIPLET_BUILD_FOR/6.0.0 58 | - -usr/lib/aspell/* 59 | - -usr/share/lintian 60 | gpu-2404: 61 | after: [kblocks] 62 | source: https://github.com/canonical/gpu-snap.git 63 | plugin: dump 64 | override-prime: | 65 | craftctl default 66 | ${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404 67 | prime: 68 | - bin/gpu-2404-wrapper 69 | cleanup: 70 | after: 71 | - kblocks 72 | plugin: nil 73 | build-snaps: 74 | - core24 75 | - kf6-core24 76 | override-prime: | 77 | set -eux 78 | for snap in "core24" "kf6-core24"; do 79 | cd "/snap/$snap/current" && find . -type f,l -exec rm -rf "${CRAFT_PRIME}/{}" \; 80 | done 81 | -------------------------------------------------------------------------------- /sounds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | install( FILES block-fall.ogg block-move.ogg block-remove.ogg DESTINATION ${KDE_INSTALL_DATADIR}/kblocks/sounds ) 3 | 4 | -------------------------------------------------------------------------------- /sounds/block-fall.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/sounds/block-fall.ogg -------------------------------------------------------------------------------- /sounds/block-move.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/sounds/block-move.ogg -------------------------------------------------------------------------------- /sounds/block-remove.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/sounds/block-remove.ogg -------------------------------------------------------------------------------- /src/AI/EvaluationInterface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef EVALUATIONINTERFACE_H 8 | #define EVALUATIONINTERFACE_H 9 | 10 | #include "../KBlocksField.h" 11 | #include "../KBlocksPiece.h" 12 | 13 | #define DEBUG_EVALUATION 14 | #ifdef DEBUG_EVALUATION 15 | #define CLASSNAME(class)\ 16 | const char* evaluationName()\ 17 | override {\ 18 | return #class;\ 19 | } 20 | #else 21 | #define CLASSNAME(class) 22 | #endif 23 | 24 | class EvaluationInterface 25 | { 26 | public: 27 | EvaluationInterface() {}; 28 | virtual ~EvaluationInterface() {}; 29 | virtual double evaluate(KBlocksField *) = 0; 30 | #ifdef DEBUG_EVALUATION 31 | virtual const char *evaluationName() 32 | { 33 | return ""; 34 | } 35 | #endif 36 | }; 37 | 38 | class SpecialEvaluationInterface : public EvaluationInterface 39 | { 40 | public: 41 | SpecialEvaluationInterface() 42 | { 43 | mpPiece = nullptr; 44 | mpField = nullptr; 45 | } 46 | ~SpecialEvaluationInterface() override {}; 47 | 48 | double evaluate(KBlocksField *) override = 0; 49 | void setCurrentPiece(KBlocksPiece *piece) 50 | { 51 | mpPiece = piece; 52 | } 53 | void setCurrentBoard(KBlocksField *field) 54 | { 55 | mpField = field; 56 | } 57 | 58 | #ifdef DEBUG_EVALUATION 59 | const char *evaluationName() override 60 | { 61 | return ""; 62 | } 63 | #endif 64 | 65 | protected: 66 | KBlocksPiece *mpPiece; 67 | KBlocksField *mpField; 68 | }; 69 | 70 | #endif //EVALUATIONINTERFACE_H 71 | -------------------------------------------------------------------------------- /src/AI/KBlocksAILog.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSAILOG_H 8 | #define KBLOCKSAILOG_H 9 | 10 | #include "KBlocksAITypeDefine.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "../KBlocksPiece.h" 17 | #include "../KBlocksField.h" 18 | 19 | enum Log_Mode { 20 | LOG_MODE_PRINTSCREEN, 21 | LOG_MODE_PRINTFILE, 22 | LOG_MODE_PRINTBOTH 23 | }; 24 | 25 | /***************************************************************** 26 | ** screen setting ********************************************** 27 | *****************************************************************/ 28 | #ifndef KSIRTET 29 | void gotoXY(int x, int y); 30 | #endif 31 | 32 | /***************************************************************** 33 | ** channel setting ********************************************* 34 | *****************************************************************/ 35 | void set_channel(int ch); 36 | void set_screen_channel(); 37 | void set_screen_file_channel(int ch); 38 | void open_file(const char *fn); 39 | void open_file(int ch, const char *fn); 40 | void close_file(); 41 | void close_file(int ch); 42 | 43 | /***************************************************************** 44 | ** print element *********************************************** 45 | *****************************************************************/ 46 | void println(); 47 | void print(const char *s); 48 | void println(const char *s); 49 | void print(int i); 50 | void println(int i); 51 | void print(int i); 52 | void println(int i); 53 | void print(double d); 54 | void println(double d); 55 | 56 | /***************************************************************** 57 | ** print object ************************************************ 58 | *****************************************************************/ 59 | void println(KBlocksPiece *); 60 | void println(KBlocksPiece *, bool full); 61 | void println(KBlocksPiece *, int x, int y, bool full = false); 62 | 63 | void println(KBlocksField *); 64 | void println(KBlocksField *, int x, int y); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/AI/KBlocksAIPlanner.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSAIPLANNER_H 8 | #define KBLOCKSAIPLANNER_H 9 | 10 | #include 11 | #include 12 | 13 | #include "PlannerInterface.h" 14 | 15 | typedef std::list AIPlanner_PieceValue_Sequence; 16 | typedef std::vector AIPlanner_PieceInfo_Sequence; 17 | 18 | class KBlocksAIPlanner : public PlannerInterface 19 | { 20 | public: 21 | explicit KBlocksAIPlanner(KBlocksField *p); 22 | ~KBlocksAIPlanner() override; 23 | 24 | int process(KBlocks_PieceType_Detail pieceValue) override; 25 | bool getNextBoardStatus(int index, KBlocksField *field) override; 26 | bool getNextPieceState(int index, KBlocksPiece *piece) override; 27 | 28 | int count() override; 29 | 30 | private: 31 | AIPlanner_PieceInfo_Sequence mNextPieceValues; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/AI/KBlocksAIPlannerExtend.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSAIPLANNEREXTEND_H 8 | #define KBLOCKSAIPLANNEREXTEND_H 9 | 10 | #include "KBlocksAIPlanner.h" 11 | #include 12 | #include 13 | 14 | /**************************************************************** 15 | ** Planning Path ********************************************** 16 | ****************************************************************/ 17 | namespace PlanningPath 18 | { 19 | class PathNode 20 | { 21 | public: 22 | explicit PathNode(KBlocksPiece *piece); 23 | ~PathNode(); 24 | 25 | KBlocksPiece getContent(); 26 | void setContent(KBlocksPiece *piece); 27 | void setParent(PathNode *parent); 28 | PathNode *getParent(); 29 | 30 | void setNext(std::vector *&); 31 | 32 | private: 33 | KBlocksPiece content; 34 | PathNode *parent; 35 | std::vector *next; 36 | }; 37 | 38 | typedef std::vector PathTree; 39 | typedef std::vector LeafList; 40 | } 41 | 42 | /**************************************************************** 43 | ** Planner **************************************************** 44 | ****************************************************************/ 45 | class KBlocksAIPlannerExtend : public KBlocksAIPlanner 46 | { 47 | public: 48 | explicit KBlocksAIPlannerExtend(KBlocksField *field); 49 | ~KBlocksAIPlannerExtend() override; 50 | 51 | int process(KBlocks_PieceType_Detail pieceValue) override; 52 | int process(const AIPlanner_PieceValue_Sequence &p); 53 | 54 | bool getNextBoardStatus(int index, KBlocksField *field) override; 55 | bool getNextBoardStatus(int index, KBlocksField *field, bool first); 56 | bool getNextPieceState(int index, KBlocksPiece *piece) override; 57 | bool getPath(int index, AIPlanner_PieceInfo_Sequence *pseq); 58 | 59 | int count() override; 60 | 61 | private: 62 | PlanningPath::PathTree *mPathTree; 63 | PlanningPath::LeafList *mPathList; 64 | void process_nstep_recursive(PlanningPath::PathNode *parent, 65 | AIPlanner_PieceValue_Sequence &pseq, 66 | PlanningPath::PathTree &tree, 67 | PlanningPath::LeafList &leaf); 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/AI/KBlocksAIPlayer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSAIPLAYER_H 8 | #define KBLOCKSAIPLAYER_H 9 | 10 | #include 11 | using namespace std; 12 | 13 | #include "KBlocksAITypeDefine.h" 14 | 15 | #include "../GamePlayerInterface.h" 16 | 17 | #include "../SingleGameInterface.h" 18 | #include "../KBlocksField.h" 19 | #include "../KBlocksPiece.h" 20 | 21 | #include "EvaluationInterface.h" 22 | #include "PlannerInterface.h" 23 | 24 | class KBlocksAIPlayer : public GamePlayerInterface 25 | { 26 | public: 27 | explicit KBlocksAIPlayer(const string &name = ""); 28 | ~KBlocksAIPlayer() override; 29 | 30 | public: 31 | void startGame(SingleGameInterface *p) override; 32 | void stopGame() override; 33 | 34 | void pauseGame(bool flag) override; 35 | 36 | void think(GamePlayer_ActionList *actionList) override; 37 | 38 | string getName() override; 39 | 40 | private: 41 | string mAIName; 42 | 43 | // Private Control Data 44 | bool mAIStarted; 45 | bool mAIPaused; 46 | 47 | // Phase I - State Update 48 | KBlocksField *mpAIField; 49 | KBlocksPiece *mpCurPiece; 50 | KBlocksPiece *mpNextPiece; 51 | void update(); 52 | 53 | // Phase II - Planning 54 | PlannerInterface *mpPlanner; 55 | int mNextCount; 56 | void planning(); 57 | 58 | // Phase III - Situation Analysis 59 | EvaluationInterface *mpEvaluatorFinal; 60 | EvaluationInterface *mpEvaluatorFirst; 61 | EvaluationInterface *mpEvaluatorPre; 62 | void situationAdaption(); 63 | 64 | // Phase IV - States Evaluation 65 | int mBestPosition; 66 | int mBestRotation; 67 | void generateGoalAction(); 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/AI/KBlocksAITypeDefine.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSAITYPEDEFINE_H 8 | #define KBLOCKSAITYPEDEFINE_H 9 | 10 | #include 11 | #include 12 | 13 | #define KSIRTET 14 | 15 | #define INITLIST 16 | 17 | #ifndef DEBUG 18 | #define DEBUG 19 | #endif 20 | 21 | #ifndef LOG 22 | #define LOG 23 | #endif 24 | 25 | #define UNIX 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/AI/PlannerInterface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 University Freiburg * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef PLANNERINTERFACE_H 8 | #define PLANNERINTERFACE_H 9 | 10 | #include "KBlocksAITypeDefine.h" 11 | 12 | #include "../KBlocksField.h" 13 | #include "../KBlocksPiece.h" 14 | 15 | class PlannerInterface 16 | { 17 | public: 18 | explicit PlannerInterface(KBlocksField *p) 19 | { 20 | mpField = p; 21 | }; 22 | virtual ~PlannerInterface() {}; 23 | 24 | virtual int process(KBlocks_PieceType_Detail) = 0; 25 | 26 | virtual bool getNextBoardStatus(int, KBlocksField *) = 0; 27 | virtual bool getNextPieceState(int, KBlocksPiece *) = 0; 28 | 29 | virtual int count() = 0; 30 | 31 | protected: 32 | KBlocksField *mpField; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/FieldInterface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef FIELD_INTERFACE 8 | #define FIELD_INTERFACE 9 | 10 | class FieldInterface 11 | { 12 | protected: 13 | FieldInterface() : maBoard(nullptr), mHeight(0), mWidth(0) {}; 14 | 15 | public: 16 | virtual ~FieldInterface() {}; 17 | 18 | public: 19 | virtual bool getCell(int xPos, int yPos) = 0; 20 | 21 | virtual int getWidth() = 0; 22 | virtual int getHeight() = 0; 23 | 24 | protected: 25 | bool **maBoard; 26 | int mHeight; 27 | int mWidth; 28 | }; 29 | 30 | #endif //FIELD_INTERFACE 31 | -------------------------------------------------------------------------------- /src/GameLogicInterface.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #include "GameLogicInterface.h" 8 | 9 | GameLogicInterface::GameLogicInterface() 10 | : maGameList(nullptr) 11 | { 12 | } 13 | 14 | #include "moc_GameLogicInterface.cpp" 15 | -------------------------------------------------------------------------------- /src/GameLogicInterface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Zhongjie Cai * 4 | * Julian Helfferich * 5 | * * 6 | * SPDX-License-Identifier: GPL-2.0-or-later 7 | ******************************************************************************/ 8 | #ifndef GAME_LOGIC_INTERFACE 9 | #define GAME_LOGIC_INTERFACE 10 | 11 | #include 12 | 13 | #include "SingleGameInterface.h" 14 | 15 | class GameLogicInterface : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | GameLogicInterface(); 20 | ~GameLogicInterface() override {}; 21 | 22 | public: 23 | virtual SingleGameInterface *getSingleGame(int) = 0; 24 | 25 | virtual int levelUpGame(int) = 0; 26 | virtual int updateGame(int *) = 0; 27 | 28 | virtual void setGameSeed(int) = 0; 29 | 30 | virtual void setGameStandbyMode(bool) = 0; 31 | 32 | virtual bool startGame(int) = 0; 33 | virtual bool stopGame() = 0; 34 | 35 | virtual void pauseGame(bool) = 0; 36 | virtual void continueGame() = 0; 37 | 38 | virtual bool hasSingleGames() = 0; 39 | virtual void deleteSingleGames() = 0; 40 | 41 | Q_SIGNALS: 42 | void allGamesStopped(); 43 | 44 | protected: 45 | SingleGameInterface **maGameList; 46 | }; 47 | 48 | #endif //GAME_LOGIC_INTERFACE 49 | -------------------------------------------------------------------------------- /src/GamePlayerInterface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef GAMEPLAYERINTERFACE_H 8 | #define GAMEPLAYERINTERFACE_H 9 | 10 | #include 11 | #include 12 | 13 | enum KBlocks_Player_Action { 14 | PlayerAction_None = 0, 15 | PlayerAction_Move_Left, 16 | PlayerAction_Move_Right, 17 | PlayerAction_Move_Down, 18 | PlayerAction_Push_Down, 19 | PlayerAction_Rotate_CW, 20 | PlayerAction_Rotate_CCW, 21 | PlayerAction_Max_Count 22 | }; 23 | 24 | typedef std::list GamePlayer_ActionList; 25 | 26 | #include "SingleGameInterface.h" 27 | 28 | class GamePlayerInterface 29 | { 30 | public: 31 | GamePlayerInterface() : mpGame(nullptr) {}; 32 | virtual ~GamePlayerInterface() {}; 33 | 34 | public: 35 | virtual void startGame(SingleGameInterface *) = 0; 36 | virtual void stopGame() = 0; 37 | 38 | virtual void pauseGame(bool) = 0; 39 | 40 | virtual void think(GamePlayer_ActionList *actionList) = 0; 41 | 42 | virtual std::string getName() = 0; 43 | 44 | protected: 45 | SingleGameInterface *mpGame; 46 | }; 47 | 48 | #endif //GAMEPLAYERINTERFACE_H 49 | -------------------------------------------------------------------------------- /src/GraphicsInterface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef GRAPHICSINTERFACE_H 8 | #define GRAPHICSINTERFACE_H 9 | 10 | class QSize; 11 | class QString; 12 | class QSvgRenderer; 13 | class KBlocksTheme; 14 | 15 | enum class BackgroundLocation { 16 | Stretch, 17 | TopLeft, 18 | Center 19 | }; 20 | 21 | class GraphicsInterface 22 | { 23 | public: 24 | GraphicsInterface() 25 | : m_Block_Size{}, 26 | m_View_Size_Width{}, 27 | m_View_Size_Height{}, 28 | m_PlayArea_OffsetPoint_X{}, 29 | m_PlayArea_OffsetPoint_Y{}, 30 | m_PlayArea_NumberOfBlocks_X{}, 31 | m_PlayArea_NumberOfBlocks_Y{}, 32 | m_PreviewArea_CenterPoint_X{}, 33 | m_PreviewArea_CenterPoint_Y{}, 34 | m_BackgroundLocation{} 35 | {} 36 | virtual ~GraphicsInterface() = default; 37 | 38 | public: 39 | virtual bool loadTheme(const KBlocksTheme *theme) = 0; 40 | virtual void readThemeValues(const KBlocksTheme *theme) = 0; 41 | virtual QSvgRenderer *renderer() const = 0; 42 | 43 | int m_Block_Size; 44 | int m_View_Size_Width; 45 | int m_View_Size_Height; 46 | int m_PlayArea_OffsetPoint_X; 47 | int m_PlayArea_OffsetPoint_Y; 48 | int m_PlayArea_NumberOfBlocks_X; 49 | int m_PlayArea_NumberOfBlocks_Y; 50 | int m_PreviewArea_CenterPoint_X; 51 | int m_PreviewArea_CenterPoint_Y; 52 | 53 | BackgroundLocation m_BackgroundLocation; 54 | }; 55 | 56 | #endif // GRAPHICSINTERFACE_H 57 | -------------------------------------------------------------------------------- /src/KBlocksAnimDrop.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #include "KBlocksAnimDrop.h" 10 | 11 | #include "SvgItemInterface.h" 12 | 13 | KBlocksAnimDrop::KBlocksAnimDrop(const QList &items, int duration, QTimeLine::Direction direction) 14 | { 15 | mItemList = items; 16 | 17 | mpTimeLine = new QTimeLine(duration); 18 | mpTimeLine->setFrameRange(0, 30); 19 | mpTimeLine->setDirection(direction); 20 | 21 | connect(mpTimeLine, &QTimeLine::valueChanged, this, &KBlocksAnimDrop::valueChanged); 22 | connect(mpTimeLine, &QTimeLine::finished, this, &KBlocksAnimDrop::endAnimation); 23 | 24 | mpTimeLine->start(); 25 | } 26 | 27 | KBlocksAnimDrop::~KBlocksAnimDrop() 28 | { 29 | mpTimeLine->deleteLater(); 30 | } 31 | 32 | void KBlocksAnimDrop::valueChanged(qreal value) 33 | { 34 | Q_UNUSED(value); 35 | for (SvgItemInterface *pItem : std::as_const(mItemList)) { 36 | pItem->execPosAnim(value); 37 | } 38 | } 39 | 40 | void KBlocksAnimDrop::endAnimation() 41 | { 42 | Q_EMIT animationFinished(); 43 | } 44 | 45 | #include "moc_KBlocksAnimDrop.cpp" 46 | -------------------------------------------------------------------------------- /src/KBlocksAnimDrop.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSANIMDROP_H 10 | #define KBLOCKSANIMDROP_H 11 | 12 | #include 13 | 14 | class SvgItemInterface; 15 | 16 | class KBlocksAnimDrop : public QObject 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | KBlocksAnimDrop(const QList &items, int duration, QTimeLine::Direction direction); 22 | ~KBlocksAnimDrop() override; 23 | 24 | Q_SIGNALS: 25 | void animationFinished(); 26 | 27 | private Q_SLOTS: 28 | void valueChanged(qreal value); 29 | void endAnimation(); 30 | 31 | private: 32 | QTimeLine *mpTimeLine; 33 | QList mItemList; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/KBlocksAnimFade.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #include "KBlocksAnimFade.h" 10 | 11 | #include "SvgItemInterface.h" 12 | 13 | KBlocksAnimFade::KBlocksAnimFade(const QList &items, int duration, QTimeLine::Direction direction) 14 | { 15 | mItemList = items; 16 | 17 | mpTimeLine = new QTimeLine(duration); 18 | mpTimeLine->setFrameRange(0, 30); 19 | mpTimeLine->setDirection(direction); 20 | 21 | connect(mpTimeLine, &QTimeLine::valueChanged, this, &KBlocksAnimFade::valueChanged); 22 | connect(mpTimeLine, &QTimeLine::finished, this, &KBlocksAnimFade::endAnimation); 23 | 24 | mpTimeLine->start(); 25 | } 26 | 27 | KBlocksAnimFade::~KBlocksAnimFade() 28 | { 29 | mpTimeLine->deleteLater(); 30 | } 31 | 32 | void KBlocksAnimFade::valueChanged(qreal value) 33 | { 34 | for (SvgItemInterface *pItem : std::as_const(mItemList)) { 35 | pItem->setOpacity(value); 36 | } 37 | } 38 | 39 | void KBlocksAnimFade::endAnimation() 40 | { 41 | Q_EMIT animationFinished(); 42 | } 43 | 44 | #include "moc_KBlocksAnimFade.cpp" 45 | -------------------------------------------------------------------------------- /src/KBlocksAnimFade.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSANIMFADE_H 10 | #define KBLOCKSANIMFADE_H 11 | 12 | #include 13 | 14 | class SvgItemInterface; 15 | 16 | class KBlocksAnimFade : public QObject 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | KBlocksAnimFade(const QList &items, int duration, QTimeLine::Direction direction); 22 | ~KBlocksAnimFade() override; 23 | 24 | Q_SIGNALS: 25 | void animationFinished(); 26 | 27 | private Q_SLOTS: 28 | void valueChanged(qreal value); 29 | void endAnimation(); 30 | 31 | private: 32 | QTimeLine *mpTimeLine; 33 | QList mItemList; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/KBlocksAnimator.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #include "KBlocksAnimator.h" 10 | 11 | #include "SvgItemInterface.h" 12 | 13 | KBlocksAnimator::KBlocksAnimator() 14 | { 15 | } 16 | 17 | KBlocksAnimator::~KBlocksAnimator() 18 | { 19 | if (mpAnimDrop) { 20 | delete mpAnimDrop; 21 | mpAnimDrop = nullptr; 22 | } 23 | if (mpAnimFade) { 24 | delete mpAnimFade; 25 | mpAnimFade = nullptr; 26 | } 27 | } 28 | 29 | bool KBlocksAnimator::createFadeAnim(const QList &items, int duration, QTimeLine::Direction direction) 30 | { 31 | if (mpAnimFade) { 32 | return false; 33 | } 34 | 35 | mpAnimFade = new KBlocksAnimFade(items, duration, direction); 36 | 37 | if (direction == QTimeLine::Forward) { 38 | connect(mpAnimFade, &KBlocksAnimFade::animationFinished, this, &KBlocksAnimator::endFadeInAnim); 39 | } else { 40 | connect(mpAnimFade, &KBlocksAnimFade::animationFinished, this, &KBlocksAnimator::endFadeOutAnim); 41 | } 42 | 43 | return true; 44 | } 45 | 46 | bool KBlocksAnimator::deleteFadeAnim() 47 | { 48 | if (mpAnimFade) { 49 | delete mpAnimFade; 50 | mpAnimFade = nullptr; 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | KBlocksAnimFade *KBlocksAnimator::getFadeAnim() 57 | { 58 | return mpAnimFade; 59 | } 60 | 61 | bool KBlocksAnimator::createDropAnim(const QList &items, int duration, QTimeLine::Direction direction) 62 | { 63 | if (mpAnimDrop) { 64 | return false; 65 | } 66 | 67 | mpAnimDrop = new KBlocksAnimDrop(items, duration, direction); 68 | 69 | connect(mpAnimDrop, &KBlocksAnimDrop::animationFinished, this, &KBlocksAnimator::endDropAnim); 70 | 71 | return true; 72 | } 73 | 74 | bool KBlocksAnimator::deleteDropAnim() 75 | { 76 | if (mpAnimDrop) { 77 | delete mpAnimDrop; 78 | mpAnimDrop = nullptr; 79 | return true; 80 | } 81 | return false; 82 | } 83 | 84 | KBlocksAnimDrop *KBlocksAnimator::getDropAnim() 85 | { 86 | return mpAnimDrop; 87 | } 88 | 89 | void KBlocksAnimator::endFadeInAnim() 90 | { 91 | Q_EMIT animFinished(KBlocks_Animation_Fade_In); 92 | } 93 | 94 | void KBlocksAnimator::endFadeOutAnim() 95 | { 96 | Q_EMIT animFinished(KBlocks_Animation_Fade_Out); 97 | } 98 | 99 | void KBlocksAnimator::endDropAnim() 100 | { 101 | Q_EMIT animFinished(KBlocks_Animation_Drop); 102 | } 103 | 104 | #include "moc_KBlocksAnimator.cpp" 105 | -------------------------------------------------------------------------------- /src/KBlocksAnimator.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSANIMATOR_H 10 | #define KBLOCKSANIMATOR_H 11 | 12 | #include 13 | 14 | #include "KBlocksAnimFade.h" 15 | #include "KBlocksAnimDrop.h" 16 | 17 | class SvgItemInterface; 18 | 19 | enum KBlocks_Animation_Type { 20 | KBlocks_Animation_None = 0, 21 | KBlocks_Animation_Fade_In, 22 | KBlocks_Animation_Fade_Out, 23 | KBlocks_Animation_Drop, 24 | KBlocks_Animation_Max_Count 25 | }; 26 | 27 | class KBlocksAnimator : public QObject 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | KBlocksAnimator(); 33 | ~KBlocksAnimator() override; 34 | 35 | bool createFadeAnim(const QList &items, int duration, QTimeLine::Direction direction); 36 | bool deleteFadeAnim(); 37 | KBlocksAnimFade *getFadeAnim(); 38 | 39 | bool createDropAnim(const QList &items, int duration, QTimeLine::Direction direction); 40 | bool deleteDropAnim(); 41 | KBlocksAnimDrop *getDropAnim(); 42 | 43 | private Q_SLOTS: 44 | void endFadeInAnim(); 45 | void endFadeOutAnim(); 46 | void endDropAnim(); 47 | 48 | Q_SIGNALS: 49 | void animFinished(int animType); 50 | 51 | protected: 52 | KBlocksAnimFade *mpAnimFade = nullptr; 53 | KBlocksAnimDrop *mpAnimDrop = nullptr; 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/KBlocksAppThread.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksAppThread.h" 8 | 9 | KBlocksAppThread::KBlocksAppThread(KBlocksPlayNetwork *p) 10 | { 11 | mPlayNetwork = p; 12 | } 13 | 14 | KBlocksAppThread::~KBlocksAppThread() 15 | { 16 | } 17 | 18 | void KBlocksAppThread::run() 19 | { 20 | mPlayNetwork->execute(); 21 | } 22 | -------------------------------------------------------------------------------- /src/KBlocksAppThread.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSAPPTHREAD_H 8 | #define KBLOCKSAPPTHREAD_H 9 | 10 | #include 11 | #include "KBlocksPlayNetwork.h" 12 | 13 | class KBlocksAppThread : public QThread 14 | { 15 | public: 16 | explicit KBlocksAppThread(KBlocksPlayNetwork *p); 17 | ~KBlocksAppThread() override; 18 | 19 | public: 20 | void run() override; 21 | 22 | private: 23 | KBlocksPlayNetwork *mPlayNetwork; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/KBlocksConfigManager.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSCONFIGMANAGER_H_INCLUDED 8 | #define KBLOCKSCONFIGMANAGER_H_INCLUDED 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | class KBlocksConfigManager 16 | { 17 | private: 18 | map< int, string > stConfigSectionList; 19 | map< string, map< int, string > > stConfigKeyNameList; 20 | map< string, map< string, string > > stConfigDataTable; 21 | 22 | bool isDebug; 23 | 24 | public: 25 | KBlocksConfigManager(); 26 | ~KBlocksConfigManager(); 27 | 28 | int SetDebugOutput(bool flag); 29 | 30 | int LoadConfigFile(const string &filename); 31 | int SaveConfigFile(const string &filename); 32 | 33 | int GetSectionCount(); 34 | int GetKeyCount(const string &SectionName); 35 | 36 | int GetKeyString(const string &SectionName, const string &KeyName, string *KeyString, const string &Default); 37 | int GetKeyInt(const string &SectionName, const string &KeyName, int *KeyInt, const int Default); 38 | int GetKeyBool(const string &SectionName, const string &KeyName, bool *KeyBool, const bool Default); 39 | 40 | int SetKeyString(string SectionName, string KeyName, string KeyString); 41 | int SetKeyInt(string SectionName, string KeyName, int KeyInt); 42 | int SetKeyBool(const string &SectionName, const string &KeyName, bool KeyBool); 43 | 44 | private: 45 | int ParseConfigFile(FILE *fp); 46 | int ConstructConfigFile(FILE *fp); 47 | 48 | string int16tostring(int input); 49 | }; 50 | 51 | #endif // KBLOCKSCONFIGMANAGER_H_INCLUDED 52 | 53 | -------------------------------------------------------------------------------- /src/KBlocksDefine.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksDefine.h" 8 | 9 | const char *KBlocksRecordText[RecordDataType_Max_Count] = { 10 | "GameCount", 11 | "GameSeed", 12 | "Skipped", 13 | "MovePieceLeft", 14 | "MovePieceRight", 15 | "MovePieceUp", 16 | "MovePieceDown", 17 | "RotatePieceCW", 18 | "RotatePieceCCW", 19 | "GameOneStep", 20 | "PunishLineCount", 21 | "PunishLineSeed", 22 | }; 23 | -------------------------------------------------------------------------------- /src/KBlocksDefine.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | 8 | #ifndef KBLOCKSDEFINE_H 9 | #define KBLOCKSDEFINE_H 10 | 11 | #define PREPARE_AREA_WIDTH 5 12 | 13 | #define FADE_ANIM_TIME_LINE 250 14 | #define DROP_ANIM_TIME_LINE 250 15 | 16 | typedef unsigned long timeLong; 17 | 18 | enum KBlocks_Game_Action { 19 | GameAction_None = 0, 20 | GameAction_Punish_Line, 21 | GameAction_Remove_Line, 22 | GameAction_Freeze_Piece_Color, 23 | GameAction_Freeze_Piece_X, 24 | GameAction_Freeze_Piece_Y, 25 | GameAction_New_Piece_X, 26 | GameAction_New_Piece_Y, 27 | GameAction_Max_Count 28 | }; 29 | 30 | enum KBlocks_Game_Result { 31 | GameResult_None = 0, 32 | GameResult_Game_Over, 33 | GameResult_One_Step, 34 | GameResult_Next_Piece, 35 | GameResult_Remove_Line_1, 36 | GameResult_Remove_Line_2, 37 | GameResult_Remove_Line_3, 38 | GameResult_Remove_Line_4, 39 | GameResult_Max_Count 40 | }; 41 | 42 | enum KBlocks_Game_State { 43 | GameState_Stop = 0, 44 | GameState_Running, 45 | GameState_Pause, 46 | GameState_Max_Count 47 | }; 48 | 49 | enum KBlocks_Record_DataType { 50 | RecordDataType_GameCount = 0, 51 | RecordDataType_GameSeed, 52 | 53 | RecordDataType_Skipped, 54 | RecordDataType_MovePieceLeft, 55 | RecordDataType_MovePieceRight, 56 | RecordDataType_MovePieceUp, 57 | RecordDataType_MovePieceDown, 58 | RecordDataType_RotatePieceCW, 59 | RecordDataType_RotatePieceCCW, 60 | RecordDataType_GameOneStep, 61 | RecordDataType_PunishLineCount, 62 | RecordDataType_PunishLineSeed, 63 | 64 | RecordDataType_Max_Count 65 | }; 66 | 67 | extern const char *KBlocksRecordText[RecordDataType_Max_Count]; 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /src/KBlocksDisplay.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Zhongjie Cai * 4 | * Julian Helfferich * 5 | * * 6 | * SPDX-License-Identifier: GPL-2.0-or-later 7 | ******************************************************************************/ 8 | #ifndef KBLOCKSDISPLAY_H 9 | #define KBLOCKSDISPLAY_H 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include "KBlocksScene.h" 17 | #include "KBlocksView.h" 18 | 19 | #include "KBlocksGameLogic.h" 20 | #include "KBlocksNetClient.h" 21 | 22 | using std::string; 23 | 24 | class QLabel; 25 | class GraphicsInterface; 26 | class SoundInterface; 27 | 28 | class KBlocksDisplay : public KMainWindow 29 | { 30 | Q_OBJECT 31 | 32 | public: 33 | KBlocksDisplay( 34 | GraphicsInterface* graphics, 35 | SoundInterface* sound, 36 | int gameCount, 37 | const std::string& serverIP, 38 | int localPort 39 | ); 40 | ~KBlocksDisplay() override; 41 | 42 | public: 43 | void setGamesPerLine(int count); 44 | void setUpdateInterval(int interval); 45 | 46 | public: 47 | void startDisplay(); 48 | void stopDisplay(); 49 | 50 | private: 51 | int formIntFromByte(char *data); 52 | void updateScore(); 53 | 54 | private Q_SLOTS: 55 | void updateEvent(); 56 | void updateGameDisplay(int size); 57 | 58 | private: 59 | int mGameCount; 60 | //int mGamesPerWidth; 61 | 62 | int mUpdateInterval; 63 | QTimer mUpdateTimer; 64 | 65 | int maScoreList[8]; 66 | 67 | KBlocksScene *mpGameScene = nullptr; 68 | KBlocksView *mpGameView = nullptr; 69 | 70 | KBlocksGameLogic *mpGameLogic = nullptr; 71 | KBlocksNetClient *mpNetClient = nullptr; 72 | QLabel *mScore = nullptr; 73 | }; 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /src/KBlocksDummyAI.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksDummyAI.h" 8 | 9 | #include 10 | 11 | KBlocksDummyAI::KBlocksDummyAI() 12 | { 13 | mPauseFlag = false; 14 | 15 | mFieldWidth = 0; 16 | mRotateCount = 0; 17 | } 18 | 19 | KBlocksDummyAI::~KBlocksDummyAI() 20 | { 21 | } 22 | 23 | void KBlocksDummyAI::startGame(SingleGameInterface *p) 24 | { 25 | mpGame = p; 26 | mPauseFlag = false; 27 | 28 | mFieldWidth = mpGame->getField()->getWidth(); 29 | mRotateCount = mpGame->getPiece(0)->getRotationCount(); 30 | } 31 | 32 | void KBlocksDummyAI::stopGame() 33 | { 34 | mpGame = nullptr; 35 | } 36 | 37 | void KBlocksDummyAI::pauseGame(bool flag) 38 | { 39 | mPauseFlag = flag; 40 | } 41 | 42 | void KBlocksDummyAI::think(GamePlayer_ActionList *actionList) 43 | { 44 | if (mPauseFlag) { 45 | return; 46 | } 47 | 48 | auto random = QRandomGenerator::global(); 49 | int rotation = random->bounded(mRotateCount + 1) - mRotateCount / 2; 50 | int motionx = random->bounded(mFieldWidth + 1) - mFieldWidth / 2; 51 | 52 | if (rotation > 0) { 53 | for (int i = 0; i < rotation; i++) { 54 | actionList->push_back(PlayerAction_Rotate_CW); 55 | } 56 | } else { 57 | rotation = -rotation; 58 | for (int i = 0; i < rotation; i++) { 59 | actionList->push_back(PlayerAction_Rotate_CCW); 60 | } 61 | } 62 | 63 | if (motionx > 0) { 64 | for (int i = 0; i < motionx; i++) { 65 | actionList->push_back(PlayerAction_Move_Right); 66 | } 67 | } else { 68 | motionx = -motionx; 69 | for (int i = 0; i < motionx; i++) { 70 | actionList->push_back(PlayerAction_Move_Left); 71 | } 72 | } 73 | 74 | //actionList->push_back(PlayerAction_Push_Down); 75 | } 76 | -------------------------------------------------------------------------------- /src/KBlocksDummyAI.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSDUMMYAI_H 8 | #define KBLOCKSDUMMYAI_H 9 | 10 | #include "GamePlayerInterface.h" 11 | 12 | class KBlocksDummyAI : public GamePlayerInterface 13 | { 14 | public: 15 | KBlocksDummyAI(); 16 | ~KBlocksDummyAI() override; 17 | 18 | public: 19 | void startGame(SingleGameInterface *p) override; 20 | void stopGame() override; 21 | 22 | void pauseGame(bool flag) override; 23 | 24 | void think(GamePlayer_ActionList *actionList) override; 25 | 26 | protected: 27 | bool mPauseFlag; 28 | 29 | int mFieldWidth; 30 | int mRotateCount; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/KBlocksField.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSFIELD_H 8 | #define KBLOCKSFIELD_H 9 | 10 | #include "FieldInterface.h" 11 | 12 | class KBlocksField : public FieldInterface 13 | { 14 | protected: 15 | bool **maBoard; 16 | int mHeight; 17 | int mWidth; 18 | 19 | private: 20 | int mCurModifyID; 21 | int mLastModifyID; 22 | unsigned char *maEncodeData; 23 | 24 | public: 25 | explicit KBlocksField(int width = 10, int height = 20); 26 | explicit KBlocksField(FieldInterface *p); 27 | ~KBlocksField() override; 28 | 29 | public: 30 | bool getCell(int xPos, int yPos) override; 31 | void setCell(int xPos, int yPos, bool value); 32 | 33 | void copy(FieldInterface *p); 34 | void clear(); 35 | 36 | bool checkFilledLine(int lineID); 37 | void removeFilledLine(int lineID); 38 | 39 | bool addPunishLine(int lineCount, int punishSeed); 40 | 41 | int getModifyID(); 42 | int encodeData(unsigned char *data); 43 | void decodeData(unsigned char *data); 44 | 45 | int getWidth() override; 46 | int getHeight() override; 47 | 48 | bool equals(KBlocksField *rhs); 49 | 50 | int getBlockHeight(int xPos); 51 | int getFreeHeight(int xPos); 52 | void getSignature(int *data); 53 | }; 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /src/KBlocksGameLogic.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Zhongjie Cai * 4 | * Julian Helfferich * 5 | * * 6 | * SPDX-License-Identifier: GPL-2.0-or-later 7 | ******************************************************************************/ 8 | #ifndef KBLOCKSGAMELOGIC_H 9 | #define KBLOCKSGAMELOGIC_H 10 | 11 | #include 12 | 13 | #include "GameLogicInterface.h" 14 | #include "SingleGameInterface.h" 15 | 16 | #include "KBlocksDefine.h" 17 | 18 | #include "KBlocksGameRecorder.h" 19 | #include "KBlocksGameReplayer.h" 20 | 21 | #include "KBlocksSingleGame.h" 22 | 23 | class KBlocksGameLogic : public GameLogicInterface 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | explicit KBlocksGameLogic(int capacity, bool record = false); 29 | explicit KBlocksGameLogic(KBlocksGameReplayer *p); 30 | ~KBlocksGameLogic() override; 31 | 32 | public: 33 | int getActiveGameCount(); 34 | KBlocksSingleGame *getSingleGame(int index) override; 35 | 36 | bool playRecordOneStep(int *changedPiece); 37 | void saveRecord(const char *fileName, bool binaryMode = true); 38 | 39 | int levelUpGame(int level) override; 40 | int updateGame(int *lineList) override; 41 | 42 | void setGameSeed(int seed) override; 43 | void setGamePunish(bool flag); 44 | 45 | void setGameStandbyMode(bool flag) override; 46 | void setGameInterval(int interval); 47 | void setInitInterval(int interval); 48 | void setLevelUpInterval(int interval); 49 | 50 | bool startGame(int gameCount) override; 51 | 52 | void pauseGame(bool pauseFlag) override; 53 | void continueGame() override; 54 | 55 | /** 56 | * Return whether single games have been created. 57 | */ 58 | bool hasSingleGames() override; 59 | void deleteSingleGames() override; 60 | 61 | public Q_SLOTS: 62 | bool stopGame() override; 63 | 64 | private: 65 | void createSingleGames(int gameCount); 66 | 67 | protected: 68 | KBlocksSingleGame **maGameList; 69 | 70 | private: 71 | int mGameMax; 72 | int mGameCount; 73 | 74 | int mGameSeed; 75 | int mPunishFlag; 76 | 77 | bool mStandbyMode; 78 | int mGameInterval; 79 | int mInitialInterval; 80 | int mLevelUpInterval; 81 | 82 | KBlocksGameRecorder *mpGameRecorder = nullptr; 83 | KBlocksGameReplayer *mpGameReplayer = nullptr; 84 | }; 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /src/KBlocksGameMessage.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksGameMessage.h" 8 | 9 | KBlocksGameMessage::KBlocksGameMessage(int poolSize) 10 | { 11 | mPoolSize = poolSize; 12 | 13 | mActionCount = 0; 14 | maActionType = new int[mPoolSize]; 15 | maActionList = new int[mPoolSize]; 16 | 17 | mResultCount = 0; 18 | maResultList = new int[mPoolSize]; 19 | } 20 | 21 | KBlocksGameMessage::~KBlocksGameMessage() 22 | { 23 | delete [] maResultList; 24 | delete [] maActionList; 25 | delete [] maActionType; 26 | } 27 | 28 | bool KBlocksGameMessage::pickGameResult(int *result) 29 | { 30 | if (mResultCount == 0) { 31 | return false; 32 | } 33 | 34 | *result = maResultList[0]; 35 | 36 | for (int j = 0; j < mResultCount - 1; j++) { 37 | maResultList[j] = maResultList[j + 1]; 38 | } 39 | 40 | mResultCount--; 41 | 42 | return true; 43 | } 44 | 45 | bool KBlocksGameMessage::putGameResult(int result) 46 | { 47 | if (mResultCount == mPoolSize) { 48 | return false; 49 | } 50 | 51 | maResultList[mResultCount] = result; 52 | 53 | mResultCount++; 54 | 55 | return true; 56 | } 57 | 58 | void KBlocksGameMessage::clearGameResult() 59 | { 60 | mResultCount = 0; 61 | } 62 | 63 | bool KBlocksGameMessage::pickGameAction(int *type, int *action) 64 | { 65 | if (mActionCount == 0) { 66 | return false; 67 | } 68 | 69 | if (*type != GameAction_None) { 70 | for (int i = 0; i < mActionCount; i++) { 71 | if (*type == maActionType[i]) { 72 | *action = maActionList[i]; 73 | 74 | for (int j = i; j < mActionCount - 1; j++) { 75 | maActionType[j] = maActionType[j + 1]; 76 | maActionList[j] = maActionList[j + 1]; 77 | } 78 | 79 | mActionCount--; 80 | 81 | return true; 82 | } 83 | } 84 | 85 | return false; 86 | } else { 87 | *type = maActionType[0]; 88 | *action = maActionList[0]; 89 | 90 | for (int j = 0; j < mActionCount - 1; j++) { 91 | maActionType[j] = maActionType[j + 1]; 92 | maActionList[j] = maActionList[j + 1]; 93 | } 94 | 95 | mActionCount--; 96 | 97 | return true; 98 | } 99 | } 100 | 101 | bool KBlocksGameMessage::putGameAction(int type, int action) 102 | { 103 | if (mActionCount == mPoolSize) { 104 | return false; 105 | } 106 | 107 | maActionType[mActionCount] = type; 108 | maActionList[mActionCount] = action; 109 | 110 | mActionCount++; 111 | 112 | return true; 113 | } 114 | 115 | void KBlocksGameMessage::clearGameAction() 116 | { 117 | mActionCount = 0; 118 | } 119 | -------------------------------------------------------------------------------- /src/KBlocksGameMessage.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSGAMEMESSAGE_H 8 | #define KBLOCKSGAMEMESSAGE_H 9 | 10 | #include "KBlocksDefine.h" 11 | 12 | class KBlocksGameMessage 13 | { 14 | public: 15 | explicit KBlocksGameMessage(int poolSize); 16 | ~KBlocksGameMessage(); 17 | 18 | public: 19 | bool pickGameResult(int *result); 20 | bool putGameResult(int result); 21 | void clearGameResult(); 22 | 23 | bool pickGameAction(int *type, int *action); 24 | bool putGameAction(int type, int action); 25 | void clearGameAction(); 26 | 27 | private: 28 | int mPoolSize; 29 | 30 | int mActionCount; 31 | int *maActionType; 32 | int *maActionList; 33 | 34 | int mResultCount; 35 | int *maResultList; 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /src/KBlocksGameRecorder.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksGameRecorder.h" 8 | #include "utils.h" 9 | 10 | KBlocksGameRecorder::KBlocksGameRecorder() 11 | { 12 | mGameRecord.clear(); 13 | } 14 | 15 | KBlocksGameRecorder::~KBlocksGameRecorder() 16 | { 17 | mGameRecord.clear(); 18 | } 19 | 20 | void KBlocksGameRecorder::append(int index, int type, int value) 21 | { 22 | _game_record_data tmpLastData; 23 | tmpLastData.index = index; 24 | tmpLastData.type = type; 25 | tmpLastData.value = value; 26 | tmpLastData.time = Utils::getMillisecOfNow(); 27 | mGameRecord.push_back(tmpLastData); 28 | } 29 | 30 | void KBlocksGameRecorder::save(const char *fileName, bool isBinaryMode) 31 | { 32 | FILE *pFile = fopen(fileName, "w"); 33 | if (isBinaryMode) { 34 | saveBinary(pFile); 35 | } else { 36 | saveText(pFile); 37 | } 38 | fclose(pFile); 39 | } 40 | 41 | void KBlocksGameRecorder::saveText(FILE *pFile) 42 | { 43 | int tmpTime = 0; 44 | timeLong oldTime = mGameRecord.front().time; 45 | list<_game_record_data>::iterator it; 46 | for (it = mGameRecord.begin(); it != mGameRecord.end(); ++it) { 47 | tmpTime = (int)(it->time - oldTime); 48 | oldTime = it->time; 49 | fprintf(pFile, "%d %s %d %d\n", tmpTime, KBlocksRecordText[it->type], it->index, it->value); 50 | } 51 | } 52 | 53 | void KBlocksGameRecorder::saveBinary(FILE *pFile) 54 | { 55 | int tmpTime = 0; 56 | timeLong oldTime = mGameRecord.front().time; 57 | list<_game_record_data>::iterator it; 58 | for (it = mGameRecord.begin(); it != mGameRecord.end(); ++it) { 59 | tmpTime = (int)(it->time - oldTime); 60 | oldTime = it->time; 61 | if (tmpTime > 255) { 62 | while (tmpTime > 255) { 63 | writeByte(pFile, 255); 64 | writeByte(pFile, RecordDataType_Skipped); 65 | writeByte(pFile, it->index); 66 | writeByte(pFile, it->value); 67 | tmpTime -= 255; 68 | } 69 | } 70 | writeByte(pFile, tmpTime); 71 | writeByte(pFile, it->type); 72 | writeByte(pFile, it->index); 73 | writeByte(pFile, it->value); 74 | } 75 | } 76 | 77 | void KBlocksGameRecorder::writeByte(FILE *pFile, int value) 78 | { 79 | int tmpByte = (value & 0xFF); 80 | fputc(tmpByte, pFile); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/KBlocksGameRecorder.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSGAMERECORDER_H 8 | #define KBLOCKSGAMERECORDER_H 9 | 10 | #include "KBlocksDefine.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using std::string; 17 | using std::list; 18 | 19 | struct _game_record_data { 20 | int index; 21 | int type; 22 | int value; 23 | timeLong time; 24 | }; 25 | 26 | class KBlocksGameRecorder 27 | { 28 | public: 29 | KBlocksGameRecorder(); 30 | ~KBlocksGameRecorder(); 31 | 32 | public: 33 | void append(int index, int type, int value); 34 | void save(const char *fileName, bool isBinaryMode = true); 35 | 36 | private: 37 | void saveText(FILE *pFile); 38 | void saveBinary(FILE *pFile); 39 | void writeByte(FILE *pFile, int value); 40 | 41 | private: 42 | list<_game_record_data> mGameRecord; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/KBlocksGameReplayer.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksGameReplayer.h" 8 | 9 | #include 10 | 11 | #include "kblocks_replay_debug.h" 12 | 13 | KBlocksGameReplayer::KBlocksGameReplayer(const char *fileName, bool isBinaryMode) 14 | { 15 | // Map data types to strings for reading text file 16 | for (int i = 0; i < RecordDataType_Max_Count; ++i) { 17 | mRTMap[ KBlocksRecordText[i] ] = i; 18 | } 19 | mRTMap[string("MaxCount")] = -1; 20 | 21 | // Set default variables in case loading the file fails 22 | mGameCount = 0; 23 | mGameSeed = 0; 24 | mSameSeed = false; 25 | mStepLength = 1; 26 | 27 | // Open replay file 28 | std::ifstream replayFile; 29 | if (isBinaryMode) { 30 | replayFile.open(fileName, std::ios::binary); 31 | } else { 32 | replayFile.open(fileName); 33 | } 34 | 35 | // Check that replay file was opened successfully 36 | if (!replayFile.is_open()) { 37 | qCWarning(KBReplay) << "Unable to open file " << fileName; 38 | return; 39 | } 40 | 41 | if (isBinaryMode) { 42 | loadBinary(replayFile); 43 | } else { 44 | loadText(replayFile); 45 | } 46 | 47 | // Check that more than two Replay steps have been loaded 48 | // The two first steps set the required variables. 49 | if (mReplayList.size() < 2) { 50 | qCWarning(KBReplay) << "Problem loading replay file" << fileName; 51 | return; 52 | } 53 | 54 | mGameCount = mReplayList.front().value; 55 | mReplayList.pop_front(); 56 | mGameSeed = mReplayList.front().value; 57 | mSameSeed = (mReplayList.front().index == 1); 58 | mReplayList.pop_front(); 59 | 60 | replayFile.close(); 61 | } 62 | 63 | KBlocksGameReplayer::~KBlocksGameReplayer() 64 | { 65 | } 66 | 67 | int KBlocksGameReplayer::getGameCount() 68 | { 69 | return mGameCount; 70 | } 71 | 72 | int KBlocksGameReplayer::getGameSeed() 73 | { 74 | return mGameSeed; 75 | } 76 | 77 | bool KBlocksGameReplayer::isSameSeed() 78 | { 79 | return mSameSeed; 80 | } 81 | 82 | void KBlocksGameReplayer::setStepLength(int stepLen) 83 | { 84 | if (stepLen > 1) { 85 | mStepLength = stepLen; 86 | } else { 87 | mStepLength = 1; 88 | } 89 | } 90 | 91 | bool KBlocksGameReplayer::getNextRecords(vector *data) 92 | { 93 | if (mReplayList.empty()) { 94 | return false; 95 | } 96 | 97 | KBlocksReplayData tmpData; 98 | int tmpLength = mStepLength; 99 | while (tmpLength > 0) { 100 | tmpData = mReplayList.front(); 101 | tmpLength -= tmpData.time; 102 | if (tmpLength > 0) { 103 | data->push_back(tmpData); 104 | mReplayList.pop_front(); 105 | } else { 106 | mReplayList.front().time = -tmpLength; 107 | } 108 | if (mReplayList.empty()) { 109 | return true; 110 | } 111 | } 112 | 113 | return true; 114 | } 115 | 116 | void KBlocksGameReplayer::loadText(std::ifstream &replayFile) 117 | { 118 | std::string line; 119 | std::istringstream inStream; 120 | std::string tmpString; 121 | KBlocksReplayData tmpData; 122 | mReplayList.clear(); 123 | do { 124 | std::getline(replayFile, line); 125 | inStream.str(line); 126 | inStream >> tmpData.time >> tmpString >> tmpData.index >> tmpData.value; 127 | tmpData.type = mRTMap[tmpString]; 128 | if ((tmpData.type == -1) || inStream.fail()) { 129 | break; 130 | } 131 | mReplayList.push_back(tmpData); 132 | inStream.clear(); 133 | } while (!replayFile.eof()); 134 | } 135 | 136 | void KBlocksGameReplayer::loadBinary(std::ifstream &replayFile) 137 | { 138 | KBlocksReplayData tmpData; 139 | mReplayList.clear(); 140 | 141 | tmpData.time = replayFile.get(); 142 | tmpData.type = replayFile.get(); 143 | tmpData.index = replayFile.get(); 144 | tmpData.value = replayFile.get(); 145 | 146 | do { 147 | if (tmpData.type == RecordDataType_Skipped) { 148 | int tmpTime = tmpData.time; 149 | while (tmpData.type == RecordDataType_Skipped) { 150 | tmpData.time = replayFile.get(); 151 | tmpData.type = replayFile.get(); 152 | tmpData.index = replayFile.get(); 153 | tmpData.value = replayFile.get(); 154 | 155 | tmpTime += tmpData.time; 156 | } 157 | tmpData.time = tmpTime; 158 | } 159 | mReplayList.push_back(tmpData); 160 | tmpData.time = replayFile.get(); 161 | tmpData.type = replayFile.get(); 162 | tmpData.index = replayFile.get(); 163 | tmpData.value = replayFile.get(); 164 | } while (!replayFile.eof()); 165 | } 166 | 167 | -------------------------------------------------------------------------------- /src/KBlocksGameReplayer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSGAMEREPLAYER_H 8 | #define KBLOCKSGAMEREPLAYER_H 9 | 10 | #include "KBlocksDefine.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | using std::string; 19 | using std::vector; 20 | using std::list; 21 | using std::map; 22 | 23 | struct KBlocksReplayData { 24 | int index; 25 | int type; 26 | int value; 27 | int time; 28 | }; 29 | 30 | class KBlocksGameReplayer 31 | { 32 | public: 33 | explicit KBlocksGameReplayer(const char *fileName, bool isBinaryMode = true); 34 | ~KBlocksGameReplayer(); 35 | 36 | public: 37 | void setStepLength(int stepLen); 38 | 39 | int getGameCount(); 40 | int getGameSeed(); 41 | bool isSameSeed(); 42 | 43 | bool getNextRecords(vector *data); 44 | 45 | private: 46 | void loadText(std::ifstream &pFile); 47 | void loadBinary(std::ifstream &pFile); 48 | 49 | private: 50 | int mGameCount; 51 | int mGameSeed; 52 | bool mSameSeed; 53 | int mStepLength; 54 | list mReplayList; 55 | map mRTMap; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/KBlocksGraphics.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * * 6 | * SPDX-License-Identifier: GPL-2.0-or-later 7 | ***************************************************************************/ 8 | #include "KBlocksGraphics.h" 9 | 10 | #include "KBlocksTheme.h" 11 | #include "kblocks_graphics_debug.h" 12 | 13 | #include 14 | 15 | KBlocksGraphics::KBlocksGraphics(const KBlocksTheme *theme) 16 | { 17 | m_renderer = new QSvgRenderer(theme->graphicsPath()); 18 | readThemeValues(theme); 19 | } 20 | 21 | KBlocksGraphics::~KBlocksGraphics() 22 | { 23 | delete m_renderer; 24 | } 25 | 26 | bool KBlocksGraphics::loadTheme(const KBlocksTheme *theme) 27 | { 28 | if (!m_renderer->load(theme->graphicsPath())) { 29 | qCWarning(KBGraphics) << "Error loading SVG theme" 30 | << theme->graphicsPath(); 31 | return false; 32 | } 33 | //clear the cache or pixmaps from the old theme will be returned 34 | //QPixmapCache::clear(); 35 | readThemeValues(theme); 36 | 37 | return true; 38 | } 39 | 40 | void KBlocksGraphics::readThemeValues(const KBlocksTheme *theme) 41 | { 42 | //Extract values from SVG elements 43 | QRectF bounds; 44 | bounds = m_renderer->boundsOnElement(QStringLiteral("BLOCK_SIZE")); 45 | m_Block_Size = bounds.width(); 46 | bounds = m_renderer->boundsOnElement(QStringLiteral("VIEW")); 47 | m_View_Size_Width = bounds.width(); 48 | m_View_Size_Height = bounds.height(); 49 | bounds = m_renderer->boundsOnElement(QStringLiteral("PLAY_AREA")); 50 | m_PlayArea_OffsetPoint_X = bounds.x(); 51 | m_PlayArea_OffsetPoint_Y = bounds.y(); 52 | m_PlayArea_NumberOfBlocks_X = bounds.width() / (double)m_Block_Size; 53 | m_PlayArea_NumberOfBlocks_Y = bounds.height() / (double)m_Block_Size; 54 | bounds = m_renderer->boundsOnElement(QStringLiteral("NEXTPIECE_AREA")); 55 | m_PreviewArea_CenterPoint_X = bounds.center().x(); 56 | m_PreviewArea_CenterPoint_Y = bounds.center().y(); 57 | 58 | const QString backgroundLocation = theme->customData(QStringLiteral("BackgroundLocation"), QStringLiteral("Stretch")); 59 | if(backgroundLocation == QStringLiteral("Stretch")) { 60 | m_BackgroundLocation = BackgroundLocation::Stretch; 61 | } else if(backgroundLocation == QStringLiteral("TopLeft")) { 62 | m_BackgroundLocation = BackgroundLocation::TopLeft; 63 | } else if(backgroundLocation == QStringLiteral("Center")) { 64 | m_BackgroundLocation = BackgroundLocation::Center; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /src/KBlocksGraphics.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2020 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSGRAPHICS_H 10 | #define KBLOCKSGRAPHICS_H 11 | 12 | #include 13 | #include 14 | 15 | #include "GraphicsInterface.h" 16 | 17 | class KBlocksGraphics : public GraphicsInterface 18 | { 19 | public: 20 | explicit KBlocksGraphics(const KBlocksTheme *theme); 21 | ~KBlocksGraphics() override; 22 | 23 | public: 24 | bool loadTheme(const KBlocksTheme *theme) override; 25 | void readThemeValues(const KBlocksTheme *theme) override; 26 | QSvgRenderer *renderer() const override 27 | { 28 | return m_renderer; 29 | } 30 | 31 | private: 32 | QSvgRenderer *m_renderer = nullptr; 33 | 34 | //QPixmap renderElement(int width, int height, const QString & elementid); 35 | //QString pixmapCacheNameFromElementId(int width, int height, const QString & elementid); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/KBlocksItemGroup.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | 10 | #ifndef KBLOCKSITEMGROUP_H 11 | #define KBLOCKSITEMGROUP_H 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "KBlocksAnimator.h" 18 | 19 | #include "SingleGameInterface.h" 20 | 21 | #include "KBlocksDefine.h" 22 | 23 | class GraphicsInterface; 24 | class KBlocksLayout; 25 | class KBlocksSvgItem; 26 | class SoundInterface; 27 | class SvgItemInterface; 28 | 29 | class KBlocksItemGroup : public QObject, public QGraphicsItemGroup 30 | { 31 | Q_OBJECT 32 | 33 | public: 34 | KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS, bool snapshotMode = false); 35 | ~KBlocksItemGroup() override; 36 | 37 | public: 38 | void setUpdateInterval(int interval); 39 | void setGameAnimEnabled(bool flag); 40 | void setWaitForAllUpdate(bool flag); 41 | void refreshPosition(); 42 | 43 | void startGame(); 44 | void stopGame(); 45 | 46 | void pauseGame(bool flag); 47 | 48 | Q_SIGNALS: 49 | void readyForAction(int groupID); 50 | 51 | protected Q_SLOTS: 52 | void updateGame(); 53 | 54 | private Q_SLOTS: 55 | void updateSnapshot(); 56 | void endAnimation(int animType); 57 | 58 | private: 59 | bool updateLayout(); 60 | void refreshItems(); 61 | 62 | void refreshItemByPos(const QList &dataList); 63 | 64 | void fadeInNewPiece(); 65 | void fadeOutOldLine(); 66 | void dropFreezeLine(); 67 | 68 | void updateGraphicInfo(); 69 | 70 | protected: 71 | int mMaxFreezeCellNum; 72 | SvgItemInterface **maFreezeCells; 73 | 74 | int mMaxPrepareCellNum; 75 | SvgItemInterface **maPrepareCells; 76 | 77 | private: 78 | int mGroupID; 79 | 80 | KBlocksSvgItem *mpBackground; 81 | 82 | SingleGameInterface *mpSingleGame; 83 | KBlocksLayout *mpGameLayout = nullptr; 84 | GraphicsInterface *mpGrafx = nullptr; 85 | SoundInterface *mpSnd = nullptr; 86 | 87 | QTimer mUpdateTimer; 88 | int mUpdateInterval; 89 | bool mGameAnimEnabled; 90 | bool mWaitForAllUpdate; 91 | 92 | KBlocksAnimator *mpAnimator; 93 | QList mFadeInItems; 94 | QList mFadeOutItems; 95 | QList mDropItems; 96 | 97 | QList mRemovedLine; 98 | QList mPunishLine; 99 | QList mNewPiecePos; 100 | 101 | int mFieldWidth; 102 | int mFieldHeight; 103 | 104 | int mItemSize; 105 | int mPrepareLeft; 106 | int mPrepareTop; 107 | int mFieldLeft; 108 | int mFieldTop; 109 | }; 110 | 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /src/KBlocksKeyboardPlayer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSKEYBOARDPLAYER_H 8 | #define KBLOCKSKEYBOARDPLAYER_H 9 | 10 | #include 11 | using namespace std; 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "GamePlayerInterface.h" 19 | 20 | class KBlocksKeyboardPlayer : public QObject, public GamePlayerInterface 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | explicit KBlocksKeyboardPlayer(KXmlGuiWindow *parent, const string &name = "", bool netMode = false); 26 | ~KBlocksKeyboardPlayer() override; 27 | 28 | public: 29 | void startGame(SingleGameInterface *p) override; 30 | void stopGame() override; 31 | 32 | void pauseGame(bool flag) override; 33 | 34 | void think(GamePlayer_ActionList *actionList) override; 35 | 36 | string getName() override; 37 | 38 | private: 39 | void bindKeys(); 40 | 41 | Q_SIGNALS: 42 | void blockMoved(); 43 | void blockDropped(); 44 | 45 | private Q_SLOTS: 46 | void moveLeft(); 47 | void moveRight(); 48 | void moveDown(); 49 | void pushDown(); 50 | void rotateCW(); 51 | void rotateCCW(); 52 | 53 | protected: 54 | SingleGameInterface *mpGame = nullptr; 55 | bool mPauseFlag; 56 | 57 | QAction *rotatecw = nullptr; 58 | QAction *rotateccw = nullptr; 59 | QAction *moveleft = nullptr; 60 | QAction *moveright = nullptr; 61 | QAction *movedown = nullptr; 62 | QAction *pushdown = nullptr; 63 | 64 | private: 65 | bool mNetMode; 66 | string mPlayerName; 67 | GamePlayer_ActionList mActionList; 68 | 69 | KXmlGuiWindow *mpKeyWindow = nullptr; 70 | KActionCollection *mpKeyShortcuts = nullptr; 71 | }; 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /src/KBlocksLayout.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSLAYOUT_H 8 | #define KBLOCKSLAYOUT_H 9 | 10 | #include "FieldInterface.h" 11 | #include "PieceInterface.h" 12 | 13 | #include "KBlocksDefine.h" 14 | 15 | #include 16 | #include 17 | 18 | enum KBlocks_Layout_Update_Type { 19 | KBlocksLayout_Update_FreezePiece = 0, 20 | KBlocksLayout_Update_RemoveLine, 21 | KBlocksLayout_Update_PunishLine, 22 | KBlocksLayout_Update_Max_Count 23 | }; 24 | 25 | class KBlocksLayout 26 | { 27 | public: 28 | KBlocksLayout(FieldInterface *pF, PieceInterface *pA, PieceInterface *pN); 29 | ~KBlocksLayout(); 30 | 31 | void beginUpdate(QList *list); 32 | void updateLayout(int type, const QList &dataList); 33 | void endUpdate(); 34 | 35 | void updateSnapshot(); 36 | 37 | int getFieldColor(int posX, int posY); 38 | int getPrepareColor(int posX, int posY); 39 | 40 | private: 41 | void updatePrepareArea(); 42 | void updateFreezePiece(const QList &dataList); 43 | void updateRemoveLine(const QList &dataList); 44 | void updatePunishLine(const QList &dataList); 45 | 46 | private: 47 | FieldInterface *mpGameField = nullptr; 48 | PieceInterface *mpActivePiece = nullptr; 49 | PieceInterface *mpNextPiece = nullptr; 50 | 51 | int **boardInfo; 52 | int **prepareInfo; 53 | 54 | int mPieceCellCount; 55 | QPoint **mpLastPiecePos; 56 | 57 | int mWidth; 58 | int mHeight; 59 | }; 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /src/KBlocksNetClient.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksNetClient.h" 8 | 9 | KBlocksNetClient::KBlocksNetClient(const QString &remoteIP, quint16 localPort) 10 | { 11 | mLocalAddress = QHostAddress::Any; 12 | mLocalPort = localPort; 13 | 14 | parseIPString(remoteIP, &mRemoteAddress, &mRemotePort); 15 | 16 | mpClientSocket = new QUdpSocket(this); 17 | mpClientSocket->bind(mLocalAddress, mLocalPort); 18 | connect(mpClientSocket, &QUdpSocket::readyRead, this, &KBlocksNetClient::receivedData); 19 | } 20 | 21 | KBlocksNetClient::~KBlocksNetClient() 22 | { 23 | delete mpClientSocket; 24 | } 25 | 26 | int KBlocksNetClient::sendData(int count, char *data) 27 | { 28 | int ret = mpClientSocket->writeDatagram(data, count, mRemoteAddress, mRemotePort); 29 | if (ret < 0) { 30 | printf("Send error\n"); 31 | } 32 | return ret; 33 | } 34 | 35 | int KBlocksNetClient::recvData(int count, char *data) 36 | { 37 | if (!mpClientSocket->hasPendingDatagrams()) { 38 | return -1; 39 | } 40 | return mpClientSocket->readDatagram(data, count); 41 | } 42 | 43 | bool KBlocksNetClient::parseIPString(const QString &input, QHostAddress *ip, quint16 *port) 44 | { 45 | bool result = false; 46 | ip->setAddress(input.left(input.indexOf(QStringLiteral(":")))); 47 | *port = QStringView(input).mid(input.indexOf(QStringLiteral(":")) + 1).toUInt(&result); 48 | return result; 49 | } 50 | 51 | void KBlocksNetClient::receivedData() 52 | { 53 | Q_EMIT(dataArrived(mpClientSocket->pendingDatagramSize())); 54 | } 55 | 56 | #include "moc_KBlocksNetClient.cpp" 57 | -------------------------------------------------------------------------------- /src/KBlocksNetClient.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSNETCLIENT_H 8 | #define KBLOCKSNETCLIENT_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | class KBlocksNetClient : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | KBlocksNetClient(const QString &remoteIP, quint16 localPort); 20 | ~KBlocksNetClient() override; 21 | 22 | public: 23 | int sendData(int count, char *data); 24 | int recvData(int count, char *data); 25 | 26 | Q_SIGNALS: 27 | void dataArrived(int size); 28 | 29 | private: 30 | bool parseIPString(const QString &input, QHostAddress *ip, quint16 *port); 31 | 32 | private Q_SLOTS: 33 | void receivedData(); 34 | 35 | private: 36 | QUdpSocket *mpClientSocket = nullptr; 37 | 38 | QHostAddress mLocalAddress; 39 | quint16 mLocalPort; 40 | 41 | QHostAddress mRemoteAddress; 42 | quint16 mRemotePort; 43 | }; 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /src/KBlocksNetPlayer.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksNetPlayer.h" 8 | 9 | #include "AI/KBlocksAILog.h" 10 | 11 | KBlocksNetPlayer::KBlocksNetPlayer(GamePlayerInterface *player, const string &serverIP, int localPort) 12 | { 13 | mpNetClient = new KBlocksNetClient(QString::fromStdString(serverIP), localPort); 14 | 15 | mpPlayer = player; 16 | mpGame = nullptr; 17 | 18 | mSendLength = 0; 19 | mActionList.clear(); 20 | } 21 | 22 | KBlocksNetPlayer::~KBlocksNetPlayer() 23 | { 24 | delete mpNetClient; 25 | } 26 | 27 | void KBlocksNetPlayer::joinGame(int gameIndex) 28 | { 29 | int tmpByteCount = 0; 30 | char tmpByteData[256]; 31 | string tmpName = mpPlayer->getName(); 32 | 33 | tmpByteData[tmpByteCount++] = '|'; 34 | tmpByteData[tmpByteCount++] = 'a'; 35 | tmpByteData[tmpByteCount++] = 'p'; 36 | tmpByteData[tmpByteCount++] = '|'; 37 | tmpByteData[tmpByteCount++] = (char)gameIndex + '0'; 38 | tmpByteData[tmpByteCount++] = '|'; 39 | for (size_t i = 0; i < tmpName.length(); ++i) { 40 | tmpByteData[tmpByteCount++] = (char)tmpName[i]; 41 | } 42 | tmpByteData[tmpByteCount++] = 0; 43 | 44 | mpNetClient->sendData(tmpByteCount, tmpByteData); 45 | } 46 | 47 | void KBlocksNetPlayer::quitGame() 48 | { 49 | char tmpByteData[5] = {'|', 'd', 'p', '|', '\0'}; 50 | mpNetClient->sendData(5, tmpByteData); 51 | } 52 | 53 | void KBlocksNetPlayer::startGame(KBlocksSingleGame *p) 54 | { 55 | char tmpByteData[4] = {'|', 's', '|', '\0'}; 56 | mpNetClient->sendData(4, tmpByteData); 57 | 58 | mpGame = p; 59 | mpPlayer->startGame(mpGame); 60 | 61 | mActionList.clear(); 62 | } 63 | 64 | void KBlocksNetPlayer::stopGame() 65 | { 66 | char tmpByteData[4] = {'|', 'c', '|', '\0'}; 67 | mpNetClient->sendData(4, tmpByteData); 68 | 69 | mpPlayer->stopGame(); 70 | mpGame = nullptr; 71 | 72 | mActionList.clear(); 73 | } 74 | 75 | bool KBlocksNetPlayer::execute() 76 | { 77 | bool execResult = true; 78 | char *tmpByteData = new char[256]; 79 | 80 | int ret = mpNetClient->recvData(256, tmpByteData); 81 | if (ret < 0) { 82 | // Do nothing... 83 | //printf("--Nothing received\n"); 84 | } else if (tmpByteData[0] == -1) { 85 | mSendLength = (unsigned char)tmpByteData[1]; 86 | //printf("--Send Length = %d\n", mSendLength); 87 | } else if (tmpByteData[0] == 127) { 88 | execResult = false; 89 | //printf("--Game Ended\n"); 90 | } else { 91 | //printf("++Game Updates (%d) of [%d bytes]\n", (int)tmpByteData[0], ret); 92 | int tmpPieceCount = formIntFromByte(tmpByteData + 13); 93 | for (int i = 0; i < tmpPieceCount; ++i) { 94 | mpGame->getPiece(i)->decodeData((unsigned char *)tmpByteData + 17 + i * 4); 95 | } 96 | 97 | mpGame->getField()->decodeData((unsigned char *)tmpByteData + 18 + tmpPieceCount * 4); 98 | 99 | mActionList.clear(); 100 | mpPlayer->think(&mActionList); 101 | 102 | GamePlayer_ActionList::iterator it; 103 | int byteCounter = 0; 104 | char *tmpSendData = new char[256]; 105 | tmpSendData[byteCounter++] = '|'; 106 | tmpSendData[byteCounter++] = 'r'; 107 | tmpSendData[byteCounter++] = 'p'; 108 | tmpSendData[byteCounter++] = '|'; 109 | if (mSendLength == 0) { 110 | for (it = mActionList.begin(); it != mActionList.end(); ++it) { 111 | tmpSendData[byteCounter++] = (char) * it + '0'; 112 | } 113 | } else if (!mActionList.empty()) { 114 | for (int i = 0; i < mSendLength; i++) { 115 | tmpSendData[byteCounter++] = (char)mActionList.front() + '0'; 116 | mActionList.pop_front(); 117 | if (mActionList.empty()) { 118 | break; 119 | } 120 | } 121 | } 122 | tmpSendData[byteCounter++] = '|'; 123 | tmpSendData[byteCounter++] = '\0'; 124 | 125 | mpNetClient->sendData(byteCounter, tmpSendData); 126 | //printf("Sending : [%s]\n", tmpSendData); 127 | 128 | delete [] tmpSendData; 129 | } 130 | 131 | delete [] tmpByteData; 132 | 133 | return execResult; 134 | } 135 | 136 | int KBlocksNetPlayer::formIntFromByte(char *data) 137 | { 138 | int value = 0; 139 | value += ((int)data[0]) & 0x000000FF; 140 | value += (((int)data[1]) << 8) & 0x0000FF00; 141 | value += (((int)data[2]) << 16) & 0x00FF0000; 142 | value += (((int)data[3]) << 24) & 0xFF000000; 143 | return value; 144 | } 145 | -------------------------------------------------------------------------------- /src/KBlocksNetPlayer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSNETPLAYER_H 8 | #define KBLOCKSNETPLAYER_H 9 | 10 | #include "KBlocksNetClient.h" 11 | #include "KBlocksSingleGame.h" 12 | #include "GamePlayerInterface.h" 13 | 14 | class KBlocksNetPlayer 15 | { 16 | public: 17 | KBlocksNetPlayer(GamePlayerInterface *player, const string &serverIP, int localPort); 18 | ~KBlocksNetPlayer(); 19 | 20 | public: 21 | void joinGame(int gameIndex); 22 | void quitGame(); 23 | 24 | void startGame(KBlocksSingleGame *p); 25 | void stopGame(); 26 | 27 | bool execute(); 28 | 29 | private: 30 | int formIntFromByte(char *data); 31 | 32 | private: 33 | GamePlayerInterface *mpPlayer = nullptr; 34 | KBlocksSingleGame *mpGame = nullptr; 35 | KBlocksNetClient *mpNetClient = nullptr; 36 | 37 | int mSendLength; 38 | 39 | GamePlayer_ActionList mActionList; 40 | }; 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /src/KBlocksNetServer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSNETSERVER_H 8 | #define KBLOCKSNETSERVER_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "KBlocksGameLogic.h" 18 | #include "KBlocksScore.h" 19 | 20 | using namespace std; 21 | 22 | class KBlocksNetServer : public QObject 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | KBlocksNetServer(KBlocksGameLogic *p, const QString &localIP); 28 | ~KBlocksNetServer() override; 29 | 30 | public: 31 | int executeGame(int gameCount, bool waitForAll); 32 | 33 | void setSendLength(int initLen, int lvUpLen); 34 | void setRecordFile(const char *fileName, bool binaryMode = true); 35 | 36 | private: 37 | void recvRemoteData(QList *recvData, QList *recvAddr); 38 | int processGame(int gameIndex); 39 | 40 | void addPlayerIP(int gameIndex, const QByteArray &data, const QString &addr); 41 | void delPlayerIP(const QString &addr); 42 | 43 | void sendPlayerActionLength(); 44 | void sendPlayerData(int gameIndex); 45 | void sendGameOver(); 46 | void sendGuiData(const QString &addr); 47 | 48 | int parseRemoteData(const QByteArray &data, const QString &addr); 49 | int parsePlayerReply(const QByteArray &data, const QString &addr); 50 | 51 | bool parseIPString(const QString &input, QHostAddress *ip, quint16 *port); 52 | QString formIPString(const QHostAddress &inAddr, quint16 inPort); 53 | void formByteFromInt(int value, char *data); 54 | 55 | void printGameResult(); 56 | 57 | private: 58 | KBlocksGameLogic *mpGameLogic; 59 | KBlocksScore **maGameScoreList; 60 | 61 | bool mWaitForAll; 62 | //bool mSpeedMode; 63 | //int mTimeOut; 64 | int mTopGameLevel; 65 | int mInitSendLength; 66 | int mLvUpSendLength; 67 | 68 | QHostAddress mLocalAddress; 69 | quint16 mLocalPort; 70 | QUdpSocket *mpServerSocket; 71 | 72 | QHostAddress mRemoteAddress; 73 | quint16 mRemotePort; 74 | 75 | bool mRunningFlag; 76 | int mGameCount; 77 | bool mGameStarted; 78 | 79 | QMap mPlayerMapping; 80 | QMap mPlayerName; 81 | QList mPlayerIPList; 82 | 83 | string mRecordFileName; 84 | bool mRecordFileType; 85 | }; 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /src/KBlocksPiece.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSPIECE_H 8 | #define KBLOCKSPIECE_H 9 | 10 | #include "PieceInterface.h" 11 | 12 | #define KBlocksPiece_CellCount 4 13 | 14 | enum KBlocks_PieceType { 15 | PieceType_Shape_Z = 0, 16 | PieceType_Shape_S, 17 | PieceType_Shape_I, 18 | PieceType_Shape_T, 19 | PieceType_Shape_O, 20 | PieceType_Shape_L, 21 | PieceType_Shape_J, 22 | PieceType_Max_Count 23 | }; 24 | 25 | enum KBlocks_PieceRotation { 26 | PieceRotation_Up = 0, 27 | PieceRotation_Left, 28 | PieceRotation_Down, 29 | PieceRotation_Right, 30 | PieceRotation_Max_Count 31 | }; 32 | 33 | enum KBlocks_PieceType_Detail { 34 | PieceType_Shape_Z_1 = 0, 35 | PieceType_Shape_Z_2, 36 | PieceType_Shape_Z_3, 37 | PieceType_Shape_Z_4, 38 | PieceType_Shape_S_1, 39 | PieceType_Shape_S_2, 40 | PieceType_Shape_S_3, 41 | PieceType_Shape_S_4, 42 | PieceType_Shape_I_1, 43 | PieceType_Shape_I_2, 44 | PieceType_Shape_I_3, 45 | PieceType_Shape_I_4, 46 | PieceType_Shape_T_1, 47 | PieceType_Shape_T_2, 48 | PieceType_Shape_T_3, 49 | PieceType_Shape_T_4, 50 | PieceType_Shape_O_1, 51 | PieceType_Shape_O_2, 52 | PieceType_Shape_O_3, 53 | PieceType_Shape_O_4, 54 | PieceType_Shape_L_1, 55 | PieceType_Shape_L_2, 56 | PieceType_Shape_L_3, 57 | PieceType_Shape_L_4, 58 | PieceType_Shape_J_1, 59 | PieceType_Shape_J_2, 60 | PieceType_Shape_J_3, 61 | PieceType_Shape_J_4, 62 | PieceType_Detail_Max_Count 63 | }; 64 | 65 | class PiecePoint 66 | { 67 | public: 68 | PiecePoint(int x, int y); 69 | ~PiecePoint(); 70 | 71 | public: 72 | int x(); 73 | int y(); 74 | 75 | private: 76 | int mPosX; 77 | int mPosY; 78 | }; 79 | 80 | class KBlocksPiece : public PieceInterface 81 | { 82 | public: 83 | KBlocksPiece(); 84 | explicit KBlocksPiece(PieceInterface *p); 85 | ~KBlocksPiece() override; 86 | 87 | public: 88 | void copy(PieceInterface *p); 89 | 90 | int toValue() override; 91 | void fromValue(int val); 92 | 93 | int getType() override; 94 | void setType(int newType); 95 | 96 | int getRotation() override; 97 | void setRotation(int newRotation); 98 | 99 | int getPosX() override; 100 | void setPosX(int newPosX); 101 | 102 | int getPosY() override; 103 | void setPosY(int newPosY); 104 | 105 | int getCellCount() override; 106 | int getCellPosX(int index) override; 107 | int getCellPosY(int index) override; 108 | 109 | int getWidth(); 110 | int getHeight(); 111 | int getRotationCount() override; 112 | 113 | int getSignature(int *signature); 114 | 115 | void encodeData(unsigned char *data); 116 | void decodeData(unsigned char *data); 117 | }; 118 | 119 | #endif 120 | 121 | -------------------------------------------------------------------------------- /src/KBlocksPieceGenerator.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksPieceGenerator.h" 8 | 9 | #include 10 | #include 11 | 12 | #include "KBlocksPiece.h" 13 | 14 | KBlocksPieceGenerator::KBlocksPieceGenerator(int size) 15 | { 16 | maxCapacity = size; 17 | pieceIndex = 0; 18 | maPieceList = new int[maxCapacity]; 19 | } 20 | 21 | KBlocksPieceGenerator::~KBlocksPieceGenerator() 22 | { 23 | delete [] maPieceList; 24 | } 25 | 26 | void KBlocksPieceGenerator::genList(int seed) 27 | { 28 | QRandomGenerator randomGenerator(seed); 29 | for (int i = 0; i < maxCapacity; i++) { 30 | maPieceList[i] = randomGenerator.bounded(PieceType_Detail_Max_Count); 31 | } 32 | 33 | pieceIndex = 0; 34 | } 35 | 36 | int KBlocksPieceGenerator::getPiece() 37 | { 38 | pieceIndex++; 39 | 40 | if (pieceIndex > maxCapacity) { 41 | pieceIndex = 0; 42 | genList(maPieceList[0]); 43 | } 44 | 45 | return maPieceList[pieceIndex]; 46 | } 47 | 48 | int KBlocksPieceGenerator::getIndex() 49 | { 50 | return pieceIndex; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/KBlocksPieceGenerator.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSPIECEGENERATOR_H 8 | #define KBLOCKSPIECEGENERATOR_H 9 | 10 | class KBlocksPieceGenerator 11 | { 12 | public: 13 | explicit KBlocksPieceGenerator(int size = 4096); 14 | ~KBlocksPieceGenerator(); 15 | 16 | public: 17 | void genList(int seed); 18 | int getPiece(); 19 | int getIndex(); 20 | 21 | private: 22 | int maxCapacity; 23 | int pieceIndex; 24 | int *maPieceList = nullptr; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/KBlocksPlayManager.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksPlayManager.h" 8 | 9 | KBlocksPlayManager::KBlocksPlayManager(GameLogicInterface *p, int capacity) 10 | { 11 | mpGameLogic = p; 12 | 13 | mPlayerCount = 0; 14 | mMaxCapacity = capacity; 15 | 16 | maPlayerList = new KBlocksSinglePlayer*[mMaxCapacity]; 17 | } 18 | 19 | KBlocksPlayManager::~KBlocksPlayManager() 20 | { 21 | delete [] maPlayerList; 22 | } 23 | 24 | bool KBlocksPlayManager::addGamePlayer(GamePlayerInterface *p, int thinkInterval, int processInterval) 25 | { 26 | if (mPlayerCount == mMaxCapacity) { 27 | return false; 28 | } 29 | maPlayerList[mPlayerCount] = new KBlocksSinglePlayer(p, thinkInterval, processInterval); 30 | mPlayerCount++; 31 | return true; 32 | } 33 | 34 | void KBlocksPlayManager::clearGamePlayer() 35 | { 36 | for (int i = 0; i < mPlayerCount; i++) { 37 | delete maPlayerList[i]; 38 | maPlayerList[i] = nullptr; 39 | } 40 | mPlayerCount = 0; 41 | } 42 | 43 | void KBlocksPlayManager::startGame() 44 | { 45 | for (int i = 0; i < mPlayerCount; i++) { 46 | maPlayerList[i]->startGame(mpGameLogic->getSingleGame(i)); 47 | } 48 | } 49 | 50 | void KBlocksPlayManager::stopGame() 51 | { 52 | for (int i = 0; i < mPlayerCount; i++) { 53 | maPlayerList[i]->stopGame(); 54 | } 55 | } 56 | 57 | void KBlocksPlayManager::pauseGame(bool flag) 58 | { 59 | for (int i = 0; i < mPlayerCount; i++) { 60 | maPlayerList[i]->pauseGame(flag); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/KBlocksPlayManager.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSPLAYMANAGER_H 8 | #define KBLOCKSPLAYMANAGER_H 9 | 10 | #include "GamePlayerInterface.h" 11 | #include "GameLogicInterface.h" 12 | #include "KBlocksSinglePlayer.h" 13 | 14 | class KBlocksPlayManager 15 | { 16 | public: 17 | KBlocksPlayManager(GameLogicInterface *p, int capacity); 18 | ~KBlocksPlayManager(); 19 | 20 | public: 21 | bool addGamePlayer(GamePlayerInterface *p, int thinkInterval, int processInterval); 22 | void clearGamePlayer(); 23 | 24 | void startGame(); 25 | void stopGame(); 26 | 27 | void pauseGame(bool flag); 28 | 29 | private: 30 | GameLogicInterface *mpGameLogic = nullptr; 31 | 32 | int mPlayerCount; 33 | int mMaxCapacity; 34 | KBlocksSinglePlayer **maPlayerList; 35 | }; 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /src/KBlocksPlayNetwork.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksPlayNetwork.h" 8 | 9 | #ifdef Q_OS_WIN 10 | #include 11 | #else 12 | #include 13 | #endif 14 | 15 | KBlocksPlayNetwork::KBlocksPlayNetwork(int capacity, const string &serverIP, int localPort) 16 | { 17 | mServerIP = serverIP; 18 | mLocalPort = localPort; 19 | 20 | mRunning = false; 21 | 22 | mPlayerCount = 0; 23 | mMaxCapacity = capacity; 24 | 25 | maPlayerList = new KBlocksNetPlayer*[mMaxCapacity]; 26 | 27 | mpGameLogic = new KBlocksGameLogic(mMaxCapacity); 28 | mpGameLogic->setGameSeed(0); 29 | mpGameLogic->setGamePunish(false); 30 | mpGameLogic->setGameStandbyMode(true); 31 | mpGameLogic->setInitInterval(0); 32 | mpGameLogic->setLevelUpInterval(0); 33 | } 34 | 35 | KBlocksPlayNetwork::~KBlocksPlayNetwork() 36 | { 37 | mpGameLogic->stopGame(); 38 | delete mpGameLogic; 39 | 40 | delete [] maPlayerList; 41 | } 42 | 43 | bool KBlocksPlayNetwork::addGamePlayer(GamePlayerInterface *p) 44 | { 45 | if (mPlayerCount == mMaxCapacity) { 46 | return false; 47 | } 48 | maPlayerList[mPlayerCount] = new KBlocksNetPlayer(p, mServerIP, mLocalPort + mPlayerCount); 49 | mPlayerCount++; 50 | return true; 51 | } 52 | 53 | void KBlocksPlayNetwork::clearGamePlayer() 54 | { 55 | for (int i = 0; i < mPlayerCount; i++) { 56 | delete maPlayerList[i]; 57 | maPlayerList[i] = nullptr; 58 | } 59 | mPlayerCount = 0; 60 | } 61 | 62 | void KBlocksPlayNetwork::startGame() 63 | { 64 | mpGameLogic->startGame(mPlayerCount); 65 | for (int i = 0; i < mPlayerCount; i++) { 66 | mpGameLogic->getSingleGame(i)->stopGame(); 67 | maPlayerList[i]->joinGame(i); 68 | } 69 | for (int i = 0; i < mPlayerCount; i++) { 70 | maPlayerList[i]->startGame(mpGameLogic->getSingleGame(i)); 71 | } 72 | } 73 | 74 | void KBlocksPlayNetwork::stopGame() 75 | { 76 | for (int i = 0; i < mPlayerCount; i++) { 77 | maPlayerList[i]->stopGame(); 78 | maPlayerList[i]->quitGame(); 79 | } 80 | mpGameLogic->stopGame(); 81 | } 82 | 83 | int KBlocksPlayNetwork::execute() 84 | { 85 | mRunning = true; 86 | 87 | while (mRunning) { 88 | for (int i = 0; i < mPlayerCount; i++) { 89 | if (!maPlayerList[i]->execute()) { 90 | mRunning = false; 91 | break; 92 | } 93 | } 94 | #ifndef Q_OS_WIN 95 | usleep(100000); 96 | #else 97 | Sleep(100); 98 | #endif 99 | } 100 | 101 | return 0; 102 | } 103 | 104 | void KBlocksPlayNetwork::cancelExecute() 105 | { 106 | mRunning = false; 107 | } 108 | -------------------------------------------------------------------------------- /src/KBlocksPlayNetwork.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSPLAYNETWORK_H 8 | #define KBLOCKSPLAYNETWORK_H 9 | 10 | #include "KBlocksGameLogic.h" 11 | #include "GamePlayerInterface.h" 12 | #include "KBlocksNetPlayer.h" 13 | 14 | class KBlocksPlayNetwork 15 | { 16 | public: 17 | KBlocksPlayNetwork(int capacity, const string &serverIP, int localPort); 18 | ~KBlocksPlayNetwork(); 19 | 20 | public: 21 | bool addGamePlayer(GamePlayerInterface *p); 22 | void clearGamePlayer(); 23 | 24 | void startGame(); 25 | void stopGame(); 26 | 27 | int execute(); 28 | 29 | void cancelExecute(); 30 | 31 | private: 32 | string mServerIP; 33 | int mLocalPort; 34 | 35 | bool mRunning; 36 | 37 | int mPlayerCount; 38 | int mMaxCapacity; 39 | KBlocksNetPlayer **maPlayerList; 40 | 41 | KBlocksGameLogic *mpGameLogic = nullptr; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/KBlocksRepWin.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Zhongjie Cai * 4 | * Julian Helfferich * 5 | * * 6 | * SPDX-License-Identifier: GPL-2.0-or-later 7 | ******************************************************************************/ 8 | #ifndef KBLOCKSREPWIN_H 9 | #define KBLOCKSREPWIN_H 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "KBlocksScene.h" 17 | #include "KBlocksView.h" 18 | #include "KBlocksGameLogic.h" 19 | #include "KBlocksGameReplayer.h" 20 | 21 | using std::string; 22 | 23 | class GraphicsInterface; 24 | class SoundInterface; 25 | 26 | class KBlocksRepWin : public KMainWindow 27 | { 28 | Q_OBJECT 29 | 30 | public: 31 | explicit KBlocksRepWin( 32 | GraphicsInterface *graphics, 33 | SoundInterface *sound, 34 | const char *replayFile, 35 | bool binaryMode = true 36 | ); 37 | ~KBlocksRepWin() override; 38 | 39 | public: 40 | void setGamesPerLine(int count); 41 | 42 | void setUpdateInterval(int interval); 43 | void setReplayStepLength(int stepLen); 44 | 45 | void setSnapshotFolder(const QString &folder); 46 | void setSnapshotFilename(const QString &fileName); 47 | 48 | bool replayLoaded(); 49 | 50 | public: 51 | void startReplay(); 52 | void stopReplay(); 53 | 54 | private: 55 | QString getTimeString(); 56 | void snapshotView(); 57 | 58 | private Q_SLOTS: 59 | void replayOneStep(); 60 | 61 | private: 62 | int mGameCount; 63 | //int mGamesPerWidth; 64 | 65 | int mUpdateInterval; 66 | QTimer mUpdateTimer; 67 | 68 | QString mSnapshotFolder; 69 | QString mSnapshotFilename; 70 | QPixmap mSnapshoter; 71 | 72 | KBlocksScene *mpGameScene = nullptr; 73 | KBlocksView *mpGameView = nullptr; 74 | 75 | KBlocksGameLogic *mpGameLogic = nullptr; 76 | KBlocksGameReplayer *mpGameReplayer = nullptr; 77 | }; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/KBlocksScene.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSSCENE_H 10 | #define KBLOCKSSCENE_H 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "KBlocksSound.h" 18 | #include "KBlocksGraphics.h" 19 | #include "KBlocksItemGroup.h" 20 | #include "KBlocksScore.h" 21 | 22 | #include "GameLogicInterface.h" 23 | 24 | #include "KBlocksDefine.h" 25 | #include "SceneInterface.h" 26 | 27 | class SoundInterface; 28 | class GraphicsInterface; 29 | 30 | class KBlocksScene : public SceneInterface 31 | { 32 | Q_OBJECT 33 | 34 | public: 35 | explicit KBlocksScene( 36 | GameLogicInterface *p, 37 | GraphicsInterface *graphics, 38 | SoundInterface *sound, 39 | int capacity = 1 40 | ); 41 | ~KBlocksScene() override; 42 | 43 | KBlocksItemGroup *getItemGroup(int index); 44 | KBlocksScore *getScoreHandler(int index); 45 | 46 | void createGameItemGroups(int groupCount, bool snapshotMode = false) override; 47 | void deleteGameItemGroups() override; 48 | 49 | void setGamesPerLine(int count) override; 50 | void setGameAnimEnabled(bool flag) override; 51 | void setWaitForAllUpdate(bool flag) override; 52 | void setUpdateInterval(int interval) override; 53 | void setSoundsEnabled(bool enabled) override; 54 | 55 | void readSettings() override; 56 | void loadTheme(const KBlocksTheme *theme) override; 57 | 58 | void startGame() override; 59 | void stopGame() override; 60 | 61 | void pauseGame(bool flag, bool fromUI = false) override; 62 | 63 | void addScore(int gameIndex, int lineCount) override; 64 | 65 | private: 66 | void updateDimensions(); 67 | 68 | private Q_SLOTS: 69 | void greetPlayer(); 70 | void gameOverPlayer(); 71 | void gameOverMultiWin(); 72 | void gameOverMultiLose(); 73 | 74 | void showMessage(const QString &message, int ms); 75 | 76 | void updateGame(); 77 | void readyForAction(int groupID); 78 | 79 | public Q_SLOTS: 80 | void playMoveSound() override; 81 | void playDropSound() override; 82 | 83 | protected: 84 | void drawBackground(QPainter *painter, const QRectF &rect) override; 85 | 86 | private: 87 | GameLogicInterface *mpGameLogic = nullptr; 88 | bool mGameStarted; 89 | 90 | GraphicsInterface *mpGrafx = nullptr; 91 | SoundInterface *mpSnd = nullptr; 92 | 93 | int mSceneGamesPerLine; 94 | bool mGameAnimEnabled; 95 | bool mWaitForAllUpdate; 96 | bool *maGameReadySignal = nullptr; 97 | 98 | bool mSnapshotMode; 99 | 100 | int mTopGameLevel; 101 | 102 | int mMaxCapacity; 103 | int mGroupCount; 104 | KBlocksItemGroup **maGroupList = nullptr; 105 | KBlocksScore **maGameScoreList = nullptr; 106 | 107 | QSizeF mBackgroundSize; 108 | 109 | KGamePopupItem *mMessageBox = nullptr; 110 | 111 | int mUpdateInterval; 112 | QTimer mUpdateTimer; 113 | }; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /src/KBlocksScore.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksScore.h" 8 | 9 | KBlocksScore::KBlocksScore() 10 | { 11 | mPoint = 0; 12 | mLines = 0; 13 | mLevel = 0; 14 | 15 | mType = 0; 16 | mLFactor = 0; 17 | mSFactor = 0; 18 | } 19 | 20 | KBlocksScore::~KBlocksScore() 21 | { 22 | } 23 | 24 | int KBlocksScore::getScorePoint() 25 | { 26 | return mPoint; 27 | } 28 | 29 | int KBlocksScore::getLineCount() 30 | { 31 | return mLines; 32 | } 33 | 34 | int KBlocksScore::getGameLevel() 35 | { 36 | return mLevel; 37 | } 38 | 39 | void KBlocksScore::setLevelUpFactor(int type, int factor) 40 | { 41 | mType = type; 42 | mLFactor = factor; 43 | } 44 | 45 | void KBlocksScore::setScoreUpFactor(int factor) 46 | { 47 | mSFactor = factor; 48 | } 49 | 50 | bool KBlocksScore::addScore(int lines) 51 | { 52 | mLines += lines; 53 | 54 | switch (lines) { 55 | case 1: 56 | mPoint += mSFactor; 57 | break; 58 | case 2: 59 | mPoint += mSFactor * 3; 60 | break; 61 | case 3: 62 | mPoint += mSFactor * 6; 63 | break; 64 | case 4: 65 | mPoint += mSFactor * 10; 66 | break; 67 | default: 68 | break; 69 | } 70 | 71 | int levelUpScore = 0; 72 | switch (mType) { 73 | case KBlocksScore_Level_x_Factor: 74 | levelUpScore = mLevel * mLFactor; 75 | break; 76 | case KBlocksScore_Level_x_Level_x_Factor: 77 | levelUpScore = mLevel * mLevel * mLFactor; 78 | break; 79 | default: 80 | levelUpScore = mLevel * mLFactor; 81 | break; 82 | } 83 | 84 | if (mPoint >= levelUpScore) { 85 | mLevel++; 86 | return true; 87 | } 88 | 89 | return false; 90 | } 91 | 92 | void KBlocksScore::clearScore() 93 | { 94 | mPoint = 0; 95 | mLines = 0; 96 | mLevel = 0; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /src/KBlocksScore.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSSCORE_H 8 | #define KBLOCKSSCORE_H 9 | 10 | enum KBlocks_Score_Type { 11 | KBlocksScore_Level_x_Factor = 0, 12 | KBlocksScore_Level_x_Level_x_Factor, 13 | KBlocksScore_Max_Count 14 | }; 15 | 16 | class KBlocksScore 17 | { 18 | public: 19 | KBlocksScore(); 20 | ~KBlocksScore(); 21 | 22 | int getScorePoint(); 23 | int getLineCount(); 24 | int getGameLevel(); 25 | 26 | void setLevelUpFactor(int type, int factor); 27 | void setScoreUpFactor(int factor); 28 | 29 | bool addScore(int lines); 30 | void clearScore(); 31 | 32 | private: 33 | int mPoint; 34 | int mLines; 35 | int mLevel; 36 | 37 | int mType; 38 | int mLFactor; 39 | int mSFactor; 40 | }; 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /src/KBlocksSingleGame.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSSINGLEGAME_H 8 | #define KBLOCKSSINGLEGAME_H 9 | 10 | #include 11 | 12 | #include "SingleGameInterface.h" 13 | 14 | #include "KBlocksField.h" 15 | #include "KBlocksPiece.h" 16 | #include "KBlocksPieceGenerator.h" 17 | #include "KBlocksGameMessage.h" 18 | 19 | #include "KBlocksGameRecorder.h" 20 | 21 | #include "KBlocksDefine.h" 22 | 23 | class KBlocksSingleGame : public QObject, public SingleGameInterface 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | explicit KBlocksSingleGame(int gameIndex, int fieldWidth = 10, int fieldHeight = 20, int showPieceCount = 2, int messagePoolSize = 256); 29 | ~KBlocksSingleGame() override; 30 | 31 | public: 32 | KBlocksField *getField() override; 33 | 34 | int getPieceCount() override; 35 | KBlocksPiece *getPiece(int index) override; 36 | 37 | bool isActive() override; 38 | bool isGameRunning() override; 39 | 40 | void setGameStandbyMode(bool flag); 41 | void setGameInterval(int interval); 42 | void setGameRecorder(KBlocksGameRecorder *p); 43 | 44 | int forceUpdateGame() override; 45 | int updateGame() override; 46 | int punishGame(int lineCount, int punishSeed); 47 | 48 | bool setCurrentPiece(int xPos, int yPos, int rotation) override; 49 | 50 | int startGame(int seed); 51 | int stopGame(); 52 | 53 | int pauseGame(bool flag); 54 | int continueGame() override; 55 | 56 | bool pickGameResult(int *result) override; 57 | bool pickGameAction(int *type, int *action) override; 58 | 59 | Q_SIGNALS: 60 | void gameStopped(); 61 | 62 | private: 63 | int doUpdateGame(bool force); 64 | bool runGameOneStep(int *gameResult); 65 | bool checkPieceTouchGround(KBlocksPiece *p); 66 | void freezePieceToField(KBlocksPiece *p); 67 | int removeFieldLines(); 68 | void prepareNextPiece(); 69 | 70 | protected: 71 | KBlocksField *mpField = nullptr; 72 | 73 | int mPieceCount; 74 | KBlocksPiece **mpPieceList = nullptr; 75 | 76 | private: 77 | KBlocksPieceGenerator *mpPieceGenerator = nullptr; 78 | KBlocksGameMessage *mpGameMessage = nullptr; 79 | KBlocksGameRecorder *mpGameRecorder = nullptr; 80 | 81 | int mGameIndex; 82 | int mCurrentGameState; 83 | 84 | bool mStandbyMode; 85 | bool mStandbyFlag; 86 | int mGameInterval; 87 | timeLong mGameStartTime; 88 | }; 89 | 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /src/KBlocksSinglePlayer.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "KBlocksSinglePlayer.h" 8 | 9 | KBlocksSinglePlayer::KBlocksSinglePlayer(GamePlayerInterface *player, int thinkInterval, int processInterval) 10 | { 11 | mpPlayer = player; 12 | mpGame = nullptr; 13 | 14 | mPlayerState = KBlocksPlayer_ThinkingState; 15 | 16 | mThinkInterval = thinkInterval; 17 | mProcessInterval = (processInterval < 0) ? 0 : processInterval; 18 | if (mThinkInterval >= 0) { 19 | mActionTimer.setInterval(thinkInterval); 20 | connect(&mActionTimer, &QTimer::timeout, this, &KBlocksSinglePlayer::doAction); 21 | } 22 | mActionTimer.stop(); 23 | 24 | mActionList.clear(); 25 | } 26 | 27 | KBlocksSinglePlayer::~KBlocksSinglePlayer() 28 | { 29 | } 30 | 31 | void KBlocksSinglePlayer::startGame(SingleGameInterface *p) 32 | { 33 | mpGame = p; 34 | mpPlayer->startGame(mpGame); 35 | 36 | mPlayerState = KBlocksPlayer_ThinkingState; 37 | 38 | mActionList.clear(); 39 | 40 | if (mThinkInterval > 0) { 41 | mActionTimer.start(); 42 | } 43 | } 44 | 45 | void KBlocksSinglePlayer::stopGame() 46 | { 47 | mActionTimer.stop(); 48 | 49 | mActionList.clear(); 50 | 51 | mpPlayer->stopGame(); 52 | mpGame = nullptr; 53 | } 54 | 55 | void KBlocksSinglePlayer::pauseGame(bool flag) 56 | { 57 | if (flag) { 58 | mActionTimer.stop(); 59 | } else if (mThinkInterval > 0) { 60 | mActionTimer.start(); 61 | } 62 | } 63 | 64 | void KBlocksSinglePlayer::think() 65 | { 66 | mActionList.clear(); 67 | mpPlayer->think(&mActionList); 68 | 69 | if ((!mActionList.empty()) && (mThinkInterval > 0)) { 70 | mActionTimer.stop(); 71 | mActionTimer.setInterval(mProcessInterval); 72 | mPlayerState = KBlocksPlayer_ProcessingState; 73 | mActionTimer.start(); 74 | } 75 | } 76 | 77 | bool KBlocksSinglePlayer::process() 78 | { 79 | if (mActionList.empty()) { 80 | if (mThinkInterval > 0) { 81 | mActionTimer.stop(); 82 | mActionTimer.setInterval(mThinkInterval); 83 | mPlayerState = KBlocksPlayer_ThinkingState; 84 | mActionTimer.start(); 85 | } 86 | return false; 87 | } 88 | 89 | if (!mpGame->isActive()) { 90 | return false; 91 | } 92 | 93 | KBlocks_Player_Action tmpAction = mActionList.front(); 94 | mActionList.pop_front(); 95 | switch (tmpAction) { 96 | case PlayerAction_Move_Left: 97 | mpGame->setCurrentPiece(-1, 0, 0); 98 | break; 99 | case PlayerAction_Move_Right: 100 | mpGame->setCurrentPiece(1, 0, 0); 101 | break; 102 | case PlayerAction_Move_Down: 103 | mpGame->setCurrentPiece(0, 1, 0); 104 | break; 105 | case PlayerAction_Push_Down: 106 | while (mpGame->setCurrentPiece(0, 1, 0)) ; 107 | mpGame->forceUpdateGame(); 108 | break; 109 | case PlayerAction_Rotate_CW: 110 | mpGame->setCurrentPiece(0, 0, 1); 111 | break; 112 | case PlayerAction_Rotate_CCW: 113 | mpGame->setCurrentPiece(0, 0, -1); 114 | break; 115 | case PlayerAction_None: 116 | default: 117 | break; 118 | } 119 | 120 | return true; 121 | } 122 | 123 | void KBlocksSinglePlayer::doAction() 124 | { 125 | if (!mpGame) { 126 | return; 127 | } 128 | 129 | if (mPlayerState == KBlocksPlayer_ThinkingState) { 130 | think(); 131 | } else if (mPlayerState == KBlocksPlayer_ProcessingState) { 132 | process(); 133 | } 134 | } 135 | 136 | #include "moc_KBlocksSinglePlayer.cpp" 137 | -------------------------------------------------------------------------------- /src/KBlocksSinglePlayer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef KBLOCKSSINGLEPLAYER_H 8 | #define KBLOCKSSINGLEPLAYER_H 9 | 10 | #include 11 | 12 | #include "SingleGameInterface.h" 13 | #include "GamePlayerInterface.h" 14 | 15 | enum KBlocksPlayer_State { 16 | KBlocksPlayer_ThinkingState = 0, 17 | KBlocksPlayer_ProcessingState, 18 | KBlocksPlayer_Max_State_Count 19 | }; 20 | 21 | class KBlocksSinglePlayer : public QObject 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | KBlocksSinglePlayer(GamePlayerInterface *player, int thinkInterval, int processInterval); 27 | ~KBlocksSinglePlayer() override; 28 | 29 | public: 30 | void startGame(SingleGameInterface *p); 31 | void stopGame(); 32 | 33 | void pauseGame(bool flag); 34 | 35 | private: 36 | void think(); 37 | bool process(); 38 | 39 | private Q_SLOTS: 40 | void doAction(); 41 | 42 | private: 43 | GamePlayerInterface *mpPlayer = nullptr; 44 | SingleGameInterface *mpGame = nullptr; 45 | 46 | int mPlayerState; 47 | 48 | int mThinkInterval; 49 | int mProcessInterval; 50 | 51 | QTimer mActionTimer; 52 | 53 | GamePlayer_ActionList mActionList; 54 | }; 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /src/KBlocksSound.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | //Uses routines from Kapman sound manager (game.cpp) 10 | 11 | #include "KBlocksSound.h" 12 | 13 | #include "KBlocksTheme.h" 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include "kblocks_sound_debug.h" 20 | #include "settings.h" 21 | 22 | KBlocksSound::KBlocksSound(const KBlocksTheme *theme) 23 | : SoundInterface() 24 | { 25 | loadTheme(theme); 26 | } 27 | 28 | KBlocksSound::~KBlocksSound() 29 | { 30 | delete m_blockFallSound; 31 | delete m_blockMoveSound; 32 | delete m_blockRemoveSound; 33 | } 34 | 35 | bool KBlocksSound::loadTheme(const KBlocksTheme *theme) 36 | { 37 | QString themeMoveSound = theme->blockMoveSoundPath(); 38 | if (themeMoveSound.isEmpty()) { 39 | themeMoveSound = QStandardPaths::locate( 40 | QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-move.ogg")); 41 | } 42 | 43 | QString themeFallSound = theme->blockFallSoundPath(); 44 | if (themeFallSound.isEmpty()) { 45 | themeFallSound = QStandardPaths::locate( 46 | QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-fall.ogg")); 47 | } 48 | 49 | QString themeRemoveSound = theme->blockRemoveSoundPath(); 50 | if (themeRemoveSound.isEmpty()) { 51 | themeRemoveSound = QStandardPaths::locate( 52 | QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-remove.ogg")); 53 | } 54 | 55 | delete m_blockFallSound; 56 | delete m_blockMoveSound; 57 | delete m_blockRemoveSound; 58 | m_blockFallSound = new KGameSound(themeFallSound); 59 | m_blockMoveSound = new KGameSound(themeMoveSound); 60 | m_blockRemoveSound = new KGameSound(themeRemoveSound); 61 | return true; 62 | } 63 | 64 | void KBlocksSound::setSoundsEnabled(bool p_enabled) 65 | { 66 | sndActive = p_enabled; 67 | } 68 | 69 | void KBlocksSound::playSound(Sound soundType) 70 | { 71 | if (sndActive) { 72 | switch (soundType) { 73 | case Sound::BlockFall: 74 | m_blockFallSound->start(); 75 | break; 76 | case Sound::BlockMove: 77 | m_blockMoveSound->start(); 78 | break; 79 | case Sound::BlockRemove: 80 | m_blockRemoveSound->start(); 81 | break; 82 | default: 83 | qCWarning(KBSound) << "Unknown Sound requested for playback."; 84 | break; 85 | } 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/KBlocksSound.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSSOUND_H 10 | #define KBLOCKSSOUND_H 11 | 12 | #include "SoundInterface.h" 13 | 14 | class KGameSound; 15 | 16 | class KBlocksSound : public SoundInterface 17 | { 18 | public: 19 | explicit KBlocksSound(const KBlocksTheme *theme); 20 | ~KBlocksSound() override; 21 | 22 | public: 23 | bool loadTheme(const KBlocksTheme *theme) override; 24 | void setSoundsEnabled(bool p_enabled) override; 25 | void playSound(Sound soundType) override; 26 | 27 | private: 28 | KGameSound *m_blockFallSound = nullptr; 29 | KGameSound *m_blockMoveSound = nullptr; 30 | KGameSound *m_blockRemoveSound = nullptr; 31 | bool sndActive; 32 | 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/KBlocksSvgItem.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * * 6 | * SPDX-License-Identifier: GPL-2.0-or-later 7 | ***************************************************************************/ 8 | #include "KBlocksSvgItem.h" 9 | 10 | 11 | KBlocksSvgItem::KBlocksSvgItem(KBlocksLayout *p, int type, int posX, int posY) 12 | { 13 | mpGameLayout = p; 14 | 15 | mPosX = posX; 16 | mPosY = posY; 17 | 18 | mType = type; 19 | mColor = -1; 20 | 21 | setCacheMode(QGraphicsItem::DeviceCoordinateCache); 22 | } 23 | 24 | KBlocksSvgItem::~KBlocksSvgItem() 25 | { 26 | } 27 | 28 | void KBlocksSvgItem::setLayoutPos(int posX, int posY) 29 | { 30 | mPosX = posX; 31 | mPosY = posY; 32 | } 33 | 34 | bool KBlocksSvgItem::updateSelf() 35 | { 36 | int tmpColor; 37 | 38 | if (mType == KBlocksSvgItem_FieldArea) { 39 | tmpColor = mpGameLayout->getFieldColor(mPosX, mPosY); 40 | } else if (mType == KBlocksSvgItem_PrepareArea) { 41 | tmpColor = mpGameLayout->getPrepareColor(mPosX, mPosY); 42 | } else { 43 | return false; 44 | } 45 | 46 | if (mColor != tmpColor) { 47 | mColor = tmpColor; 48 | if (mColor == -1) { 49 | setVisible(false); 50 | } else { 51 | setElementId(QStringLiteral("BLOCK_%1").arg(mColor)); 52 | setVisible(true); 53 | } 54 | } 55 | 56 | return true; 57 | } 58 | 59 | void KBlocksSvgItem::clearCache() 60 | { 61 | setCacheMode(NoCache); 62 | setCacheMode(DeviceCoordinateCache); 63 | } 64 | 65 | 66 | void KBlocksSvgItem::startOpAnim() 67 | { 68 | setElementId(QStringLiteral("BLOCK_OUT_%1").arg(mColor)); 69 | } 70 | 71 | void KBlocksSvgItem::stopOpAnim() 72 | { 73 | setElementId(QStringLiteral("BLOCK_%1").arg(mColor)); 74 | } 75 | 76 | void KBlocksSvgItem::startPosAnim(QPointF target) 77 | { 78 | mOriginPos = pos(); 79 | mTargetPos = pos() + target; 80 | } 81 | 82 | void KBlocksSvgItem::execPosAnim(qreal step) 83 | { 84 | QPointF delta = mTargetPos - mOriginPos; 85 | delta = delta * step; 86 | setPos(mOriginPos + delta); 87 | } 88 | 89 | void KBlocksSvgItem::stopPosAnim() 90 | { 91 | setPos(mOriginPos); 92 | mTargetPos = mOriginPos; 93 | } 94 | 95 | #include "moc_KBlocksSvgItem.cpp" 96 | -------------------------------------------------------------------------------- /src/KBlocksSvgItem.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSSVGITEM_H 10 | #define KBLOCKSSVGITEM_H 11 | 12 | #include 13 | 14 | #include "KBlocksLayout.h" 15 | #include "SvgItemInterface.h" 16 | 17 | enum KBlocks_SvgItem_Type { 18 | KBlocksSvgItem_None = -1, 19 | KBlocksSvgItem_FieldArea = 0, 20 | KBlocksSvgItem_PrepareArea, 21 | KBlocksSvgItem_Max_Count 22 | }; 23 | 24 | class KBlocksSvgItem : public SvgItemInterface 25 | { 26 | Q_OBJECT 27 | 28 | public: 29 | KBlocksSvgItem(KBlocksLayout *p, int type, int posX, int posY); 30 | ~KBlocksSvgItem() override; 31 | 32 | void setLayoutPos(int posX, int posY); 33 | 34 | bool updateSelf() override; 35 | void clearCache() override; 36 | 37 | void startOpAnim() override; 38 | void stopOpAnim() override; 39 | 40 | void startPosAnim(QPointF target) override; 41 | void execPosAnim(qreal step) override; 42 | void stopPosAnim() override; 43 | 44 | private: 45 | KBlocksLayout *mpGameLayout; 46 | 47 | int mPosX; 48 | int mPosY; 49 | 50 | int mType; 51 | int mColor; 52 | 53 | QPointF mOriginPos; 54 | QPointF mTargetPos; 55 | }; 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /src/KBlocksTheme.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SPDX-FileCopyrightText: 2024 Friedrich W. H. Kossebau 3 | 4 | SPDX-License-Identifier: GPL-2.0-or-later 5 | */ 6 | 7 | #include "KBlocksTheme.h" 8 | 9 | #include 10 | 11 | KBlocksTheme::KBlocksTheme(const QByteArray &identifier, QObject *parent) 12 | : KGameTheme(identifier, parent) 13 | { 14 | } 15 | 16 | KBlocksTheme::~KBlocksTheme() = default; 17 | 18 | bool KBlocksTheme::readFromDesktopFile(const QString &path) 19 | { 20 | // Base-class call. 21 | if (!KGameTheme::readFromDesktopFile(path)) { 22 | return false; 23 | } 24 | 25 | // Estimate the paths to sound files. 26 | // Always assume relative path for sound entries 27 | const QFileInfo fi(path); 28 | const QString themePath = fi.absolutePath() + QLatin1Char('/'); 29 | 30 | m_blockMoveSoundPath = customData(QStringLiteral("Sound_Block_Move")); 31 | if (!m_blockMoveSoundPath.isEmpty()) { 32 | m_blockMoveSoundPath.prepend(themePath); 33 | } 34 | 35 | m_blockFallSoundPath = customData(QStringLiteral("Sound_Block_Fall")); 36 | if (!m_blockFallSoundPath.isEmpty()) { 37 | m_blockFallSoundPath.prepend(themePath); 38 | } 39 | 40 | m_blockRemoveSoundPath = customData(QStringLiteral("Sound_Block_Remove")); 41 | if (!m_blockRemoveSoundPath.isEmpty()) { 42 | m_blockRemoveSoundPath.prepend(themePath); 43 | } 44 | 45 | return true; 46 | } 47 | 48 | #include "moc_KBlocksTheme.cpp" 49 | -------------------------------------------------------------------------------- /src/KBlocksTheme.h: -------------------------------------------------------------------------------- 1 | /* 2 | SPDX-FileCopyrightText: 2024 Friedrich W. H. Kossebau 3 | 4 | SPDX-License-Identifier: GPL-2.0-or-later 5 | */ 6 | 7 | #ifndef KBLOCKSTHEME_H 8 | #define KBLOCKSTHEME_H 9 | 10 | #include 11 | 12 | // TODO: extend KGameTheme to provide look-up of relativ path with custom entries 13 | // For now subclass and use the readFromDesktopFile override to estimate the 14 | // sounds path from the custom data and the path of the desktop file available there. 15 | class KBlocksTheme : public KGameTheme 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | Q_INVOKABLE KBlocksTheme(const QByteArray &identifier, QObject *parent = nullptr); 21 | ~KBlocksTheme() override; 22 | 23 | bool readFromDesktopFile(const QString& path) override; 24 | 25 | QString blockMoveSoundPath() const; 26 | QString blockFallSoundPath() const; 27 | QString blockRemoveSoundPath() const; 28 | 29 | private: 30 | QString m_blockMoveSoundPath; 31 | QString m_blockFallSoundPath; 32 | QString m_blockRemoveSoundPath; 33 | }; 34 | 35 | inline QString KBlocksTheme::blockMoveSoundPath() const { return m_blockMoveSoundPath; } 36 | inline QString KBlocksTheme::blockFallSoundPath() const { return m_blockFallSoundPath; } 37 | inline QString KBlocksTheme::blockRemoveSoundPath() const { return m_blockRemoveSoundPath; } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /src/KBlocksView.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #include 10 | 11 | #include "KBlocksView.h" 12 | #include "SceneInterface.h" 13 | 14 | KBlocksView::KBlocksView(SceneInterface *scene, QWidget *parent): QGraphicsView(scene, parent) 15 | { 16 | //setViewportUpdateMode(QGraphicsView::FullViewportUpdate); 17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 18 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 19 | setFrameStyle(QFrame::NoFrame); 20 | 21 | setOptimizationFlags( 22 | QGraphicsView::DontSavePainterState /*| 23 | QGraphicsView::DontAdjustForAntialiasing*/); 24 | 25 | setCacheMode(QGraphicsView::CacheBackground); 26 | setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); 27 | } 28 | 29 | KBlocksView::~KBlocksView() 30 | { 31 | } 32 | 33 | void KBlocksView::loadTheme(const KBlocksTheme *theme) 34 | { 35 | SceneInterface* s = dynamic_cast(scene()); 36 | if (s) { 37 | s->loadTheme(theme); 38 | } 39 | fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); 40 | } 41 | 42 | void KBlocksView::settingsChanged() 43 | { 44 | SceneInterface* s = dynamic_cast(scene()); 45 | if (s) { 46 | s->readSettings(); 47 | } 48 | fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); 49 | } 50 | 51 | void KBlocksView::focusInEvent(QFocusEvent *) 52 | { 53 | Q_EMIT focusEvent(false); 54 | } 55 | 56 | void KBlocksView::focusOutEvent(QFocusEvent *) 57 | { 58 | Q_EMIT focusEvent(true); 59 | } 60 | 61 | void KBlocksView::resizeEvent(QResizeEvent *event) 62 | { 63 | fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); 64 | event->accept(); 65 | } 66 | 67 | #include "moc_KBlocksView.cpp" 68 | -------------------------------------------------------------------------------- /src/KBlocksView.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSVIEW_H 10 | #define KBLOCKSVIEW_H 11 | 12 | #include 13 | 14 | class SceneInterface; 15 | class KBlocksTheme; 16 | 17 | class KBlocksView : public QGraphicsView 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | explicit KBlocksView(SceneInterface *scene, QWidget *parent = nullptr); 23 | ~KBlocksView() override; 24 | 25 | Q_SIGNALS: 26 | void focusEvent(bool flag); 27 | 28 | public Q_SLOTS: 29 | void settingsChanged(); 30 | 31 | public: 32 | void loadTheme(const KBlocksTheme *theme); 33 | 34 | protected: 35 | void focusInEvent(QFocusEvent *event) override; 36 | void focusOutEvent(QFocusEvent *event) override; 37 | void resizeEvent(QResizeEvent *event) override; 38 | }; 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /src/KBlocksWin.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Mauricio Piacentini * 4 | * Zhongjie Cai * 5 | * Julian Helfferich * 6 | * * 7 | * SPDX-License-Identifier: GPL-2.0-or-later 8 | ******************************************************************************/ 9 | #ifndef KBLOCKSWIN_H 10 | #define KBLOCKSWIN_H 11 | 12 | #include 13 | 14 | #include "KBlocksView.h" 15 | 16 | #include "KBlocksKeyboardPlayer.h" 17 | #include "AI/KBlocksAIPlayer.h" 18 | 19 | #include "KBlocksPlayManager.h" 20 | 21 | class KGameThemeSelector; 22 | class KGameThemeProvider; 23 | class KGameTheme; 24 | class QLabel; 25 | class GameLogicInterface; 26 | class GraphicsInterface; 27 | class SceneInterface; 28 | class SoundInterface; 29 | 30 | class KBlocksWin : public KXmlGuiWindow 31 | { 32 | Q_OBJECT 33 | 34 | public: 35 | KBlocksWin( 36 | GameLogicInterface *p, 37 | GraphicsInterface *graphics, 38 | SoundInterface *sound, 39 | KGameThemeProvider *themeProvider, 40 | KBlocksPlayManager *pM, 41 | int capacity, 42 | int gamecount 43 | ); 44 | ~KBlocksWin() override; 45 | 46 | public: 47 | void setGamesPerLine(int count); 48 | void setGameAnimEnabled(bool flag); 49 | void setWaitForAllUpdate(bool flag); 50 | void setUpdateInterval(int interval); 51 | 52 | void addScore(int gameIndex, int lineCount); 53 | 54 | void setupGUILayout(); 55 | 56 | protected Q_SLOTS: 57 | void stopGame(); 58 | 59 | private Q_SLOTS: 60 | void startGame(); 61 | void pauseGame(); 62 | 63 | void singleGame(); 64 | void pveStepGame(); 65 | 66 | void focusEvent(bool flag); 67 | 68 | void configureSettings(); 69 | void showHighscore(); 70 | void onScoreChanged(int index, int points, int lines, int level); 71 | void onIsHighscore(int index, int points, int level); 72 | void onAllGamesStopped(); 73 | void levelChanged(); 74 | void setSoundsEnabled(bool enabled); 75 | void onThemeChanged(const KGameTheme *theme); 76 | 77 | protected: 78 | void closeEvent(QCloseEvent *event) override; 79 | 80 | protected: 81 | SceneInterface *mpGameScene = nullptr; 82 | KBlocksView *mpGameView = nullptr; 83 | 84 | KBlocksKeyboardPlayer *mpKBPlayer = nullptr; 85 | 86 | private: 87 | int mMaxGameCapacity; 88 | int mGameCount; 89 | 90 | bool mGameAnim; 91 | bool mWaitForAll; 92 | 93 | GameLogicInterface *mpGameLogic = nullptr; 94 | KBlocksPlayManager *mpPlayManager = nullptr; 95 | 96 | KBlocksAIPlayer *mpAIPlayer = nullptr; 97 | 98 | KGameThemeSelector *m_themeSelector = nullptr; 99 | QAction *m_pauseAction = nullptr; 100 | QLabel *mScore = nullptr; 101 | }; 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /src/Messages.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | $EXTRACTRC `find . -name \*.rc -o -name \*.kcfg` >> rc.cpp 3 | $XGETTEXT `find . -name '*.cpp'` -o $podir/kblocks.pot 4 | -------------------------------------------------------------------------------- /src/PieceInterface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef PIECE_INTERFACE 8 | #define PIECE_INTERFACE 9 | 10 | class PieceInterface 11 | { 12 | public: 13 | PieceInterface() : mType(0), mPosX(0), mPosY(0), mRotation(0) {}; 14 | virtual ~PieceInterface() {}; 15 | 16 | public: 17 | virtual int toValue() = 0; 18 | 19 | virtual int getType() = 0; 20 | virtual int getPosX() = 0; 21 | virtual int getPosY() = 0; 22 | virtual int getRotation() = 0; 23 | 24 | virtual int getCellCount() = 0; 25 | virtual int getRotationCount() = 0; 26 | virtual int getCellPosX(int index) = 0; 27 | virtual int getCellPosY(int index) = 0; 28 | 29 | protected: 30 | int mType; 31 | int mPosX; 32 | int mPosY; 33 | int mRotation; 34 | }; 35 | 36 | #endif //PIECE_INTERFACE 37 | -------------------------------------------------------------------------------- /src/SceneInterface.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | 8 | #include "SceneInterface.h" 9 | 10 | SceneInterface::SceneInterface() 11 | : QGraphicsScene() 12 | { 13 | } 14 | 15 | #include "moc_SceneInterface.cpp" 16 | -------------------------------------------------------------------------------- /src/SceneInterface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | 8 | #ifndef SCENEINTERFACE_H 9 | #define SCENEINTERFACE_H 10 | 11 | #include 12 | 13 | class KBlocksTheme; 14 | 15 | class SceneInterface : public QGraphicsScene 16 | { 17 | Q_OBJECT 18 | public: 19 | SceneInterface(); 20 | ~SceneInterface() override = default; 21 | 22 | public: 23 | virtual void createGameItemGroups(int, bool snapshotMode = false) = 0; 24 | virtual void deleteGameItemGroups() = 0; 25 | virtual void setGamesPerLine(int) = 0; 26 | virtual void setGameAnimEnabled(bool) = 0; 27 | virtual void setWaitForAllUpdate(bool) = 0; 28 | virtual void setUpdateInterval(int) = 0; 29 | virtual void setSoundsEnabled(bool) = 0; 30 | virtual void readSettings() = 0; 31 | virtual void loadTheme(const KBlocksTheme *theme) = 0; 32 | virtual void startGame() = 0; 33 | virtual void stopGame() = 0; 34 | virtual void pauseGame(bool, bool fromUI = false) = 0; 35 | virtual void addScore(int, int) = 0; 36 | 37 | Q_SIGNALS: 38 | void scoreChanged(int index, int points, int lines, int level); 39 | void isHighscore(int index, int points, int level); 40 | 41 | public Q_SLOTS: 42 | virtual void playMoveSound() = 0; 43 | virtual void playDropSound() = 0; 44 | }; 45 | 46 | #endif // SCENEINTERFACE_H 47 | -------------------------------------------------------------------------------- /src/SingleGameInterface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010 Zhongjie Cai * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef SINGLE_GAME_INTERFACE 8 | #define SINGLE_GAME_INTERFACE 9 | 10 | #include "FieldInterface.h" 11 | #include "PieceInterface.h" 12 | 13 | 14 | class SingleGameInterface 15 | { 16 | public: 17 | SingleGameInterface() 18 | : mpField(nullptr), mPieceCount(0), mpPieceList(nullptr) {} 19 | virtual ~SingleGameInterface() {} 20 | 21 | public: 22 | virtual FieldInterface *getField() = 0; 23 | 24 | virtual int getPieceCount() = 0; 25 | virtual PieceInterface *getPiece(int) = 0; 26 | 27 | virtual bool isActive() = 0; 28 | virtual bool isGameRunning() = 0; 29 | 30 | virtual int forceUpdateGame() = 0; 31 | virtual int updateGame() = 0; 32 | virtual int continueGame() = 0; 33 | 34 | virtual bool setCurrentPiece(int, int, int) = 0; 35 | 36 | virtual bool pickGameResult(int *) = 0; 37 | virtual bool pickGameAction(int *, int *) = 0; 38 | 39 | protected: 40 | FieldInterface *mpField = nullptr; 41 | 42 | int mPieceCount; 43 | PieceInterface **mpPieceList = nullptr; 44 | }; 45 | 46 | #endif //SINGLE_GAME_INTERFACE 47 | -------------------------------------------------------------------------------- /src/SoundInterface.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef SOUNDINTERFACE_H 8 | #define SOUNDINTERFACE_H 9 | 10 | enum class Sound { 11 | BlockFall, 12 | BlockMove, 13 | BlockRemove 14 | }; 15 | 16 | class KBlocksTheme; 17 | 18 | class SoundInterface 19 | { 20 | public: 21 | SoundInterface() = default; 22 | virtual ~SoundInterface() = default; 23 | 24 | public: 25 | virtual bool loadTheme(const KBlocksTheme *) = 0; 26 | virtual void setSoundsEnabled(bool) = 0; 27 | virtual void playSound(Sound) = 0; 28 | }; 29 | 30 | #endif // SOUNDINTERFACE_H 31 | -------------------------------------------------------------------------------- /src/SvgItemInterface.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef SVGITEMINTERFACE_H 8 | #define SVGITEMINTERFACE_H 9 | 10 | #include 11 | #include 12 | 13 | class SvgItemInterface : public QGraphicsSvgItem 14 | { 15 | public: 16 | SvgItemInterface() = default; 17 | ~SvgItemInterface() override = default; 18 | 19 | public: 20 | virtual bool updateSelf() = 0; 21 | virtual void clearCache() = 0; 22 | 23 | virtual void startOpAnim() = 0; 24 | virtual void stopOpAnim() = 0; 25 | 26 | virtual void startPosAnim(QPointF target) = 0; 27 | virtual void execPosAnim(qreal step) = 0; 28 | virtual void stopPosAnim() = 0; 29 | }; 30 | 31 | #endif // SVGITEMINTERFACE_H 32 | -------------------------------------------------------------------------------- /src/Testing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(KBlocksTesting STATIC 2 | TestingKBlocksWin.cpp 3 | ) 4 | target_link_libraries(KBlocksTesting 5 | KBlocksCore 6 | ) 7 | -------------------------------------------------------------------------------- /src/Testing/MockField.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKFIELD_H 8 | #define MOCKFIELD_H 9 | 10 | #include "FieldInterface.h" 11 | 12 | class MockField : public FieldInterface 13 | { 14 | public: 15 | MockField() : FieldInterface() {} 16 | ~MockField() override = default; 17 | 18 | public: 19 | bool getCell(int, int) override { return false; } 20 | 21 | int getWidth() override { return 0; } 22 | int getHeight() override { return 0; } 23 | }; 24 | 25 | #endif //MOCKFIELD_H 26 | -------------------------------------------------------------------------------- /src/Testing/MockGameLogic.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKGAMELOGIC_H 8 | #define MOCKGAMELOGIC_H 9 | 10 | #include "GameLogicInterface.h" 11 | #include "Testing/MockSingleGame.h" 12 | 13 | class MockGameLogic : public GameLogicInterface 14 | { 15 | public: 16 | MockGameLogic() 17 | : singleGamesDeleted(false), 18 | singleGame{} 19 | { 20 | } 21 | ~MockGameLogic() override = default; 22 | 23 | public: 24 | SingleGameInterface *getSingleGame(int) override { return &singleGame; } 25 | 26 | int levelUpGame(int) override { return 0; } 27 | int updateGame(int *) override { return 0; } 28 | 29 | void setGameSeed(int) override {} 30 | 31 | void setGameStandbyMode(bool) override {} 32 | 33 | bool startGame(int) override { return true; } 34 | bool stopGame() override { return true; } 35 | 36 | void pauseGame(bool) override {} 37 | void continueGame() override {} 38 | 39 | bool hasSingleGames() override { return true; } 40 | void deleteSingleGames() override { singleGamesDeleted = true; } 41 | 42 | public: 43 | bool singleGamesDeleted; 44 | 45 | private: 46 | MockSingleGame singleGame; 47 | }; 48 | 49 | #endif //MOCKGAMELOGIC_H 50 | -------------------------------------------------------------------------------- /src/Testing/MockGraphics.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKGRAPHICS_H 8 | #define MOCKGRAPHICS_H 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "GraphicsInterface.h" 15 | 16 | class QSize; 17 | class QString; 18 | 19 | class MockGraphics : public GraphicsInterface 20 | { 21 | public: 22 | MockGraphics() : mRenderer(new QSvgRenderer()) 23 | { 24 | m_PlayArea_NumberOfBlocks_X = 1; 25 | m_PlayArea_NumberOfBlocks_Y = 1; 26 | } 27 | ~MockGraphics() override = default; 28 | 29 | public: 30 | bool loadTheme(const KBlocksTheme *) override { return false; } 31 | void readThemeValues(const KBlocksTheme *) override {} 32 | QSvgRenderer *renderer() const override { return mRenderer.get(); } 33 | 34 | private: 35 | std::unique_ptr mRenderer; 36 | }; 37 | 38 | #endif // MOCKGRAPHICS_H 39 | -------------------------------------------------------------------------------- /src/Testing/MockPiece.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKPIECE_H 8 | #define MOCKPIECE_H 9 | 10 | #include "PieceInterface.h" 11 | 12 | class MockPiece : public PieceInterface 13 | { 14 | public: 15 | MockPiece() : PieceInterface() {} 16 | ~MockPiece() override = default; 17 | 18 | public: 19 | int toValue() override { return 0; } 20 | 21 | int getType() override { return 0; } 22 | int getPosX() override { return 0; } 23 | int getPosY() override { return 0; } 24 | int getRotation() override { return 0; } 25 | 26 | int getCellCount() override { return 0; } 27 | int getRotationCount() override { return 0; } 28 | int getCellPosX(int) override { return 0; } 29 | int getCellPosY(int) override { return 0; } 30 | }; 31 | 32 | #endif //MOCKPIECE_H 33 | -------------------------------------------------------------------------------- /src/Testing/MockScene.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKSCENE_H 8 | #define MOCKSCENE_H 9 | 10 | #include "SceneInterface.h" 11 | #include "Testing/MockGameLogic.h" 12 | 13 | class MockScene : public SceneInterface 14 | { 15 | public: 16 | MockScene(MockGameLogic *gameLogic) 17 | : singleGameDeletedWhenStopGameCalled(false), 18 | readSettingsCalled(false), 19 | mpGameLogic(gameLogic) 20 | { 21 | } 22 | ~MockScene() override = default; 23 | 24 | public: 25 | void createGameItemGroups(int, bool) override {} 26 | void deleteGameItemGroups() override {} 27 | void setGamesPerLine(int) override {} 28 | void setGameAnimEnabled(bool) override {} 29 | void setWaitForAllUpdate(bool) override {} 30 | void setUpdateInterval(int) override {} 31 | void setSoundsEnabled(bool) override {} 32 | void readSettings() override { readSettingsCalled = true; } 33 | void loadTheme(const KBlocksTheme *) override {} 34 | void startGame() override {} 35 | void stopGame() override { 36 | if (mpGameLogic->singleGamesDeleted) { 37 | singleGameDeletedWhenStopGameCalled = true; 38 | } 39 | } 40 | void pauseGame(bool, bool) override {} 41 | void addScore(int, int) override {} 42 | 43 | public Q_SLOTS: 44 | void playMoveSound() override {} 45 | void playDropSound() override {} 46 | 47 | public: 48 | bool singleGameDeletedWhenStopGameCalled; 49 | bool readSettingsCalled; 50 | 51 | private: 52 | MockGameLogic *mpGameLogic; 53 | }; 54 | 55 | #endif // MOCKSCENE_H 56 | -------------------------------------------------------------------------------- /src/Testing/MockSingleGame.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKSINGLEGAME_H 8 | #define MOCKSINGLEGAME_H 9 | 10 | #include 11 | 12 | #include "MockField.h" 13 | #include "MockPiece.h" 14 | #include "SingleGameInterface.h" 15 | 16 | class FieldInterface; 17 | class PieceInterface; 18 | 19 | class MockSingleGame : public SingleGameInterface 20 | { 21 | public: 22 | MockSingleGame() 23 | : SingleGameInterface(), 24 | numberOfPickGameActionCalls(0), 25 | updateGameReturnValue(0), 26 | mockField(new MockField()), 27 | mockPiece(new MockPiece()) 28 | {} 29 | ~MockSingleGame() override = default; 30 | 31 | public: 32 | FieldInterface *getField() override { return mockField.get(); } 33 | 34 | int getPieceCount() override { return 0; } 35 | PieceInterface *getPiece(int) override { return mockPiece.get(); } 36 | 37 | bool isActive() override { return false; } 38 | bool isGameRunning() override { return false; } 39 | 40 | int forceUpdateGame() override { return 0; } 41 | int updateGame() override { return updateGameReturnValue; } 42 | int continueGame() override { return 0; } 43 | 44 | bool setCurrentPiece(int, int, int) override { return false; } 45 | 46 | bool pickGameResult(int *) override { return false; } 47 | 48 | bool pickGameAction(int *, int *) override 49 | { 50 | ++numberOfPickGameActionCalls; 51 | return false; 52 | } 53 | 54 | public: 55 | unsigned int numberOfPickGameActionCalls; 56 | int updateGameReturnValue; 57 | 58 | private: 59 | std::unique_ptr mockField; 60 | std::unique_ptr mockPiece; 61 | }; 62 | 63 | #endif //SINGLE_GAME_INTERFACE 64 | -------------------------------------------------------------------------------- /src/Testing/MockSound.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2009-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKSOUND_H 8 | #define MOCKSOUND_H 9 | 10 | #include "SoundInterface.h" 11 | 12 | class MockSound : public SoundInterface 13 | { 14 | public: 15 | MockSound() = default; 16 | ~MockSound() override = default; 17 | 18 | public: 19 | bool loadTheme(const KBlocksTheme *) override { return false; } 20 | void setSoundsEnabled(bool) override {} 21 | void playSound(Sound) override {} 22 | }; 23 | 24 | #endif // MOCKSOUND_H 25 | -------------------------------------------------------------------------------- /src/Testing/MockSvgItem.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | #ifndef MOCKSVGITEM_H 8 | #define MOCKSVGITEM_H 9 | 10 | #include "SvgItemInterface.h" 11 | 12 | class MockSvgItem : public SvgItemInterface 13 | { 14 | public: 15 | MockSvgItem() = default; 16 | 17 | ~MockSvgItem() override = default; 18 | 19 | public: 20 | bool updateSelf() override { updateSelfCalled = true; return true; } 21 | void clearCache() override { clearCacheCalled = true; } 22 | void startOpAnim() override {} 23 | void stopOpAnim() override {} 24 | void startPosAnim(QPointF) override {} 25 | void execPosAnim(qreal) override {} 26 | void stopPosAnim() override {} 27 | 28 | bool updateSelfCalled = false; 29 | bool clearCacheCalled = false; 30 | }; 31 | 32 | #endif //MOCKSVGITEM_H 33 | -------------------------------------------------------------------------------- /src/Testing/TestingKBlocksItemGroup.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | 8 | #ifndef TESTINGKBLOCKSITEMGROUP_H 9 | #define TESTINGKBLOCKSITEMGROUP_H 10 | 11 | #include "KBlocksItemGroup.h" 12 | #include "SvgItemInterface.h" 13 | 14 | class TestingKBlocksItemGroup : public KBlocksItemGroup 15 | { 16 | public: 17 | TestingKBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS) 18 | : KBlocksItemGroup(groupID, p, pG, pS) 19 | {} 20 | ~TestingKBlocksItemGroup() override = default; 21 | 22 | void callUpdateGame() 23 | { 24 | KBlocksItemGroup::updateGame(); 25 | } 26 | 27 | SvgItemInterface *getFreezeCell(int cellNum) 28 | { 29 | if (cellNum < mMaxFreezeCellNum) { 30 | return maFreezeCells[cellNum]; 31 | } 32 | return nullptr; 33 | } 34 | 35 | int getMaxPrepareCellNum() const 36 | { 37 | return mMaxPrepareCellNum; 38 | } 39 | 40 | SvgItemInterface *getPrepareCell(int cellNum) 41 | { 42 | if (cellNum < mMaxPrepareCellNum) { 43 | return maPrepareCells[cellNum]; 44 | } 45 | return nullptr; 46 | } 47 | 48 | void replacePrepareCell(int cellNum, SvgItemInterface* newItem) 49 | { 50 | if (cellNum >= mMaxPrepareCellNum) { 51 | return; 52 | } 53 | removeFromGroup(maPrepareCells[cellNum]); 54 | delete maPrepareCells[cellNum]; 55 | 56 | maPrepareCells[cellNum] = newItem; 57 | addToGroup(maPrepareCells[cellNum]); 58 | } 59 | 60 | void replaceFreezeCell(int cellNum, SvgItemInterface* newItem) 61 | { 62 | if (cellNum >= mMaxFreezeCellNum) { 63 | return; 64 | } 65 | removeFromGroup(maFreezeCells[cellNum]); 66 | delete maFreezeCells[cellNum]; 67 | 68 | maFreezeCells[cellNum] = newItem; 69 | addToGroup(maFreezeCells[cellNum]); 70 | } 71 | }; 72 | 73 | #endif // TESTINGKBLOCKSITEMGROUP_H 74 | -------------------------------------------------------------------------------- /src/Testing/TestingKBlocksWin.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | 8 | #include "TestingKBlocksWin.h" 9 | 10 | TestingKBlocksWin::TestingKBlocksWin( 11 | GameLogicInterface *p, 12 | GraphicsInterface *graphics, 13 | SoundInterface *sound, 14 | KGameThemeProvider *themeProvider, 15 | KBlocksPlayManager *pM, 16 | int capacity, 17 | int gamecount 18 | ) : KBlocksWin(p, graphics, sound, themeProvider, pM, capacity, gamecount) 19 | { 20 | } 21 | 22 | void TestingKBlocksWin::callStopGame() 23 | { 24 | KBlocksWin::stopGame(); 25 | } 26 | 27 | void TestingKBlocksWin::replaceScene(SceneInterface *newScene) 28 | { 29 | disconnect( 30 | mpKBPlayer, &KBlocksKeyboardPlayer::blockMoved, 31 | mpGameScene, &SceneInterface::playMoveSound 32 | ); 33 | disconnect( 34 | mpKBPlayer, &KBlocksKeyboardPlayer::blockDropped, 35 | mpGameScene, &SceneInterface::playDropSound 36 | ); 37 | delete mpGameScene; 38 | mpGameScene = newScene; 39 | connect( 40 | mpKBPlayer, &KBlocksKeyboardPlayer::blockMoved, 41 | mpGameScene, &SceneInterface::playMoveSound 42 | ); 43 | connect( 44 | mpKBPlayer, &KBlocksKeyboardPlayer::blockDropped, 45 | mpGameScene, &SceneInterface::playDropSound 46 | ); 47 | mpGameView->setScene(mpGameScene); 48 | } 49 | -------------------------------------------------------------------------------- /src/Testing/TestingKBlocksWin.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2010-2021 Julian Helfferich * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ******************************************************************************/ 7 | 8 | #ifndef TESTINGKBLOCKSWIN_H 9 | #define TESTINGKBLOCKSWIN_H 10 | 11 | #include "KBlocksWin.h" 12 | #include "SceneInterface.h" 13 | 14 | class GameLogicInterface; 15 | class GraphicsInterface; 16 | class KBlocksPlayManager; 17 | class SoundInterface; 18 | 19 | class TestingKBlocksWin : private KBlocksWin 20 | { 21 | public: 22 | TestingKBlocksWin( 23 | GameLogicInterface *p, 24 | GraphicsInterface *graphics, 25 | SoundInterface *sound, 26 | KGameThemeProvider *themeProvider, 27 | KBlocksPlayManager *pM, 28 | int capacity, 29 | int gamecount 30 | ); 31 | ~TestingKBlocksWin() override = default; 32 | 33 | void callStopGame(); 34 | void replaceScene(SceneInterface *newScene); 35 | }; 36 | 37 | #endif // TESTINGKBLOCKSWIN_H 38 | -------------------------------------------------------------------------------- /src/config/kblocks.kcfg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | true 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/config/settings.kcfgc: -------------------------------------------------------------------------------- 1 | # Code generation options for kconfig_compiler 2 | File=kblocks.kcfg 3 | ClassName=Settings 4 | Singleton=true 5 | Mutators=true 6 | -------------------------------------------------------------------------------- /src/kblocks.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | kblocksui.rc 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/kblocksui.rc: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Main Toolbar 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/org.kde.kblocks.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=KBlocks 3 | Name[ar]=الكتل ك 4 | Name[ast]=KBlocks 5 | Name[bg]=KBlocks 6 | Name[bs]=KBlocks 7 | Name[ca]=KBlocks 8 | Name[ca@valencia]=KBlocks 9 | Name[cs]=KBlocks 10 | Name[da]=KBlocks 11 | Name[de]=KBlocks 12 | Name[el]=KBlocks 13 | Name[en_GB]=KBlocks 14 | Name[eo]=KBlocks 15 | Name[es]=KBlocks 16 | Name[et]=KBlocks 17 | Name[eu]=KBlocks 18 | Name[fi]=KBlocks 19 | Name[fr]=KBlocks 20 | Name[ga]=KBlocks 21 | Name[gl]=KBlocks 22 | Name[he]=KBlocks 23 | Name[hi]=केब्लॉक्स 24 | Name[hne]=के-बाक्स 25 | Name[hu]=KBlocks 26 | Name[ia]=KBlocks 27 | Name[id]=KBlocks 28 | Name[is]=K-Blokkir 29 | Name[it]=KBlocks 30 | Name[ja]=KBlocks 31 | Name[ka]=KBlocks 32 | Name[kk]=KBlocks 33 | Name[km]=KBlocks 34 | Name[ko]=KBlocks 35 | Name[lt]=KBlocks 36 | Name[lv]=KBlocks 37 | Name[mr]=के-ब्लॉक्स 38 | Name[nb]=KBlocks 39 | Name[nds]=KBlocks 40 | Name[nl]=KBlocks 41 | Name[nn]=KBlocks 42 | Name[pl]=KBloki 43 | Name[pt]=KBlocks 44 | Name[pt_BR]=KBlocks 45 | Name[ro]=KBlocuri 46 | Name[ru]=KBlocks 47 | Name[sa]=KBlocks इति 48 | Name[sk]=KBlocks 49 | Name[sl]=KBlocks 50 | Name[sq]=KBlocks 51 | Name[sr]=К‑блокови 52 | Name[sr@ijekavian]=К‑блокови 53 | Name[sr@ijekavianlatin]=K‑blokovi 54 | Name[sr@latin]=K‑blokovi 55 | Name[sv]=Kblock 56 | Name[tr]=K Bloklar 57 | Name[ug]=KBlocks 58 | Name[uk]=KBlocks 59 | Name[wa]=KBlocks 60 | Name[x-test]=xxKBlocksxx 61 | Name[zh_CN]=KBlocks 62 | Name[zh_TW]=KBlocks 63 | Icon=kblocks 64 | Exec=kblocks -qwindowtitle %c 65 | Type=Application 66 | X-DocPath=kblocks/index.html 67 | GenericName=Falling Blocks Game 68 | GenericName[ar]=لعبة الكتل المتساقطة 69 | GenericName[bg]=Игра с падащи блокове 70 | GenericName[bs]=Igra padajući blokovi 71 | GenericName[ca]=Joc de blocs que cauen 72 | GenericName[ca@valencia]=Joc de blocs que cauen 73 | GenericName[da]=Faldende blokke-spil 74 | GenericName[de]=„Tetris“-Spiel 75 | GenericName[el]=Παιχνίδι με τούβλα που πέφτουν 76 | GenericName[en_GB]=Falling Blocks Game 77 | GenericName[eo]=Ludo de Falantaj Blokoj 78 | GenericName[es]=Juego de bloques en cascada 79 | GenericName[et]=Langevate klotside mäng 80 | GenericName[eu]=Erortzen diren blokeen jokoa 81 | GenericName[fi]=Putoavien palojen peli 82 | GenericName[fr]=Jeu de blocs qui tombent 83 | GenericName[ga]=Cluiche le bloic atá ag titim 84 | GenericName[gl]=Xogo no que caen bloques 85 | GenericName[he]=משחק עם לבנים נופלות 86 | GenericName[hi]=गिरते खण्डों का खेल 87 | GenericName[hu]=Játék lehulló elemekkel 88 | GenericName[id]=Permainan Balok Berjatuhan 89 | GenericName[it]=Gioco di blocchi che cadono 90 | GenericName[ja]=落下するブロックのゲーム 91 | GenericName[ka]=ვარდნილი აგურების თამაში 92 | GenericName[kk]=Тетрис - тектес ойыны 93 | GenericName[km]=ល្បែង​ប្លុក​ធ្លាក់​ 94 | GenericName[ko]=떨어지는 블록 게임 95 | GenericName[lt]=Krentančių blokų žaidimas 96 | GenericName[lv]=Krītošo bloku spēle 97 | GenericName[mr]=पडणाऱ्या ब्लॉक्सचा खेळ 98 | GenericName[nb]=Spill med fallende brikker 99 | GenericName[nds]=Speel mit fallen Blöck 100 | GenericName[nl]=Vallende blokken-spel 101 | GenericName[nn]=Spel med fallande brikker 102 | GenericName[pl]=Gra w spadające bloki 103 | GenericName[pt]=Jogo de Blocos em Queda 104 | GenericName[pt_BR]=Jogo estilo Tetris 105 | GenericName[ro]=Joc de blocuri căzătoare 106 | GenericName[ru]=Тетрис 107 | GenericName[sa]=पतने खण्ड खेल 108 | GenericName[sk]=Hra s padajúcimi blokmi 109 | GenericName[sl]=Igra padajočih kock 110 | GenericName[sq]=Loja Rënia e Bloqeve 111 | GenericName[sr]=Игра падајућих блокова 112 | GenericName[sr@ijekavian]=Игра падајућих блокова 113 | GenericName[sr@ijekavianlatin]=Igra padajućih blokova 114 | GenericName[sr@latin]=Igra padajućih blokova 115 | GenericName[sv]=Spel med fallande block 116 | GenericName[tr]=Sütun Düşürme Oyunu 117 | GenericName[ug]=چۈشۈۋاتقان بۆلەك ئويۇنى 118 | GenericName[uk]=Гра з блоками, що падають 119 | GenericName[wa]=On djeu avou des blokes ki tcheyèt 120 | GenericName[x-test]=xxFalling Blocks Gamexx 121 | GenericName[zh_CN]=俄罗斯方块游戏 122 | GenericName[zh_TW]=類似俄羅斯方塊遊戲 123 | StartupNotify=true 124 | Categories=Qt;KDE;Game;ArcadeGame; 125 | -------------------------------------------------------------------------------- /src/utils.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2019 Thomas Branch * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #include "utils.h" 8 | 9 | #include 10 | #include 11 | 12 | timeLong Utils::getMillisecOfNow() 13 | { 14 | const auto now = std::chrono::system_clock::now(); 15 | 16 | return std::chrono::duration_cast(now.time_since_epoch()).count(); 17 | } 18 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * KBlocks, a falling blocks game by KDE * 3 | * SPDX-FileCopyrightText: 2019 Thomas Branch * 4 | * * 5 | * SPDX-License-Identifier: GPL-2.0-or-later 6 | ***************************************************************************/ 7 | #ifndef UTILS_H 8 | #define UTILS_H 9 | 10 | #include "KBlocksDefine.h" 11 | 12 | namespace Utils { 13 | timeLong getMillisecOfNow(); 14 | } 15 | #endif 16 | -------------------------------------------------------------------------------- /themes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Friedrich W. H. Kossebau 2 | # 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | set(KBLOCKS_INSTALL_THEMESDIR "${KDE_INSTALL_DATADIR}/kblocks/themes") 6 | 7 | function(install_theme name) 8 | cmake_parse_arguments(ARG "" "ID" "OTHER" ${ARGN}) 9 | if (NOT ARG_ID) 10 | set(ARG_ID "${name}") 11 | endif() 12 | set(svgz "${CMAKE_CURRENT_BINARY_DIR}/${name}.svgz") 13 | generate_svgz(${name}.svg ${svgz} "theme-") 14 | install( 15 | FILES 16 | ${ARG_ID}.desktop 17 | ${name}_preview.png 18 | ${svgz} 19 | ${ARG_OTHER} 20 | DESTINATION ${KBLOCKS_INSTALL_THEMESDIR} 21 | ) 22 | endfunction() 23 | 24 | install_theme(egyptian ID default 25 | OTHER 26 | default_block_move.ogg 27 | default_block_fall.ogg 28 | ) 29 | install_theme(oxygen) 30 | -------------------------------------------------------------------------------- /themes/default.desktop: -------------------------------------------------------------------------------- 1 | [KGameTheme] 2 | Name=Egyptian 3 | Name[ar]=مصري 4 | Name[bg]=Египетски 5 | Name[bs]=Egipatski 6 | Name[ca]=Egipci 7 | Name[ca@valencia]=Egipci 8 | Name[cs]=Egyptské 9 | Name[da]=Egyptisk 10 | Name[de]=Ägyptisch 11 | Name[el]=Αιγύπτιο 12 | Name[en_GB]=Egyptian 13 | Name[eo]=Egipta 14 | Name[es]=Egipcio 15 | Name[et]=Egiptus 16 | Name[eu]=Egiptoarra 17 | Name[fi]=Egyptiläinen 18 | Name[fr]=Égyptien 19 | Name[ga]=Éigipteach 20 | Name[gl]=Exipcio 21 | Name[he]=מצרי 22 | Name[hi]=मिस्री 23 | Name[hu]=Egyiptomi 24 | Name[id]=Mesir 25 | Name[it]=Egizio 26 | Name[ka]=ეგვიპტური 27 | Name[kk]=Мысырша 28 | Name[km]=អេហ្ស៊ីប 29 | Name[ko]=이집트 30 | Name[lt]=Egipto 31 | Name[lv]=Ēģiptes 32 | Name[mr]=इजिप्शियन 33 | Name[nb]=Egyptisk 34 | Name[nds]=Ägyptsch 35 | Name[nl]=Egyptenaar 36 | Name[nn]=Egyptisk 37 | Name[pl]=Egipski 38 | Name[pt]=Egípcio 39 | Name[pt_BR]=Egípcio 40 | Name[ro]=Egiptean 41 | Name[ru]=Египетский 42 | Name[sa]=मिस्रदेशस्य 43 | Name[sk]=Egyptská 44 | Name[sl]=Egipt 45 | Name[sq]=Egjiptian 46 | Name[sr]=Египатски 47 | Name[sr@ijekavian]=Египатски 48 | Name[sr@ijekavianlatin]=Egipatski 49 | Name[sr@latin]=Egipatski 50 | Name[sv]=Egyptisk 51 | Name[tr]=Mısırlı 52 | Name[ug]=مىسىرلىق 53 | Name[uk]=Єгиптянин 54 | Name[wa]=Edjipcyin 55 | Name[x-test]=xxEgyptianxx 56 | Name[zh_CN]=埃及 57 | Name[zh_TW]=埃及式 58 | Description=KBlocks, Egyptian style. 59 | Description[ar]=الكتل ك بسمة مصرية 60 | Description[bg]=Египетски стил за KBlocks. 61 | Description[bs]=KBlocks, Egipatski stil. 62 | Description[ca]=KBlocks, estil egipci. 63 | Description[ca@valencia]=KBlocks, estil egipci. 64 | Description[da]=KBlocks, egyptisk stil. 65 | Description[de]=Das ägyptische Design für KBlocks. 66 | Description[el]=KBlocks, Αιγυπτιακό στιλ. 67 | Description[en_GB]=KBlocks, Egyptian style. 68 | Description[eo]=KBlocks, Egipteca. 69 | Description[es]=KBlocks, estilo egipcio. 70 | Description[et]=KBlocks Egiptuse stiilis. 71 | Description[eu]=KBlocks, Egiptoko estiloa. 72 | Description[fi]=KBlocksin egyptiläistyylinen teema. 73 | Description[fr]=KBlocks, thème égyptien. 74 | Description[ga]=KBlocks, ar nós na nÉigipteach. 75 | Description[gl]=KBlocks, ao estilo exipcio. 76 | Description[he]=KBlocks, בסגנון מצרי. 77 | Description[hi]=मिस्री शैली में केब्लॉक्स । 78 | Description[hu]=KBlocks, egyiptomi stílusban. 79 | Description[id]=KBlocks, gaya Mesir. 80 | Description[it]=KBlocks, stile egizio. 81 | Description[ka]=KBlocks, ეგვიპტური ქსტილი. 82 | Description[kk]=KBlocks, Мысырша нақыш 83 | Description[km]=រចនាប័ទ្ម​អេហ្ស៊ីបរបស់ KBlocks ។ 84 | Description[ko]=KBlocks, 이집트 스타일. 85 | Description[lv]=„KBlocks“, Ēģiptes stils. 86 | Description[mr]=के-ब्लॉक्स, इजिप्शियन शैली. 87 | Description[nb]=KBlocks, egyptisk stil. 88 | Description[nds]=KBlocks, ägyptsch Stil 89 | Description[nl]=KBlocks, Egyptische stijl. 90 | Description[nn]=KBlocks i egyptisk stil. 91 | Description[pl]=KBloki, wystrój egipski. 92 | Description[pt]=KBlocks, estilo Egípcio. 93 | Description[pt_BR]=KBlocks, estilo egípcio. 94 | Description[ro]=KBlocuri, în stil egiptean. 95 | Description[ru]=KBlocks, египетский стиль. 96 | Description[sa]=KBlocks, मिस्रशैली। 97 | Description[sk]=KBlocks, Egyptský štýl. 98 | Description[sl]=KBlocks v egipčanskem slogu. 99 | Description[sq]=KBlocks, stili egjiptian 100 | Description[sr]=К‑блокови у египатском стилу 101 | Description[sr@ijekavian]=К‑блокови у египатском стилу 102 | Description[sr@ijekavianlatin]=K‑blokovi u egipatskom stilu 103 | Description[sr@latin]=K‑blokovi u egipatskom stilu 104 | Description[sv]=Kblock, egyptisk stil. 105 | Description[tr]=K Bloklar, Mısırlı stili. 106 | Description[uk]=KBlocks, єгипетський стиль. 107 | Description[wa]=KBlocks, edjipcyin stîle. 108 | Description[x-test]=xxKBlocks, Egyptian style.xx 109 | Description[zh_CN]=KBlocks 埃及风格。 110 | Description[zh_TW]=KBlocks,埃及風格 111 | VersionFormat=1 112 | Author=Sean Wilson 113 | AuthorEmail=suseux@gmail.com 114 | Type=SVG 115 | FileName=egyptian.svgz 116 | Preview=egyptian_preview.png 117 | Sound_Block_Move=default_block_move.ogg 118 | Sound_Block_Fall=default_block_fall.ogg 119 | 120 | -------------------------------------------------------------------------------- /themes/default_block_fall.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/themes/default_block_fall.ogg -------------------------------------------------------------------------------- /themes/default_block_move.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/themes/default_block_move.ogg -------------------------------------------------------------------------------- /themes/egyptian_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/themes/egyptian_preview.png -------------------------------------------------------------------------------- /themes/oxygen.desktop: -------------------------------------------------------------------------------- 1 | [KGameTheme] 2 | Name=Oxygen 3 | Name[ar]=أكسجين 4 | Name[bg]=Oxygen 5 | Name[bs]=kiseonik 6 | Name[ca]=Oxygen 7 | Name[ca@valencia]=Oxygen 8 | Name[cs]=Oxygen 9 | Name[da]=Oxygen 10 | Name[de]=Oxygen 11 | Name[el]=Oxygen 12 | Name[en_GB]=Oxygen 13 | Name[eo]=Oxygen 14 | Name[es]=Oxígeno 15 | Name[et]=Oxygen 16 | Name[eu]=Oxygen 17 | Name[fa]=اکسیژن 18 | Name[fi]=Oxygen 19 | Name[fr]=Oxygen 20 | Name[ga]=Oxygen 21 | Name[gl]=Oxygen 22 | Name[he]=חמצן 23 | Name[hi]=ऑक्सीजन 24 | Name[hne]=आक्सीजन 25 | Name[hu]=Oxygen 26 | Name[ia]=Oxygen 27 | Name[id]=Oxygen 28 | Name[it]=Oxygen 29 | Name[ka]=Oxygen 30 | Name[kk]=Oxygen 31 | Name[km]=អុកស៊ីសែន 32 | Name[ko]=Oxygen 33 | Name[lt]=Oxygen 34 | Name[lv]=Oxygen 35 | Name[mai]=आक्सीजन 36 | Name[mr]=ऑक्सीजन 37 | Name[nb]=Oxygen 38 | Name[nds]=Oxygen 39 | Name[ne]=अक्सिजन 40 | Name[nl]=Oxygen 41 | Name[nn]=Oksygen 42 | Name[pl]=Tlen 43 | Name[pt]=Oxygen 44 | Name[pt_BR]=Oxygen 45 | Name[ro]=Oxygen 46 | Name[ru]=Oxygen 47 | Name[sa]=आक्सीजन 48 | Name[se]=Oksygena 49 | Name[sk]=Kyslík 50 | Name[sl]=Kisik 51 | Name[sq]=Oksigjen 52 | Name[sr]=Кисеоник 53 | Name[sr@ijekavian]=Кисеоник 54 | Name[sr@ijekavianlatin]=Kiseonik 55 | Name[sr@latin]=Kiseonik 56 | Name[sv]=Oxygen 57 | Name[te]=ఆక్సీజన్ 58 | Name[tr]=Oxygen 59 | Name[ug]=ئوكسېگىن 60 | Name[uk]=Oxygen 61 | Name[wa]=Ocsidjinne 62 | Name[x-test]=xxOxygenxx 63 | Name[zh_CN]=轻氧 64 | Name[zh_TW]=Oxygen 65 | Description=KBlocks Oxygen theme for KDE 4 66 | Description[ar]=سمة أكسجين للكتل ك كِيدِي 4 67 | Description[bg]=Тема Oxygen от KDE 4 за KBlocks 68 | Description[bs]=Tema KBlocks kisik za KDE 4 69 | Description[ca]=Tema Oxygen del KBlocks per al KDE 4 70 | Description[ca@valencia]=Tema Oxygen de KBlocks per a KDE 4 71 | Description[cs]=Oxygen motiv pro KBlocks v KDE 4 72 | Description[da]=KBlocks' Oxygen-tema for KDE 4 73 | Description[de]=KBlocks-„Oxygen“-Design für KDE4 74 | Description[el]=Θέμα Oxygen του KBlocks για το KDE4 75 | Description[en_GB]=KBlocks Oxygen theme for KDE 4 76 | Description[eo]=KBlocks Oxygen-etoso por KDE 4 77 | Description[es]=Tema Oxígeno de KBlocks para KDE 4 78 | Description[et]=KBlocksi KDE4 Oxygeni teema 79 | Description[eu]=KBlocks Oxygen gaia KDE 4rako 80 | Description[fi]=KBlocksin Oxygen-teema KDE4:lle 81 | Description[fr]=Thème « Oxygen » pour KBlocks pour KDE 4 82 | Description[ga]=Téama Oxygen KBlocks le haghaidh KDE 4 83 | Description[gl]=Tema visual Oxygen de KBlocks para KDE 4 84 | Description[he]=ערכת עיצוב KBlocks חמצן ל־KDE4 85 | Description[hi]=केडीई४ के लिए केब्लॉक्स ऑक्सीजन प्रसंग 86 | Description[hne]=केडीई४ बर केब्लाक्स आक्सीजन प्रसंग 87 | Description[hu]=KBlocks Oxygen-alapú téma a KDE 4-hez 88 | Description[id]=Tema Oxygen KBlocks untuk KDE 4 89 | Description[it]=Tema Oxygen di KBlocks per KDE 4 90 | Description[ja]=KBlocks の KDE 4 用 Oxygen テーマ 91 | Description[ka]=KBlocks-ის Oxygen თემა KDE 4-სთვის 92 | Description[kk]=KDE4-тің KBlocks Oxygen нақышы 93 | Description[km]=ស្បែក​អុកស៊ីសែន​របស់ KBlocks សម្រាប់ KDE 4 94 | Description[ko]=KDE 4용 KBlocks Oxygen 테마 95 | Description[lv]=„KBlocks“ „Oxygen“ motīvs priekš KDE 4 96 | Description[mr]=केडीई४ करिता के-ब्लॉक्स ऑक्सीजन शैली 97 | Description[nb]=KBlocks oxygen-tema for KDE 4 98 | Description[nds]=Oxygen-Muster ut KDE4 för KBlocks 99 | Description[nl]=KBlocks Oxygen-thema voor KDE 4 100 | Description[nn]=Oksygen-tema for KBlocks 101 | Description[pl]=Wystrój Tlenu dla KBloków w KDE4 102 | Description[pt]=Tema do Oxygen para o KBlocks do KDE 4 103 | Description[pt_BR]=Tema do Oxygen para o KBlocks do KDE 4 104 | Description[ro]=Tematică KBlocuri Oxygen pentru KDE4 105 | Description[ru]=Стиль оформления Oxygen для KBlocks из KDE4 106 | Description[sa]=KDE 4 कृते आक्सीजन विषयं KBlocks करोति 107 | Description[sk]=Oxygen téma pre KBlocks v KDE 4 108 | Description[sl]=Tema Kisik za igro KBlocks 109 | Description[sq]=Tema KBlocks Oxygen për KDE 4 110 | Description[sr]=Кисеоничка тема К‑блокова за КДЕ‑4 111 | Description[sr@ijekavian]=Кисеоничка тема К‑блокова за КДЕ‑4 112 | Description[sr@ijekavianlatin]=Kiseonička tema K‑blokova za KDE4 113 | Description[sr@latin]=Kiseonička tema K‑blokova za KDE4 114 | Description[sv]=Oxygen-tema för Kblock i KDE 4 115 | Description[tr]=KDE 4 için K Bloklar Oxygen Teması 116 | Description[uk]=Тема KBlocks Oxygen для KDE 4 117 | Description[wa]=Tinme Ocsidjinne di KBlocks po KDE 4 118 | Description[x-test]=xxKBlocks Oxygen theme for KDE 4xx 119 | Description[zh_CN]=为 KDE 4 设计的 KBlocks 轻氧主题 120 | Description[zh_TW]=KBlocks KDE4 Oxygen 外觀主題 121 | VersionFormat=1 122 | Author=Johann-Ollivier Lapeyre 123 | AuthorEmail=johann.ollivierlapeyre@gmail.com 124 | Type=SVG 125 | FileName=oxygen.svgz 126 | Preview=oxygen_preview.png 127 | Sound_Block_Move=default_block_move.ogg 128 | Sound_Block_Fall=default_block_fall.ogg 129 | 130 | -------------------------------------------------------------------------------- /themes/oxygen_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/kblocks/ec1ad7b47201a0b3c0e7f3a7bc45f911aeaf52ce/themes/oxygen_preview.png --------------------------------------------------------------------------------