(c语言)可以变色的俄罗斯方块

#include <stdio.h>
#include <Windows.h>
#include <time.h>
#include <conio.h>
#include <stdlib.h>
#pragma comment(lib, "Winmm.lib")
#define	hang 25
#define	lie	30

int map[hang+1][lie+1];
int judge[hang+1];
int flag = 1,speed=400, choose = 1,next_choose=1,score=0;
//出现一个方块的位置
struct  {
   
	int x;
	int y;
}m[4];
//下一个方块的形状
struct {
   
	int x;
	int y;
}next[4];
int wherex();
int wherey();
void gotoxy(int x,int y);
void init();
void graph();
void console();
void down();
int stop();
void remove();
void change();

int main()
{
   
	//界面输出
	init();
	//添加背景音乐
	//PlaySound(TEXT("The Truth That You Leave.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
	//初始化地图
	for (int i = 0; i <= hang; ++i)
	{
   
		judge[i] = 0;
		for (int j = 0; j <= lie; ++j)
		{
   
			map[i][j] = 0;
		}
	}
	//调用第一个随机选择图形函数
	graph();
	//俄罗斯方块开始
	while (flag == 1)
	{
   
		for (int i = 0; i < 4; i++)
		{
   
			m[i].x = next[i].x;
			m[i].y = next[i].y;
		}
		choose = next_choose;
		down();
	}
	//俄罗斯方块结束
	system("cls");
	printf("gameover!");
	system("pause");
	return	0;
}

int wherex()
{
   
	CONSOLE_SCREEN_BUFFER_INFO pBuffer;
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &pBuffer);
	return (pBuffer.dwCursorPosition.X + 1);
}

int wherey()
{
   
	CONSOLE_SCREEN_BUFFER_INFO pBuffer;
	GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &pBuffer);
	return (pBuffer.dwCursorPosition.Y + 1);
}

//移动光标函数
void gotoxy(int x, int y)//控制光标位置
{
   
	COORD c;
	c.X = x - 1;
	c.Y = y - 1;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

//初始化地图函数
void init()
{
   
	for (int i = 1; i <= hang; ++i)//输出两列
	{
   
		gotoxy(1,i);
		printf("*");
		gotoxy(lie,i);
		printf("*");
	}
	for (int i = 1; i <= lie; ++i)//输出两行
	{
   
		gotoxy(i,1);
		printf("*");
		gotoxy(i,hang);
		printf("*");
	}
	gotoxy(lie + lie / 2, 2);
	printf("下一个图形");
	for (int i = 3; i < 9; i++)
	{
   
		gotoxy(lie + lie / 2, i);
		printf("*");
		gotoxy(lie + lie / 2 + 10, i);
		printf("*");
	}
	for (int i = lie + lie / 2; i < lie + lie / 2 + 11; i++)
	{
   
		gotoxy(i, 3);
		printf("*");
		gotoxy(i, 9);
		printf("*");
	}
	gotoxy(lie + lie / 2, hang);
	printf("你的得分是:");
	return;
}

//生成随机图形
void graph()
{
   
	//初始化图形坐标,准备下落
	next[0].x = lie / 2 - 1;
	next[0].y = 2;
	srand((unsigned)time(NULL));
	next_choose = rand() % 7 + 1;
	switch (next_choose)
	{
   
	case 1:
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1);
		for (int i = 1; i < 4; i++)
		{
   
			next[i].x = next[i - 1].x;
			next[i].y = next[i - 1].y - 1;
		}
		break;
	case 2:
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
		next[1].x = next[0].x;
		next[1].y = next[0].y - 1;
		for (int i = 2; i < 4; i++)
		{
   
			next[i].x = next[i - 1].x+2;
			next[i].y = next[i - 1].y;
		}
		break;
	case 3:
		SetConsoleTextAttribute(GetStdHandle
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值