QT-QML2048小游戏

这篇具有很好参考价值的文章主要介绍了QT-QML2048小游戏。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


一、演示效果

QT-QML2048小游戏,qt,数据库,java

二、关键程序

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.1
import QtQuick.Window 2.1
import "2048.js" as MyScript

ApplicationWindow {
    id: mainWindow
    visible: true
    width: 550
    height: 740
    title: qsTr("2048 Game");
//    flags: Qt.Window | Qt.WindowTitleHint  | Qt.WindowMinimizeButtonHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHint

    x: (Screen.width - width) / 2
    y: (Screen.height - height) / 2

    ExclusiveGroup { id: labelSettingsGroup }
    ExclusiveGroup { id: languageSettingsGroup }

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("New Game")
                shortcut: "Ctrl+N"
                onTriggered: MyScript.startupFunction();
            }
            MenuItem {
                text: qsTr("Exit")
                shortcut: "Ctrl+Q"
                onTriggered: MyScript.cleanUpAndQuit();
            }
        }

        Menu {
            title: qsTr("Settings")
            Menu {
                title: qsTr("Labeling")
                MenuItem {
                    text: qsTr("2048")
                    checkable: true
                    exclusiveGroup: labelSettingsGroup
                    checked: MyScript.label === MyScript.labelOptions[0] ? true : false
                    onTriggered: {
                        if (MyScript.label !== MyScript.labelOptions[0]) {
                            MyScript.label = MyScript.labelOptions[0];
                            MyScript.startupFunction();
                        }
                    }
                }
                MenuItem {
                    text: qsTr("Degree")
                    checkable: true
                    exclusiveGroup: labelSettingsGroup
                    checked: MyScript.label === MyScript.labelOptions[1] ? true : false
                    onTriggered: {
                        if (MyScript.label !== MyScript.labelOptions[1]) {
                            MyScript.label = MyScript.labelOptions[1];
                            MyScript.startupFunction();
                        }
                    }
                }
                MenuItem {
                    text: qsTr("Military Rank")
                    checkable: true
                    exclusiveGroup: labelSettingsGroup
                    checked: MyScript.label === MyScript.labelOptions[2] ? true : false
                    onTriggered: {
                        if (MyScript.label !== MyScript.labelOptions[2]) {
                            MyScript.label = MyScript.labelOptions[2];
                            MyScript.startupFunction();
                        }
                    }
                }
                MenuItem {
                    text: qsTr("PRC")
                    checkable: true
                    exclusiveGroup: labelSettingsGroup
                    checked: MyScript.label === MyScript.labelOptions[3] ? true : false
                    onTriggered: {
                        if (MyScript.label !== MyScript.labelOptions[3]) {
                            MyScript.label = MyScript.labelOptions[3];
                            MyScript.startupFunction();
                        }
                    }
                }
            }
            Menu {
                title: qsTr("Language")
                MenuItem {
                    text: "English"
                    checkable: true
                    exclusiveGroup: languageSettingsGroup
                    checked: settings.value("language") === "en_US" ? true : false
                    onTriggered: {
                        if (settings.value("language") !== "en_US") {
                            settings.setValue("language", "en_US");
                            changeLanguageDialog.open();
                        }
                    }
                }
                MenuItem {
                    text: "Français"
                    checkable: true
                    exclusiveGroup: languageSettingsGroup
                    checked: settings.value("language") === "fr_FR" ? true : false
                    onTriggered: {
                        if (settings.value("language") !== "fr_FR") {
                            settings.setValue("language", "fr_FR");
                            changeLanguageDialog.open();
                        }
                    }
                }
                MenuItem {
                    text: "简体中文"
                    checkable: true
                    exclusiveGroup: languageSettingsGroup
                    checked: settings.value("language") === "zh_CN" ? true : false
                    onTriggered: {
                        if (settings.value("language") !== "zh_CN") {
                            settings.setValue("language", "zh_CN");
                            changeLanguageDialog.open();
                        }
                    }
                }
                MenuItem {
                    text: "Polski"
                    checkable: true
                    exclusiveGroup: languageSettingsGroup
                    checked: settings.value("language") === "pl_PL" ? true : false
                    onTriggered: {
                        if (settings.value("language") !== "pl_PL") {
                            settings.setValue("language", "pl_PL");
                            changeLanguageDialog.open();
                        }
                    }
                }

                MenuItem {
                    text: "Русский"
                    checkable: true
                    exclusiveGroup: languageSettingsGroup
                    checked: settings.value("language") === "ru_RU" ? true : false
                    onTriggered: {
                        if (settings.value("language") !== "ru_RU") {
                            settings.setValue("language", "ru_RU");
                            changeLanguageDialog.open();
                        }
                    }
                }
                MenuItem {
                    text: "German"
                    checkable: true
                    exclusiveGroup: languageSettingsGroup
                    checked: settings.value("language") == "de_DE" ?  true : false
                    onTriggered: {
                        if (settings.value("language") != "de_DE") {
                            settings.setValue("language", "de_DE");
                            changeLanguageDialog.open();
                        }
                    }
                }
            }
        }

        Menu {
            id: helpMenu
            title: qsTr("Help")
            MenuItem {
                text: qsTr("About")
                onTriggered: aboutDialog.open();
            }
            MenuItem {
                text: qsTr("About Qt")
                onTriggered: myClass.aboutQt();
            }
        }
    }


    Item {
        id: helper
        focus: false
        property var myColors: {"bglight": "#FAF8EF",
                                "bggray": Qt.rgba(238/255, 228/255, 218/255, 0.35),
                                "bgdark": "#BBADA0",
                                "fglight": "#EEE4DA",
                                "fgdark": "#776E62",
                                "bgbutton": "#8F7A66", // Background color for the "New Game" button
                                "fgbutton": "#F9F6F2" // Foreground color for the "New Game" button
        }
    }
    color: helper.myColors.bglight

    Item {
        width: 500
        height: 670
        anchors.centerIn: parent

        focus: true
        Keys.onPressed: MyScript.moveKey(event)

        MouseArea {
            anchors.fill: parent
            onClicked: parent.forceActiveFocus()
        }

        FontLoader { id: localFont; source: "qrc:///res/fonts/DroidSansFallback.ttf" }

        Text {
            id: gameName
            font.family: localFont.name
            font.pixelSize: 55
            font.bold: true
            text: "2048"
            color: helper.myColors.fgdark
        }

        Row {
            anchors.right: parent.right
            spacing: 5
            Repeater {
                id: scoreBoard
                model: 2
                Rectangle {
                    width: (index == 0) ? 95 : 125
                    height: 55
                    radius: 3
                    color: helper.myColors.bgdark
                    property string scoreText: (index === 0) ? MyScript.score.toString() : MyScript.bestScore.toString()
                    Text {
                        text: (index == 0) ? qsTr("SCORE") : qsTr("BEST")
                        anchors.horizontalCenter: parent.horizontalCenter
                        y: 6
                        font.family: localFont.name
                        font.pixelSize: 13
                        color: helper.myColors.fglight
                    }
                    Text {
                        text: scoreText
                        anchors.horizontalCenter: parent.horizontalCenter
                        y: 22
                        font.family: localFont.name
                        font.pixelSize: 25
                        font.bold: true
                        color: "white"
                    }
                }
            }

            Text {
                id: addScoreText
                font.family: localFont.name
                font.pixelSize: 25
                font.bold: true
                color: Qt.rgba(119/255, 110/255, 101/255, 0.9);
//                parent: scoreBoard.itemAt(0)
                anchors.horizontalCenter: parent.horizontalCenter

                property bool runAddScore: false
                property real yfrom: 0
                property real yto: -(parent.y + parent.height)
                property int addScoreAnimTime: 600

                ParallelAnimation {
                    id: addScoreAnim
                    running: false

                    NumberAnimation {
                        target: addScoreText
                        property: "y"
                        from: addScoreText.yfrom
                        to: addScoreText.yto
                        duration: addScoreText.addScoreAnimTime

                    }
                    NumberAnimation {
                        target: addScoreText
                        property: "opacity"
                        from: 1
                        to: 0
                        duration: addScoreText.addScoreAnimTime
                    }
                }
            }
        }

        Text {
            id: banner
            y: 90
            height: 40
            text: qsTr("Join the numbers and get to the <b>2048 tile</b>!")
            color: helper.myColors.fgdark
            font.family: localFont.name
            font.pixelSize: 16
            verticalAlignment: Text.AlignVCenter
        }

        Button {
            width: 129
            height: 40
            y: 90
            anchors.right: parent.right

            style: ButtonStyle {
                background: Rectangle {
                    color: helper.myColors.bgbutton
                    radius: 3
                    Text{
                        anchors.centerIn: parent
                        text: qsTr("New Game")
                        color: helper.myColors.fgbutton
                        font.family: localFont.name
                        font.pixelSize: 18
                        font.bold: true
                    }
                }
            }
            onClicked: MyScript.startupFunction()
        }

        Rectangle {
            y: 170
            width: 500
            height: 500
            color: helper.myColors.bgdark
            radius: 6

            Grid {
                id: tileGrid
                x: 15;
                y: 15;
                rows: 4; columns: 4; spacing: 15

                Repeater {
                    id: cells
                    model: 16
                    Rectangle {
                        width: 425/4; height: 425/4
                        radius: 3
                        color: helper.myColors.bggray
                    }
                }
            }
        }

        MessageDialog {
            id: changeLanguageDialog
            title: qsTr("Language Setting Hint")
            text: qsTr("Please restart the program to make the language setting take effect.")
            standardButtons: StandardButton.Ok
        }

        MessageDialog {
            id: aboutDialog
            title: qsTr("About 2048-Qt")
            text: qsTr("<p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version " + settings.getVersion() + "</p><p>2015 Qiaoyong Zhong &lt;solary.sh@gmail.com&gt;</p>")
            standardButtons: StandardButton.Ok
        }

        MessageDialog {
            id: deadMessage
            title: qsTr("Game Over")
            text: qsTr("Game Over!")
            standardButtons: StandardButton.Retry | StandardButton.Abort
            onAccepted: {
                MyScript.startupFunction();
            }
            onRejected: MyScript.cleanUpAndQuit();
        }

        MessageDialog {
            id: winMessage
            title: qsTr("You Win")
            text: qsTr("You win! Continue playing?")
            standardButtons: StandardButton.Yes | StandardButton.No
            onYes: {
                MyScript.checkTargetFlag = false;
                close()
            }
            onNo: MyScript.startupFunction()
            onRejected: {
                MyScript.checkTargetFlag = false;
                close()
            }
        }

    }

    Component.onCompleted: MyScript.startupFunction();
}

