QT-QML2048小游戏

QT-QML2048小游戏

  • 一、演示效果
  • 二、关键程序
  • 三、下载链接


一、演示效果

在这里插入图片描述

二、关键程序

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 MyScriptApplicationWindow {id: mainWindowvisible: truewidth: 550height: 740title: qsTr("2048 Game");
//    flags: Qt.Window | Qt.WindowTitleHint  | Qt.WindowMinimizeButtonHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHintx: (Screen.width - width) / 2y: (Screen.height - height) / 2ExclusiveGroup { 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: trueexclusiveGroup: labelSettingsGroupchecked: MyScript.label === MyScript.labelOptions[0] ? true : falseonTriggered: {if (MyScript.label !== MyScript.labelOptions[0]) {MyScript.label = MyScript.labelOptions[0];MyScript.startupFunction();}}}MenuItem {text: qsTr("Degree")checkable: trueexclusiveGroup: labelSettingsGroupchecked: MyScript.label === MyScript.labelOptions[1] ? true : falseonTriggered: {if (MyScript.label !== MyScript.labelOptions[1]) {MyScript.label = MyScript.labelOptions[1];MyScript.startupFunction();}}}MenuItem {text: qsTr("Military Rank")checkable: trueexclusiveGroup: labelSettingsGroupchecked: MyScript.label === MyScript.labelOptions[2] ? true : falseonTriggered: {if (MyScript.label !== MyScript.labelOptions[2]) {MyScript.label = MyScript.labelOptions[2];MyScript.startupFunction();}}}MenuItem {text: qsTr("PRC")checkable: trueexclusiveGroup: labelSettingsGroupchecked: MyScript.label === MyScript.labelOptions[3] ? true : falseonTriggered: {if (MyScript.label !== MyScript.labelOptions[3]) {MyScript.label = MyScript.labelOptions[3];MyScript.startupFunction();}}}}Menu {title: qsTr("Language")MenuItem {text: "English"checkable: trueexclusiveGroup: languageSettingsGroupchecked: settings.value("language") === "en_US" ? true : falseonTriggered: {if (settings.value("language") !== "en_US") {settings.setValue("language", "en_US");changeLanguageDialog.open();}}}MenuItem {text: "Français"checkable: trueexclusiveGroup: languageSettingsGroupchecked: settings.value("language") === "fr_FR" ? true : falseonTriggered: {if (settings.value("language") !== "fr_FR") {settings.setValue("language", "fr_FR");changeLanguageDialog.open();}}}MenuItem {text: "简体中文"checkable: trueexclusiveGroup: languageSettingsGroupchecked: settings.value("language") === "zh_CN" ? true : falseonTriggered: {if (settings.value("language") !== "zh_CN") {settings.setValue("language", "zh_CN");changeLanguageDialog.open();}}}MenuItem {text: "Polski"checkable: trueexclusiveGroup: languageSettingsGroupchecked: settings.value("language") === "pl_PL" ? true : falseonTriggered: {if (settings.value("language") !== "pl_PL") {settings.setValue("language", "pl_PL");changeLanguageDialog.open();}}}MenuItem {text: "Русский"checkable: trueexclusiveGroup: languageSettingsGroupchecked: settings.value("language") === "ru_RU" ? true : falseonTriggered: {if (settings.value("language") !== "ru_RU") {settings.setValue("language", "ru_RU");changeLanguageDialog.open();}}}MenuItem {text: "German"checkable: trueexclusiveGroup: languageSettingsGroupchecked: settings.value("language") == "de_DE" ?  true : falseonTriggered: {if (settings.value("language") != "de_DE") {settings.setValue("language", "de_DE");changeLanguageDialog.open();}}}}}Menu {id: helpMenutitle: qsTr("Help")MenuItem {text: qsTr("About")onTriggered: aboutDialog.open();}MenuItem {text: qsTr("About Qt")onTriggered: myClass.aboutQt();}}}Item {id: helperfocus: falseproperty 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.bglightItem {width: 500height: 670anchors.centerIn: parentfocus: trueKeys.onPressed: MyScript.moveKey(event)MouseArea {anchors.fill: parentonClicked: parent.forceActiveFocus()}FontLoader { id: localFont; source: "qrc:///res/fonts/DroidSansFallback.ttf" }Text {id: gameNamefont.family: localFont.namefont.pixelSize: 55font.bold: truetext: "2048"color: helper.myColors.fgdark}Row {anchors.right: parent.rightspacing: 5Repeater {id: scoreBoardmodel: 2Rectangle {width: (index == 0) ? 95 : 125height: 55radius: 3color: helper.myColors.bgdarkproperty string scoreText: (index === 0) ? MyScript.score.toString() : MyScript.bestScore.toString()Text {text: (index == 0) ? qsTr("SCORE") : qsTr("BEST")anchors.horizontalCenter: parent.horizontalCentery: 6font.family: localFont.namefont.pixelSize: 13color: helper.myColors.fglight}Text {text: scoreTextanchors.horizontalCenter: parent.horizontalCentery: 22font.family: localFont.namefont.pixelSize: 25font.bold: truecolor: "white"}}}Text {id: addScoreTextfont.family: localFont.namefont.pixelSize: 25font.bold: truecolor: Qt.rgba(119/255, 110/255, 101/255, 0.9);
//                parent: scoreBoard.itemAt(0)anchors.horizontalCenter: parent.horizontalCenterproperty bool runAddScore: falseproperty real yfrom: 0property real yto: -(parent.y + parent.height)property int addScoreAnimTime: 600ParallelAnimation {id: addScoreAnimrunning: falseNumberAnimation {target: addScoreTextproperty: "y"from: addScoreText.yfromto: addScoreText.ytoduration: addScoreText.addScoreAnimTime}NumberAnimation {target: addScoreTextproperty: "opacity"from: 1to: 0duration: addScoreText.addScoreAnimTime}}}}Text {id: bannery: 90height: 40text: qsTr("Join the numbers and get to the <b>2048 tile</b>!")color: helper.myColors.fgdarkfont.family: localFont.namefont.pixelSize: 16verticalAlignment: Text.AlignVCenter}Button {width: 129height: 40y: 90anchors.right: parent.rightstyle: ButtonStyle {background: Rectangle {color: helper.myColors.bgbuttonradius: 3Text{anchors.centerIn: parenttext: qsTr("New Game")color: helper.myColors.fgbuttonfont.family: localFont.namefont.pixelSize: 18font.bold: true}}}onClicked: MyScript.startupFunction()}Rectangle {y: 170width: 500height: 500color: helper.myColors.bgdarkradius: 6Grid {id: tileGridx: 15;y: 15;rows: 4; columns: 4; spacing: 15Repeater {id: cellsmodel: 16Rectangle {width: 425/4; height: 425/4radius: 3color: helper.myColors.bggray}}}}MessageDialog {id: changeLanguageDialogtitle: qsTr("Language Setting Hint")text: qsTr("Please restart the program to make the language setting take effect.")standardButtons: StandardButton.Ok}MessageDialog {id: aboutDialogtitle: 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: deadMessagetitle: qsTr("Game Over")text: qsTr("Game Over!")standardButtons: StandardButton.Retry | StandardButton.AbortonAccepted: {MyScript.startupFunction();}onRejected: MyScript.cleanUpAndQuit();}MessageDialog {id: winMessagetitle: qsTr("You Win")text: qsTr("You win! Continue playing?")standardButtons: StandardButton.Yes | StandardButton.NoonYes: {MyScript.checkTargetFlag = false;close()}onNo: MyScript.startupFunction()onRejected: {MyScript.checkTargetFlag = false;close()}}}Component.onCompleted: MyScript.startupFunction();
}

