求C语言小程序源代码,300行左右40
发布网友
发布时间:2023-10-21 19:00
我来回答
共4个回答
热心网友
时间:2024-12-12 00:07
黑白棋游戏
#include "graphics.h" /*图形系统头文件*/
#define LEFT 0x4b00 /*光标左键值*/
#define RIGHT 0x4d00 /*光标右键值*/
#define DOWN 0x5000 /*光标下键值*/
#define UP 0x4800 /*光标上键值*/
#define ESC 0x011b /* ESC键值*/
#define ENTER 0x1c0d /* 回车键值*/
int a[8][8]={0},key,score1,score2;/*具体分数以及按键与存放棋子的变量*/
char playone[3],playtwo[3];/*两个人的得分转换成字符串输出*/
void playtoplay(void);/*人人对战函数*/
void DrawQp(void);/*画棋盘函数*/
void SetPlayColor(int x);/*设置棋子第一次的颜色*/
void MoveColor(int x,int y);/*恢复原来棋盘状态*/
int QpChange(int x,int y,int z);/*判断棋盘的变化*/
void DoScore(void);/*处理分数*/
void PrintScore(int n);/*输出成绩*/
void playWin(void);/*输出胜利者信息*/
/******主函数*********/
void main(void)
{
int gd=DETECT,gr;
initgraph(&gd,&gr,"c:\\tc"); /*初始化图形系统*/
DrawQp();/*画棋盘*/
playtoplay();/*人人对战*/
getch();
closegraph();/*关闭图形系统*/
}
void DrawQp()/*画棋盘*/
{
int i,j;
score1=score2=0;/*棋手一开始得分都为0*/
setbkcolor(BLUE);
for(i=100;i<=420;i+=40)
{
line(100,i,420,i);/*画水平线*/
line(i,100,i,420); /*画垂直线*/
}
setcolor(0);/*取消圆周围的一圈东西*/
setfillstyle(SOLID_FILL,15);/*白色实体填充模式*/
fillellipse(500,200,15,15); /*在显示得分的位置画棋*/
setfillstyle(SOLID_FILL,8); /*黑色实体填充模式*/
fillellipse(500,300,15,15);
a[3][3]=a[4][4]=1;/*初始两个黑棋*/
a[3][4]=a[4][3]=2;/*初始两个白棋*/
setfillstyle(SOLID_FILL,WHITE);
fillellipse(120+3*40,120+3*40,15,15);
fillellipse(120+4*40,120+4*40,15,15);
setfillstyle(SOLID_FILL,8);
fillellipse(120+3*40,120+4*40,15,15);
fillellipse(120+4*40,120+3*40,15,15);
score1=score2=2; /*有棋后改变分数*/
DoScore();/*输出开始分数*/
}
void playtoplay()/*人人对战*/
{
int x,y,t=1,i,j,cc=0;
while(1)/*换棋手走棋*/
{
x=120,y=80;/*每次棋子一开始出来的坐标,x为行坐标,y为列坐标*/
while(1) /*具体一个棋手走棋的过程*/
{
PrintScore(1);/*输出棋手1的成绩*/
PrintScore(2);/*输出棋手2的成绩*/
SetPlayColor(t);/*t变量是用来判断棋手所执棋子的颜色*/
fillellipse(x,y,15,15);
key=bioskey(0);/*接收按键*/
if(key==ESC)/*跳出游戏*/
break;
else
if(key==ENTER)/*如果按键确定就可以跳出循环*/
{
if(y!=80&&a[(x-120)/40][(y-120)/40]!=1
&&a[(x-120)/40][(y-120)/40]!=2)/*如果落子位置没有棋子*/
{
if(t%2==1)/*如果是棋手1移动*/
a[(x-120)/40][(y-120)/40]=1;
else/*否则棋手2移动*/
a[(x-120)/40][(y-120)/40]=2;
if(!QpChange(x,y,t))/*落子后判断棋盘的变化*/
{
a[(x-120)/40][(y-120)/40]=0;/*恢复空格状态*/
cc++;/*开始统计尝试次数*/
if(cc>=64-score1-score2) /*如果尝试超过空格数则停步*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
break;
}
else
continue;/*如果按键无效*/
}
DoScore();/*分数的改变*/
break;/*棋盘变化了,则轮对方走棋*/
}
else/*已经有棋子就继续按键*/
continue;
}
else /*四个方向按键的判断*/
if(key==LEFT&&x>120)/*左方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x-=40;
fillellipse(x,y,15,15);
}
else
if(key==RIGHT&&x<400&&y>80)/*右方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x+=40;
fillellipse(x,y,15,15);
}
else
if(key==UP&&y>120)/*上方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y-=40;
fillellipse(x,y,15,15);
}
else
if(key==DOWN&&y<400)/*下方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y+=40;
fillellipse(x,y,15,15);
}
}
if(key==ESC)/*结束游戏*/
break;
if((score1+score2)==64||score1==0||score2==0)/*格子已经占满或一方棋子为0判断胜负*/
{
playWin();/*输出最后结果*/
break;
}
t=t%2+1; /*一方走后,改变棋子颜色即轮对方走*/
cc=0; /*计数值恢复为0*/
} /*endwhile*/
}
void SetPlayColor(int t)/*设置棋子颜色*/
{
if(t%2==1)
setfillstyle(SOLID_FILL,15);/*白色*/
else
setfillstyle(SOLID_FILL,8);/*灰色*/
}
void MoveColor(int x,int y)/*走了一步后恢复原来格子的状态*/
{
if(y<100)/*如果是从起点出发就恢复蓝色*/
setfillstyle(SOLID_FILL,BLUE);
else/*其他情况如果是1就恢复白色棋子,2恢复黑色棋子,或恢复蓝色棋盘*/
switch(a[(x-120)/40][(y-120)/40])
{
case 1:
setfillstyle(SOLID_FILL,15);break; /*白色*/
case 2:
setfillstyle(SOLID_FILL,8);break; /*黑色*/
default:
setfillstyle(SOLID_FILL,BLUE); /*蓝色*/
}
}
int QpChange(int x,int y,int t)/*判断棋盘的变化*/
{
int i,j,k,kk,ii,jj,yes;
yes=0;
i=(x-120)/40; /*计算数组元素的行下标*/
j=(y-120)/40; /*计算数组元素的列下标*/
SetPlayColor(t);/*设置棋子变化的颜色*/
/*开始往8个方向判断变化*/
if(j<6)/*往右边*/
{
for(k=j+1;k<8;k++)
if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格结束*/
break;
if(a[i][k]!=0&&k<8)
{
for(kk=j+1;kk<k&&k<8;kk++)/*判断右边*/
{
a[i][kk]=a[i][j]; /*改变棋子颜色*/
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j+1) /*条件成立则有棋子改变过颜色*/
yes=1;
}
}
if(j>1)/*判断左边*/
{
for(k=j-1;k>=0;k--)
if(a[i][k]==a[i][j]||!a[i][k])
break;
if(a[i][k]!=0&&k>=0)
{
for(kk=j-1;kk>k&&k>=0;kk--)
{
a[i][kk]=a[i][j];
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j-1)
yes=1;
}
}
if(i<6)/*判断下边*/
{
for(k=i+1;k<8;k++)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k<8)
{
for(kk=i+1;kk<k&&k<8;kk++)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i+1)
yes=1;
}
}
if(i>1)/*判断上边*/
{
for(k=i-1;k>=0;k--)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k>=0)
{
for(kk=i-1;kk>k&&k>=0;kk--)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i-1)
yes=1;
}
}
if(i>1&&j<6)/*右上*/
{
for(k=i-1,kk=j+1;k>=0&&kk<8;k--,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]&&k>=0&&kk<8)
{
for(ii=i-1,jj=j+1;ii>k&&k>=0;ii--,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j>1)/*左下*/
{
for(k=i+1,kk=j-1;k<8&&kk>=0;k++,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k<8&&kk>=0)
{
for(ii=i+1,jj=j-1;ii<k&&k<8;ii++,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
if(i>1&&j>1)/*左上*/
{
for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k>=0&&kk>=0)
{
for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j<6)/* 右下*/
{
for(k=i+1,kk=j+1;kk<8&&kk<8;k++,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&kk<8&&k<8)
{
for(ii=i+1,jj=j+1;ii<k&&k<8;ii++,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
return yes;/*返回是否改变过棋子颜色的标记*/
}
void DoScore()/*处理分数*/
{
int i,j;
score1=score2=0;/*重新开始计分数*/
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(a[i][j]==1)/*分别统计两个人的分数*/
score1++;
else
if(a[i][j]==2)
score2++;
}
void PrintScore(int playnum)/*输出成绩*/
{
if(playnum==1)/*清除以前的成绩*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(550,100,640,400);
}
setcolor(RED);
settextstyle(0,0,4);/*设置文本输出样式*/
if(playnum==1)/*判断输出哪个棋手的分,在不同的位置输出*/
{
sprintf(playone,"%d",score1);
outtextxy(550,200,playone);
}
else
{
sprintf(playtwo,"%d",score2);
outtextxy(550,300,playtwo);
}
setcolor(0);
}
void playWin()/*输出最后的胜利者结果*/
{
settextstyle(0,0,4);
setcolor(12);
if(score2>score1)/*开始判断最后的结果*/
outtextxy(100,50,"black win!");
else
if(score2<score1)
outtextxy(100,50,"white win!");
else
outtextxy(60,50,"you all win!");
}
五子棋游戏
/*五子棋*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920
#define BILI 20
#define JZ 4
#define JS 3
#define N 19
int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;
void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();
void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戏操作规则:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向键移动棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move Piece");
gotoxy(15,10);
printf("2、按空格确定落棋子");
gotoxy(15,12);
printf("2. Press Space to place the Piece");
gotoxy(15,14);
printf("3、禁止在棋盘外按空格");
gotoxy(15,16);
printf("3. DO NOT press Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戏规则(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}
void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}
void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :
if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :
if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :
if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :
if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;
case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重笔划字体, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重笔划字体, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}
void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}
void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}
int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左数*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右数*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*垂直向上数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下数*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向左上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方数*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向右上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方数*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}
void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}
热心网友
时间:2024-12-12 00:07
贪吃蛇游戏
#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*得分*/
int gamespeed=50000;/*游戏速度自己调整*/
struct Food
{
int x;/*食物的横坐标*/
int y;/*食物的纵坐标*/
int yes;/*判断是否要出现食物的变量*/
}food;/*食物的结构体*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的节数*/
int direction;/*蛇移动方向*/
int life;/* 蛇的生命,0活着,1死亡*/
}snake;
void Init(void);/*图形驱动*/
void Close(void);/*图形结束*/
void DrawK(void);/*开始画面*/
void GameOver(void);/*结束游戏*/
void GamePlay(void);/*玩游戏具体过程*/
void PrScore(void);/*输出成绩*/
/*主函数*/
void main(void)
{
Init();/*图形驱动*/
DrawK();/*开始画面*/
GamePlay();/*玩游戏具体过程*/
Close();/*图形结束*/
}
/*图形驱动*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*设置线型*/
for(i=50;i<=600;i+=10)/*画围墙*/
{
rectangle(i,40,i+10,49); /*上边*/
rectangle(i,451,i+10,460);/*下边*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /*左边*/
rectangle(601,i,610,i+10);/*右边*/
}
}
/*玩游戏具体过程*/
void GamePlay(void)
{
randomize();/*随机数发生器*/
food.yes=1;/*1表示需要出现新食物,0表示已经存在食物*/
snake.life=0;/*活着*/
snake.direction=1;/*方向往右*/
snake.x[0]=100;snake.y[0]=100;/*蛇头*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*节数*/
PrScore();/*输出得分*/
while(1)/*可以重复玩游戏,压ESC键结束*/
{
while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/
{
if(food.yes==1)/*需要出现新食物*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*画面上有食物了*/
}
if(food.yes==0)/*画面上有食物了就要显示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*显示失败*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到墙壁*/
{
GameOver();/*本次游戏结束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/
{
setcolor(0);/*把画面上的食物东西去掉*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/
snake.node++;/*蛇的身体长一节*/
food.yes=1;/*画面上需要出现新的食物*/
score+=10;
PrScore();/*输出新得分*/
}
setcolor(4);/*画出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一节*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循环*/
break;
key=bioskey(0);/*接收按键*/
if(key==ESC)/*按ESC键退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判断是否往相反的方向移动*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戏结束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*输出成绩*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*图形结束*/
void Close(void)
{
getch();
closegraph();
}
热心网友
时间:2024-12-12 00:08
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
int a=0,sheng=20,gong=10,fang=10,b,shengm=20,yao=0,smsxy=0,gong1,fang1;
int guais,guaig,qian=0,defen=0,c,fangc=1,sheng1;
int sjq,sjsm;
srand(time(0));
cout<<"勇者的成长"<<endl;
cout<<"此游戏中禁止输入字符,否则会出错,后果自负!"<<endl;
cout<<"按任意键开始游戏"<<endl;
system("pause");
while(a==0) {
cout<<"1.勇者商店"<<endl;
cout<<"2.讨伐魔物"<<endl;
cout<<"3.角色资料"<<endl;
cout<<"4.背包"<<endl;
cout<<"请选择..."<<endl;
cin>>b;
if(b==1) {
cout<<"1.装备"<<endl;
cout<<"2.药品"<<endl;
cout<<"其它.退出"<<endl;
cout<<endl;
cin>>b;
if(b==1) {
while(b==1&&b==2&&b==3) {
cout<<"1.武器"<<endl;
cout<<"2.盾牌"<<endl;
cout<<"3.盔甲"<<endl;
cout<<"其它.退出"<<endl;
cin>>b;
if(b==1) {
cout<<"1.骑士长剑(+10) 价值:20"<<endl;
cout<<"2.石中剑(+20) 价值40"<<endl;
cout<<"3.魔王的右手(+90) 价值150"<<endl;
cout<<"其它.退出"<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
cin>>b;
if(b==1&&qian>=20) {
gong=20;
qian-=20;
cout<<"自身攻击"<<gong<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
}
if(b==2&&qian>=40) {
gong=30;
qian-=40;
cout<<"自身攻击"<<gong<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
}
if(b==3&&qian>=150) {
gong=100;
qian-=150;
cout<<"自身攻击"<<gong<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
}
}
if(b==2) {
cout<<"1.皇家盾牌(+10) 价值:20"<<endl;
cout<<"2.永恒堡垒(+20) 价值40"<<endl;
cout<<"3.魔王的左手(+90) 价值150"<<endl;
cout<<"其它.退出"<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
cin>>b;
if(b==1&&qian>=20) {
fang=20;
qian-=20;
cout<<"自身防御"<<fang<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==1) cout<<"钱不够!"<<endl;
if(b==2&&qian>=40) {
fang=30;
qian-=40;
cout<<"自身防御"<<fang<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==2) cout<<"钱不够!"<<endl;
if(b==3&&qian>=150) {
fang=100;
qian-=150;
cout<<"自身防御"<<fang<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==3) cout<<"钱不够!"<<endl;
}
if(b==3) {
cout<<"1.战争盔甲(+10) 价值:20"<<endl;
cout<<"2.不灭龙甲(+20) 价值40"<<endl;
cout<<"3.魔王的精华(+90) 价值150"<<endl;
cout<<"其它.退出"<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
cin>>b;
if(b==1&&qian>=20) {
shengm=20;
qian-=20;
cout<<"自身生命"<<shengm<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==1) cout<<"钱不够!"<<endl;
if(b==2&&qian>=40) {
shengm=30;
qian-=40;
cout<<"自身生命"<<shengm<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==2) cout<<"钱不够!"<<endl;
if(b==3&&qian>=150) {
shengm=100;
qian-=150;
cout<<"自身生命"<<shengm<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==3) cout<<"钱不够!"<<endl;
}
}
}
if(b==2) {
cout<<"1.快速回复(花费1)"<<endl;
cout<<"2.恢复药剂*5(花费5)"<<endl;
cout<<"3.生命上限药剂(随机)(花费15)"<<endl;
cout<<"其它.退出"<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
cin>>b;
if(b==1&&qian>=1) {
sheng=shengm;
qian--;
cout<<"自身生命"<<sheng<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==1) cout<<"钱不够!"<<endl;
if(b==2&&qian>=5) {
yao+=5;
qian-=5;
cout<<"恢复药剂数量剩余"<<yao<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==2)cout<<"钱不够!"<<endl;
if(b==3&&qian>=15) {
smsxy++;
qian-=15;
cout<<"生命上限药剂剩余"<<smsxy<<endl;
cout<<"当前拥有"<<qian<<"个金币"<<endl;
} else if(b==3)cout<<"钱不够!"<<endl;
}
} else if(b==2) {
cout<<"1.小怪"<<endl;
cout<<"2.精英怪"<<endl;
cout<<"3.大魔王"<<endl;
cout<<"其它.退出"<<endl;
cin>>b;
if(b==1) {
fangc=1;
guais=rand()%20+10;
c=5;
cout<<"怪物生命("<<guais<<"/"<<guais<<")"<<endl;
cout<<"自身生命("<<sheng<<'/'<<shengm<<")"<<endl;
while(guais>0&&sheng>0) {
guaig=rand()%2+5;
cout<<"1.攻击"<<endl;
cout<<"2.防御(次数"<<c<<")"<<endl;
cout<<"3.回复(闪避+使用药品回复)"<<endl;
cin>>b;
if(b==1) {
fangc=1;
printf("你与怪兽进行了激烈的打斗");
for(int i=1; i<=6; i++) {
printf(".");
Sleep(250);
}
gong1=guais;
guais-=gong;
if(guais<=0) {
guais=0;
cout<<"\n怪物生命-"<<gong1<<"=0"<<endl;
} else {
sheng=sheng-guaig;
cout<<"\n怪物生命-"<<gong<<"="<<guais<<endl;
cout<<"自身生命-"<<guaig<<"="<<sheng<<endl;
}
}
if(b==2&&c!=0) {
if(fangc==2) cout<<"进攻是最好的防守!"<<endl;
else {
if(fang>guaig) {
fang1=guais;
guais=guais-(fang-guaig);
if(guais<0) cout<<"怪物生命-"<<fang1<<"=0"<<endl;
else cout<<"怪物生命-"<<(fang-guaig)<<"="<<guais<<endl;
cout<<"(连续防御上限"<<fangc<<"/1)"<<endl;
} else {
fang1=sheng;
sheng=sheng-(guaig-fang);
if(sheng<0) cout<<"自身生命-"<<fang1<<"=0"<<endl;
else cout<<"自身生命-"<<(guaig-fang)<<"="<<sheng<<endl;
cout<<"(连续防御上限"<<fangc<<"/1)"<<endl;
}
fangc++;
c--;
}
} else if(b==2) cout<<"你已筋疲力竭,无法防御"<<endl;
if(b==3) {
printf("1.使用恢复药剂(剩余%d)\n",yao);
printf("2.使用生命上限药剂(剩余%d)\n",smsxy);
printf("其它.退出\n");
cin>>b;
if(b==1&&yao>0) {
yao--;
sheng1=shengm-sheng;
sheng+=20;
if(sheng>shengm) {
sheng=shengm;
cout<<"自身生命+"<<sheng1<<"("<<shengm<<")"<<endl;
} else cout<<"自身生命+20("<<sheng<<")"<<endl;
} else if(b==1) printf("没药了!\n");
else if(b==2&&smsxy>0) {
smsxy--;
sjsm=rand()%10+10;
shengm+=sjsm;
sheng+=sjsm;
cout<<"生命上限+"<<sjsm<<"("<<shengm<<")"<<endl;
cout<<"自身生命+"<<sjsm<<"("<<sheng<<")"<<endl;
} else if(b==2) printf("没药了!\n");
}
if(sheng<=0) {
cout<<"你死了"<<endl;
break;
}
}
if(sheng>0) {
sjq=rand()%4+1;
qian=qian+sjq;
cout<<"金币+"<<sjq<<"("<<qian<<")"<<endl;
defen+=sjq;
}
} else if(b==2&&gong>=20&&shengm>=60&&sheng==shengm) {
fangc=1;
guais=rand()%50+50;
c=7;
cout<<"怪物生命("<<guais<<"/"<<guais<<")"<<endl;
cout<<"自身生命("<<sheng<<'/'<<shengm<<")"<<endl;
while(guais>0&&sheng>0) {
guaig=rand()%20+20;
cout<<"1.攻击"<<endl;
cout<<"2.防御(次数"<<c<<")"<<endl;
cout<<"3.回复(闪避)"<<endl;
cin>>b;
if(b==1) {
fangc=1;
printf("你与怪兽进行了激烈的打斗");
for(int i=1; i<=6; i++) {
printf(".");
Sleep(250);
}
gong1=guais;
guais-=gong;
if(guais<=0) {
guais=0;
cout<<"\n怪物生命-"<<gong1<<"=0"<<endl;
} else {
sheng=sheng-guaig;
cout<<"\n怪物生命-"<<gong<<"="<<guais<<endl;
cout<<"自身生命-"<<guaig<<"="<<sheng<<endl;
}
}
if(b==2&&c!=0) {
if(fangc==4) cout<<"进攻是最好的防守!"<<endl;
else {
if(fang>guaig) {
fang1=guais;
guais=guais-(fang-guaig);
if(guais<0) cout<<"怪物生命-"<<fang1<<"=0"<<endl;
else cout<<"怪物生命-"<<(fang-guaig)<<"="<<guais<<endl;
cout<<"(连续防御上限"<<fangc<<"/3)"<<endl;
} else {
fang1=sheng;
sheng=sheng-(guaig-fang);
if(sheng<0) cout<<"自身生命-"<<fang1<<"=0"<<endl;
else cout<<"自身生命-"<<(guaig-fang)<<"="<<sheng<<endl;
cout<<"(连续防御上限"<<fangc<<"/3)"<<endl;
}
fangc++;
c--;
}
} else if(b==2) cout<<"你已筋疲力竭,无法防御"<<endl;
if(b==3) {
printf("1.使用恢复药剂(剩余%d)\n",yao);
printf("2.使用生命上限药剂(剩余%d)\n",smsxy);
printf("其它.退出\n");
cin>>b;
if(b==1&&yao>0) {
yao--;
sheng1=shengm-sheng;
sheng+=20;
if(sheng>shengm) {
sheng=shengm;
cout<<"自身生命+"<<sheng1<<"("<<shengm<<")"<<endl;
} else cout<<"自身生命+20("<<sheng<<")"<<endl;
} else if(b==1) printf("没药了!\n");
else if(b==2&&smsxy>0) {
smsxy--;
sjsm=rand()%10+10;
shengm+=sjsm;
sheng+=sjsm;
cout<<"生命上限+"<<sjsm<<"("<<shengm<<")"<<endl;
cout<<"自身生命+"<<sjsm<<"("<<sheng<<")"<<endl;
} else if(b==2) printf("没药了!\n");
}
if(sheng<=0) {
cout<<"你死了"<<endl;
break;
}
}
if(sheng>0) {
sjq=rand()%8+7;
qian+=sjq;
cout<<"金币+"<<sjq<<"("<<qian<<")"<<endl;
defen+=sjq;
}
} else if(b==2) {
cout<<"你的能力不够,还不能挑战它,快去讨伐低级一些的魔物,增加你的能力后再来吧!"<<endl;
cout<<"解锁条件:攻击:"<<gong<<"/20 生命上限:"<<shengm<<"/60 生命:"<<sheng<<"/"<<shengm<<endl;
} else if(b==3&&gong>=50&&shengm>=150&&sheng==shengm) {
fangc=1;
guais=rand()%100+100;
c=15;
cout<<"怪物生命("<<guais<<"/"<<guais<<")"<<endl;
cout<<"自身生命("<<sheng<<'/'<<shengm<<")"<<endl;
while(guais>0&&sheng>0) {
guaig=rand()%50+50;
cout<<"1.攻击"<<endl;
cout<<"2.防御(次数"<<c<<")"<<endl;
cout<<"3.回复(闪避)"<<endl;
cin>>b;
if(b==1) {
fangc=1;
printf("你与怪兽进行了激烈的打斗");
for(int i=1; i<=6; i++) {
printf(".");
Sleep(250);
}
gong1=guais;
guais-=gong;
if(guais<=0) {
guais=0;
cout<<"\n怪物生命-"<<gong1<<"=0"<<endl;
} else {
sheng=sheng-guaig;
cout<<"\n怪物生命-"<<gong<<"="<<guais<<endl;
cout<<"自身生命-"<<guaig<<"="<<sheng<<endl;
}
}
if(b==2&&c!=0) {
if(fangc==6) cout<<"进攻是最好的防守!"<<endl;
else {
if(fang>guaig) {
fang1=guais;
guais=guais-(fang-guaig);
if(guais<0) cout<<"怪物生命-"<<fang1<<"=0"<<endl;
else cout<<"怪物生命-"<<(fang-guaig)<<"="<<guais<<endl;
cout<<"(连续防御上限"<<fangc<<"/5)"<<endl;
} else {
fang1=sheng;
sheng=sheng-(guaig-fang);
if(sheng<0) cout<<"自身生命-"<<fang1<<"=0"<<endl;
else cout<<"自身生命-"<<(guaig-fang)<<"="<<sheng<<endl;
cout<<"(连续防御上限"<<fangc<<"/5)"<<endl;
}
fangc++;
c--;
}
} else if(b==2) cout<<"你已筋疲力竭,无法防御"<<endl;
if(b==3) {
printf("1.使用恢复药剂(剩余%d)\n",yao);
printf("2.使用生命上限药剂(剩余%d)\n",smsxy);
printf("其它.退出\n");
cin>>b;
if(b==1&&yao>0) {
yao--;
sheng1=shengm-sheng;
sheng+=20;
if(sheng>shengm) {
sheng=shengm;
cout<<"自身生命+"<<sheng1<<"("<<shengm<<")"<<endl;
} else cout<<"自身生命+20("<<sheng<<")"<<endl;
} else if(b==1) printf("没药了!\n");
else if(b==2&&smsxy>0) {
smsxy--;
sjsm=rand()%10+10;
shengm+=sjsm;
sheng+=sjsm;
cout<<"生命上限+"<<sjsm<<"("<<shengm<<")"<<endl;
cout<<"自身生命+"<<sjsm<<"("<<sheng<<")"<<endl;
} else if(b==2) printf("没药了!\n");
}
if(sheng<=0) {
cout<<"你死了"<<endl;
break;
}
}
if(sheng>0) {
sjq=rand()%45+75;
qian+=sjq;
cout<<"金币+"<<sjq<<"("<<qian<<")"<<endl;
defen+=sjq;
}
} else if(b==3) {
cout<<"你的能力不够,还不能挑战它,快去讨伐低级一些的魔物,增加你的能力后再来吧!"<<endl;
cout<<"解锁条件:攻击:"<<gong<<"/50 生命上限:"<<shengm<<"/150 生命:"<<sheng<<"/"<<shengm<<endl;
}
} else if(b==3) {
printf("请稍后");
for(int i=1; i<=6; i++) {
printf(".");
Sleep(500);
}
printf("\n自身资料\n");
printf("----------------------------------------------\n");
printf("生命上限:%d\n",shengm);
printf("生命:%d\n",sheng);
printf("攻击:%d\n",gong);
printf("防御:%d\n",fang);
} else if(b==4) {
printf("请稍后");
for(int i=1; i<=6; i++) {
printf(".");
Sleep(500);
}
printf("\n金币:%d\n",qian);
printf("恢复药剂:%d\n",yao);
printf("生命上限药剂(随机):%d\n",smsxy);
printf("1.使用恢复药剂\n");
printf("2.使用生命上限药剂\n");
printf("其它.退出\n");
cin>>b;
if(b==1&&yao>0) {
yao--;
sheng+=20;
if(sheng>shengm) sheng=shengm;
cout<<"自身生命+20("<<sheng<<")"<<endl;
} else if(b==1) printf("没药了!\n");
else if(b==2&&smsxy>0) {
smsxy--;
sjsm=rand()%10+10;
shengm+=sjsm;
sheng+=sjsm;
cout<<"生命上限+"<<sjsm<<"("<<shengm<<")"<<endl;
cout<<"自身生命+"<<sjsm<<"("<<sheng<<")"<<endl;
} else if(b==2) printf("没药了!\n");
}
if(sheng==0&&qian==0&&yao==0) {
cout<<"你一无所有,彻彻底底地死了!"<<endl;
cout<<"游戏结束"<<endl;
cout<<"得分:"<<defen<<endl;
return 0;
}
}
return 0;
}
热心网友
时间:2024-12-12 00:09
嗯,那就给你一个我自己编写的科学计算器代码吧,不懂Q我:281754179
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define Esc 27
#define Tab 9
void needle(char* s,char* carriage,int start)//needle意为“用针缝”
{
int size_carriage=(int)strlen(carriage);
int i,j;
for(j=0;j<size_carriage;j++)
{
for(i=(int)strlen(s);i>=start;i--)
s[i+1]=s[i];
s[i+1]=carriage[j];
start=i+2;
}
}
double factorial(double d)//factorial意为“阶乘”
{
return d==0?1:d*factorial(d-1);
}
void handle(char* carriage)//handle意为“处理”
{
void find_start(char*,int*);
char* save1,*save2,ch;
char op[111];
double d1,d2;
int start,i;
find_start(carriage,&start);
ch=carriage[start];
d1=strtod(carriage,&save1);//strtod是库函数,功能是将字符串carriage中出现的第一个浮点数转化为double,并将剩余字符储存在save1中
if(ch=='!')
{
sprintf(op,"%g",factorial(d1));//springf是库函数,功能是将显示在屏幕上的内容储存在op中
strcpy(carriage,op);
return;
}
for(i=0;i<(int)strlen(save1);i++)//对于第一个不是'+'或'-'或数字的字符串,strtod无法作用。所以得去掉诸如"*22"字符串中的'*'
save1[i]=save1[i+1];
d2=strtod(save1,&save2);
switch(ch)
{
case '*':sprintf(op,"%.32g",d1*d2);break;
case '/':sprintf(op,"%.32g",d1/d2);break;
case '+':sprintf(op,"%.16g",d1+d2);break;
case '-':sprintf(op,"%.16g",d1-d2);
}
strcpy(carriage,op);
}
void delete(char* s,int start,int end)//delete意为“删除”
{
int i,j;
int size=(int)strlen(s);
for(i=end;i>=start;i--)
for(j=i;j<size;j++)
s[j]=s[j+1];
}
void copy(char* s,char* carriage,int start,int end)//copy意为“复制”
{
int i;
for(i=0;start<=end;i++,start++)
carriage[i]=s[start];
carriage[i]='\0';
}
void scissor(char* s,char* carriage,int* start)//scissor意为“用剪刀剪”
{
int sta,end;
for(sta=*start-1;(s[sta]>='0'&&s[sta]<='9')||s[sta]=='.';sta--);
if(sta!=0||s[*start]=='!') //处理式子是-2+3或-2!的特殊情况
sta++;
if(s[*start]=='!')//'!'是单目运算符
end=*start;
else
{
for(end=*start+1;(s[end]>='0'&&s[end]<='9')||s[end]=='.';end++);
if((s[end-1]=='*'||s[end-1]=='/')&&(s[end]=='+'||s[end]=='-'))//处理式子是2*-2等的特殊情况
for(end++;(s[end]>='0'&&s[end]<='9')||s[end]=='.';end++);
end--;
}
copy(s,carriage,sta,end);
delete(s,sta,end);
*start=sta;//记住等下针线函数needle要开始缝的地方
}
void find_start(char* s,int* start)//find_start意为“找到操作符号开始处”
{
int i;
int size=(int)strlen(s);
//由优先级决定从上而下的顺序
for(i=0;i<size;i++)
if(s[i]=='!')
{
*start=i;
return;
}
for(i=0;i<size;i++)
if(s[i]=='*'||s[i]=='/')
{
*start=i;
return;
}
if(s[0]=='+'||s[0]=='-')
{
for(*start=1;(s[*start]>='0'&&s[*start]<='9')||s[*start]=='.';(*start)++);
return;
}
for(i=0;i<size;i++)
if(s[i]=='+'||s[i]=='-')
{
*start=i;
return;
}
}
int judge(char* s)//judge意为“判断”
{
int i;
int size=(int)strlen(s);
for(i=1;i<size;i++)
if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='!')
return 1;
return 0;
}
void count(char* s)//count意为“计算”
{
int start,i;
char carriage[555];//carriage意为“运载体”
while(judge(s))//判断式子是否还需要进行运算
{
for(i=0;i<(int)strlen(s);i++)//此循环作用是将式子中出现的'--'替换为'+'
{
for(;s[i]!='-'&&i<(int)strlen(s);i++);
if(s[i+1]=='-')
{
delete(s,i,i+1);
needle(s,"+",i);
}
}
find_start(s,&start);//让下标start指向式子应该最先开始处理的运算符
scissor(s,carriage,&start);//用剪刀scissor将start指向的运算符及相对应的操作数剪下并储存在运载体carriage上
handle(carriage);//处理该运载体,并将运载体上运载的式子的计算结果储存在运载体上
needle(s,carriage,start);//见函数simplify中的说明
}
}
void simplify(char* s)//simplify意为“简化”
{
char carriage[555];//carriage意为“运载体”
int start,end,i;
int size=(int)strlen(s);
while(1)
{
for(i=0;s[i]!='('&&i<size;i++);
if(i==size)
break;//说明式子已不含括号
for(end=0;s[end]!=')';end++);//使end下标指向式子中第一个出现')'的地方
end--;
for(start=end;s[start]!='(';start--);//寻找与上面一个')'配对的'('
start++;
copy(s,carriage,start,end);//将括号里的内容复制给运载体carriage
delete(s,start-1,end+1);//删除整个括号及其里面的内容
count(carriage);//计算运载体运载的表达式,运算结果储存在运载体上
needle(s,carriage,start-1);//将运载体运载过来的结果用针线needle缝在刚才删除式子s括号及其内容的地方
}
}
int main()
{
int i=0;
char s[555],ch;
puts(" 本程序不对用户输入数据进行检测:");
puts(" 即用户应输入规范的计算式,包括分母不能为0:");
puts(" 式子不能含有空格及其他非计算字符;");
puts(" 按任意一个键开始,按回车键显示运算结果;");
while(1)
{
i++;
ch=getch();
if(Esc==ch)
break;
if(Tab==ch)
{
system("cls");//清除当前屏幕
puts("显示运算结果后:按“Esc”键退出,按“Tab”键清除当前屏幕");
}
if(i==1)
{
system("cls");
puts("显示运算结果后:按“Esc”键退出,按“Tab”键清除当前屏幕");
}
puts("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
gets(s);
simplify(s);
count(s);
puts(s);
//实验数据:23.243*(5!-23.123/.133+(2!-13/13.23)*(2!-.235)-((4!-20)!/2!)-32*(3!+2.23/(2*3)!))
//其正确结果是:-5953.9401265774754346182917611489
}
puts("谢谢使用!");
getch();
return 0;
}
参考资料:http://hi.baidu.com/liangxiaowen1989/blog/item/af972310f7119670ca80c413.html