调整到vscode兼容 初始化项目

This commit is contained in:
2026-04-23 18:26:00 +08:00
commit b0c29d4a24
20 changed files with 549 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
# Build outputs
/.vscode-build/
/build/
/bin/
/obj/
/out/
/dist/
# Executables and libraries
*.exe
*.dll
*.lib
*.a
*.so
*.dylib
# Object and intermediate files
*.o
*.obj
*.pch
*.pdb
*.ilk
*.idb
*.exp
*.res
# Logs and runtime dumps
*.log
*.tmp
*.temp
*.stackdump
# IDE and editor user files
.idea/
*.suo
*.user
*.userossc
*.vcxproj.user
*.code-workspace
# VS Code: keep shared project settings, ignore local history/cache
.vscode/*.log
.vscode/*.tmp
.vscode/.ropeproject/
# OS files
.DS_Store
Thumbs.db
Desktop.ini
+19
View File
@@ -0,0 +1,19 @@
{
"version": 4,
"configurations": [
{
"name": "MinGW",
"compilerPath": "g++.exe",
"intelliSenseMode": "windows-gcc-x64",
"cppStandard": "c++17",
"includePath": [
"${workspaceFolder}\\src"
],
"defines": [
"UNICODE",
"_UNICODE",
"_WINDOWS"
]
}
]
}
+19
View File
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Tetris MinGW",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\.vscode-build\\mingw\\Tetris.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}\\src",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "build Tetris MinGW"
}
]
}
+10
View File
@@ -0,0 +1,10 @@
{
"C_Cpp.default.compilerPath": "g++.exe",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.intelliSenseMode": "windows-gcc-x64",
"files.associations": {
"*.rc": "cpp",
"tchar.h": "cpp",
"windows.h": "cpp"
}
}
+37
View File
@@ -0,0 +1,37 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build Tetris MinGW",
"type": "shell",
"command": "powershell",
"args": [
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-File",
"${workspaceFolder}\\build-mingw.ps1"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc"
},
{
"label": "run Tetris MinGW",
"type": "shell",
"command": "powershell",
"args": [
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-File",
"${workspaceFolder}\\build-mingw.ps1",
"-Run"
],
"group": "test",
"problemMatcher": "$gcc"
}
]
}
+13
View File
@@ -0,0 +1,13 @@
# VS Code 运行说明
1. 用 VS Code 打开本文件所在文件夹: `C:\Users\27282\Desktop\src_学生版`
2. 安装 VS Code 扩展: `C/C++`,发布者是 `Microsoft`
3.`Ctrl+Shift+B` 编译
4.`F5` 调试运行,或在命令面板执行 `Tasks: Run Task` -> `run Tetris MinGW`
说明:
- 默认配置优先使用系统 `PATH` 中的 `g++.exe` / `gdb.exe`,也兼容 `C:\mingw64\bin\g++.exe`
- 源码目录是 `src`,资源目录是 `assets`
- MinGW 构建输出文件在 `.vscode-build\mingw\Tetris.exe`
- 由于原项目的 `Tetris.rc` 是 UTF-16,MinGW 暂不编译资源文件;这只影响图标/菜单资源,不影响源码编译运行。
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+66
View File
@@ -0,0 +1,66 @@
param(
[switch]$Run
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectDir = Join-Path $Root "src"
$BuildDir = Join-Path $Root ".vscode-build\mingw"
$ExePath = Join-Path $BuildDir "Tetris.exe"
$GxxCandidates = @(
"g++.exe",
"C:\mingw64\bin\g++.exe"
)
$Gxx = $null
foreach ($Candidate in $GxxCandidates) {
try {
$Resolved = Get-Command $Candidate -ErrorAction Stop
$Gxx = $Resolved.Source
break
} catch {
if (Test-Path $Candidate) {
$Gxx = $Candidate
break
}
}
}
if (-not $Gxx) {
throw "g++.exe not found. Add MinGW to PATH or install it at C:\mingw64\bin\g++.exe."
}
New-Item -ItemType Directory -Force -Path $BuildDir | Out-Null
$Sources = @(
(Join-Path $ProjectDir "stdafx.cpp"),
(Join-Path $ProjectDir "Tetris.cpp"),
(Join-Path $ProjectDir "TetrisLogic.cpp"),
(Join-Path $ProjectDir "TetrisRender.cpp")
)
& $Gxx `
-std=c++17 `
-g `
-O0 `
-municode `
-mwindows `
-DUNICODE `
-D_UNICODE `
-D_WINDOWS `
-I $ProjectDir `
@Sources `
-lwinmm `
-lgdi32 `
-luser32 `
-o $ExePath
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
if ($Run) {
Start-Process -FilePath $ExePath -WorkingDirectory $ProjectDir
}
+57
View File
@@ -0,0 +1,57 @@
// Tetris.cpp : 程序入口、窗口初始化与消息处理
#include "stdafx.h"
#include "Tetris.h"
#define MAX_LOADSTRING 100
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO(作业1): 补全 Win32 程序入口函数。
return 0;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
// TODO(作业2): 注册窗口类。
UNREFERENCED_PARAMETER(hInstance);
return 0;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
// TODO(作业3): 创建并显示主窗口。
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(nCmdShow);
return FALSE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO(作业4): 补全主窗口消息处理函数。
return DefWindowProc(hWnd, message, wParam, lParam);
}
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
// TODO(作业5): 补全“关于”对话框的消息处理。
UNREFERENCED_PARAMETER(hDlg);
UNREFERENCED_PARAMETER(message);
UNREFERENCED_PARAMETER(wParam);
return (INT_PTR)FALSE;
}
+52
View File
@@ -0,0 +1,52 @@
#pragma once
#include "resource.h"
#include "stdafx.h"
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
constexpr int GRID = 30;
constexpr int nGameWidth = 10;
constexpr int nGameHeight = 20;
constexpr int nWidth = 16;
constexpr int nHeight = 22;
// 定义一个点,用来表示方块的位置
struct Point
{
int x;
int y;
};
extern int nType; // 下一方块类型
extern int type; // 当前方块类型
extern int state; // 当前方块状态
extern int tScore; // 当前得分
extern bool gameOverFlag; // 游戏已经结束
extern bool suspendFlag; // 暂停游戏
extern bool targetFlag; // 启用瞄准器
extern int workRegion[20][10]; // 工作区数据,0 表示该位置没有被占用
extern Point point; // 当前方块的当前位置
extern Point target; // 当前方块目标位置,用于瞄准器
extern int bricks[7][4][4][4];
extern COLORREF BrickColor[7];
// 游戏逻辑相关函数
bool CanMoveDown();
bool CanMoveLeft();
bool CanMoveRight();
void MoveDown();
void MoveLeft();
void MoveRight();
void Rotate();
void DropDown();
void Fixing();
void DeleteOneLine(int number);
void DeleteLines();
bool GameOver();
void ComputeTarget();
void Restart();
// 绘图函数
void TDrawScreen(HDC hdc, HWND hWnd);
BIN
View File
Binary file not shown.
+148
View File
@@ -0,0 +1,148 @@
#include "stdafx.h"
#include "Tetris.h"
int nType = 0;
int type = 0;
int state = 0;
int tScore = 0;
bool gameOverFlag = false;
bool suspendFlag = false;
bool targetFlag = false;
int workRegion[20][10] = { 0 };
Point point = { 0, 0 };
Point target = { 0, 0 };
int bricks[7][4][4][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0, 5, 5, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 5, 5, 0}, {0, 5, 5, 0}, {0, 0, 0, 0}}
},
{
{{0, 6, 0, 0}, {0, 6, 6, 0}, {0, 0, 6, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 6, 6, 0}, {6, 6, 0, 0}, {0, 0, 0, 0}},
{{6, 0, 0, 0}, {6, 6, 0, 0}, {0, 6, 0, 0}, {0, 0, 0, 0}},
{{0, 6, 6, 0}, {6, 6, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
},
{
{{0, 0, 7, 0}, {0, 7, 7, 0}, {0, 7, 0, 0}, {0, 0, 0, 0}},
{{0, 7, 7, 0}, {0, 0, 7, 7}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 7}, {0, 0, 7, 7}, {0, 0, 7, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 7, 7, 0}, {0, 0, 7, 7}, {0, 0, 0, 0}}
}
};
COLORREF BrickColor[7] =
{
RGB(255, 0, 0),
RGB(0, 255, 0),
RGB(0, 0, 255),
RGB(0, 255, 255),
RGB(255, 150, 0),
RGB(255, 255, 0),
RGB(168, 0, 168)
};
bool CanMoveDown()
{
// TODO(作业6): 判断当前方块是否可以继续下落。
return true;
}
bool CanMoveLeft()
{
// TODO(作业7): 判断当前方块是否可以向左移动。
return true;
}
bool CanMoveRight()
{
// TODO(作业8): 判断当前方块是否可以向右移动。
return true;
}
void MoveDown()
{
// TODO(作业9): 方块下移一格。
point.y = point.y;
}
void MoveLeft()
{
// TODO(作业10): 方块左移一格。
point.x = point.x;
}
void MoveRight()
{
// TODO(作业11): 方块右移一格。
point.x = point.x;
}
void Rotate()
{
// TODO(作业12): 旋转当前方块。
}
void DropDown()
{
// TODO(作业13): 实现“一键到底”。
}
void Fixing()
{
// TODO(作业14): 将当前方块固定到工作区,并生成下一个方块。
}
void DeleteOneLine(int number)
{
// TODO(作业15): 删除指定行,并让其上方所有行整体下移。
UNREFERENCED_PARAMETER(number);
}
void DeleteLines()
{
// TODO(作业16): 完成消行与计分逻辑。
}
bool GameOver()
{
// TODO(作业17): 判断游戏是否结束。
return false;
}
void ComputeTarget()
{
// TODO(作业18): 计算瞄准器的预测落点。
}
void Restart()
{
// TODO(作业19): 重置游戏状态。
}
+9
View File
@@ -0,0 +1,9 @@
#include "stdafx.h"
#include "Tetris.h"
void TDrawScreen(HDC hdc, HWND hWnd)
{
// TODO(作业20): 完整绘制游戏界面。
UNREFERENCED_PARAMETER(hdc);
UNREFERENCED_PARAMETER(hWnd);
}
+32
View File
@@ -0,0 +1,32 @@
#pragma once
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 Tetris.rc 使用
//
#define IDS_APP_TITLE 103
#define IDR_MAINFRAME 128
#define IDD_TETRIS_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_TETRIS 107
#define IDI_SMALL 108
#define IDC_TETRIS 109
#define IDC_MYICON 2
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 130
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif
+8
View File
@@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// Tetris.pch 将作为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
// 引用任何所需的附加头文件,而不是在此文件中引用
+22
View File
@@ -0,0 +1,22 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的信息
// Windows 头文件:
#include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <time.h>
// TODO: 在此处引用程序需要的其他头文件
+8
View File
@@ -0,0 +1,8 @@
#pragma once
// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
#include <SDKDDKVer.h>