用C语言设计小游戏的程序??急!!!
用C语言写的程序,通过编译就可以生成exe格式的文件,如果是想生成可安装的文件用个工具叫setup factory就可以了
可以学写“贪吃蛇”代码:
#include
#include
#include
#include
#include
#define W 78 //游戏框的宽,x轴
#define H 26 //游戏框的高,y轴
int dir=3; //方向变量,初值3表示向“左”
int Flag=0; //吃了食物的标志(1是0否)
int score=0; //玩家得分
struct food{ int x; //食物的x坐标
int y; //食物的y坐标
}fod; //结构体fod有2个成员
struct snake{ int len; //蛇身长度
int speed; //速度
int x[100];
int y[100];
}snk; //结构体snk有4个成员
void gtxy( int x,int y) //控制光标移动的函数
{ COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gtxy( int x,int y); //以下声明要用到的几个自编函数
void csh( ); //初始化界面
void keymove( ); //按键操作移动蛇
void putFod( ); //投放食物
int Over( ); //游戏结束(1是0否)
void setColor(unsigned short p, unsigned short q); //设定显示颜色
int main( ) //主函数
{ csh( );
while(1)
{ Sleep(snk.speed);
keymove( );
putFod( );
if(Over( )) {system(“cls”);
gtxy(W/2+1,H/2); printf(“游戏结束!T__T”);
gtxy(W/2+1,H/2+2); printf(“玩家总分:%d分”,score);
getch( ); break;
}
}
return 0;
}
void csh( ) //初始化界面
{ int i; gtxy(0,0);
CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下两行是隐藏光标的设置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
for(i=0;i<=W;i=i+2) //横坐标要为偶数,因为这个要打印的字符占2个位置
{ setColor(2, 0); //设定打印颜色为绿字黑底
gtxy(i,0); printf("■"); //打印上边框
gtxy(i,H); printf("■"); //打印下边框
}
for(i=1;i<H;i++)
{ gtxy(0,i); printf("■"); //打印左边框
gtxy(W,i); printf("■"); //打印右边框
}
while(1)
{ srand((unsigned)time(NULL)); //启动随机数发生器srand( )
fod.x=rand()%(W-4)+2; //随机函数rand( )产生一个从0到比”(W-4)”小1的数再加2
fod.y=rand()%(H-2)+1; //随机函数rand( )产生一个从0到比”(H-2)”小1的数再加1
if (fod.x%2==0) break; //fod.x是食物的横坐标,要是2的倍数(为偶数)
}
setColor(12, 0); //设定打印颜色为淡红字黑底
gtxy(fod.x,fod.y); printf("●"); //到食物坐标处打印初试食物
snk.len=3; //蛇身长
snk.speed=350; //刷新蛇的时间,即是移动速度
snk.x[0]=W/2+1; //蛇头横坐标要为偶数(因为W/2=39)
snk.y[0]=H/2; //蛇头纵坐标
setColor(9, 0); //设定打印颜色为淡蓝字黑底
gtxy(snk.x[0], snk.y[0]); printf("■"); //打印蛇头
for(i=1;i<snk.len;i++)
{ snk.x[i]=snk.x[i-1]+2; snk.y[i]=snk.y[i-1];
gtxy(snk.x[i],snk.y[i]); printf("■"); //打印蛇身
}
setColor(7, 0); //恢复默认的白字黑底
return;
}
void keymove( ) //按键操作移动蛇
{ int key;
if( kbhit( ) ) //如有按键输入才执行下面操作
{ key=getch( );
if (key==224) //值为224表示按下了方向键,下面要再次获取键值
{ key=getch( );
if(key==72&&dir!=2)dir=1; //72表示按下了向上方向键
if(key==80&&dir!=1)dir=2; //80为向下
if(key==75&&dir!=4)dir=3; //75为向左
if(key==77&&dir!=3)dir=4; //77为向右
}
if (key==32)
{ while(1) if((key=getch( ))==32) break; } //32为空格键,这儿用来暂停
}
if (Flag==0) //如没吃食物,才执行下面操作擦掉蛇尾
{gtxy(snk.x[snk.len-1],snk.y[snk.len-1]); printf(" "); }
int i;
for (i = snk.len - 1; i > 0; i--) //从蛇尾起每节存储前一节坐标值(蛇头除外)
{ snk.x[i]=snk.x[i-1]; snk.y[i]=snk.y[i-1]; }
switch (dir) //判断蛇头该往哪个方向移动,并获取最新坐标值
{ case 1: snk.y[0]--; break; //dir=1要向上移动
case 2: snk.y[0]++; break; //dir=2要向下移动
case 3: snk.x[0]-=2; break; //dir=3要向左移动
case 4: snk.x[0]+=2; break; //dir=4要向右移动
}
setColor(9, 0);
gtxy(snk.x[0], snk.y[0]); printf("■"); //打印蛇头
if (snk.x[0] == fod.x && snk.y[0] == fod.y) //如吃到食物则执行以下操作
{ printf("\007"); snk.len++; score += 100; snk.speed -= 5; Flag = 1; }//这007是响铃
else Flag = 0; //没吃到食物Flag的值为0
if(snk.speed<150) snk.speed= snk.speed+5; //作弊码,不让速度无限加快
}
void putFod( ) //投放食物
{ if (Flag == 1) //如吃到食物才执行以下操作,生成另一个食物
{ while (1)
{ int i,n= 1;
srand((unsigned)time(NULL)); //启动随机数发生器srand( ),接下产生食物坐标值
fod.x = rand( ) % (W - 4) + 2; //产生在游戏框范围内的一个x坐标值
fod.y = rand( ) % (H - 2) + 1; //产生在游戏框范围内的一个y坐标值
for (i = 0; i < snk.len; i++) //随机生成的食物不能在蛇的身体上
{ if (fod.x == snk.x[i] &&fod.y == snk.y[i]) { n= 0; break;} }
if (n && fod.x % 2 == 0) break; //n不为0且横坐标为偶数,则食物坐标取值成功
}
setColor(12, 0);
gtxy(fod.x, fod.y); printf("●"); //光标到取得的坐标处打印食物
}
return;
}
int Over( ) //判断游戏是否结束的函数
{ int i;
setColor(7, 0);
gtxy(2,H+1); printf(“暂停键:space.”); //以下打印一些其它信息
gtxy(2,H+2); printf(“游戏得分:%d”,score);
if (snk.x[0] == 0 || snk.x[0] == W) return 1; //蛇头触碰左右边界
if (snk.y[0] == 0 || snk.y[0] == H) return 1; //蛇头触碰上下边界
for (i = 1; i < snk.len; i++)
{ if (snk.x[0] == snk.x[i] && snk.y[0] == snk.y[i]) return 1; } //蛇头触碰自身
return 0; //没碰到边界及自身时就返回0
}
void setColor(unsigned short ForeColor = 7, unsigned short BackGroundColor = 0)
{ HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, ForeColor + BackGroundColor * 0x10);
} //用来设定颜色的函数
// greedsnake.cpp
#include <bios.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include "conf.h"
typedef struct node
{
int x,y;
struct node *next;
}Node;
typedef struct
{
Node *head,*tail;
int length;
}Snake;
typedef struct
{
int left,top,right,bottom;
}Frame;
typedef enum //四个方向
{
up,down,left,right
}Direction;
typedef enum
{
false,true
}bool;//*/
void InitGraphMode(); //初始化图形驱动
void CloseGraphMode();
void Foot(int,int);
void Head(int,int);
void CreateFrame(); //完成整个游戏框架的绘制
void CreateSnake(); //创建一条两个节点的蛇,蛇的每一节是队列中的一个节点
bool PlayGame(); //游戏的主体函数,
int Hit(int,int); //判断是否越界,或者撞到自身,两个参数分别是新的头接点的x,y坐标
bool GameOver(); //绘制游戏结束时弹出的对话框
void Enqueue(Node); //入队函数
Node Dequeue(); //出队函数
void ClearKeyBuf(); //清除键盘缓冲,此函数可以消除不停的按无效键的影响
Snake snake;
Frame frame;
void main()
{
InitGraphMode();
do
{
CreateFrame();
}while(PlayGame());
CloseGraphMode();
}
void InitGraphMode()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"../bgi/");
cleardevice();
}
void CloseGraphMode()
{
cleardevice();
closegraph();
}
void CreateFrame()
{
setbkcolor(CYAN);
//下面的四行代码用于计算主框架的左上角和右下角的坐标
frame.left=(getmaxx()+1-BlockWidth*RowOfFrame)/2;
frame.top=(getmaxy()+1-BlockHeight*ColumnOfFrame)/2;
frame.right=frame.left+BlockWidth*RowOfFrame;
frame.bottom=frame.top+BlockHeight*ColumnOfFrame;
Head(frame.left+100,frame.top-20);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(frame.left,frame.top,frame.right,frame.bottom);
setlinestyle(SOLID_LINE,1,1);
setcolor(DARKGRAY);
line(frame.left,frame.top,frame.right,frame.top);
line(frame.left,frame.top,frame.left,frame.bottom);
setlinestyle(SOLID_LINE,1,1);
setcolor(WHITE);
line(frame.left,frame.bottom,frame.right,frame.bottom);
line(frame.right,frame.top,frame.right,frame.bottom);
setlinestyle(DOTTED_LINE,1,1);
setcolor(BLUE);
for(int row=1;row<RowOfFrame;row++)
line(frame.left+row*BlockWidth,frame.top,frame.left+row*BlockWidth,frame.bottom);
for(int column=1;column<ColumnOfFrame;column++)
line(frame.left,frame.top+column*BlockHeight,frame.right,frame.top+column*BlockHeight);
Foot(frame.left,frame.bottom+20);
}
void CreateSnake()
{
Node *node1=new Node;
Node *node2=new Node;
node1->x=frame.left+BlockWidth;
node1->y=frame.top;
node1->next=NULL;
snake.tail=node1;
node2->x=frame.left;
node2->y=frame.top;
node2->next=snake.tail;
snake.head=node2;
snake.length=2;
setfillstyle(SOLID_FILL,BLUE);
bar(snake.head->x+1,snake.head->y+1,snake.head->x+BlockWidth-1,snake.head->y+BlockHeight-1);
bar(snake.tail->x+1,snake.tail->y+1,snake.tail->x+BlockWidth-1,snake.tail->y+BlockHeight-1);
}
bool PlayGame()
{
int speed=300,key;
Direction CurrentDirection=right;
Node randomNode;
Node newNode,outNode;
bool neednode=true;
bool overlap=false;
int randx,randy;
CreateSnake();
while(true)
{
if(neednode==true)
{
randomize();
do
{
randx=frame.left+rand()%RowOfFrame*BlockWidth;
randy=frame.top+rand()%ColumnOfFrame*BlockHeight;
for(Node *p=snake.head;p!=NULL;p=p->next)//hit itself
if(randx==p->x&&randy==p->y)
{overlap=true;break;}
}
while(overlap==true);
randomNode.x=randx;
randomNode.y=randy;
randomNode.next=NULL;
setfillstyle(SOLID_FILL,RED);
bar(randomNode.x+1,randomNode.y+1,randomNode.x+BlockWidth-1,randomNode.y+BlockHeight-1);
neednode=false;
}
if((key=bioskey(1))!=0)
{
switch(key)
{
case ESC: return false;
case UP:
if(CurrentDirection!=down)
CurrentDirection=up;
ClearKeyBuf();
break;
case DOWN:
if(CurrentDirection!=up)
CurrentDirection=down;
ClearKeyBuf();
break;
case LEFT:
if(CurrentDirection!=right)
CurrentDirection=left;
ClearKeyBuf();
break;
case RIGHT:
if(CurrentDirection!=left)
CurrentDirection=right;
ClearKeyBuf();
break;
case PAGEUP:speed=speed-100;
if(speed<100)
speed=100;
ClearKeyBuf();
break;
case PAGEDOWN:speed=speed+100;
if(speed>500)
speed=500;
ClearKeyBuf();
break;
default :break;
}
}
int headx=snake.tail->x;
int heady=snake.tail->y;
switch(CurrentDirection)
{
case up: heady-=BlockHeight;break;
case down: heady+=BlockHeight;break;
case left: headx-=BlockWidth;break;
case right: headx+=BlockWidth;break;
}
if(Hit(headx,heady)) //whether the snake hit the wall or itself
return GameOver();
else
{ //eat
if(headx==randomNode.x&&heady==randomNode.y)
{
Enqueue(randomNode);
setfillstyle(SOLID_FILL,BLUE);
bar(randomNode.x+1,randomNode.y+1,randomNode.x-1+BlockWidth,randomNode.y-1+BlockHeight);
neednode=true;
}
else //no eat
{
newNode.x=headx;
newNode.y=heady;
newNode.next=NULL;
Enqueue(newNode);
outNode=Dequeue();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(outNode.x+1,outNode.y+1,outNode.x+BlockWidth-1,outNode.y+BlockHeight-1);
setfillstyle(SOLID_FILL,BLUE);
bar(newNode.x+1,newNode.y+1,newNode.x-1+BlockWidth,newNode.y-1+BlockHeight);
}
}
delay(speed);
}
}
void ClearKeyBuf()
{
do
bioskey(0);
while(bioskey(1));
}
void Foot(int x,int y)
{
setcolor(BLUE);
outtextxy(x,y,"writer:[T]RealXL E-MAIL:realgeneral@hotmail.com");
}
void Head(int x,int y)
{
setcolor(RED);
outtextxy(x,y,"GREEDY SNAKE");
}
void Enqueue(Node inNode)
{
Node *p=new Node;
p->x=inNode.x;
p->y=inNode.y;
p->next=inNode.next;
snake.tail->next=p;
snake.tail=p;
snake.length++;
}
Node Dequeue()
{
Node *p=snake.head;
Node outNode=*p;
snake.head=p->next;
snake.length--;
delete p;
return outNode;
}
int Hit(int x,int y)
{
if(x<frame.left||x>=frame.right||y<frame.top||y>=frame.bottom)//hit the wall
return 1;
Node *p=snake.head->next;
for(int i=snake.length-1;i>3;i--,p=p->next)//hit itself
if(x==p->x&&y==p->y)
return 1;
return 0;
}
bool GameOver()
{
int x=getmaxx()/2-50;
int y=getmaxy()/2-20;
setfillstyle(SOLID_FILL,DARKGRAY);
bar(x+3,y+3,x+103,y+43);
setfillstyle(SOLID_FILL,MAGENTA);
bar(x,y,x+100,y+40);
setlinestyle(0,3,1);
setcolor(RED);
rectangle(x,y,x+100,y+40);
outtextxy(x+20,y+10,"GAGE OVER!");
char c;
while(true) //按q或Q表示退出程序,按r或R表示重新开始游戏
{
c=getch();
if(c=='q'||c=='Q')
return false;
else if(c=='r'||c=='R')
return true;
}
}
C++五子棋源程序:
#include
#include
#include
#define backcolor CYAN
#define defaultcolor BLACK
#define linecolor MAGENTA
#define player1_color RED
#define player2_color WHITE
#define error_color RED
#define winner_color RED
const int left=40;
const int top=390;
const int d=30;
const int line_num=9;
const int turn=0;
const int r=d/3;
const int j=10;
int x,y,k=1,step=(line_num+1)*(line_num+1);
union REGS regs1,regs2;
class player1;
class player2;
class qipan{
public:
qipan();
~qipan(){};
void init_qipan();
friend void fall(player1 &num1,player2 &num2,qipan &num);
friend void input(player1 &num1,player2 &num2,qipan &num);
private:
int point[line_num+1][line_num+1];
};
class player1{
public:
player1();
~player1(){};
friend void fall(player1 &num1,player2 &num2,qipan &num);
friend void input(player1 &num1,player2 &num2);
friend int judge_winner(player1 &num1,player2 &num2);
private:
int point1[line_num+1][line_num+1];
};
class player2{
public:
player2();
~player2(){};
friend void fall(player1 &num1,player2 &num2,qipan &num);
friend void input(player1 &num1,player2 &num2,qipan &num);
friend int judge_winner(player1 &num1,player2 &num2);
private:
int point2[line_num+1][line_num+1];
};
void input(player1 &num1,player2 &num2);
void fall(player1 &num1,player2 &num2,qipan &num);
int judge_winner(qipan &num,player1 &num1,player2 &num2);
void inputerror();
void display_winner(int);
void main()
{
int driver=DETECT,mode;
initgraph(&driver,&mode,"e:\tc30\bgi");
qipan num;
player1 num1;
player2 num2;
while(step--)
{
input(num1,num2,num);
fall(num1,num2,num);
if(judge_winner(num1,num2))
{
display_winner(k);
}
}
// getchar();
}
qipan::qipan(void)
{ int j,i;
char ch[2]="0";
setbkcolor(backcolor);
setcolor(linecolor);
for(i=0;i<=line_num;i++)
{
line(left,top-i*d,left+line_num*d,top-i*d);
}
for(i=0;i<=line_num;i++)
{
line(left+i*d,top,left+i*d,top-line_num*d);
}
for(i=0;i<=line_num;i++)
{ if(*ch=='9'+1) *ch='a';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+i*d-2,top+r+3,ch);
(*ch)=(*ch)+1;
}
*ch='0';
for(i=0;i<=line_num;i++)
{if(*ch=='9'+1) *ch='a';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left-r-10,top-d*i-3,ch);
(*ch)=(*ch)+1;
}
setcolor(defaultcolor);
for(i=0;i<=line_num;i++)
{
for(j=0;j<=line_num;j++)
point[i][j]=0;
}
}
void fall(player1 &num1,player2 &num2,qipan &num)
{
int flag=k%2;
if(flag)
{ setcolor(player2_color);
num2.point2[x][y]=1;
num.point[x][y]=2;
circle(left+d*x,top-d*y,r);
setfillstyle(1,player2_color);
floodfill(left+d*x,top-d*y,player2_color);
}
else
{ num1.point1[x][y]=1;
num.point[x][y]=1;
setcolor(player1_color);
circle(left+d*x,top-d*y,r);
setfillstyle(1,player1_color);
floodfill(left+d*x,top-d*y,player1_color);
}
setcolor(defaultcolor);
}
void input(player1 &num1,player2 &num2,qipan &num)
{ char xx,yy;
k++;
while(1)
{
regs1.h.ah=0;
xx=int86(22,®s1,®s1)-'0';
if(xx==('q'-'0')||xx==('Q'-'0'))
{ step=0;
return;
}
regs1.h.ah=0;
yy=int86(22,®s1,®s1)-'0';
if(yy==('q'-'0')||yy==('Q'-'0'))
{
step=0;
return ;
}
if(xx<0||xx>line_num)
{ inputerror();
continue;
}
if(yy<0||yy>line_num)
{inputerror();
continue;
}
if(num.point[xx][yy]==0)
{
break;
}
else
{
inputerror();
continue;
}
}
x=(int)xx;
y=(int)yy;
setcolor(backcolor);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+d*line_num/3,top+d*2,"Input error");
setcolor(defaultcolor);
}
player1::player1()
{
int i,j;
for(i=0;i<=line_num;i++)
{
for(j=0;j<=line_num;j++)
point1[i][j]=0;
}
}
player2::player2()
{ int i,j;
for(i=0;i<=line_num;i++)
{
for(j=0;j<=line_num;j++)
point2[i][j]=0;
}
}
void inputerror(void)
{ setcolor(error_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+d*line_num/3,top+d*2,"Input error");
setcolor(defaultcolor);
}
int judge_winner(player1 &num1,player2 &num2)
{
int count=0,m=0,n=0,a=0,b=0,xx0,yy0;
int flag=k%2;
xx0=x; yy0=y;
if(!flag)
{ //left <-------> right
while(xx0>=1&&m<4) {xx0--;m++;}
while(n<9&&xx0<=line_num)
{
if(num1.point1[xx0][y]==1)
{
count++;
if(count==5) return 1;
}
else
{
count=0;
}
n++;
xx0++;
}
//up <------> down
count=0; xx0=x; m=0; n=0;
while(yy0>=1&&m<4){yy0--;m++;}
while(n<9&&yy0<=line_num)
{
if(num1.point1[x][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
n++;
yy0++;
}
//left up ----- right down
xx0=x;
yy0=y;
m=0;
n=0;
count=0;
while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0;
while(yy0<=line_num&&m<4){ yy0++; b++; m++;}
if(a<=b)
{
xx0=x-a; yy0=y+a;
}
else
{
xx0=x-b; yy0=y+b;
}
while(xx0<=line_num&&yy0>=0&&n<9)
{
if(num1.point1[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
xx0++;
yy0--;
n++;
}
//right up <-----> left down
count=0;
a=0;
b=0;
n=0;
m=0;
xx0=x;
yy0=y;
while(xx0while(yy0if(a<=b)
{
xx0=x+a;
yy0=y+a;
}
else
{
xx0=x+b;
yy0=y+b;
}
while(xx0>=0&&yy0>=0&&n<9)
{
if(num1.point1[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
count=0;
xx0--;
yy0--;
n++;
}
//no winer
return 0;
}
else
{
//left <-------> right
while(xx0>=1&&m<4) {xx0--;m++;}
while(n<9&&xx0<=line_num)
{
if(num1.point1[xx0][y]==1)
{
count++;
if(count==5) return 1;
}
else
{
count=0;
}
n++;
xx0++;
}
//up <------> down
count=0; xx0=x; m=0; n=0;
while(yy0>=1&&m<4){yy0--;m++;}
while(n<9&&yy0<=line_num)
{
if(num2.point2[x][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
n++;
yy0++;
}
//left up ----- right down
xx0=x;
yy0=y;
m=0;
n=0;
count=0;
while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0;
while(yy0<=line_num&&m<4){ yy0++; b++; m++;}
if(a<=b)
{
xx0=x-a; yy0=y+a;
}
else
{
xx0=x-b; yy0=y+b;
}
while(xx0<=line_num&&yy0>=0&&n<9)
{
if(num2.point2[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
xx0++;
yy0--;
n++;
}
//right up <-----> left down
count=0;
a=0;
b=0;
n=0;
m=0;
xx0=x;
yy0=y;
while(xx0while(yy0if(a<=b)
{
xx0=x+a;
yy0=y+a;
}
else
{
xx0=x+b;
yy0=y+b;
}
while(xx0>=0&&yy0>=0&&n<9)
{
if(num2.point2[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
count=0;
xx0--;
yy0--;
n++;
}
//no winer
return 0;
}
}
void display_winner(int k)
{
int flag=k%2;
if(!flag)
{ setcolor(winner_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(left+d*2,top+40,"Red is winner");
setcolor(defaultcolor);
step=0;
getchar();
}
else
{ setcolor(winner_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(left+2*d,top+40,"White is winner");
setcolor(defaultcolor);
step=0;
}
}
百度很多的
这个……
c语言如何制作幸运52小游戏 求代码。。。?
\/\/简单的猜字游戏代码:include <cstdlib> include <stdio.h> main(){ int ran_num,guess=-1;int range;printf("请输入要竞猜的范围(1~?):");scanf("%d",&range);srand((unsigned)time(0));ran_num=rand()%range;while(guess!=ran_num){ printf("请输入您竞猜的价格:");scanf("%d",...
仅用c语言能编出哪些小游戏?
可以编写狼追兔子游戏,掷骰子游戏,24点游戏,井字棋游戏,农夫过河游戏,扫雷小游戏,人机猜数游戏,三色球游戏, 推箱子游戏,坦克大战游戏,贪吃蛇游戏等。
求一个c语言制作的小游戏或者小软件,行数不小于600,挺急的
贪吃蛇代码 include <stdio.h> include <graphics.h> include <stdlib.h> include <dos.h> \/*引用的库函数*\/ define LEFT 0x4b00 define RIGHT 0x4d00 define DOWN 0x5000 define UP 0x4800 define ESC 0x011b\/*宏定义键名*\/ define N 200 int i,key;int level;\/*游戏等级*\/ int score...
用c语言编写21点小游戏
include<iostream> include<string> include<cmath> using namespace std;const double PRECISION=1E-6;const int COUNT_OF_NUMBER=4;const int NUMBER_TO_BE_CAL=21;double number[COUNT_OF_NUMBER];string expression[COUNT_OF_NUMBER];bool Search(int n){ if(n==1){ if(fabs(number[0]-...
用C语言编一个小游戏,注明编码,(简单易懂的游戏,不要复杂)
\/\/C语言写的,一个玩石头、剪刀、布的小游戏。下面是源码。include<stdio.h> include<stdlib.h> int main(){ char cq[][10]={"石头","剪刀","布"};int guess=-1,r,youwin=0,mewin=0,daping=0,total=0;srand(time(NULL));while(1){ r=(int)((rand()\/(RAND_MAX+1.0))*3)...
用C语言for语句设计一个小游戏
我写一个猜数字游戏吧!:\/*猜数字游戏:计算机随机给出一个1~100之间的数,你输入一个数,程序判断是否是程序 选定的那个数字,如果不正确,程序会告诉你大于或者小于这个数的提示,如:程序选择是7,你输入8,则提示大于了,给你猜10次*\/ include <stdio.h> main(){int i,guess,number;number...
c语言剪刀石头布小游戏
include <stdio.h> include <stdlib.h> include int main(){ char m;\/\/表示选择的是哪个人 int a,b;\/\/分别表示人和电脑 printf("(J)iandao, (S)hitou, hu(B)u :\\n");scanf("%c",&m);if(m!='J' && m!='S' && m!='B')printf("Input error!\\n");else\/\/分别用0,1...
c语言小游戏代码
C语言里还有 srand()函数等。\/\/头文件:stdlib.h if(color == 14) color -= rand() % 13 + 1; \/\/变色 SetColor(color); gotoxy(ix*2, iy); printf("■"); } if(Snake[ix][iy] == Snake_Len) { gotoxy(ix*2, iy); SetColor(0xe); printf("≈"); } } } void Clear_Snake()\/\/...
跪求C语言能存盘的小游戏源代码
class Csnake { Cmp firstSign; \/\/蛇头坐标 Cmp secondSign;\/\/蛇颈坐标 Cmp lastSign; \/\/蛇尾坐标 Cmp nextSign; \/\/预备蛇头 int row; \/\/列数 int line; \/\/行数 int count; \/\/蛇身长度 vector<vector<char> > snakeMap;\/\/整个游戏界面 queue<Cmp> snakeBody; \/\/蛇身 public:int Get...
如何用c语言编写一个小游戏?
一、数学知识:长方形的面积S=a*b 长方形周长L=2*(a+b)其中a b分别为长方形的宽和高。二、算法分析:长方形面积及周长均依赖于宽和高,所以先要输入宽高值,然后根据公式计算,输出结果即可。三、参考代码:include <stdio.h>void main(){ double a,b; double L,S; scanf("%l...
步凯威哌: #include "stdio.h"#include "math.h"#include "string.h"#include "stdlib.h"#define SIZE 5void main(){int answer[SIZE], guess[SIZE], a=1, b , times=0, i,j ,flag, f;char c[SIZE+1]; puts ( " 猜数字游戏 0.001版 "); //随机生成一个4位不同数...
琅琊区19180681106: 用C语言设计小游戏的程序??急!!! - ?
步凯威哌: 用c++实现的"贪吃蛇"游戏源码 // greedsnake.cpp #include <bios.h> #include <conio.h> #include <dos.h> #include <graphics.h> #include <stdlib.h> #include <time.h> #include "conf.h" typedef struct node { int x,y; struct node *next; }Node; ...
琅琊区19180681106: 教你如何使用C语言编写简单小游戏 - ?
步凯威哌: 编写程序,实现如下表所示的5-魔方阵.17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 5-魔方阵 问题分析 所谓“n-魔方阵”,指的是使用1〜n2共n2个自然数排列成一个n*n的方阵,其中n为奇数;该方阵的每行、每列及对...
琅琊区19180681106: 用C语言编个小游戏?
步凯威哌: // pukepai.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <time.h> #include <stdlib.h> #define N 100 #define M 21 void swapnum(int n, int m) { int tmp = 0; tmp = n; n = m; m = tmp; return; } void randnum(const int *psrc, int *...
琅琊区19180681106: 如何用C语言编写控制台小游戏 - ?
步凯威哌: //C语言实例:推箱子小游戏#include <stdio.h> #include <stdlib.h> #include<string.h> #include <conio.h> //行和列 #define ROW 10 #define COL 11 /* run this program using the console pauser or add your own getch, system("pause") or input ...
琅琊区19180681106: 谁有一些简单小游戏的C语言程序? - ?
步凯威哌: 可以学写“贪吃蛇”代码:#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <time.h>#include <Windows.h>#define W 78 //游戏框的宽,x轴#define H 26 //游戏框的高,y轴 int dir=3; //方向变量,初值3表示向“左” int Flag=0; ...
琅琊区19180681106: 猜数游戏C语言程序设计 - ?
步凯威哌: 这道题不难,只要知道怎样用c语言生成1~100的随机数就很好办了!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45附代码如下! #include<stdio.h> #include <...
琅琊区19180681106: 用C语言编一个小游戏,注明编码,(简单易懂的游戏,不要复杂) - ?
步凯威哌: 我这有许多C的小游戏.给你一个基础的简单的汉诺塔程序.你看看:这是个汉诺塔程序,在调试的时候,输入的数字最好不要大于15,因为每大一个数 所得的结果的步骤都会多一倍.如果你有耐心等待结果的话除外.汉诺塔是在欧洲 流行的...
琅琊区19180681106: 求个C语言小游戏程序 - ?
步凯威哌: #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;/*游戏速...
琅琊区19180681106: C语言程序小游戏 - ---一条龙游戏设计 - ?
步凯威哌: #include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; typedef __int64 BigInteger; typedef unsigned int Index; typedef double Number; class CombinationIterator { vector<Index> mCurrent; Index mN; Index...