调整到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
+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][4] =
{
{
{{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
{{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
{{0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}}
},
{
{{0, 0, 0, 0}, {0, 0, 2, 0}, {0, 2, 2, 2}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 0, 2, 0}, {0, 0, 2, 2}, {0, 0,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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>