网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

sink函数c语言 c语言中的sin函数

C语言中,如何启动一个类?

C语言中没有类这个概念的。

网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了偃师免费建站欢迎大家使用!

不太明白启动是什么意思。

这个类中含有纯虚函数,属于抽象类,只能通过具体子类对象来完成相关操作,可以使用Rtpart指针。

求一个用C语言编写的小游戏代码

#include graphics.h

#include conio.h

#include time.h

/////////////////////////////////////////////

// 定义常量、枚举量、结构体、全局变量

/////////////////////////////////////////////

#define WIDTH 10 // 游戏区宽度

#define HEIGHT 22 // 游戏区高度

#define SIZE 20 // 每个游戏区单位的实际像素

// 定义操作类型

enum CMD

{

CMD_ROTATE, // 方块旋转

CMD_LEFT, CMD_RIGHT, CMD_DOWN, // 方块左、右、下移动

CMD_SINK, // 方块沉底

CMD_QUIT // 退出游戏

};

// 定义绘制方块的方法

enum DRAW

{

SHOW, // 显示方块

HIDE, // 隐藏方块

FIX // 固定方块

};

// 定义七种俄罗斯方块

struct BLOCK

{

WORD dir[4]; // 方块的四个旋转状态

COLORREF color; // 方块的颜色

} g_Blocks[7] = { {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, // I

{0x0660, 0x0660, 0x0660, 0x0660, BLUE}, // 口

{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, // L

{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, // 反L

{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, // Z

{0x0360, 0x4620, 0x0360, 0x4620, GREEN}, // 反Z

{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; // T

// 定义当前方块、下一个方块的信息

struct BLOCKINFO

{

byte id; // 方块 ID

char x, y; // 方块在游戏区中的坐标

byte dir:2; // 方向

} g_CurBlock, g_NextBlock;

// 定义游戏区

BYTE g_World[WIDTH][HEIGHT] = {0};

/////////////////////////////////////////////

// 函数声明

/////////////////////////////////////////////

void Init(); // 初始化游戏

void Quit(); // 退出游戏

void NewGame(); // 开始新游戏

void GameOver(); // 结束游戏

CMD GetCmd(); // 获取控制命令

void DispatchCmd(CMD _cmd); // 分发控制命令

void NewBlock(); // 生成新的方块

bool CheckBlock(BLOCKINFO _block); // 检测指定方块是否可以放下

void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 画方块

void OnRotate(); // 旋转方块

void OnLeft(); // 左移方块

void OnRight(); // 右移方块

void OnDown(); // 下移方块

void OnSink(); // 沉底方块

/////////////////////////////////////////////

// 函数定义

/////////////////////////////////////////////

// 主函数

void main()

{

Init();

CMD c;

while(true)

{

c = GetCmd();

DispatchCmd(c);

// 按退出时,显示对话框咨询用户是否退出

if (c == CMD_QUIT)

{

HWND wnd = GetHWnd();

if (MessageBox(wnd, _T("您要退出游戏吗?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)

Quit();

}

}

}

// 初始化游戏

void Init()

{

initgraph(640, 480);

srand((unsigned)time(NULL));

// 显示操作说明

setfont(14, 0, _T("宋体"));

outtextxy(20, 330, _T("操作说明"));

outtextxy(20, 350, _T("上:旋转"));

outtextxy(20, 370, _T("左:左移"));

outtextxy(20, 390, _T("右:右移"));

outtextxy(20, 410, _T("下:下移"));

outtextxy(20, 430, _T("空格:沉底"));

outtextxy(20, 450, _T("ESC:退出"));

// 设置坐标原点

setorigin(220, 20);

// 绘制游戏区边界

rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);

rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// 开始新游戏

NewGame();

}

// 退出游戏

void Quit()

{

closegraph();

exit(0);

}

// 开始新游戏

void NewGame()

{

// 清空游戏区

setfillstyle(BLACK);

bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);

ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一个方块

g_NextBlock.id = rand() % 7;

g_NextBlock.dir = rand() % 4;

g_NextBlock.x = WIDTH + 1;

g_NextBlock.y = HEIGHT - 1;

// 获取新方块

NewBlock();

}

// 结束游戏

void GameOver()

{

HWND wnd = GetHWnd();

if (MessageBox(wnd, _T("游戏结束。\n您想重新来一局吗?"), _T("游戏结束"), MB_YESNO | MB_ICONQUESTION) == IDYES)

NewGame();

else

Quit();

}

// 获取控制命令

DWORD m_oldtime;

CMD GetCmd()

{

// 获取控制值

while(true)

{

// 如果超时,自动下落一格

DWORD newtime = GetTickCount();

if (newtime - m_oldtime = 500)

{

m_oldtime = newtime;

return CMD_DOWN;

}

// 如果有按键,返回按键对应的功能

if (kbhit())

{

switch(getch())

{

case 'w':

case 'W': return CMD_ROTATE;

case 'a':

case 'A': return CMD_LEFT;

case 'd':

case 'D': return CMD_RIGHT;

case 's':

case 'S': return CMD_DOWN;

case 27: return CMD_QUIT;

case ' ': return CMD_SINK;

case 0:

case 0xE0:

switch(getch())

{

case 72: return CMD_ROTATE;

case 75: return CMD_LEFT;

case 77: return CMD_RIGHT;

case 80: return CMD_DOWN;

}

}

}

// 延时 (降低 CPU 占用率)

Sleep(20);

}

}

// 分发控制命令

void DispatchCmd(CMD _cmd)

{

switch(_cmd)

{

case CMD_ROTATE: OnRotate(); break;

case CMD_LEFT: OnLeft(); break;

case CMD_RIGHT: OnRight(); break;

case CMD_DOWN: OnDown(); break;

case CMD_SINK: OnSink(); break;

case CMD_QUIT: break;

}

}

// 生成新的方块

void NewBlock()

{

g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;

g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;

g_CurBlock.x = (WIDTH - 4) / 2;

g_CurBlock.y = HEIGHT + 2;

// 下移新方块直到有局部显示

WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];

while((c 0xF) == 0)

{

g_CurBlock.y--;

c = 4;

}

// 绘制新方块

DrawBlock(g_CurBlock);

// 绘制下一个方块

setfillstyle(BLACK);

bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);

DrawBlock(g_NextBlock);

// 设置计时器,用于判断自动下落

m_oldtime = GetTickCount();

}

// 画方块

void DrawBlock(BLOCKINFO _block, DRAW _draw)

{

WORD b = g_Blocks[_block.id].dir[_block.dir];

int x, y;

int color = BLACK;

switch(_draw)

{

case SHOW: color = g_Blocks[_block.id].color; break;

case HIDE: color = BLACK; break;

case FIX: color = g_Blocks[_block.id].color / 3; break;

}

setfillstyle(color);

for(int i=0; i16; i++)

{

if (b 0x8000)

{

x = _block.x + i % 4;

y = _block.y - i / 4;

if (y HEIGHT)

{

if (_draw != HIDE)

bar3d(x * SIZE + 2, (HEIGHT - y - 1) * SIZE + 2, (x + 1) * SIZE - 4, (HEIGHT - y) * SIZE - 4, 3, true);

else

bar(x * SIZE, (HEIGHT - y - 1) * SIZE, (x + 1) * SIZE - 1, (HEIGHT - y) * SIZE - 1);

}

}

b = 1;

}

}

// 检测指定方块是否可以放下

bool CheckBlock(BLOCKINFO _block)

{

WORD b = g_Blocks[_block.id].dir[_block.dir];

int x, y;

for(int i=0; i16; i++)

{

if (b 0x8000)

{

x = _block.x + i % 4;

y = _block.y - i / 4;

if ((x 0) || (x = WIDTH) || (y 0))

return false;

if ((y HEIGHT) (g_World[x][y]))

return false;

}

b = 1;

}

return true;

}

// 旋转方块

void OnRotate()

{

// 获取可以旋转的 x 偏移量

int dx;

BLOCKINFO tmp = g_CurBlock;

tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }

tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }

tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }

tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }

tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }

return;

rotate:

// 旋转

DrawBlock(g_CurBlock, HIDE);

g_CurBlock.dir++;

g_CurBlock.x += dx;

DrawBlock(g_CurBlock);

}

