C++制作俄罗斯方块

各位都玩过俄罗斯方块否?想必这是一个废话。怎么可能有人没有玩过这个游戏?

那么,谁会用C++写出俄罗斯方块的代码?

“我不会!”(台下观众)

“我不会!”(台下观众)

哦,我会!那么,今天,大佬就来教教你们什么叫做:如何制作俄罗斯方块(C++版)。

首先,即是代码。

这次的代码,我只展示一部分,剩下的各位可以通过下方链接下载。

毕竟,发博客还是要赚点钱的。

源码链接:https://download.csdn.net/download/Wanghs0716/29133629

//部分代码,仅展示前100行

#include 
#include 
#include 
#include 
#include 
#include 
#ifdef _MSC_VER
 #if _MSC_VER <= 1200
  #error VC6不能使用。 
 #else
  #if _MSC_VER >= 1600
   #include 
  #else 
   typedef signed char int8_t;
   typedef unsigned short uint16_t;
  #endif
  #ifndef __cplusplus 
   typedef int bool;
   #define true 1
   #define false 0
  #endif
 #endif
#else 
 #include 
 #ifndef __cplusplus 
  #include 
 #endif
#endif
static const uint16_t gs_uTetrisTable[7][4] =
{
 { 0x00F0U, 0x2222U, 0x00F0U, 0x2222U }, 
 { 0x0072U, 0x0262U, 0x0270U, 0x0232U }, 
 { 0x0223U, 0x0074U, 0x0622U, 0x0170U }, 
 { 0x0226U, 0x0470U, 0x0322U, 0x0071U }, 
 { 0x0063U, 0x0264U, 0x0063U, 0x0264U }, 
 { 0x006CU, 0x0462U, 0x006CU, 0x0462U }, 
 { 0x0660U, 0x0660U, 0x0660U, 0x0660U } 
};
 int n,k; 
static const uint16_t gs_uInitialTetrisPool[28] =
{   
 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U,
 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U,
 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U,
 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xFFFFU, 0xFFFFU
};
 
#define COL_BEGIN 2
#define COL_END 14
#define ROW_BEGIN 4
#define ROW_END 26
typedef struct TetrisManager
{
 uint16_t pool[28];
 int8_t x; 
 int8_t y; 
 int8_t type[3]; 
 int8_t orientation[3]; 
 unsigned score; 
 unsigned erasedCount[4]; 
 unsigned erasedTotal; 
 unsigned tetrisCount[7]; 
 unsigned tetrisTotal; 
 bool dead; 
} TetrisManager;
typedef struct TetrisControl 
{
 bool pause; 
 bool clockwise; 
 int8_t direction; 
 int8_t color[28][16];
} TetrisControl;
 
HANDLE g_hConsoleOutput;
void initGame(TetrisManager *manager, TetrisControl *control); 
void restartGame(TetrisManager *manager, TetrisControl *control); 
void giveTetris(TetrisManager *manager);
bool checkCollision(const TetrisManager *manager);
void insertTetris(TetrisManager *manager); 
void removeTetris(TetrisManager *manager);
void horzMoveTetris(TetrisManager *manager, TetrisControl *control); 
void moveDownTetris(TetrisManager *manager, TetrisControl *control); 
void rotateTetris(TetrisManager *manager, TetrisControl *control); 
void dropDownTetris(TetrisManager *manager, TetrisControl *control); 
bool checkErasing(TetrisManager *manager, TetrisControl *control); 
void keydownControl(TetrisManager *manager, TetrisControl *control, int key); 
void setPoolColor(const TetrisManager *manager, TetrisControl *control);
void gotoxyWithFullwidth(short x, short y); 
void printPoolBorder();
void printTetrisPool(const TetrisManager *manager, const TetrisControl *control); 
void printCurrentTetris(const TetrisManager *manager, const TetrisControl *control); 
void printNextTetris(const TetrisManager *manager);
void printScore(const TetrisManager *manager); 
void runGame(TetrisManager *manager, TetrisControl *control); 
void printPrompting(); 
bool ifPlayAgain(); 
int main()
{
	printf("欢迎来到俄罗斯方块,游戏加载中");
    for(int i=1;i<=300000000;i++)n=k/2;

这次的源码展示,大部分都是头文件哈!

“这,难道就是大佬级作品吗?”(台下观众)

额,我可不自恋。那么,如果你觉得文章不错······

点赞、评论、收藏起来!

谢谢大家!

你可能感兴趣的