#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
(c语言)可以变色的俄罗斯方块
最新推荐文章于 2023-02-03 11:47:14 发布