C语语言言实实现现俄俄罗罗斯斯方方块块
本文实例为大家分享了C语言俄罗斯方块的具体代码,供大家参考,具体内容如下
本代码 行环境是Windows下的VS2013
首先创建tetris.cpp
然后依次创建view.h以及view.cpp、model.h以及model.cpp。
代代码码如如下下::
view.h
#pragma once
#include
void ShowBackground();
void ShowBrick();
void ShowGame();
void On eft();
void OnRight();
void OnUp();
void OnDown();
view.cpp
#include
#include "view.h"
#include "model.h"
void On eft()
{//如果能够左移,则左移
if (IsCanMove(g_nRow, g_nCol - 1))
{
g_nCol--;
ShowGame();
}
}
void OnRight()
{
if (IsCanMove(g_nRow, g_nCol + 1))
{
g_nCol++;
ShowGame();
}
}
void OnUp()
{
if (IsCanRotate())
{
Rotate();
ShowGame();
}
}
void OnDown()
{
if (IsCanMove(g_nRow+1, g_nCol))
{
g_nRow++;
ShowGame();
}
else
{
//固定方块至背景,并且产生新方块
CombineBgBrick();
GetNewBrick();
//判断游戏是否结束,并给出对应提示
}
}
void ShowGame()
{
system("cls");
CombineBgBrick();
ShowBackground();
DetachBgBrick();
}
void ShowBrick()
{
for (size_t i = 0; i < 4; i++)
{
for (size_t j = 0; j < 4; j++)
{
if (g_chBrick[i][j] == 1)
{
printf("■");
}
}
printf("\r\n");
}
}
void ShowBackground()
{
for (size_t nRow = 0; nRow < GAME_ROWS; nRow++)
{
for (size_t nCol = 0; nCol < GAME_CO S; nCol++)
{
if (g_chBackground[nRow][nCol] == 1)
{
printf("■");
}
else
{
printf("□");
}
}
printf("\r\n");
}
}
model.cpp
#include
#include
#include