| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 359 人关注过本帖
标题:俄罗斯方块,想问下,红色部分为什么不成功,我利用的是坐标求解
只看楼主 加入收藏
cjyzwg
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2014-11-18
结帖率:100%
收藏
 问题点数:0 回复次数:0 
俄罗斯方块,想问下,红色部分为什么不成功,我利用的是坐标求解
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#define M 27
#define N 20
int a = 0, b = 5;
int id;
int score = 0, next, map[M][N] = { 0 }, gamespeed = 300;
int shape[28][6] = { { 0, -1, 0, -2, 1, 0 }, { 0, 1, 1, 0, 2, 0 }, { -1, 0, 0, 1, 0, 2 }, { 0, -1, -1, 0, -2, 0 },
{ 0, -1, 0, 1, -1, 0 }, { 0, 1, 1, 0, -1, 0 }, { 1, 0, 0, -1, 0, 1 }, { 1, 0, -1, 0, 0, -1 },
{ -1, 1, 0, 1, 1, 0 }, { 0, -1, 1, 0, 1, 1 }, { -1, 0, 0, -1, 1, -1 }, { -1, -1, -1, 0, 0, 1 },
{ -1, 0, 0, 1, 1, 1 }, { 0, 1, 1, -1, 1, 0 }, { -1, 0, 0, 1, 1, 1 }, { 0, 1, 1, -1, 1, 0 },
{ -1, 0, 0, -1, 0, -2 }, { -1, 0, -2, 0, 0, 1 }, { 0, 1, 0, 2, 1, 0 }, { 0, -1, 1, 0, 2, 0 },
{ 0, 1, 1, 0, 1, 1 }, { 0, -1, 1, 0, 1, -1 }, { -1, 0, 0, -1, -1, -1 }, { -1, 0, -1, 1, 0, 1 },
{ 0, 1, 0, 2, 0, 3 }, { 1, 0, 2, 0, 3, 0 }, { 0, -1, 0, -2, 0, -3 }, { -1, 0, -2, 0, -3, 0 }
};
void gotoxy(int x, int y)
{
    COORD c;
    c.X = x - 1;
    c.Y = y - 1;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void gameover(int h[M][N])
{
    int i, j, flag = 0;
    for (j = 1; j < 17; j++)
    if (h[1][j] != 0)
    {
        flag = 0;
        break;
    }
    if (flag == 1)
    {
        for (i = 1; i < 17; i++)
        {
            gotoxy(2, i + 1);
            for (j = 1; j < 11; j++)
                printf("□");
            gotoxy(7, 9);
            printf("game over!");
            gotoxy(1, 19);
            exit(0);
        }
    }
}
void block(int x, int y, int h[M][N])
{
    int i;
    h[x][y] = 3;
    for (i = 0; i < 6; i += 2)
        h[x + shape[id][i]][y + shape[id][i + 1]] = 3;
}
void clsc(int x, int y, int h[M][N])
{
    int i;
    h[x][y] = 0;
    for (i = 0; i < 6; i += 2)
        h[x + shape[id][i]][y + shape[id][i + 1]] = 0;
}
int judge(int x, int y, int h[M][N])
{
    int i;
    if (h[x][y] != 0)
        return 0;
    for (i = 0; i < 6; i += 2)
    if (h[x + shape[id][i]][y + shape[id][i + 1]] != 0)
        return 0;
    return 1;
}
void print(int h[M][N])
{
    int i, j;
    for (i = 0; i < 19; i++)
    {
        for (j = 0; j < 12; j++)
        {
            if (i == 18) h[i][j] = 2;
            if (j == 0 || j == 11)h[i][j] = 1;
                  if (h[i][j] == 0)
                printf("  ");
            if (h[i][j] == 1)
                printf("|");
            if (h[i][j] == 2)
                printf("--");
            if (h[i][j] == 3)
                printf("■");
            if (i == 1 && j == 11)printf("next:");
            if (i == 11 && j == 11)printf("score:%d", score);
            if (i == 14 && j == 11)printf("speed:%d", score / 100 + 1);
        }
        printf("\n");
    }
}


void ne(int h[M][N])        {
    int i, j;
    for (i = 0; i < 6; i += 2)
        h[6 + shape[id][i]][16 + shape[id][i + 1]] = 0;
    h[6][16] = 3;
    for (j = 0; j < 6; j += 2)
        h[6 + shape[next][j]][16 + shape[next][j + 1]] = 3;
}
void main()
{
    int i, j, id;
    int flag = 0;
    srand(time(NULL));
    id = rand() % 27;
    print(map);
    while (1)
    {
        next = rand() % 27;
        id = next;
        ne(map);
        while (!_kbhit())
        {
            if (judge(a + 1, b, map) == 1)
            {
                clsc(a, b, map);
                block(a++, b, map);
            }
            else
            {
                for (i = 1; i < 17; i++)
                for (j = 1; j < 11; j++)
                if (map[i][j] != 3)
                {
                    flag = 1;
                    break;
                }
                if (flag == 0)
                    map[i][j] = map[i - 1][j];
                print(map);
                a = 0;
                b = 5;
                score += 10;
                if (score % 100 == 0) gamespeed -= 50;
                Sleep(gamespeed);
            }
        }
        switch (_getch())
        {
        case'a':case'A':if (judge(a, b - 1, map) == 1)clsc(a, b, map), block(a, --b, map); break;
        case'd':case'D':if (judge(a, b + 1, map) == 1)clsc(a, b, map), block(a, ++b, map); break;
        case's':case'S':if (judge(a + 1, b, map) == 1)clsc(a, b, map), block(a++, b, map); break;
        case'w':case'W':if (id % 4 == 0 && id != 0)id -= 4, block(a, b, map); break;
        }
    }
}
搜索更多相关主题的帖子: 俄罗斯方块 include 
2014-12-24 11:03
快速回复:俄罗斯方块,想问下,红色部分为什么不成功,我利用的是坐标求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024631 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved