| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 310 人关注过本帖
标题:debug了几天,求高人解决这段程序的问题。
只看楼主 加入收藏
Blackdavid
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-1-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
debug了几天,求高人解决这段程序的问题。
/*****************************************************************************\                                            
*                                                                             *
*  RusBlock_Rewrite.c                                                         *
*                                                                             *
*  Developed by Yagami_Tao                                                    *
*                                                                             *
\*****************************************************************************/


/*
 *ATTENTION!
 *MAIN PROBLEM CONTAINING WITH RUSBLOCK:
 *1,DeleteLine();
 *2,GameOver();
 *3,DropBlock();
 *4,DropBlockPreview();
 *5,Initial_G();
 *6,KeyAction();
 *7,Socor();
 */

/*
 * This Program is Written at 2011.4.30.
 * Have a good time.
 */

/*Some Statement and Defination and Include Before Running Program*/

#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <stdlib.h>
#include <graphics.h>
#ifdef __cplusplus
# define __CPPARGS ...
#else
# define __CPPARGS
#endif
#define BLOCKSIZE 20
#define VITUAL_COLOR RED
#define BK_COLOR YELLOW
#define MATRIX (block_window[i][j])
#define MATRIX_SUB (block_preview_window[i][j])
#define POINTER ((draw_window == "block_window") ? block_window : block_preview_window)
#define UP 0x4800/*chage shape*/
#define DOWN 0x5000/*drop block imediatilly*/
#define LEFT 0x4b00/*control block to left*/
#define RIGHT 0x4d00/*control block to right*/
#define SPACE 0x3920/*drop block faster*/
#define ENTER 0x1c0d/*pause game and resume game*/
#define ESC 0x011b/*exit game*/
#define BLOCK_J 3
#define BLOCK_I 1
#define WIDTH 12
#define HIGH 22
#define BLANK 50
int dropnow = 0;
int block_j,block_i;
int block_shape;
int block_color;
int block_preview_shape;
int block_preview_color;
struct window {
  int left;
  int top;
  int right;
  int bottom;
  int sign;
  int color;
};
struct window block_window[HIGH][WIDTH];
struct window block_preview_window[6][6];

int block_model[7][4][4] =
{
  {{0,0,0,1},
   {0,0,0,1},
   {0,0,0,1},
   {0,0,0,1}},
  {{0,1,1,1},
   {0,0,1,0},
   {0,0,0,0},
   {0,0,0,0}},
  {{0,0,1,1},
   {0,0,1,1},
   {0,0,0,0},
   {0,0,0,0}},
  {{0,0,1,1},
   {0,0,1,0},
   {0,0,1,0},
   {0,0,0,0}},
  {{0,0,1,1},
   {0,0,0,1},
   {0,0,0,1},
   {0,0,0,0}},
  {{0,0,0,1},
   {0,0,1,1},
   {0,0,1,0},
   {0,0,0,0}},
  {{0,0,1,0},
   {0,0,1,1},
   {0,0,0,1},
   {0,0,0,0}}
};
/*Function Defination Before Main Function*/
void delete_line(int line)
{
  int j;
  while(line > 0)
    {
      /*move line*/
      for(j = 1; j <WIDTH-1; j++)
    {
      block_window[line][j].sign = block_window[line-1][j].sign;
      block_window[line][j].color = block_window[line-1][j].color;
      if(line == 1)
        {
          block_window[line][j].sign = 0;
          block_window[line][j].color = BLANK;        
        }
    }
      /*draw line*/
      for(j = 1; j < WIDTH-1; j++)
    {
      if(block_window[line][j].sign || line == 1)
        {
          setfillstyle(SOLID_FILL, block_window[line][j].color);
          bar(block_window[line][j].left,    \
          block_window[line][j].top,        \
          block_window[line][j].right,        \
          block_window[line][j].bottom);
        }
    }
      /**/
      line--;
    }
}

int Full_Scan(void)
{
  int i,j;
  int full_line = 0;
  int full_sign = 1;
  /*scanning*/
  for(i = 1; i < HIGH - 1 && full_sign; i++)
    {
      for(j = 1; j < WIDTH - 1; j++)
    {
      if(!block_window[i][j].sign)
        full_sign = 0;
    }
      if(full_sign)
    {
      full_line = i;
      full_sign = 0;
    }
      else
    full_sign = 1;
    }
  return full_line;
}