三、下载链接

https://download.csdn.net/download/u013083044/88758829

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/413114.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于深度学习的时间序列算法总结

1.概述 深度学习方法是一种利用神经网络模型进行高级模式识别和自动特征提取的机器学习方法&#xff0c;近年来在时序预测领域取得了很好的成果。常用的深度学习模型包括循环神经网络&#xff08;RNN&#xff09;、长短时记忆网络&#xff08;LSTM&#xff09;、门控循环单元&a…

PHP Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported.

这个错误是关于三元运算符的错误 这个错误在php8.0以下的版本好像是没问题呢 PHP Fatal error: Unparenthesized a ? b : c ? d : e is not supported. Use either (a ? b : c) ? d : e or a ? b : (c ? d : e) in /cangku/app/common.php on line 57 这个问题是 程…

一款 StarRocks 客户端工具,支持可视化建表、数据编辑

什么是 StarRocks&#xff1f; StarRocks 是新一代极速全场景 MPP (Massively Parallel Processing) 数据库。StarRocks 的愿景是能够让用户的数据分析变得更加简单和敏捷。用户无需经过复杂的预处理&#xff0c;就可以用 StarRocks 来支持多种数据分析场景的极速分析。 为了…

Android 布局菜鸟 android中的布局类型和特点?

一、LinearLayout(线性布局) 1、 特点: 主要以水平或垂直方式来排列界面中的控件。并将控件排列到一条直线上。在线性布局中,如果水平排列,垂直方向上只能放一个控件,如果垂直排列,水平方向上也只能放一个控件。 2、适⽤场景: Android开发中最常见的 ⼀种布局⽅式,排列…

