龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > C/C++开发 >

打字游戏

时间:2009-12-22 15:42来源:未知 作者:admin 点击:
分享到:
#define MAXCOUNT 100 #define FALLSTEP 5 #define SCREENW 60 #define SCREENH 19 #define USERNAME "hmz" #include stdio.h #include stdlib.h #include dos.h#define FULLBLOCK 219 int Alphabit[26][5][5]={0,0,1,0,0, 0,1,0,1,0, 1,1,1,1,1, 1,0,0,0,1, 1
#define MAXCOUNT 100
  #define FALLSTEP 5
  #define SCREENW 60
  #define SCREENH 19
  #define USERNAME "hmz"
  #include <stdio.h>
  #include <stdlib.h>
  #include <dos.h> #define FULLBLOCK 219
  int Alphabit[26][5][5]={0,0,1,0,0,
                          0,1,0,1,0,
                          1,1,1,1,1,
                          1,0,0,0,1,
                          1,0,0,0,1,      /* A */                         1,1,1,1,0,
                          1,0,0,0,1,
                          1,1,1,1,0,
                          1,0,0,0,1,
                          1,1,1,1,1,      /* B */                         0,1,1,1,0,
                          1,0,0,0,1,
                          1,0,0,0,0,
                          1,0,0,0,1,
                          0,1,1,1,0,      /* C */                         1,1,1,1,0,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          1,0,0,0,1,
  
                           1,1,1,1,0,      /* D */                         1,1,1,1,1,
                          1,0,0,0,0,
                          1,1,1,1,0,
                          1,0,0,0,0,
                          1,1,1,1,1,      /* E */                         1,1,1,1,1,
                          1,0,0,0,0,
                          1,1,1,1,0,
                          1,0,0,0,0,
                          1,0,0,0,0,      /* F */                         0,1,1,1,0,
                          1,0,0,0,0,
                          1,0,1,1,0,
                          1,0,0,1,0,
                          0,1,1,1,0,      /* G */                         1,0,0,0,1,
                          1,0,0,0,1,
                          1,1,1,1,1,
  
                           1,0,0,0,1,
                          1,0,0,0,1,      /* H */                         0,1,1,1,0,
                          0,0,1,0,0,
                          0,0,1,0,0,
                          0,0,1,0,0,
                          0,1,1,1,0,      /* I */                         0,1,1,1,0,
                          0,0,1,0,0,
                          0,0,1,0,0,
                          1,0,1,0,0,
                          0,1,0,0,0,      /* J */                         1,0,0,1,0,
                          1,0,1,0,0,
                          1,1,0,0,0,
                          1,0,1,0,0,
                          1,0,0,1,0,      /* K */                         1,0,0,0,0,
                          1,0,0,0,0,
  
                           1,0,0,0,0,
                          1,0,0,0,0,
                          1,1,1,1,0,      /* L */                         0,1,0,1,0,
                          1,0,1,0,1,
                          1,0,1,0,1,
                          1,0,1,0,1,
                          1,0,1,0,1,      /* M */                         1,0,0,0,1,
                          1,1,0,0,1,
                          1,0,1,0,1,
                          1,0,0,1,1,
                          1,0,0,0,1,      /* N */                         0,1,1,1,0,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          0,1,1,1,0,      /* O */                         0,1,1,1,0,
  
                           1,0,0,0,1,
                          1,1,1,1,0,
                          1,0,0,0,0,
                          1,0,0,0,0,      /* P */                         0,1,1,1,0,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          0,1,1,1,0,
                          0,0,0,0,1,      /* Q */                         0,1,1,1,0,
                          1,0,0,0,1,
                          1,1,1,1,0,
                          1,0,1,0,0,
                          1,0,0,1,0,      /* R */                         0,0,1,1,0,
                          0,1,0,0,1,
                          0,0,1,0,0,
                          0,1,0,1,0,
                          0,0,1,1,0,      /* S */                         1,1,1,1,1,
  
                           0,0,1,0,0,
                          0,0,1,0,0,
                          0,0,1,0,0,
                          0,0,1,0,0,      /* T */                         1,0,0,0,1,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          0,1,1,1,0,      /* U */                         1,0,0,0,1,
                          1,0,0,0,1,
                          1,0,0,0,1,
                          0,1,0,1,0,
                          0,0,1,0,0,      /* V */                         1,0,0,0,1,
                          1,0,0,0,1,
                          1,0,1,0,1,
                          0,1,0,1,1,
                          1,0,0,0,1,      /* W */                         1,0,0,0,1,
  
                           0,1,0,1,0,
                          0,0,1,0,0,
                          0,1,0,1,0,
                          1,0,0,0,1,      /* X */                         1,0,0,0,1,
                          0,1,0,1,0,
                          0,0,1,0,0,
                          0,0,1,0,0,
                          0,0,1,0,0,      /* Y */                         1,1,1,1,1,
                          0,0,0,1,0,
                          0,0,1,0,0,
                          0,1,0,0,0,
                          1,1,1,1,1,      /* Z */}; void RecoverArea(int x,int y,int width,int height,int ScreenColor[80][24])
  {
          int i,j;
          for(i=x;i<x+width;i++)
          {
                  for(j=y;j<y+height;j++)
                  {
                          gotoxy(i,j);
                          textcolor(ScreenColor[i-1][j-1]);
  
                           putch(FULLBLOCK);
                  }
          }
  }
  void PrintFrame(int x,int y,int width,int height,char username[12],int score,int miss)
  {
          int i;
          textcolor(1);
          gotoxy(x,y);
          putch(201);
          for(i=2;i<=width-1;i++)
          {
                  putch(205);
          }
          putch(187);         for(i=2;i<=height-1;i++)
          {
                  gotoxy(x+width-1,y+i-1);
                  putch(186);
                  gotoxy(x,y+i-1);
                  putch(186);
          }
          gotoxy(x,y+height-1);
          putch(200);
          for(i=2;i<=width-1;i++)
          {
                  putch(205);
          }
          putch(188);
          gotoxy(x+2,y+2);
          cprintf("Player:");
          gotoxy(x+2,y+3);
          cprintf("%s",username);
          gotoxy(x+2,y+5);
          cprintf("Score:%d",score);
          gotoxy(x+2,y+8);
          cprintf("Miss:%d",miss); }
  void PrintValue(int x,int y,int score,int miss)
  {
          gotoxy(x+2,y+6);
          printf("%3d",score);
          gotoxy(x+2,y+9);
          printf("%3d",miss);
  } void PrintLine(int x,int y,int width,int height)
  {
          int i;
  
           gotoxy(x,y);
          textcolor(11);
          putch(201);
          for(i=2;i<=width-1;i++)
                  putch(205);
          putch(187);
          for(i=2;i<=height-1;i++)
          {
                  gotoxy(x+width-1,y+i-1);
                  putch(186);
                  gotoxy(x,y+i-1);
                  putch(186);
          }
          gotoxy(x,y+height-1);
          putch(200);
          for(i=2;i<=width-1;i++)
                  putch(205);
          putch(188);
  } void AlphabitColor(int index,int x,int y)
  {
          int i,j,c;
          if(index<0 index>25 x<1 x>76 y<1 y>20)
                  return;
          for(c=1;c<16;c++)
          {
                  textcolor(c);
                  for(i=0;i<5;i++)
                  {
                          for(j=0;j<5;j++)
                    {
                                          if(Alphabit[index][j][i])
                     {
                                                  gotoxy(x+i,y+j);
  
                                                   putch(FULLBLOCK);
                     }
                                          if(Alphabit[index][j][i])
                     {
                                                  gotoxy(x+i,y+j);
                                    putch(32);
                     }
                    }
                  }
                  delay(8000);
          }
  }
  void AlphabitRotate(int index,int x,int y)
  {
          int i,j,aa,bb,ScreenColor;
          if(index<0 index>25 x<1 x>76 y<1 y>20)
                  return;
          RecoverArea(x,y,5,5,ScreenColor);
          for(i=0;i<5;i++)
                  for(j=0;j<5;j++)
                  {
                          if(Alphabit[index][i][j])
                   {
                                  gotoxy(x+i,y+j);
                                  putch(FULLBLOCK);
  
                    }
                  }
          delay(6000);
          RecoverArea(x,y,5,5,ScreenColor);
          for(i=0;i<5;i++)
                  for(j=0;j<5;j++)
                  {
                          if(Alphabit[index][j][i])
                   {
                                  gotoxy(x+i,y+j);
                                  putch(FULLBLOCK);
                   }
                  }
          delay(6000);
          RecoverArea(x,y,5,5,ScreenColor);
          for(i=0;i<5;i++)
                  for(j=0;j<5;j++)
                  {
                          if(Alphabit[index][4-i][4-j])
                   {
                                  gotoxy(x+i,y+j);
                                  putch(FULLBLOCK);
                   }
                  }
          delay(6000);
          RecoverArea(x,y,5,5,ScreenColor);
          for(i=0;i<5;i++)
                  for(j=0;j<5;j++)
  
                   {
                          if(Alphabit[index][4-j][4-i])
                   {
                                  gotoxy(x+i,y+j);
                                  putch(FULLBLOCK);
                   }
                  }
          delay(6000);
          RecoverArea(x,y,5,5,ScreenColor);
  }
  void ShowFace(int x,int y,int a)
  {
          char s[3][9][15]={      "    _______    ",
                                  "   /          ",
                                  "    O   O    ",
                                  "      .      ",
                                  "    \___/    ",
                                  "   \_______/   ",
                                  "  ---------  ",
                                  "    GOOD!    ",
                                  "  ---------  ",
  
                                   "    _______    ",
                                  "   /          ",
                                  "    o   o    ",
                                  "      ^      ",
                                  "     ---     ",
                                  "   \_______/   ",
                                  "  ---------  ",
                                  "  HURRY!!   ",
                                  "  ---------  ",
                                  "    _______    ",
                                  "   /          ",
                                  "    _   _    ",
                                  "      .      ",
  
                                   "      /     ",
                                  "   \_______/   ",
                                  "  ---------  ",
                                  "    Oh no!   ",
                                  "  ---------  ",      };
          int i,j;
          if(a<0 a>=3)
                  return;
          textcolor(13);
          for(i=0;i<9;i++)
          {
                  gotoxy(x,y+i);
                  for(j=0;j<15;j++)
                          putch(s[a][i][j]);
          }
  }
  void RandomBackground(int number,int ScreenColor[80][24])
  {
          int i,j,k,c,x,y,g;
          int pic[5][5][8]={0,0,1,0,0,0,0,0,
                            0,1,0,1,1,1,1,0,
                            1,0,0,0,0,0,0,1,
                            0,1,1,1,1,1,0,1,
                            0,0,0,0,0,0,1,0,                           0,0,1,1,0,0,0,0,
  
                             0,1,0,0,1,1,1,0,
                            1,0,0,0,0,0,0,1,
                            0,1,1,1,1,1,1,0,
                            0,0,0,0,0,0,0,0,      /* No 2:a small '+' */                           0,0,0,0,0,0,0,0,
                            0,1,1,1,1,1,1,0,
                            1,0,0,0,0,0,0,1,
                            0,1,0,1,0,1,1,0,
                            0,0,1,0,1,0,0,0,  /* No 3 */                           0,0,0,1,1,0,0,0,
                            0,1,1,0,0,1,1,0,
                            1,0,0,0,0,0,1,0,
                            0,1,1,1,1,1,1,0,
                            0,0,0,0,0,0,0,0,  /* No 4 */                           0,0,0,0,0,1,0,0,
                            0,1,1,1,1,0,1,0,
                            1,0,0,0,0,0,0,1,
  
                             0,1,1,1,1,0,1,0,
                            0,0,0,0,0,1,0,0       /* No 5 */};
          for(i=1;i<80;i++)
                  for(j=0;j<25;j++)
                          ScreenColor[i][j]=0;
          for(i=0;i<number;i++)
          {
                  x=rand()%55+1;
                  y=rand()%18+1;
                  c=rand()%15+1;
                  g=rand()%5;
                  textcolor(c);
                  for(j=0;j<5;j++)
                          for(k=0;k<8;k++)
                                  if(pic[g][j][k]==1)
                    {
                                          gotoxy(k+x,j+y);
                                          ScreenColor[k+x-1][j+y-1]=c;
                                          putch(FULLBLOCK);
                    }
          }
  }
  void PrintAlphabitFade(int index,int x,int y)
  {   /* index 0-6 means alphabit a-f */
  
           int i,j,l;
          char c[7]={FULLBLOCK,'','-','','/','.',' '};
          if(index<0 index>25 x<1 x>76 y<1 y>20)
                  return;
          for(l=0;l<7;l++)
          {
                  for(i=0;i<5;i++)
                          for(j=0;j<5;j++)
                   {
                                  if(Alphabit[index][j][i])
                    {
                                          gotoxy(x+i,y+j);
                                          putch(c[l]);
                    }
                   }
                  delay(100000);
          }
  }
  void PrintAlphabit(int index,int x,int y,int p)
  {   /* index 0-6 means alphabit a-f */
          int i,j;
          if(index<0 index>25 x<1 x>76 y<1 y>20)
                  return;
          for(i=0;i<5;i++)
                  for(j=0;j<5;j++)
                          if(Alphabit[index][j][i])
                   {
                                  textcolor(p);
  
                                   gotoxy(x+i,y+j);
                                  putch(FULLBLOCK);
                   }
  }  
  void ShowLose(int x,int y,int q)
  {
          sound(622);
          delay(3000);
          nosound();
          gotoxy(x,y);
          putch(' ');
          ShowFace(65,14,2);
          AlphabitColor(q,x,y);
  } void ShowWin(int x,int y,int q)
  {
          sound(3000);
          delay(2000);
          nosound();
          sound(2400);
          delay(2000);
          nosound();
          gotoxy(x,y);
          putch(' ');
          PrintAlphabitFade(q,x,y);
          ShowFace(65,14,0);
  } main()
  {
          int x[MAXCOUNT],y[MAXCOUNT],c[MAXCOUNT],p[MAXCOUNT];
          char presskey;
          int count=0;
          int step=0,despeed=0;
          int i,j,t,a,score=0,miss=0;
          int ScreenColor[80][24];
          clrscr();
          RandomBackground(10,ScreenColor);
          PrintLine(1,1,80,24);
          randomize();
          while(1)
          {
                  step++;
                  PrintFrame(66,1,14,12,USERNAME,score,miss);
                  PrintValue(66,1,score,miss);
                  if(step==FALLSTEP)
                  {
  
                           step=0;
                          if(count<MAXCOUNT)
                   {
                                  x[count]=rand()%SCREENW+1;
                                  y[count]=2;
                                  c[count]=rand()%26;
                                  p[count]=rand()%15+1;
                                  count++;
                   }
                  }
                  for(i=0;i<count;i++)
                          RecoverArea(x[i],y[i],5,5,ScreenColor);
                  for(i=0;i<count;i++)
                  {
                          y[i]++;
                          if(y[i]>SCREENH)
                   {
                                  ShowLose(x[i],y[i],c[i]);
                                  for(j=i+1;j<count;j++)
  
                     {
                                          x[j-1]=x[j];
                                          y[j-1]=y[j];
                                          c[j-1]=c[j];
                                   score-=5;
                                   miss++;
                    }
                                  count--;
                    i--;
                   }
                  }
                  for(i=0;i<count;i++)
                          PrintAlphabit (c[i],x[i],y[i],p[i]);
                  for(t=0;t<100;t++)
                  {
                          if(bioskey(1))
                   {
                                  presskey=bioskey(0);
                                  for(i=0;i<count;i++)
  
                     {
                                   
精彩图集

赞助商链接