// 左移方块

void OnLeft()

{

BLOCKINFO tmp = g_CurBlock;

tmp.x--;

if (CheckBlock(tmp))

{

DrawBlock(g_CurBlock, HIDE);

g_CurBlock.x--;

DrawBlock(g_CurBlock);

}

}

// 右移方块

void OnRight()

{

BLOCKINFO tmp = g_CurBlock;

tmp.x++;

if (CheckBlock(tmp))

{

DrawBlock(g_CurBlock, HIDE);

g_CurBlock.x++;

DrawBlock(g_CurBlock);

}

}

// 下移方块

void OnDown()

{

BLOCKINFO tmp = g_CurBlock;

tmp.y--;

if (CheckBlock(tmp))

{

DrawBlock(g_CurBlock, HIDE);

g_CurBlock.y--;

DrawBlock(g_CurBlock);

}

else

OnSink(); // 不可下移时,执行“沉底方块”操作

}

// 沉底方块

void OnSink()

{

int i, x, y;

// 连续下移方块

DrawBlock(g_CurBlock, HIDE);

BLOCKINFO tmp = g_CurBlock;

tmp.y--;

while (CheckBlock(tmp))

{

g_CurBlock.y--;

tmp.y--;

}

DrawBlock(g_CurBlock, FIX);

// 固定方块在游戏区

WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];