【占用网络】FlashOcc:快速、易部署的占用预测模型

前言 FlashOcc是一个它只需2D卷积就能实现“占用预测模型”&#xff0c;具有快速、节约内存、易部署的特点。 它首先采用2D卷积提取图形信息&#xff0c;生成BEV特征。然后通过通道到高度变换&#xff0c;将BEV特征提升到3D空间特征。 对于常规的占用预测模型&#xff0c;将…

算法刷题——拿出最少数目的魔法豆(力扣)

文章目录 题目描述我的解法思路结果分析 官方题解分析 查漏补缺更新日期参考来源 题目描述 传送门 拿出最少数目的魔法豆&#xff1a;给定一个正整数 数组beans &#xff0c;其中每个整数表示一个袋子里装的魔法豆的数目。请你从每个袋子中拿出 一些豆子&#xff08;也可以 拿…

MATLAB R2023a安装教程

鼠标右击软件压缩包&#xff0c;选择“解压到MATLAB.R2023a”。 打开解压后的文件夹&#xff0c;鼠标右击“R2023a_Windows_iso”选择“装载”。 鼠标右击“setup.exe”选择“以管理员身份运行”。 点击“高级选项”选择“我有文件安装密钥”。 点击“是”&#xff0c;然后点击…

[linux]基于libqrencode和libpng库的数据转为png格式的二维码图像的方法

一、需求 按照数据生成png格式的二维码图片。 二、方案 整合libqrencode、libpng的两个方法&#xff0c;从而实现&#xff0c;详见文&#xff1a; [linux]使用libqrencode库生成二维码数据https://evenurs.blog.csdn.net/article/details/135655176?spm1001.2014.3001.5502…

RabbitMQ交换机(3)-Topic

1.Topic模式 RabbitMQ的Topic模式是一种基于主题的消息传递模式。它允许发送者向一个特定的主题&#xff08;topic&#xff09;发布消息&#xff0c;同时&#xff0c;订阅者也可以针对自己感兴趣的主题进行订阅。 在Topic模式中&#xff0c; 主题通过一个由单词和点号组成的字…

23.实战演练--个人主页

<?xml version"1.0" encoding"utf-8"?> <manifest xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.android.com/tools"><applicationandroid:allowBackup"true"an…

[Linux 进程(五)] 程序地址空间深度剖析

文章目录 1、前言2、什么是进程地址空间&#xff1f;3、进程地址空间的划分4、虚拟地址与物理地址的关系5、页表的作用扩展 6、为什么要有地址空间&#xff1f; 1、前言 Linux学习路线比较线性&#xff0c;也比较长&#xff0c;因此一个完整的知识点学习就会分布在两篇文章中&…

设计模式入门

0. 类图 1. 设计原则 1.单一职责原则&#xff1a;每个类只有一个功能 2.开放封闭原则&#xff1a;模块和函数应该对扩展开放(对提供方)&#xff0c;对修改关闭(对使用方) 3.里氏代换原则&#xff1a;子类拥有父类的所有方法和属性&#xff0c;从而可以减少创建类的工作量 4.依…