搭建VC2010 开发环境,创建《C语言实现俄罗斯方块游戏》教程

Posted perseverance52

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建VC2010 开发环境,创建《C语言实现俄罗斯方块游戏》教程相关的知识,希望对你有一定的参考价值。

搭建VC2010 开发环境,创建《C语言实现俄罗斯方块游戏》教程


搭建VC2010 开发环境

安装 Visual C++ 2010 Express

先安装VC2010中文版,再接着安装SP1补丁包。

  • VC2010 中文版
下载地址:https://pan.baidu.com/s/1IBaNrOtdx3b7wz7nq7BeEA
提取码:7cou
  • SP1 补丁包
下载地址:https://pan.baidu.com/s/1JK-InWFnURSmNlucyoy3hQ

提取码:d5ei

安装EasyX

C语言实现俄罗斯方块

  • 这位坛友的《C语言实现俄罗斯方块》游戏代码
    ==注意: 在代码前面需要添加取消Unicode宏定义和添加tchar.h头文件,完整代码如下:
#undef UNICODE
#undef _UNICODE
#include <tchar.h>
#include<graphics.h>
#include<stdio.h>
#include<time.h>
#include<conio.h>	//kbhit()
 
int score = 0;	//总分
int rank = 0;	//等级
 
#define BLOCK_COUNT 5
#define BLOCK_WIDTH 5
#define BLOCK_HEIGHT 5
 
#define UNIT_SIZE 20	//小方块宽度
 
#define START_X 130		//方块降落框,方块降落起始位置
#define START_Y 30
 
#define KEY_UP 87		//用户操作
#define KEY_LEFT 65
#define KEY_RIGHT 68
#define KEY_DOWN 83
#define KEY_SPACE 32
 
#define MinX 30		//游戏左上角位置
#define MinY 30
int speed = 500;	//方块降落速度
 
 
int NextIndex = -1;		//下一个方块
int BlockIndex = -1;		//当前方块
 
typedef enum 		//方块朝向
	BLOCK_UP,
	BLOCK_RIGHT,
	BLOCK_LEFT,
	BLOCK_DOWN
block_dir_t;
 
typedef enum 		//方块移动方向
	MOVE_DOWN,
	MOVE_LEFT,
	MOVE_RIGHT
move_dir_t;
 
//方块颜色
int color[BLOCK_COUNT] = 
	GREEN,
	CYAN,
	MAGENTA,
	YELLOW,
	BROWN
;
int visit[30][15];	//访问数组visit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0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0 ,
	 0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0 ,
	 0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0 ,
	 0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0 ,
;
 
/***************************
 * 功能:欢迎页面
 * 输入:
 *		无
 * 返回:
 *		无
 **************************/
void welcome() 
	//1.初始化画布
	initgraph(550, 660);
	system("pause");
	//2.设置窗口标题
	HWND window = GetHWnd();//获得窗口,获得当前窗口
	SetWindowText(window, _T("俄罗斯方块  小明来喽"));	//设置标题
 
	//3.设置游戏初始页面
	setfont(40, 0, _T("微软雅黑"));		//设置文本的字体样式(高,宽(0表示自适应),字体)
	setcolor(WHITE);	// 设置颜色
	outtextxy(205, 200, _T("俄罗斯方法"));
 
	setfont(20, 0, _T("楷体"));
	setcolor(WHITE);	// 设置颜色
	outtextxy(175, 300, _T("编程,从俄罗斯方块开始"));
 
	Sleep(3000);

 
/***************************
 * 功能:初始化游戏场景
 * 输入:
 *		无
 * 返回:
 *		无
 **************************/
void initGameSceen() 
	char str[16];	//存放分数
	//1.清屏
	cleardevice();
	//2.画场景
	rectangle(27, 27, 336, 635);	//方块降落框外框
	rectangle(29, 29, 334, 633);	//方块降落框内框
	rectangle(370, 50, 515, 195);	//方块提示框
 
	setfont(24, 0, _T("楷体"));		//写“下一个”
	setcolor(LIGHTGRAY);	//灰色
	outtextxy(405, 215, _T("下一个:"));
 
	setcolor(RED);					//写分数
	outtextxy(405, 280, _T("分数:"));
 
	//按指定格式,将score写入str
	sprintf_s(str, 16, "%d", score);
	//这里设置字符集为多字符,保证outtextxy可以写出变量str
	outtextxy(415, 310, str);
 
	outtextxy(405, 375, _T("等级:"));	//等级
 
	//按指定格式,将rank写入str
	sprintf_s(str, 16, "%d", rank);
	//这里设置字符集为多字符,保证outtextxy可以写出变量str
	outtextxy(415, 405, str);
 
	setcolor(LIGHTBLUE);	//操作说明
	outtextxy(390, 475, "操作说明:");
	outtextxy(390, 500, "↑: 旋转");
	outtextxy(390, 525, "↓: 下降");
	outtextxy(390, 550, "←: 左移");
	outtextxy(390, 575, "→: 右移");
	outtextxy(390, 600, "空格: 暂停");

 
/*****************************************
 * 功能:清空方块提示框里的方块
 * 输入:
 *		无
 * 返回:
 *		无
 ****************************************/
void clearBlock() 
	setcolor(BLACK);
	setfont(23, 0, "楷体");
	VC++2010中文版如何编写并运行C语言程序?

设置 VC++ 命令行消息语言

使用vc将C的代码封装成为DLL

第一个C语言项目开发------俄罗斯方块的设计与实现

用c语言编写俄罗斯方块程序 求详解

我的全栈之路-C语言基础之C语言概述与开发环境搭建