三、下载链接

https://download.csdn.net/download/u013083044/88758829文章来源地址https://www.toymoban.com/news/detail-805515.html

到了这里,关于QT-QML2048小游戏的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【Qt】三种方式实现抽奖小游戏

    简介 本文章是基本Qt与C++实现一个抽奖小游戏,用到的知识点在此前发布的几篇文章。 下面是跳转链接: 【Qt控件之QLabel】用法及技巧 链接: https://blog.csdn.net/MrHHHHHH/article/details/133691441?spm=1001.2014.3001.5501 【Qt控件之QPushButton】用法及技巧 链接: https://blog.csdn.net/MrHHHHHH/article

    2024年02月07日
    浏览(35)
  • python小游戏毕设 2048小游戏设计与实现 (源码)

    🔥 Hi,各位同学好呀,这里是L学长! 🥇今天向大家分享一个今年(2022)最新完成的毕业设计项目作品 python小游戏毕设 2048小游戏设计与实现 (源码) 🥇 学长根据实现的难度和等级对项目进行评分(最低0分,满分5分) 难度系数:3分 工作量:3分 创新点:4分 项目获取: https://

    2024年02月12日
    浏览(31)
  • 2048小游戏成品源码

    2048小游戏,可以自选背景颜色,方框颜色,音乐播放。 还可以展示当前玩家的排名,动态排名,及历史玩家的排名。 前期需求: 使用pygame加载目录音乐。MP3文件: 看下运行后的效果图: =========参数设置: =========背景设置: =========方块设置: ==========源码分享:

    2024年02月16日
    浏览(34)
  • c++制作小游戏2048

    完整代码来自于爱编程的柚子《【C语言/C++游戏项目】:2048小游戏,超详细教程教会你写这个小游戏。》 这个游戏用到了#include graphics.h,思路比较简单。 首先做出游戏页面,然后画出4*4的格子,利用map二维数组,依据数字{0,2,4,8,16,32,64,128,256,512,1024,2048}找到对应颜色在固定位

    2024年02月13日
    浏览(31)
  • 使用QT制作贪吃蛇小游戏(含登录注册界面)

    login.h register.h user.h userlist.h widget.h login.cpp main.cpp register.cpp user.cpp userlist.cpp widget.cpp login.ui register.ui widget.ui

    2024年02月13日
    浏览(27)
  • python快速实现2048小游戏

    《2048》是一款比较流行的数字游戏,最早于2014年3月20日发行。原版2048首先在GitHub上发布,原作者是Gabriele Cirulli,后被移植到各个平台。这款游戏是基于《1024》和《小3传奇》的玩法开发而成的新型数字游戏。 操作指南: 每次可以选择上下左右其中一个方向去滑动,每滑动

    2024年02月11日
    浏览(29)
  • 基于C#的2048小游戏

    最近在玩过2048这个小游戏后感觉很有意思,想着正在学C#的winfrom的我能不能自己写一个2048游戏呢?于是就有了这个:   目录 1.实现思路; 2.代码实现; 1.初始化地图表示的数组; 2.绘制游戏的边框; 3.设置每个数值对应的颜色(可省略); 4.添加控件; 5.四个方向的移动;

    2024年02月08日
    浏览(31)
  • Android期末项目2048小游戏

    Android期末项目2048小游戏。 2048属于益智类小游戏,它做到了娱乐性、趣味性、教育性相统一。益智类的游戏即是需要去开动大脑去思考从而获得游戏的胜利。简单的益智类游戏可以使玩家在娱乐中不断的开发大脑。这样一来就实现了在娱乐中学习。每次可以选择上下左右其中

    2024年02月06日
    浏览(44)
  • 【Android Studio】图形化数字游戏,小游戏2048。

    手机中的小游戏是一种在日常生活中应用广泛的休闲软件,无论是在超市商店,还是在办公室,或是家庭都有着它的身影。随着移动互联网和智能手机的不断发展和进步,当今市场上已经出现了多种简单轻松的小游戏,几乎每一位智能手机的使用者都会在种类繁多的App网站上

    2024年02月03日
    浏览(30)
  • 用Python做一个2048小游戏

    2048的逻辑无非是操作 4 × 4 4times4 4 × 4 的方格,每个方格中有一个数,这些数可以移动,如果两个相同的数字在移动时相撞了,就可以彼此合并。 而这个 4 × 4 4times4 4 × 4 的方格,无非是一个矩阵。只需设计好移动逻辑,再用PyGame将这个方格表现出来就算大功告成。 2048只有

    2024年01月17日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包