diff --git a/2048uwp.sln b/2048uwp.sln
new file mode 100644
index 0000000..dc29864
--- /dev/null
+++ b/2048uwp.sln
@@ -0,0 +1,51 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30011.22
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "2048uwp", "2048uwp\2048uwp.vcxproj", "{AC1D64A4-9CB3-4F69-947C-802840993C67}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|ARM = Debug|ARM
+ Debug|ARM64 = Debug|ARM64
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|ARM = Release|ARM
+ Release|ARM64 = Release|ARM64
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|ARM.ActiveCfg = Debug|ARM
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|ARM.Build.0 = Debug|ARM
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|ARM.Deploy.0 = Debug|ARM
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|ARM64.ActiveCfg = Debug|ARM64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|ARM64.Build.0 = Debug|ARM64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|ARM64.Deploy.0 = Debug|ARM64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|x64.ActiveCfg = Debug|x64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|x64.Build.0 = Debug|x64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|x64.Deploy.0 = Debug|x64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|x86.ActiveCfg = Debug|Win32
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|x86.Build.0 = Debug|Win32
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Debug|x86.Deploy.0 = Debug|Win32
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|ARM.ActiveCfg = Release|ARM
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|ARM.Build.0 = Release|ARM
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|ARM.Deploy.0 = Release|ARM
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|ARM64.ActiveCfg = Release|ARM64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|ARM64.Build.0 = Release|ARM64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|ARM64.Deploy.0 = Release|ARM64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|x64.ActiveCfg = Release|x64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|x64.Build.0 = Release|x64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|x64.Deploy.0 = Release|x64
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|x86.ActiveCfg = Release|Win32
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|x86.Build.0 = Release|Win32
+ {AC1D64A4-9CB3-4F69-947C-802840993C67}.Release|x86.Deploy.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {0E8B49DC-49E9-4128-8FCD-4DA49640F2FE}
+ EndGlobalSection
+EndGlobal
diff --git a/2048uwp/2048uwp.vcxproj b/2048uwp/2048uwp.vcxproj
new file mode 100644
index 0000000..69c59de
--- /dev/null
+++ b/2048uwp/2048uwp.vcxproj
@@ -0,0 +1,239 @@
+
+
+
+ {ac1d64a4-9cb3-4f69-947c-802840993c67}
+ _2048uwp
+ en-US
+ 14.0
+ true
+ Windows Store
+ 10.0.19041.0
+ 10.0.17763.0
+ 10.0
+ True
+
+
+
+
+ Debug
+ ARM
+
+
+ Debug
+ ARM64
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ ARM
+
+
+ Release
+ ARM64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ Application
+ true
+ v142
+
+
+ Application
+ true
+ v142
+
+
+ Application
+ true
+ v142
+
+
+ Application
+ true
+ v142
+ true
+
+
+ Application
+ false
+ true
+ v142
+ true
+
+
+ Application
+ false
+ true
+ v142
+ true
+
+
+ Application
+ false
+ true
+ v142
+ true
+
+
+ Application
+ false
+ true
+ v142
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ False
+ SHA256
+ True
+ False
+ Always
+ x86|x64|arm|arm64
+ 0
+ 2048uwp_TemporaryKey.pfx
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+ /bigobj %(AdditionalOptions)
+ 4453;28204
+
+
+
+
+
+ App.xaml
+
+
+ MainPage.xaml
+
+
+
+
+
+
+ Designer
+
+
+ Designer
+
+
+
+
+ Designer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ App.xaml
+
+
+ MainPage.xaml
+
+
+ Create
+ Create
+ Create
+ Create
+ Create
+ Create
+ Create
+ Create
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2048uwp/2048uwp.vcxproj.filters b/2048uwp/2048uwp.vcxproj.filters
new file mode 100644
index 0000000..8d11faa
--- /dev/null
+++ b/2048uwp/2048uwp.vcxproj.filters
@@ -0,0 +1,59 @@
+
+
+
+
+ ac1d64a4-9cb3-4f69-947c-802840993c67
+
+
+ c6240b1d-a8e5-48bd-82b3-86ad23d3c936
+ bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+ Assets
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2048uwp/App.xaml b/2048uwp/App.xaml
new file mode 100644
index 0000000..2452beb
--- /dev/null
+++ b/2048uwp/App.xaml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/2048uwp/App.xaml.cpp b/2048uwp/App.xaml.cpp
new file mode 100644
index 0000000..cc0e72e
--- /dev/null
+++ b/2048uwp/App.xaml.cpp
@@ -0,0 +1,116 @@
+//
+// App.xaml.cpp
+// App 类的实现。
+//
+
+#include "pch.h"
+#include "MainPage.xaml.h"
+
+using namespace _2048uwp;
+
+using namespace Platform;
+using namespace Windows::ApplicationModel;
+using namespace Windows::ApplicationModel::Activation;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Controls;
+using namespace Windows::UI::Xaml::Controls::Primitives;
+using namespace Windows::UI::Xaml::Data;
+using namespace Windows::UI::Xaml::Input;
+using namespace Windows::UI::Xaml::Interop;
+using namespace Windows::UI::Xaml::Media;
+using namespace Windows::UI::Xaml::Navigation;
+
+///
+/// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
+/// 已执行,逻辑上等同于 main() 或 WinMain()。
+///
+App::App()
+{
+ InitializeComponent();
+ Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
+}
+
+///
+/// 在应用程序由最终用户正常启动时进行调用。
+/// 将在启动应用程序以打开特定文件等情况下使用。
+///
+/// 有关启动请求和过程的详细信息。
+void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
+{
+ auto rootFrame = dynamic_cast(Window::Current->Content);
+
+ // 不要在窗口已包含内容时重复应用程序初始化,
+ // 只需确保窗口处于活动状态
+ if (rootFrame == nullptr)
+ {
+ // 创建一个 Frame 以用作导航上下文并将其与
+ // SuspensionManager 键关联
+ rootFrame = ref new Frame();
+
+ rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed);
+
+ if (e->PreviousExecutionState == ApplicationExecutionState::Terminated)
+ {
+ // TODO: 仅当适用时还原保存的会话状态,并安排
+ // 还原完成后的最终启动步骤
+
+ }
+
+ if (e->PrelaunchActivated == false)
+ {
+ if (rootFrame->Content == nullptr)
+ {
+ // 当导航堆栈尚未还原时,导航到第一页,
+ // 并通过将所需信息作为导航参数传入来配置
+ // 新页面
+ rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments);
+ }
+ // 将框架放在当前窗口中
+ Window::Current->Content = rootFrame;
+ // 确保当前窗口处于活动状态
+ Window::Current->Activate();
+ }
+ }
+ else
+ {
+ if (e->PrelaunchActivated == false)
+ {
+ if (rootFrame->Content == nullptr)
+ {
+ // 当导航堆栈尚未还原时,导航到第一页,
+ // 并通过将所需信息作为导航参数传入来配置
+ // 参数
+ rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments);
+ }
+ // 确保当前窗口处于活动状态
+ Window::Current->Activate();
+ }
+ }
+}
+
+///
+/// 在将要挂起应用程序执行时调用。 在不知道应用程序
+/// 无需知道应用程序会被终止还是会恢复,
+/// 并让内存内容保持不变。
+///
+/// 挂起的请求的源。
+/// 有关挂起请求的详细信息。
+void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
+{
+ (void) sender; // 未使用的参数
+ (void) e; // 未使用的参数
+
+ //TODO: 保存应用程序状态并停止任何后台活动
+}
+
+///
+/// 导航到特定页失败时调用
+///
+///导航失败的框架
+///有关导航失败的详细信息
+void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e)
+{
+ throw ref new FailureException("Failed to load Page " + e->SourcePageType.Name);
+}
diff --git a/2048uwp/App.xaml.h b/2048uwp/App.xaml.h
new file mode 100644
index 0000000..8aa3a8c
--- /dev/null
+++ b/2048uwp/App.xaml.h
@@ -0,0 +1,27 @@
+//
+// App.xaml.h
+// App 类的声明。
+//
+
+#pragma once
+
+#include "App.g.h"
+
+namespace _2048uwp
+{
+ ///
+ /// 提供特定于应用程序的行为,以补充默认的应用程序类。
+ ///
+ ref class App sealed
+ {
+ protected:
+ virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override;
+
+ internal:
+ App();
+
+ private:
+ void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
+ void OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e);
+ };
+}
diff --git a/2048uwp/Assets/LockScreenLogo.scale-200.png b/2048uwp/Assets/LockScreenLogo.scale-200.png
new file mode 100644
index 0000000..41384f8
Binary files /dev/null and b/2048uwp/Assets/LockScreenLogo.scale-200.png differ
diff --git a/2048uwp/Assets/SplashScreen.scale-200.png b/2048uwp/Assets/SplashScreen.scale-200.png
new file mode 100644
index 0000000..5036781
Binary files /dev/null and b/2048uwp/Assets/SplashScreen.scale-200.png differ
diff --git a/2048uwp/Assets/Square150x150Logo.scale-200.png b/2048uwp/Assets/Square150x150Logo.scale-200.png
new file mode 100644
index 0000000..d028663
Binary files /dev/null and b/2048uwp/Assets/Square150x150Logo.scale-200.png differ
diff --git a/2048uwp/Assets/Square44x44Logo.scale-200.png b/2048uwp/Assets/Square44x44Logo.scale-200.png
new file mode 100644
index 0000000..82f8aa5
Binary files /dev/null and b/2048uwp/Assets/Square44x44Logo.scale-200.png differ
diff --git a/2048uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/2048uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
new file mode 100644
index 0000000..cdf9f6a
Binary files /dev/null and b/2048uwp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ
diff --git a/2048uwp/Assets/StoreLogo.png b/2048uwp/Assets/StoreLogo.png
new file mode 100644
index 0000000..066b736
Binary files /dev/null and b/2048uwp/Assets/StoreLogo.png differ
diff --git a/2048uwp/Assets/Wide310x150Logo.scale-200.png b/2048uwp/Assets/Wide310x150Logo.scale-200.png
new file mode 100644
index 0000000..f212f24
Binary files /dev/null and b/2048uwp/Assets/Wide310x150Logo.scale-200.png differ
diff --git a/2048uwp/Assets/miku.jpg b/2048uwp/Assets/miku.jpg
new file mode 100644
index 0000000..3ed3a66
Binary files /dev/null and b/2048uwp/Assets/miku.jpg differ
diff --git a/2048uwp/MainPage.xaml b/2048uwp/MainPage.xaml
new file mode 100644
index 0000000..adf94d4
--- /dev/null
+++ b/2048uwp/MainPage.xaml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/2048uwp/MainPage.xaml.cpp b/2048uwp/MainPage.xaml.cpp
new file mode 100644
index 0000000..6663a0a
--- /dev/null
+++ b/2048uwp/MainPage.xaml.cpp
@@ -0,0 +1,204 @@
+//
+// MainPage.xaml.cpp
+// MainPage 类的实现。
+//
+
+#include "pch.h"
+#include "MainPage.xaml.h"
+#include "ui.h"
+using namespace Concurrency;
+
+using namespace _2048uwp;
+using namespace Platform;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::UI::Popups;
+using namespace Windows::UI::ViewManagement;
+using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Controls;
+using namespace Windows::UI::Xaml::Controls::Primitives;
+using namespace Windows::UI::Xaml::Data;
+using namespace Windows::UI::Xaml::Input;
+using namespace Windows::UI::Xaml::Media;
+using namespace Windows::UI::Xaml::Navigation;
+
+static wchar_t buff[1024];
+static float rbh = 0;
+
+MainPage::MainPage()
+{
+ InitializeComponent();
+ brushinit();
+ btninit();
+ getfilepath();
+ gamedisplay();
+}
+void _2048uwp::MainPage::stage_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
+{
+ float buttonsz = (e->NewSize.Width - 50.0) / 4.0;
+ float rate = pow((float)buttonsz / (float)e->NewSize.Width - 1.0, 3);
+
+ if (rate > 1.0) rate = 1.0;
+ bs->Width = buttonsz * 2;
+ bs->Height = buttonsz * (asin(rate) / 3.14 * 2.2 + 1.0);
+}
+void _2048uwp::MainPage::Page_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
+{
+ float rate = pow((float)e->NewSize.Height / (float)e->NewSize.Width - 1.0, 3);
+
+ if (rate > 1.0) rate = 1.0;
+ rbase->Height = rbh = 127 * (asin(rate) / 3.14 * 2 + 1.0);
+ float newsize = ((e->NewSize.Width > e->NewSize.Height) ? e->NewSize.Height : e->NewSize.Width) - 128;
+ float buttonsz = (newsize - 50.0) / 4.0;
+
+ stage->Width = newsize;
+ stage->Height = newsize;
+ setbtnsz(b11); setbtnsz(b12); setbtnsz(b13); setbtnsz(b14);
+ setbtnsz(b21); setbtnsz(b22); setbtnsz(b23); setbtnsz(b24);
+ setbtnsz(b31); setbtnsz(b32); setbtnsz(b33); setbtnsz(b34);
+ setbtnsz(b41); setbtnsz(b42); setbtnsz(b43); setbtnsz(b44);
+ setbtntxtsz(b11); setbtntxtsz(b12); setbtntxtsz(b13); setbtntxtsz(b14);
+ setbtntxtsz(b21); setbtntxtsz(b22); setbtntxtsz(b23); setbtntxtsz(b24);
+ setbtntxtsz(b31); setbtntxtsz(b32); setbtntxtsz(b33); setbtntxtsz(b34);
+ setbtntxtsz(b41); setbtntxtsz(b42); setbtntxtsz(b43); setbtntxtsz(b44);
+ setbtntxtsz(bs);
+ r2->Width = 10 + buttonsz;
+ r1->Width = 30 + 2 * buttonsz;
+ c2->Height = 10 + buttonsz;
+ c1->Height = 30 + 2 * buttonsz;
+ bbk->Height = buttonsz / 2.5; bbk->Width = buttonsz / 2.5;
+ bre->Height = buttonsz / 2.5; bre->Width = buttonsz / 2.5;
+ bbk->FontSize = buttonsz / 6; bre->FontSize = buttonsz / 6;
+}
+void _2048uwp::MainPage::bbk_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
+{
+ memcpy(arr, arr2, sizeof(arr)); drawblocks(); printmyscore(); save2file();
+}
+
+void _2048uwp::MainPage::bre_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
+{
+ ContentDialog^ refreshGame = ref new ContentDialog;
+ refreshGame->Title = "重置游戏";
+ refreshGame->Content = "您将失去现有进度";
+ refreshGame->PrimaryButtonText = "重置";
+ refreshGame->CloseButtonText = "取消";
+ refreshGame->DefaultButton = ContentDialogButton::Close;
+ IAsyncOperation^ refreshTask = refreshGame->ShowAsync();
+ create_task(refreshTask).then([this](ContentDialogResult result) {
+ if (result == ContentDialogResult::Primary){
+ _wremove(filepath); gamedisplay(); savestage();
+ }
+ });
+}
+void _2048uwp::MainPage::bs_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
+{
+ wchar_t* buf = buff;
+ char c = 0;
+
+ memset(buff, 0, sizeof(buff));
+ swprintf_s(buf, 1024, L"方文社©2020 by 源文雨.\n\t\tNow\n");
+ for (int i = 0; i <= 5; i++) {
+ for (int j = 0; j <= 5; j++) {
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"%05d ", arr[i][j]);
+ if (arr[i][j]) c++;
+ }
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"\n");
+ }
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"\t\tPrev\n");
+ for (int i = 0; i <= 5; i++) {
+ for (int j = 0; j <= 5; j++) {
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"%05d ", arr[i][j]);
+ if (arr2[i][j]) c++;
+ }
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"\n");
+ }
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"Manipulation: (%d, %d). ", XPOS, YPOS);
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"Win status: %d. Fail status: %d.\n", ISWIN, ISFAIL);
+ //swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"Active blocks in all data: %d. ", c);
+ //swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"Active blocks in stage: %d.\n", activeblocks());
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"Background color is #%02X%02X%02X%02X, so the system is in ", UISettings().GetColorValue(UIColorType::Background).A, UISettings().GetColorValue(UIColorType::Background).R, UISettings().GetColorValue(UIColorType::Background).G, UISettings().GetColorValue(UIColorType::Background).B);
+ swprintf_s(buf + wcslen(buf), 1024 - wcslen(buf), L"%s mode.\n", isbglight()?L"light":L"dark");
+ //String^ s = ref new String(buf);
+ //s += L"Data folder: " + ApplicationData::Current->LocalFolder->Path;
+ ContentDialog^ message = ref new ContentDialog;
+ message->Title = "Info";
+ message->Content = ref new String(buf);
+ message->PrimaryButtonText = "确定";
+ //MessageDialog^ msg = ref new MessageDialog(ref new String(buf));
+ //msg->Title = "Info";
+ //msg->ShowAsync();
+ message->ShowAsync();
+ //delete[] s;
+ //if(!er) fclose(fp);
+}
+void _2048uwp::MainPage::bpage_KeyUp(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
+{
+ NOMOV = 1;
+
+ switch (e->Key.ToString()->Begin()[0]) {
+ case 'L': savestage(); merge(leftmove, leftadd); break;
+ case 'R': savestage(); merge(rightmove, rightadd); break;
+ case 'U': savestage(); merge(upmove, upadd); break;
+ case 'D': savestage(); merge(downmove, downadd); break;
+ case 'B': memcpy(arr, arr2, sizeof(arr)); drawblocks(); printmyscore(); save2file(); break;
+ case 'E': Windows::ApplicationModel::Core::CoreApplication::Exit();
+ default: return; break;
+ }
+ if (NOMOV) { loadfromfile(); havempty(); return; }
+ else {
+ if (havempty()) newblock();
+ if (!ISWIN && !ISFAIL) printmyscore();
+ if (!ISFAIL) { drawblocks(); save2file(); }
+ }
+}
+void _2048uwp::MainPage::basegrid_ManipulationCompleted(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationCompletedRoutedEventArgs^ e)
+{
+ MVTAG = 0;
+ rbase->Height = rbh;
+ cbase1->Width = GridLength((double)241, GridUnitType::Star);
+ cbase2->Width = GridLength((double)25, GridUnitType::Star);
+}
+void _2048uwp::MainPage::bpage_RightTapped(Platform::Object^ sender, Windows::UI::Xaml::Input::RightTappedRoutedEventArgs^ e)
+{
+ if (CH) { CH = 0; basegrid->Opacity = 0.7; }
+ else { CH = 1; basegrid->Opacity = 1.0; }
+}
+void _2048uwp::MainPage::basegrid_ManipulationDelta(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs^ e)
+{
+ if (MVTAG) {
+ rbase->Height = rbh;
+ cbase1->Width = GridLength((double)241, GridUnitType::Star);
+ cbase2->Width = GridLength((double)25, GridUnitType::Star);
+ return;
+ }
+ rbase->Height = abs(rbh + DY / 16);
+ cbase1->Width = GridLength((double)abs(241 - DX / 16), GridUnitType::Star);
+ cbase2->Width = GridLength((double)abs(25 - DX / 16), GridUnitType::Star);
+ MUMOV = 1;
+
+ AXPOS = abs(e->Cumulative.Translation.X);
+ AYPOS = abs(e->Cumulative.Translation.Y);
+ XPOS = e->Cumulative.Translation.X;
+ YPOS = e->Cumulative.Translation.Y;
+ if (abs(AXPOS - AYPOS) < 100) return;
+ else {
+ savestage();
+ MVTAG = 1;
+ if (AXPOS > AYPOS) {
+ if (XPOS < 0) { mmerge(leftmove, leftadd); }
+ else { mmerge(rightmove, rightadd); }
+ }
+ else if (YPOS > 0) { mmerge(downmove, downadd); }
+ else { mmerge(upmove, upadd); }
+ if (MUMOV) { loadfromfile(); havempty(); return; }
+ else {
+ if (havempty()) newblock();
+ if (!ISWIN && !ISFAIL) printmyscore();
+ if (!ISFAIL) { drawblocks(); save2file(); }
+ }
+ }
+}
+void _2048uwp::MainPage::bhide_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
+{
+ if (CH++ > 6) { arr[3][4] = 2048; CH = 0; }
+}
diff --git a/2048uwp/MainPage.xaml.h b/2048uwp/MainPage.xaml.h
new file mode 100644
index 0000000..5b7e95e
--- /dev/null
+++ b/2048uwp/MainPage.xaml.h
@@ -0,0 +1,37 @@
+//
+// MainPage.xaml.h
+// MainPage 类的声明。
+//
+
+#pragma once
+
+#include "MainPage.g.h"
+
+namespace _2048uwp
+{
+ ///
+ /// 可用于自身或导航至 Frame 内部的空白页。
+ ///
+ public ref class MainPage sealed
+ {
+ public:
+ MainPage();
+
+ private:
+ int havempty();
+ void printmyscore();
+ void btninit();
+ void drawblocks();
+ void gamedisplay();
+ void stage_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
+ void Page_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
+ void bbk_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void bre_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void bs_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void bpage_KeyUp(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
+ void basegrid_ManipulationCompleted(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationCompletedRoutedEventArgs^ e);
+ void bpage_RightTapped(Platform::Object^ sender, Windows::UI::Xaml::Input::RightTappedRoutedEventArgs^ e);
+ void basegrid_ManipulationDelta(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs^ e);
+ void bhide_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ };
+}
diff --git a/2048uwp/Package.appxmanifest b/2048uwp/Package.appxmanifest
new file mode 100644
index 0000000..d7d6a88
--- /dev/null
+++ b/2048uwp/Package.appxmanifest
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+ Miku2048
+ 源文雨
+ Assets\StoreLogo.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2048uwp/pch.cpp b/2048uwp/pch.cpp
new file mode 100644
index 0000000..ea14621
--- /dev/null
+++ b/2048uwp/pch.cpp
@@ -0,0 +1,5 @@
+//
+// pch.cpp
+//
+
+#include "pch.h"
diff --git a/2048uwp/pch.h b/2048uwp/pch.h
new file mode 100644
index 0000000..2162189
--- /dev/null
+++ b/2048uwp/pch.h
@@ -0,0 +1,15 @@
+//
+// pch.h
+//
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "App.xaml.h"
+
diff --git a/2048uwp/resource.h b/2048uwp/resource.h
new file mode 100644
index 0000000..78e1350
--- /dev/null
+++ b/2048uwp/resource.h
@@ -0,0 +1,16 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ ɵİļ
+// 2048uwp.rc ʹ
+//
+#define IDR_IMG1 101
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 102
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/2048uwp/ui.h b/2048uwp/ui.h
new file mode 100644
index 0000000..69e46ea
--- /dev/null
+++ b/2048uwp/ui.h
@@ -0,0 +1,565 @@
+#pragma once
+#include "pch.h"
+#include "MainPage.xaml.h"
+
+using namespace _2048uwp;
+using namespace Platform;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::Storage;
+using namespace Windows::UI::ViewManagement;
+using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Controls;
+using namespace Windows::UI::Xaml::Controls::Primitives;
+using namespace Windows::UI::Xaml::Data;
+using namespace Windows::UI::Xaml::Input;
+using namespace Windows::UI::Xaml::Media;
+using namespace Windows::UI::Xaml::Navigation;;
+
+#define C8192 Windows::UI::ColorHelper::FromArgb(0xbb, 0x36, 0x91, 0xff)
+#define C4096 Windows::UI::ColorHelper::FromArgb(0xbb, 0x8e, 0xd2, 0xff)
+#define C2048 Windows::UI::ColorHelper::FromArgb(0xbb, 0xeb, 0xc7, 0x03)
+#define C1024 Windows::UI::ColorHelper::FromArgb(0xbb, 0xe3, 0xb9, 0x15)
+#define C512 Windows::UI::ColorHelper::FromArgb(0xbb, 0xec, 0xc8, 0x50)
+#define C256 Windows::UI::ColorHelper::FromArgb(0xbb, 0xed, 0xcc, 0x61)
+#define C128 Windows::UI::ColorHelper::FromArgb(0xbb, 0xed, 0xce, 0x71)
+#define C64 Windows::UI::ColorHelper::FromArgb(0xbb, 0xf6, 0x5d, 0x3b)
+#define C32 Windows::UI::ColorHelper::FromArgb(0xbb, 0xf5, 0x7c, 0x5f)
+#define C16 Windows::UI::ColorHelper::FromArgb(0xbb, 0xf5, 0x95, 0x63)
+#define C8 Windows::UI::ColorHelper::FromArgb(0xbb, 0xf2, 0xb1, 0x79)
+#define C4 Windows::UI::ColorHelper::FromArgb(0xdd, 0xec, 0xe0, 0xc8)
+#define C2 Windows::UI::ColorHelper::FromArgb(0xdd, 0xee, 0xe4, 0xda)
+#define C0 Windows::UI::ColorHelper::FromArgb(0x55, 0xff, 0xff, 0xff)
+#define DGRAY Windows::UI::ColorHelper::FromArgb(0xff, 0x55, 0x55, 0x55)
+#define WTE Windows::UI::ColorHelper::FromArgb(0xff, 0xff, 0xff, 0xff)
+
+#define COLOR8192 colors[15]
+#define COLOR4096 colors[14]
+#define COLOR2048 colors[11]
+#define COLOR1024 colors[10]
+#define COLOR512 colors[9]
+#define COLOR256 colors[8]
+#define COLOR128 colors[7]
+#define COLOR64 colors[6]
+#define COLOR32 colors[5]
+#define COLOR16 colors[4]
+#define COLOR8 colors[3]
+#define COLOR4 colors[2]
+#define COLOR2 colors[1]
+#define COLOR0 colors[0]
+#define DARKGRAY colors[12]
+#define WHITE colors[13]
+
+#define setbtnsz(x) x->Width = buttonsz; x->Height = buttonsz
+#define setbtncolor(btn, color) btn->Background = color
+#define setbtntxt(x, t) x->Content = t
+#define setbtntxtsz(x) x->FontSize = buttonsz / 3
+#define setbtntxtcolor(x, c) x->Foreground = c
+
+static Brush^ colors[16];
+
+static short arr[6][6];
+
+#define CH arr[0][0]
+#define XPOS arr[0][1]
+#define YPOS arr[0][2]
+#define AXPOS arr[0][3]
+#define AYPOS arr[0][4]
+#define FLAG arr[0][5]
+
+#define FLAG2 arr[5][0]
+#define FLAG3 arr[5][1]
+#define FLAG4 arr[5][2]
+#define ISFAIL arr[5][3]
+#define ISWIN arr[5][4]
+#define NOMOV arr[5][5]
+
+#define SCORE arr[1][0]
+#define MUMOV arr[2][0]
+#define MVTAG arr[3][0]
+
+#define DX e->Delta.Translation.X
+#define DY e->Delta.Translation.Y
+
+static short arr2[6][6];
+#define savestage() memcpy(arr2, arr, sizeof(arr))
+#define merge(x, y) FLAG3 = !x(); FLAG4 = !y(); NOMOV = FLAG3 && FLAG4
+#define mmerge(x, y) FLAG3 = !x(); FLAG4 = !y(); MUMOV = FLAG3 && FLAG4
+
+static Button^ btngrp[4][4];
+#define drawb(color) setbtncolor(btngrp[i][j], color)
+#define drawt(color, text) setbtntxt(btngrp[i][j], text); setbtntxtcolor(btngrp[i][j], color)
+
+static FILE fbuf;
+static String^ path;
+static const wchar_t* filepath;
+#define localpath ApplicationData::Current->LocalFolder->Path
+#define getfilepath() path = localpath; path += "\\savedata"; filepath = path->Begin()
+
+int activeblocks();
+void brushinit();
+//void btninit();
+short calScore(short arr[6][6]);
+int downadd();
+int downmove();
+//void drawblocks();
+//void gamedisplay();
+//havempty();
+int isbglight();
+int leftadd();
+int leftmove();
+errno_t loadfromfile();
+void newblock();
+//printmyscore();
+int rightadd();
+int rightmove();
+int save2file();
+int upadd();
+int upmove();
+
+int activeblocks() {
+ char c = 0;
+ for (int i = 1; i <= 4; i++) {
+ for (int j = 1; j <= 4; j++) {
+ if (arr[i][j]) c++;
+ }
+ }
+ return c;
+}
+void brushinit() {
+ colors[0] = ref new SolidColorBrush(C0);
+ colors[1] = ref new SolidColorBrush(C2);
+ colors[2] = ref new SolidColorBrush(C4);
+ colors[3] = ref new SolidColorBrush(C8);
+ colors[4] = ref new SolidColorBrush(C16);
+ colors[5] = ref new SolidColorBrush(C32);
+ colors[6] = ref new SolidColorBrush(C64);
+ colors[7] = ref new SolidColorBrush(C128);
+ colors[8] = ref new SolidColorBrush(C256);
+ colors[9] = ref new SolidColorBrush(C512);
+ colors[10] = ref new SolidColorBrush(C1024);
+ colors[11] = ref new SolidColorBrush(C2048);
+ colors[12] = ref new SolidColorBrush(DGRAY);
+ colors[13] = ref new SolidColorBrush(WTE);
+ colors[14] = ref new SolidColorBrush(C4096);
+ colors[15] = ref new SolidColorBrush(C8192);
+}
+void _2048uwp::MainPage::btninit() {
+ btngrp[0][0] = b11; btngrp[0][1] = b12; btngrp[0][2] = b13; btngrp[0][3] = b14;
+ btngrp[1][0] = b21; btngrp[1][1] = b22; btngrp[1][2] = b23; btngrp[1][3] = b24;
+ btngrp[2][0] = b31; btngrp[2][1] = b32; btngrp[2][2] = b33; btngrp[2][3] = b34;
+ btngrp[3][0] = b41; btngrp[3][1] = b42; btngrp[3][2] = b43; btngrp[3][3] = b44;
+}
+short calScore(short arr[6][6]) {
+ SCORE = 0;
+ for (int i = 1; i <= 4; i++) {
+ for (int j = 1; j <= 4; j++) {
+ SCORE += arr[i][j];
+ }
+ }
+ return SCORE % 9999 + 1;
+}
+int downadd() {
+ FLAG = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[1][j] ? 8 : 0) + (arr[2][j] ? 4 : 0) + (arr[3][j] ? 2 : 0) + (arr[4][j] ? 1 : 0)) {
+ case 0: case 1: break;
+ case 3:
+ if (arr[3][j] == arr[4][j]) {
+ arr[4][j] *= 2;
+ FLAG++;
+ arr[3][j] = 0;
+ }
+ break;
+ case 7:
+ if (arr[3][j] == arr[4][j]) {
+ arr[4][j] *= 2;
+ FLAG++;
+ arr[3][j] = arr[2][j];
+ arr[2][j] = 0;
+ }
+ else if (arr[2][j] == arr[3][j]) {
+ arr[3][j] *= 2;
+ FLAG++;
+ arr[2][j] = 0;
+ }
+ break;
+ case 15:
+ if (arr[3][j] == arr[4][j]) {
+ arr[4][j] *= 2;
+ FLAG++;
+ arr[3][j] = 0;
+ }
+ else if (arr[2][j] == arr[3][j]) {
+ arr[3][j] *= 2;
+ FLAG++;
+ arr[2][j] = 0;
+ }
+ if (arr[1][j] == arr[2][j]) {
+ arr[2][j] *= 2;
+ FLAG++;
+ arr[1][j] = 0;
+ }
+ downmove();
+ break;
+ }
+ return FLAG;
+}
+int downmove() {
+ FLAG2 = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[1][j] ? 8 : 0) + (arr[2][j] ? 4 : 0) + (arr[3][j] ? 2 : 0) + (arr[4][j] ? 1 : 0)) {
+ case 0: case 1: case 3: case 7: case 15: FLAG2++; break;
+ case 2: arr[4][j] = arr[3][j]; arr[3][j] = 0; break;
+ case 4: arr[4][j] = arr[2][j]; arr[2][j] = 0; break;
+ case 5: arr[3][j] = arr[2][j]; arr[2][j] = 0; break;
+ case 6: arr[4][j] = arr[3][j]; arr[3][j] = arr[2][j]; arr[2][j] = 0; break;
+ case 8: arr[4][j] = arr[1][j]; arr[1][j] = 0; break;
+ case 9: arr[3][j] = arr[1][j]; arr[1][j] = 0; break;
+ case 10: arr[4][j] = arr[3][j]; arr[3][j] = arr[1][j]; arr[1][j] = 0; break;
+ case 11: arr[2][j] = arr[1][j]; arr[1][j] = 0; break;
+ case 12: arr[4][j] = arr[2][j]; arr[3][j] = arr[1][j]; arr[1][j] = arr[2][j] = 0; break;
+ case 13: arr[3][j] = arr[2][j]; arr[2][j] = arr[1][j]; arr[1][j] = 0; break;
+ case 14: arr[4][j] = arr[3][j]; arr[3][j] = arr[2][j]; arr[2][j] = arr[1][j]; arr[1][j] = 0; break;
+ default: break;
+ }
+ return (FLAG2 - 4);
+}
+void _2048uwp::MainPage::drawblocks() {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ switch (arr[i + 1][j + 1]) {
+ case 0:
+ drawb(COLOR0);
+ drawt(DARKGRAY, "");
+ break;
+ case 2:
+ drawb(COLOR2);
+ drawt(DARKGRAY, "2");
+ break;
+ case 4:
+ drawb(COLOR4);
+ drawt(DARKGRAY, "4");
+ break;
+ case 8:
+ drawb(COLOR8);
+ drawt(WHITE, "8");
+ break;
+ case 16:
+ drawb(COLOR16);
+ drawt(WHITE, "16");
+ break;
+ case 32:
+ drawb(COLOR32);
+ drawt(WHITE, "32");
+ break;
+ case 64:
+ drawb(COLOR64);
+ drawt(WHITE, "64");
+ break;
+ case 128:
+ drawb(COLOR128);
+ drawt(WHITE, "128");
+ break;
+ case 256:
+ drawb(COLOR256);
+ drawt(WHITE, "256");
+ break;
+ case 512:
+ drawb(COLOR512);
+ drawt(WHITE, "512");
+ break;
+ case 1024:
+ drawb(COLOR1024);
+ drawt(WHITE, "1024");
+ break;
+ case 2048:
+ drawb(COLOR2048);
+ drawt(WHITE, "2048");
+ break;
+ case 4096:
+ drawb(COLOR4096);
+ drawt(WHITE, "4096");
+ break;
+ case 8192:
+ drawb(COLOR8192);
+ drawt(WHITE, "8192");
+ break;
+ default:
+ drawb(COLOR8192);
+ drawt(WHITE, arr[i+1][j+1]);
+ break;
+ }
+ }
+ }
+}
+void _2048uwp::MainPage::gamedisplay() {
+ srand(time(0));
+ memset(arr, 0, sizeof(arr));
+ memset(arr2, 0, sizeof(arr));
+ CH = -1;
+ if(loadfromfile() || !activeblocks()) newblock();
+ if (!~CH) {
+ if ((CH = isbglight())) basegrid->Opacity = 1.0;
+ else basegrid->Opacity = 0.7;
+ }
+ drawblocks();
+ printmyscore();
+ havempty();
+}
+int _2048uwp::MainPage::havempty() {
+ char c = 0;
+ ISWIN = 0;
+ for (int i = 1; i <= 4; i++) for (int j = 1; j <= 4; j++) {
+ if (arr[i][j]) c++;
+ if (arr[i][j] >= 2048) {
+ bs->Content = "WIN!";
+ return ISWIN = 1;
+ break;
+ }
+ }
+ if (c >= 16) {
+ if (!ISFAIL) {
+ bs->Content = "FAILED!";
+ ISFAIL = 1;
+ }
+ }
+ else ISFAIL = 0;
+ return !ISFAIL;
+}
+int isbglight() {
+ return (0.299 * UISettings().GetColorValue(UIColorType::Background).R +
+ 0.587 * UISettings().GetColorValue(UIColorType::Background).G +
+ 0.114 * UISettings().GetColorValue(UIColorType::Background).B) / 255.0 > 0.5;
+}
+int leftadd() {
+ FLAG = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[j][1] ? 8 : 0) + (arr[j][2] ? 4 : 0) + (arr[j][3] ? 2 : 0) + (arr[j][4] ? 1 : 0)) {
+ case 0: case 8: break;
+ case 12:
+ if (arr[j][1] == arr[j][2]) {
+ arr[j][1] *= 2;
+ FLAG++;
+ arr[j][2] = 0;
+ }
+ break;
+ case 14:
+ if (arr[j][1] == arr[j][2]) {
+ arr[j][1] *= 2;
+ FLAG++;
+ arr[j][2] = arr[j][3];
+ arr[j][3] = 0;
+ }
+ else if (arr[j][2] == arr[j][3]) {
+ arr[j][2] *= 2;
+ FLAG++;
+ arr[j][3] = 0;
+ }
+ break;
+ case 15:
+ if (arr[j][1] == arr[j][2]) {
+ arr[j][1] *= 2;
+ FLAG++;
+ arr[j][2] = 0;
+ }
+ else if (arr[j][2] == arr[j][3]) {
+ arr[j][2] *= 2;
+ FLAG++;
+ arr[j][3] = 0;
+ }
+ if (arr[j][3] == arr[j][4]) {
+ arr[j][3] *= 2;
+ FLAG++;
+ arr[j][4] = 0;
+ }
+ leftmove();
+ break;
+ }
+ return FLAG;
+}
+int leftmove() {
+ FLAG2 = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[j][1] ? 8 : 0) + (arr[j][2] ? 4 : 0) + (arr[j][3] ? 2 : 0) + (arr[j][4] ? 1 : 0)) {
+ case 0: case 8: case 12: case 14: case 15: FLAG2++; break;
+ case 1: arr[j][1] = arr[j][4]; arr[j][4] = 0; break;
+ case 2: arr[j][1] = arr[j][3]; arr[j][3] = 0; break;
+ case 3: arr[j][1] = arr[j][3]; arr[j][2] = arr[j][4]; arr[j][3] = arr[j][4] = 0; break;
+ case 4: arr[j][1] = arr[j][2]; arr[j][2] = 0; break;
+ case 5: arr[j][1] = arr[j][2]; arr[j][2] = arr[j][4]; arr[j][4] = 0; break;
+ case 6: arr[j][1] = arr[j][2]; arr[j][2] = arr[j][3]; arr[j][3] = 0; break;
+ case 7: arr[j][1] = arr[j][2]; arr[j][2] = arr[j][3]; arr[j][3] = arr[j][4]; arr[j][4] = 0; break;
+ case 9: arr[j][2] = arr[j][4]; arr[j][4] = 0; break;
+ case 10: arr[j][2] = arr[j][3]; arr[j][3] = 0; break;
+ case 11: arr[j][2] = arr[j][3]; arr[j][3] = arr[j][4]; arr[j][4] = 0; break;
+ case 13: arr[j][3] = arr[j][4]; arr[j][4] = 0; break;
+ default: break;
+ }
+ return (FLAG2 - 4);
+}
+errno_t loadfromfile() {
+ FILE* fp = &fbuf;
+ errno_t e = _wfopen_s(&fp, filepath, L"rb");
+ if (!e) {
+ fread(arr, sizeof(short), 36, fp);
+ fread(arr2, sizeof(short), 36, fp);
+ fclose(fp);
+ }
+ return e;
+}
+void newblock() {
+ int x = rand() % 4 + 1;
+ int y = rand() % 4 + 1;
+ while (arr[x][y]) {
+ x = rand() % 4 + 1;
+ y = rand() % 4 + 1;
+ }
+ if (!(rand() % 10)) arr[x][y] = 4;
+ else arr[x][y] = 2;
+}
+void _2048uwp::MainPage::printmyscore() {
+ bs->Content = calScore(arr);
+}
+int rightadd() {
+ FLAG = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[j][1] ? 8 : 0) + (arr[j][2] ? 4 : 0) + (arr[j][3] ? 2 : 0) + (arr[j][4] ? 1 : 0)) {
+ case 0: case 1: break;
+ case 3:
+ if (arr[j][3] == arr[j][4]) {
+ arr[j][4] *= 2;
+ FLAG++;
+ arr[j][3] = 0;
+ }
+ break;
+ case 7:
+ if (arr[j][3] == arr[j][4]) {
+ arr[j][4] *= 2;
+ FLAG++;
+ arr[j][3] = arr[j][2];
+ arr[j][2] = 0;
+ }
+ else if (arr[j][2] == arr[j][3]) {
+ arr[j][3] *= 2;
+ FLAG++;
+ arr[j][2] = 0;
+ }
+ else FLAG++;
+ break;
+ case 15:
+ if (arr[j][3] == arr[j][4]) {
+ arr[j][4] *= 2;
+ FLAG++;
+ arr[j][3] = 0;
+ }
+ else if (arr[j][2] == arr[j][3]) {
+ arr[j][3] *= 2;
+ FLAG++;
+ arr[j][2] = 0;
+ }
+ if (arr[j][1] == arr[j][2]) {
+ arr[j][2] *= 2;
+ FLAG++;
+ arr[j][1] = 0;
+ }
+ rightmove();
+ break;
+ }
+ return FLAG;
+}
+int rightmove() {
+ FLAG2 = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[j][1] ? 8 : 0) + (arr[j][2] ? 4 : 0) + (arr[j][3] ? 2 : 0) + (arr[j][4] ? 1 : 0)) {
+ case 0: case 1: case 3: case 7: case 15: FLAG2++; break;
+ case 2: arr[j][4] = arr[j][3]; arr[j][3] = 0; break;
+ case 4: arr[j][4] = arr[j][2]; arr[j][2] = 0; break;
+ case 5: arr[j][3] = arr[j][2]; arr[j][2] = 0; break;
+ case 6: arr[j][4] = arr[j][3]; arr[j][3] = arr[j][2]; arr[j][2] = 0; break;
+ case 8: arr[j][4] = arr[j][1]; arr[j][1] = 0; break;
+ case 9: arr[j][3] = arr[j][1]; arr[j][1] = 0; break;
+ case 10: arr[j][4] = arr[j][3]; arr[j][3] = arr[j][1]; arr[j][1] = 0; break;
+ case 11: arr[j][2] = arr[j][1]; arr[j][1] = 0; break;
+ case 12: arr[j][4] = arr[j][2]; arr[j][3] = arr[j][1]; arr[j][1] = arr[j][2] = 0; break;
+ case 13: arr[j][3] = arr[j][2]; arr[j][2] = arr[j][1]; arr[j][1] = 0; break;
+ case 14: arr[j][4] = arr[j][3]; arr[j][3] = arr[j][2]; arr[j][2] = arr[j][1]; arr[j][1] = 0; break;
+ default: break;
+ }
+ return (FLAG2 - 4);
+}
+int save2file() {
+ FILE* fp = &fbuf;
+ if (!_wfopen_s(&fp, filepath, L"wb")) {
+ fwrite(arr, sizeof(short), 36, fp);
+ fwrite(arr2, sizeof(short), 36, fp);
+ fclose(fp);
+ }
+ return 0;
+}
+int upadd() {
+ FLAG = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[1][j] ? 8 : 0) + (arr[2][j] ? 4 : 0) + (arr[3][j] ? 2 : 0) + (arr[4][j] ? 1 : 0)) {
+ case 0: case 8: break;
+ case 12:
+ if (arr[1][j] == arr[2][j]) {
+ arr[1][j] *= 2;
+ FLAG++;
+ arr[2][j] = 0;
+ }
+ break;
+ case 14:
+ if (arr[1][j] == arr[2][j]) {
+ arr[1][j] *= 2;
+ FLAG++;
+ arr[2][j] = arr[3][j];
+ arr[3][j] = 0;
+ }
+ else if (arr[2][j] == arr[3][j]) {
+ arr[2][j] *= 2;
+ FLAG++;
+ arr[3][j] = 0;
+ }
+ break;
+ case 15:
+ if (arr[1][j] == arr[2][j]) {
+ arr[1][j] *= 2;
+ FLAG++;
+ arr[2][j] = 0;
+ }
+ else if (arr[2][j] == arr[3][j]) {
+ arr[2][j] *= 2;
+ FLAG++;
+ arr[3][j] = 0;
+ }
+ if (arr[3][j] == arr[4][j]) {
+ arr[3][j] *= 2;
+ FLAG++;
+ arr[4][j] = 0;
+ }
+ upmove();
+ break;
+ }
+ return FLAG;
+}
+int upmove() {
+ FLAG2 = 0;
+ for (int j = 1; j <= 4; j++)
+ switch ((arr[1][j] ? 8 : 0) + (arr[2][j] ? 4 : 0) + (arr[3][j] ? 2 : 0) + (arr[4][j] ? 1 : 0)) {
+ case 0: case 8: case 12: case 14: case 15: FLAG2++; break;
+ case 1: arr[1][j] = arr[4][j]; arr[4][j] = 0; break;
+ case 2: arr[1][j] = arr[3][j]; arr[3][j] = 0; break;
+ case 3: arr[1][j] = arr[3][j]; arr[2][j] = arr[4][j]; arr[3][j] = arr[4][j] = 0; break;
+ case 4: arr[1][j] = arr[2][j]; arr[2][j] = 0; break;
+ case 5: arr[1][j] = arr[2][j]; arr[2][j] = arr[4][j]; arr[4][j] = 0; break;
+ case 6: arr[1][j] = arr[2][j]; arr[2][j] = arr[3][j]; arr[3][j] = 0; break;
+ case 7: arr[1][j] = arr[2][j]; arr[2][j] = arr[3][j]; arr[3][j] = arr[4][j]; arr[4][j] = 0; break;
+ case 9: arr[2][j] = arr[4][j]; arr[4][j] = 0; break;
+ case 10: arr[2][j] = arr[3][j]; arr[3][j] = 0; break;
+ case 11: arr[2][j] = arr[3][j]; arr[3][j] = arr[4][j]; arr[4][j] = 0; break;
+ case 13: arr[3][j] = arr[4][j]; arr[4][j] = 0; break;
+ default: break;
+ }
+ return (FLAG2 - 4);
+}
\ No newline at end of file