void Draw_Artist(char *draw_window, int draw_shape, int draw_color, int draw_j, int draw_i)
{
  int i,j;
  setfillstyle(SOLID_FILL,draw_color);
  for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
      {
    if(block_model[draw_shape][i][j])
      {
        bar(POINTER[i+draw_i][j+draw_j].left,    \
        POINTER[i+draw_i][j+draw_j].top,    \
        POINTER[i+draw_i][j+draw_j].right,    \
        POINTER[i+draw_i][j+draw_j].bottom);
        POINTER[i+draw_i][j+draw_j].color = draw_color;
        if(draw_color == BLANK)
          POINTER[i+draw_i][j+draw_j].sign = 0;
        else
          POINTER[i+draw_i][j+draw_j].sign = 1;
      }
      }
}

void DrawBlock(int b_j, int b_i, int b_shape, int b_color)
{
  Draw_Artist("block_window",b_shape,BLANK,b_j,b_i);
  Draw_Artist("block_window",b_shape,b_color,b_j,b_i);
}

void DrawBlockPreview(int b_shape, int b_p_shape, int b_p_color)
{
  Draw_Artist("preview_window",b_shape,BLANK,1,1);
  Draw_Artist("preview_window",b_p_shape,b_p_color,1,1);
}

void Initial_G(int gmode,int gdriver)
{
  int errcode;
  registerbgidriver(EGAVGA_driver);
  initgraph(&gmode,&gdriver,"");
  errcode = graphresult();
  if(errcode != grOk)
    {
      printf("What The Fuck!You know what i mean??\n");
      printf("%s\n",grapherrormsg(errcode));
      while(!bioskey(1));
      exit(1);
    }
}

void Initial_Window(void)
{
  int i,j;
  setbkcolor(BK_COLOR);
  for(i = 0; i < HIGH; i++)
    for(j = 0; j < WIDTH; j++)
      {
    block_window[i][j].left = 10 + BLOCKSIZE * j ;
    block_window[i][j].top = 10 + BLOCKSIZE * i;
    block_window[i][j].right = 30 + BLOCKSIZE * j;
    block_window[i][j].bottom = 30 + BLOCKSIZE * i;
    block_window[i][j].sign = 0;
    block_window[i][j].color = VITUAL_COLOR;
      }
  for(i = 0; i < 6; i++)
    for(j = 0; j < 6; j++)
      {
    block_preview_window[i][j].left = 280 + BLOCKSIZE * j ;
    block_preview_window[i][j].top = 10 + BLOCKSIZE * i;
    block_preview_window[i][j].right = 300 + BLOCKSIZE * j;
    block_preview_window[i][j].bottom = 30 + BLOCKSIZE * i;
    block_preview_window[i][j].sign = 0;
    block_preview_window[i][j].color = VITUAL_COLOR;
      }
  for(i = 0, j = WIDTH; i < HIGH; i++)
    {
      block_window[i][0].sign = 1;
      block_window[i][j-1].sign = 1;
    }
  for(i = 0, j = 6; i < 6; i++)
    {
      block_preview_window[i][0].sign = 1;
      block_preview_window[i][j-1].sign = 1;
    }
  for(j = 0, i = HIGH; j < WIDTH; j++)
    {
      block_window[0][j].sign = 1;
      block_window[i-1][j].sign = 1;
    }
  for(j = 0, i = 6; j < 6; j++)
    {
      block_preview_window[0][j].sign = 1;
      block_preview_window[i-1][j].sign = 1;
    }
  /*draw window*/
  for(i = 0; i < HIGH; i++)
    for(j = 0; j < WIDTH; j++)
      {
    if(MATRIX.sign == 1)
      setfillstyle(SOLID_FILL,MATRIX.color);
    else
      setfillstyle(SOLID_FILL,BLANK);
    bar(MATRIX.left,MATRIX.top,MATRIX.right,MATRIX.bottom);
      }
  for(i = 0; i < 6; i++)
    for(j = 0; j <6; j++)
      {
    if(MATRIX_SUB.sign == 1)
      setfillstyle(SOLID_FILL,MATRIX_SUB.color);
    else
      setfillstyle(SOLID_FILL,BLANK);
    bar(MATRIX_SUB.left,MATRIX_SUB.top,MATRIX_SUB.right,MATRIX_SUB.bottom);
      }
}