for(i = 0; i 16; i++)

{

if (b 0x8000)

{

if (g_CurBlock.y - i / 4 = HEIGHT)

{ // 如果方块的固定位置超出高度,结束游戏

GameOver();

return;

}

else

g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;

}

b = 1;

}

// 检查是否需要消掉行,并标记

int row[4] = {0};

bool bRow = false;

for(y = g_CurBlock.y; y = max(g_CurBlock.y - 3, 0); y--)

{

i = 0;

for(x = 0; x WIDTH; x++)

if (g_World[x][y] == 1)

i++;

if (i == WIDTH)

{

bRow = true;

row[g_CurBlock.y - y] = 1;

setfillstyle(WHITE, DIAGCROSS2_FILL);

bar(0, (HEIGHT - y - 1) * SIZE + SIZE / 2 - 2, WIDTH * SIZE - 1, (HEIGHT - y - 1) * SIZE + SIZE / 2 + 2);

}

}

if (bRow)

{

// 延时 200 毫秒

Sleep(200);

// 擦掉刚才标记的行

IMAGE img;

for(i = 0; i 4; i++)

{

if (row[i])

{

for(y = g_CurBlock.y - i + 1; y HEIGHT; y++)

for(x = 0; x WIDTH; x++)

{

g_World[x][y - 1] = g_World[x][y];

g_World[x][y] = 0;

}

getimage(img, 0, 0, WIDTH * SIZE, (HEIGHT - (g_CurBlock.y - i + 1)) * SIZE);

putimage(0, SIZE, img);

}

}

}

// 产生新方块

NewBlock();

}

c语言在vc++下 编程的俄罗斯方源程序

以下代码来自 easyx 官网,已经测试过可以用,支持各版本 vc。需要安装 easyx 库才能编译。

项目直接建立控制台项目就好了。

////////////////////////////////////////////

// 程序名称:俄罗斯方块

// 编译环境:Visual C++ 6.0 / 2010,EasyX_v20131006(beta)

// 程序编写:krissi zhaoh1987@qq.com

// 更新记录:2010-12-18 zhaoh1987@qq.com 编写

//  2011-9-28 yw80@qq.com 修改了下落超时的逻辑

//  2013-10-7  zhaoh1987@qq.com 修改了绘制方法,将原来的立体效果修改为扁平效果