void Random_B(int *shape, int *color)
{
  randomize();
  *shape = random(6);
  do {
    *color = rand();
  } while(*color == BLANK);
}

void Draw_NB(void)/*bug this function!*/
{
  block_shape = block_preview_shape;
  block_color = block_preview_color;
  DrawBlock(block_j, block_i, block_shape, block_color);
  Random_B(&block_preview_shape,&block_preview_color);
  DrawBlockPreview(block_shape,block_preview_shape,block_preview_color);
}

int dropable(void)
{
  int i,j;
  int dropable_value = 1;
  for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
      {
    if(block_model[block_shape][i][j])
      block_window[i+block_i][j+block_j].sign = 0;
      }
  for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
      {
    if(block_model[block_shape][i][j] && block_window[i+block_i+1][j+block_j].sign)
      dropable_value = 0;
      }
  for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
      {
    if(block_model[block_shape][i][j])
      block_window[i+block_i][j+block_j].sign = 1;
      }
  return dropable_value;
}

void DropBlock(int b_j, int b_i)
{
  int i,j;
  setfillstyle(SOLID_FILL,BLANK);/*destory virtual block*/
  for(i = 0; i < 4; i++)
    for(j = 0; j < 4; j++)
      {
    if(block_window[i+b_i][j+b_j].sign)
      {
        bar(block_window[i+b_i][j+b_j].left,\
        block_window[i+b_i][j+b_j].top,\
        block_window[i+b_i][j+b_j].right,\
        block_window[i+b_i][j+b_j].bottom);
        block_window[i+b_i][j+b_j].sign = 0;
        block_window[i+b_i][j+b_j].color = BLANK;
      }
      }
  Draw_Artist("block_window",block_shape,block_color,b_j,b_i + 1);
  block_i += 1;
}

#define TIMER 0x1c /*interrupt function*/
void interrupt (*oldhandler)(__CPPARGS);
void interrupt DropNow_If(__CPPARGS)
{
  static int counter = 0;
  if(++counter > 10)
    {
      dropnow = 1;
      counter = 0;
    }
  oldhandler();
}
void DropNow_Begin(void interrupt ( *handler)(__CPPARGS))
{
  oldhandler = getvect(TIMER);
  disable();
  setvect(TIMER,handler);
  enable();
}

/*Main Function*/

int main(void)
{
  /*some defination*/
  int key_value;
  /*initialize graphic layer*/
  Initial_G(VGA,VGAHI);
  Initial_Window();
  block_j = BLOCK_J;
  block_i = BLOCK_I;
  Random_B(&block_preview_shape, &block_preview_color);
  Draw_NB();
  DropNow_Begin(DropNow_If);
  /*
   *main circle in running
   *only exit when gameover
   */
  while(!gameover())
    {
      /*keyaction scanning and operation*/
      if(bioskey(1))
    {
      key_value = bioskey(0);
      KeyAction(key_value);
      if() /*full line?*/
        {
          /*delete line*/
          /*socor*/
        }
    }
      /*drop block in 1 sencond*/
      if(dropnow)
    {
      dropnow = 0;
      if(dropable()) /*dropable?*/
        {
          DropBlock(block_j,block_i);/*drop block*/
        }
      else
        {
          block_j = BLOCK_J;
          block_i = BLOCK_I;
          Draw_NB();/*draw a new block*/
        }
      while(Full_Scan()) /*full line?*/
        {
          delete_line(Full_Scan()); /*delete line*/
          /*socor increase*/
        }
    }
    }
  /*gameover and some operation*/
}

/*The End*/

2011-05-05 12:21
Blackdavid
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-1-5
收藏
得分:0 
有人吗
2011-05-05 12:24
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:7 
重写一遍需要一天吗?

我就是真命天子,顺我者生,逆我者死!
2011-05-05 17:26
fangdong65
Rank: 5Rank: 5
等 级:职业侠客
帖 子:73
专家分:301
注 册:2011-4-1
收藏
得分:7 
这代码太长啦,可以在wintc环境下调试,错误会比较明显,自己再修改。
2011-05-05 19:04
江南刹
Rank: 1
等 级:新手上路
帖 子:1
专家分:7
注 册:2011-5-5
收藏
得分:7 
长了点,没时间看!,不好意思哦!

热爱C编程!
2011-05-05 19:53
快速回复:debug了几天,求高人解决这段程序的问题。
数据加载中...
 
   



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

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