//

#include easyx.h

#include conio.h

#include time.h

/////////////////////////////////////////////

// 定义常量、枚举量、结构体、全局变量

/////////////////////////////////////////////

#define WIDTH 10 // 游戏区宽度

#define HEIGHT 22 // 游戏区高度

#define UNIT 20 // 每个游戏区单位的实际像素

// 定义操作类型

enum CMD

{

CMD_ROTATE, // 方块旋转

CMD_LEFT, CMD_RIGHT, CMD_DOWN, // 方块左、右、下移动

CMD_SINK, // 方块沉底

CMD_QUIT // 退出游戏

};

// 定义绘制方块的方法

enum DRAW

{

SHOW, // 显示方块

CLEAR, // 擦除方块

FIX // 固定方块

};

// 定义七种俄罗斯方块

struct BLOCK

{

WORD dir[4]; // 方块的四个旋转状态

COLORREF color; // 方块的颜色

} g_Blocks[7] = { {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, // I

{0x0660, 0x0660, 0x0660, 0x0660, BLUE}, // 口

{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, // L

{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, // 反L

{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, // Z

{0x0360, 0x4620, 0x0360, 0x4620, GREEN}, // 反Z

{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; // T

// 定义当前方块、下一个方块的信息

struct BLOCKINFO

{

byte id; // 方块 ID

char x, y; // 方块在游戏区中的坐标

byte dir:2; // 方向

} g_CurBlock, g_NextBlock;

// 定义游戏区

BYTE g_World[WIDTH][HEIGHT] = {0};

/////////////////////////////////////////////

// 函数声明

/////////////////////////////////////////////

void Init(); // 初始化游戏

void Quit(); // 退出游戏

void NewGame(); // 开始新游戏

void GameOver(); // 结束游戏

CMD  GetCmd(); // 获取控制命令

void DispatchCmd(CMD _cmd); // 分发控制命令

void NewBlock(); // 生成新的方块

bool CheckBlock(BLOCKINFO _block); // 检测指定方块是否可以放下

void DrawUnit(int x, int y, COLORREF c, DRAW _draw); // 画单元方块

void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 画方块

void OnRotate(); // 旋转方块

void OnLeft(); // 左移方块

void OnRight(); // 右移方块

void OnDown(); // 下移方块

void OnSink(); // 沉底方块

/////////////////////////////////////////////

// 函数定义

/////////////////////////////////////////////

// 主函数

void main()

{

Init();

CMD c;

while(true)

{

c = GetCmd();

DispatchCmd(c);

// 按退出时,显示对话框咨询用户是否退出

if (c == CMD_QUIT)

{

HWND wnd = GetHWnd();

if (MessageBox(wnd, _T("您要退出游戏吗?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)

Quit();

}

}

}

// 初始化游戏

void Init()

{

initgraph(640, 480);

srand((unsigned)time(NULL));

setbkmode(TRANSPARENT); // 设置图案填充的背景色为透明

// 显示操作说明

settextstyle(14, 0, _T("宋体"));

outtextxy(20, 330, _T("操作说明"));

outtextxy(20, 350, _T("上:旋转"));

outtextxy(20, 370, _T("左:左移"));

outtextxy(20, 390, _T("右:右移"));

outtextxy(20, 410, _T("下:下移"));

outtextxy(20, 430, _T("空格:沉底"));

outtextxy(20, 450, _T("ESC:退出"));

// 设置坐标原点

setorigin(220, 20);

// 绘制游戏区边界

rectangle(-1, -1, WIDTH * UNIT, HEIGHT * UNIT);

rectangle((WIDTH + 1) * UNIT - 1, -1, (WIDTH + 5) * UNIT, 4 * UNIT);

// 开始新游戏

NewGame();

}

// 退出游戏

void Quit()

{

closegraph();

exit(0);

}

// 开始新游戏

void NewGame()

{

// 清空游戏区

setfillcolor(BLACK);

solidrectangle(0, 0, WIDTH * UNIT - 1, HEIGHT * UNIT - 1);

ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一个方块

g_NextBlock.id = rand() % 7;

g_NextBlock.dir = rand() % 4;

g_NextBlock.x = WIDTH + 1;

g_NextBlock.y = HEIGHT - 1;

// 获取新方块

NewBlock();

}

// 结束游戏

void GameOver()

{

HWND wnd = GetHWnd();

if (MessageBox(wnd, _T("游戏结束。\n您想重新来一局吗?"), _T("游戏结束"), MB_YESNO | MB_ICONQUESTION) == IDYES)

NewGame();

else

Quit();

}

// 获取控制命令

DWORD m_oldtime;

CMD GetCmd()

{

// 获取控制值

while(true)

{

// 如果超时,自动下落一格

DWORD newtime = GetTickCount();

if (newtime - m_oldtime = 500)

{

m_oldtime = newtime;

return CMD_DOWN;

}

// 如果有按键,返回按键对应的功能

if (kbhit())

{

switch(getch())

{

case 'w':

case 'W': return CMD_ROTATE;

case 'a':

case 'A': return CMD_LEFT;

case 'd':

case 'D': return CMD_RIGHT;

case 's':

case 'S': return CMD_DOWN;

case 27: return CMD_QUIT;

case ' ': return CMD_SINK;

case 0:

case 0xE0:

switch(getch())

{

case 72: return CMD_ROTATE;

case 75: return CMD_LEFT;

case 77: return CMD_RIGHT;

case 80: return CMD_DOWN;

}

}

}

// 延时 (降低 CPU 占用率)

Sleep(20);

}

}

// 分发控制命令

void DispatchCmd(CMD _cmd)

{

switch(_cmd)

{

case CMD_ROTATE: OnRotate(); break;

case CMD_LEFT: OnLeft(); break;

case CMD_RIGHT: OnRight(); break;

case CMD_DOWN: OnDown(); break;

case CMD_SINK: OnSink(); break;

case CMD_QUIT: break;

}

}

// 生成新的方块

void NewBlock()

{

g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;

g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;

g_CurBlock.x = (WIDTH - 4) / 2;

g_CurBlock.y = HEIGHT + 2;

// 下移新方块直到有局部显示

WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];

while((c  0xF) == 0)

{

g_CurBlock.y--;

c = 4;

}

// 绘制新方块

DrawBlock(g_CurBlock);

// 绘制下一个方块

setfillcolor(BLACK);

solidrectangle((WIDTH + 1) * UNIT, 0, (WIDTH + 5) * UNIT - 1, 4 * UNIT - 1);

DrawBlock(g_NextBlock);

// 设置计时器,用于判断自动下落

m_oldtime = GetTickCount();

}

// 画单元方块

void DrawUnit(int x, int y, COLORREF c, DRAW _draw)

{

// 计算单元方块对应的屏幕坐标

int left = x * UNIT;

int top = (HEIGHT - y - 1) * UNIT;

int right = (x + 1) * UNIT - 1;

int bottom = (HEIGHT - y) * UNIT - 1;

// 画单元方块

switch(_draw)

{

case SHOW:

// 画普通方块

setlinecolor(0x006060);

roundrect(left + 1, top + 1, right - 1, bottom - 1, 5, 5);

setlinecolor(0x003030);

roundrect(left, top, right, bottom, 8, 8);

setfillcolor(c);

setlinecolor(LIGHTGRAY);

fillrectangle(left + 2, top + 2, right - 2, bottom - 2);

break;

case FIX:

// 画固定的方块

setfillcolor(RGB(GetRValue(c) * 2 / 3, GetGValue(c) * 2 / 3, GetBValue(c) * 2 / 3));

setlinecolor(DARKGRAY);

fillrectangle(left + 1, top + 1, right - 1, bottom - 1);

break;

case CLEAR:

// 擦除方块

setfillcolor(BLACK);

solidrectangle(x * UNIT, (HEIGHT - y - 1) * UNIT, (x + 1) * UNIT - 1, (HEIGHT - y) * UNIT - 1);

break;

}

}

// 画方块

void DrawBlock(BLOCKINFO _block, DRAW _draw)

{

WORD b = g_Blocks[_block.id].dir[_block.dir];

int x, y;

for(int i = 0; i  16; i++, b = 1)

if (b  0x8000)

{

x = _block.x + i % 4;

y = _block.y - i / 4;

if (y  HEIGHT)

DrawUnit(x, y, g_Blocks[_block.id].color, _draw);

}

}

// 检测指定方块是否可以放下

bool CheckBlock(BLOCKINFO _block)

{

WORD b = g_Blocks[_block.id].dir[_block.dir];

int x, y;

for(int i = 0; i  16; i++, b = 1)

if (b  0x8000)

{

x = _block.x + i % 4;

y = _block.y - i / 4;

if ((x  0) || (x = WIDTH) || (y  0))

return false;

if ((y  HEIGHT)  (g_World[x][y]))

return false;

}

return true;

}

// 旋转方块

void OnRotate()

{

// 获取可以旋转的 x 偏移量

int dx;

BLOCKINFO tmp = g_CurBlock;

tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }

tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }

tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }

tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }

tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }

return;

rotate:

// 旋转

DrawBlock(g_CurBlock, CLEAR);

g_CurBlock.dir++;

g_CurBlock.x += dx;

DrawBlock(g_CurBlock);

}

// 左移方块

void OnLeft()

{

BLOCKINFO tmp = g_CurBlock;

tmp.x--;

if (CheckBlock(tmp))

{

DrawBlock(g_CurBlock, CLEAR);

g_CurBlock.x--;

DrawBlock(g_CurBlock);

}

}

// 右移方块

void OnRight()

{

BLOCKINFO tmp = g_CurBlock;

tmp.x++;

if (CheckBlock(tmp))

{

DrawBlock(g_CurBlock, CLEAR);

g_CurBlock.x++;

DrawBlock(g_CurBlock);

}

}

// 下移方块

void OnDown()

{

BLOCKINFO tmp = g_CurBlock;

tmp.y--;

if (CheckBlock(tmp))

{

DrawBlock(g_CurBlock, CLEAR);

g_CurBlock.y--;

DrawBlock(g_CurBlock);

}

else

OnSink(); // 不可下移时,执行“沉底方块”操作

}

// 沉底方块

void OnSink()

{

int i, x, y;

// 连续下移方块

DrawBlock(g_CurBlock, CLEAR);

BLOCKINFO tmp = g_CurBlock;

tmp.y--;

while (CheckBlock(tmp))

{

g_CurBlock.y--;

tmp.y--;

}

DrawBlock(g_CurBlock, FIX);

// 固定方块在游戏区

WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];

for(i = 0; i  16; i++, b = 1)

if (b  0x8000)

{

if (g_CurBlock.y - i / 4 = HEIGHT)

{ // 如果方块的固定位置超出高度,结束游戏

GameOver();

return;

}

else

g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;

}

// 检查是否需要消掉行,并标记

BYTE remove = 0; // 低 4 位用来标记方块涉及的 4 行是否有消除行为

for(y = g_CurBlock.y; y = max(g_CurBlock.y - 3, 0); y--)

{

i = 0;

for(x = 0; x  WIDTH; x++)

if (g_World[x][y] == 1)

i++;

if (i == WIDTH)

{

remove |= (1  (g_CurBlock.y - y));

setfillcolor(LIGHTGREEN);

setlinecolor(LIGHTGREEN);

setfillstyle(BS_HATCHED, HS_DIAGCROSS);

fillrectangle(0, (HEIGHT - y - 1) * UNIT + UNIT / 2 - 5, WIDTH * UNIT - 1, (HEIGHT - y - 1) * UNIT + UNIT / 2 + 5);

setfillstyle(BS_SOLID);

}

}

if (remove) // 如果产生整行消除

{

// 延时 300 毫秒

Sleep(300);

// 擦掉刚才标记的行

IMAGE img;

for(i = 0; i  4; i++, remove = 1)

{

if (remove  1)

{

for(y = g_CurBlock.y - i + 1; y  HEIGHT; y++)

for(x = 0; x  WIDTH; x++)

{

g_World[x][y - 1] = g_World[x][y];

g_World[x][y] = 0;

}

getimage(img, 0, 0, WIDTH * UNIT, (HEIGHT - (g_CurBlock.y - i + 1)) * UNIT);

putimage(0, UNIT, img);

}

}

}

// 产生新方块

NewBlock();

}

数据结构 c语言编写顺序表合并

/*

**太多错误了,包括语法和逻辑上的错误都有。。。。

**我修改了一下,现在可以了。

**请注意,下面我说的字符串均指纯数字字符串,这个程序中是以字符方式来处理成数字的

**输入的时候,第一次输入的必须是顺序串(否则还要加一个排序算法),

**不是顺序串的话输入也没有问题,但是第一个字符串不会被排序

**第二个字符串不要求顺序。因为是一个个插入第一个字符串的对应位置

**而且这里输入的会被按照单个字符来录入

**(即数组元素只能为0~9中的任一个整数),

**如果想要以多位数(比如一个数组元素为67、345、2351等)来作为一个数组元素,

**则要修改判断输入的部分(我只是根据你的来改的,不知道是不是你想要的结果)。

*/

#includeiostream

//可去掉#includestdlib.h

using namespace std;

typedef int datatype;

#define maxsize 1024

typedef struct

{

datatype data[maxsize];

int last;

}sequenlist;

sequenlist *combine (sequenlist *scrptr,sequenlist *sinkptr);//添加函数声明

void main ()

{

sequenlist *Aptr,*Bptr,*Cptr;

Aptr = new sequenlist;//注意,要申请空间,初始化指针,下同

Bptr = new sequenlist;

Cptr = NULL;

//Cptr不用申请空间,因为后面有返回指针,这里初始为NULL,以防非法操作

char ch; //注意这里

int i=0;

//注意这里

do

{

ch = getchar();

Aptr-data[i]= ch - '0';//*Aptr.data[i]——Aptr-data[i]

i++;

}

while (ch!='\n' imaxsize);

Aptr-last = i-1; //添加这句

i = 0;

do

{

ch = getchar();

Bptr-data[i]= ch - '0';//*Aptr.data[i]——Aptr-data[i]

i++;

}

while (ch!='\n' imaxsize);

Bptr-last = i-1;

Cptr=combine(Aptr,Bptr);//注意这里

for(i=0;iCptr-last;i++)//注意

printf("%d",Cptr-data[i]);

delete Aptr;//前面new的,现在要delete,否则内存泄漏(虽然编译可通过)

delete Bptr;

Aptr = Bptr = Cptr = NULL;//这句可要可不要,只是一个习惯,即delete掉的指针要置空,以防非法操作。

}

void insertlist (sequenlist *lstptr,int x)//istpter——lstptr

{

int i=0,j=0;

//没有do....until ();应用while

while(ilstptr-last)

{

if (x=lstptr-data[i])

break;

else i++;

}

if (lstptr-last=maxsize)

{

printf ("overflow");

exit(0);//exit (overflow);overflow不是一个整数值

}

for (j=lstptr-last-1;j=i;j--)//注意,j=lstptr-last-1

{

lstptr-data[j+1]=lstptr-data[j];

// lstptr-data[i]=x;

// lstptr-last++;

//这两句要放for外面

}

lstptr-data[i]=x;

lstptr-last++;

}

sequenlist *combine (sequenlist *scrptr,sequenlist *sinkptr)

{

//int x;不需要

int j;

for (j=0;jsinkptr-last;j++)

insertlist (scrptr,sinkptr-data[j]);

return scrptr;//注意

}

打字不易,如满意,望采纳。


当前题目:sink函数c语言 c语言中的sin函数
链接URL:http://bjjierui.cn/article/dodiddd.html

其他资讯