c語言做小遊戲代碼,c++小遊戲編程代碼簡單

本文目錄一覽:

求幾C語言個小遊戲代碼,簡單的,要注釋、、謝謝了、

// Calcu24.cpp : Defines the entry point for the console application.

//

/*

6-6

24點遊戲

*/

#include “conio.h”

#include “stdlib.h”

#include “time.h”

#include “math.h”

#include “string.h”/*

從一副撲克牌中,任取4張。

2-10 按其點數計算(為了表示方便10用T表示),J,Q,K,A 統一按 1 計算

要求通過加減乘除四則運算得到數字 24。

本程序可以隨機抽取紙牌,並用試探法求解。

*/void GivePuzzle(char* buf)

{

char card[] = {‘A’,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′,’T’,’J’,’Q’,’K’}; for(int i=0; i4; i++){

buf[i] = card[rand() % 13];

}

}

void shuffle(char * buf)

{

for(int i=0; i5; i++){

int k = rand() % 4;

char t = buf[k];

buf[k] = buf[0];

buf[0] = t;

}

}

int GetCardValue(int c)

{

if(c==’T’) return 10;

if(c=’0′ c=’9′) return c – ‘0’;

return 1;

}

char GetOper(int n)

{

switch(n)

{

case 0:

return ‘+’;

case 1:

return ‘-‘;

case 2:

return ‘*’;

case 3:

return ‘/’;

} return ‘ ‘;

}double MyCalcu(double op1, double op2, int oper)

{

switch(oper)

{

case 0:

return op1 + op2;

case 1:

return op1 – op2;

case 2:

return op1 * op2;

case 3:

if(fabs(op2)0.0001)

return op1 / op2;

else

return 100000;

} return 0;

}

void MakeAnswer(char* answer, int type, char* question, int* oper)

{

char p[4][3];

for(int i=0; i4; i++)

{

if( question[i] == ‘T’ )

strcpy(p[i], “10”);

else

sprintf(p[i], “%c”, question[i]);

}

switch(type)

{

case 0:

sprintf(answer, “%s %c (%s %c (%s %c %s))”,

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 1:

sprintf(answer, “%s %c ((%s %c %s) %c %s)”,

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 2:

sprintf(answer, “(%s %c %s) %c (%s %c %s)”,

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 3:

sprintf(answer, “((%s %c %s) %c %s) %c %s”,

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

case 4:

sprintf(answer, “(%s %c (%s %c %s)) %c %s”,

p[0], GetOper(oper[0]), p[1], GetOper(oper[1]), p[2], GetOper(oper[2]), p[3]);

break;

}

}

bool TestResolve(char* question, int* oper, char* answer)

{

// 等待考生完成

int type[5]={0,1,2,3,4};//計算類型

double p[4];

double sum=0;

//

for(int i=0; i4; i++) //循環取得點數

{

p[i]=GetCardValue(int(question[i]));

} for(i=0;i5;i++)

{

MakeAnswer(answer,type[i],question,oper); //獲取可能的答案

switch(type[i])

{

case 0:

sum=MyCalcu(p[0],MyCalcu( p[1],MyCalcu(p[2], p[3], oper[2]),oper[1]),oper[0]); //A*(B*(c*D))

break;

case 1:

sum=MyCalcu(p[0],MyCalcu(MyCalcu(p[1], p[2], oper[1]),p[3],oper[2]),oper[0]); //A*((B*C)*D)

break;

case 2:

sum=MyCalcu(MyCalcu(p[0], p[1], oper[0]),MyCalcu(p[2], p[3], oper[2]),oper[1]); // (A*B)*(C*D)

break;

case 3:

sum=MyCalcu(MyCalcu(MyCalcu(p[0], p[1], oper[0]),p[2],oper[1]),p[3],oper[2]); //((A*B)*C)*D

break;

case 4:

sum=MyCalcu(MyCalcu(p[0],MyCalcu(p[1], p[2], oper[1]),oper[0]),p[3],oper[2]); //(A*(B*C))*D

break;

}

if(sum==24) return true;

}

return false;

}

/*

採用隨機試探法:就是通過隨機數字產生 加減乘除的 組合,通過大量的測試來命中的解法

提示:

1. 需要考慮用括號控制計算次序的問題 比如:( 10 – 4 ) * ( 3 + A ), 實際上計算次序的數目是有限的:

A*(B*(c*D))

A*((B*C)*D)

(A*B)*(C*D)

((A*B)*C)*D

(A*(B*C))*D

2. 需要考慮計算結果為分數的情況:( 3 + (3 / 7) ) * 7

3. 題目中牌的位置可以任意交換

*/

bool TryResolve(char* question, char* answer)

{

int oper[3]; // 存儲運算符,0:加法 1:減法 2:乘法 3:除法

for(int i=0; i1000 * 1000; i++)

{

// 打亂紙牌順序

shuffle(question);

// 隨機產生運算符

for(int j=0; j3; j++)

oper[j] = rand() % 4; if( TestResolve(question, oper, answer) ) return true;

} return false;

}

int main(int argc, char* argv[])

{

// 初始化隨機種子

srand( (unsigned)time( NULL ) ); char buf1[4]; // 題目

char buf2[30]; // 解答

printf(“***************************\n”);

printf(“計算24\n”);

printf(“A J Q K 均按1計算,其它按牌點計算\n”);

printf(“目標是:通過四則運算組合出結果:24\n”);

printf(“***************************\n\n”);

for(;;)

{

GivePuzzle(buf1); // 出題

printf(“題目:”);

for(int j=0; j4; j++){

if( buf1[j] == ‘T’ )

printf(“10 “);

else

printf(“%c “, buf1[j]);

} printf(“\n按任意鍵參考答案…\n”);

getch(); if( TryResolve(buf1, buf2) ) // 解題

printf(“參考:%s\n”, buf2);

else

printf(“可能是無解…\n”); printf(“按任意鍵出下一題目,x 鍵退出…\n”);

if( getch() == ‘x’ ) break;

} return 0;

}

用C語言編寫的小遊戲代碼是什麼?

/*也不知道你是什麼級別的,我是一個新手,剛接觸編程語言,以下是我自己變得一個小程序,在所有c語言的編譯器(vc++6.0、turbo????)上都能運行,你還可以進一步改進。這是一個類似貪吃蛇的小遊戲。祝你好運*/\x0d\x0a/*貪吃蛇*/\x0d\x0a#include\x0d\x0a#include\x0d\x0a#include\x0d\x0a#include\x0d\x0aint head=3 ,tail=0;\x0d\x0aint main()\x0d\x0a{\x0d\x0aint i,j,k=0;\x0d\x0aint zuobiao[2][80];\x0d\x0along start;\x0d\x0aint direction=77;\x0d\x0aint gamespeed;\x0d\x0aint timeover;\x0d\x0aint change(char qipan[20][80],int zuobiao[2][80],char direction);\x0d\x0azuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4;\x0d\x0a/*處理棋盤*/\x0d\x0achar qipan[20][80];//定義棋盤\x0d\x0afor(i=0;i for(j=0;jqipan[i][j]=’ ‘;//初始化棋盤\x0d\x0afor(i=0;iqipan[0][i]=’_’;\x0d\x0afor(i=0;iqipan[i][0]=’|’;\x0d\x0afor(i=0;iqipan[i][79]=’|’;\x0d\x0afor(i=0;iqipan[19][i]=’_’;\x0d\x0aqipan[1][1]=qipan[1][2]=qipan[1][3]=’*’;//初始化蛇的位置\x0d\x0aqipan[1][4]=’#’;\x0d\x0aprintf(“This is a game of a SNAKE.\nGOOD LUCK TO YOU !\n”);\x0d\x0aprintf(“Input your game speed,please.(e.g.300)\n”);\x0d\x0ascanf(“%d”,gamespeed);\x0d\x0a\x0d\x0awhile(direction!=’q’)\x0d\x0a{\x0d\x0asystem(“cls”);\x0d\x0afor(i=0;ifor(j=0;jprintf(“%c”,qipan[i][j]);\x0d\x0atimeover=1;\x0d\x0astart=clock();\x0d\x0awhile(!kbhit()(timeover=clock()-startif(timeover)\x0d\x0a{\x0d\x0agetch();\x0d\x0adirection=getch();\x0d\x0a}\x0d\x0aelse\x0d\x0adirection=direction;\x0d\x0aif(!(direction==72||direction==80||direction==75||direction==77))\x0d\x0a{\x0d\x0areturn 0;\x0d\x0asystem(“cls”);\x0d\x0aprintf(“GAME OVER!\n”);\x0d\x0a}\x0d\x0aif(!change(qipan,zuobiao,direction))\x0d\x0a{\x0d\x0adirection=’q’;\x0d\x0asystem(“cls”);\x0d\x0aprintf(“GAME OVER!\n”);\x0d\x0a}\x0d\x0a}\x0d\x0areturn 0;\x0d\x0a}\x0d\x0aint change(char qipan[20][80],int zuobiao[2][80],char direction)\x0d\x0a{\x0d\x0aint x,y;\x0d\x0aif(direction==72)\x0d\x0ax=zuobiao[0][head]-1;y=zuobiao[1][head];\x0d\x0aif(direction==80)\x0d\x0ax=zuobiao[0][head]+1;y=zuobiao[1][head];\x0d\x0aif(direction==75)\x0d\x0ax=zuobiao[0][head];y=zuobiao[0][head]-1;\x0d\x0aif(direction==77)\x0d\x0ax=zuobiao[0][head];y=zuobiao[1][head]+1;\x0d\x0aif(x==0||x==18||y==78||y==0)\x0d\x0areturn 0;\x0d\x0aif(qipan[x][y]!=’ ‘)\x0d\x0areturn 0;\x0d\x0aqipan[zuobiao[0][tail]][zuobiao[1][tail]]=’ ‘;\x0d\x0atail=(tail+1)%80;\x0d\x0aqipan[zuobiao[0][head]][zuobiao[1][head]]=’*’;\x0d\x0ahead=(head+1)%80;\x0d\x0azuobiao[0][head]=x;\x0d\x0azuobiao[1][head]=y;\x0d\x0aqipan[zuobiao[0][head]][zuobiao[1][head]]=’#’;\x0d\x0areturn 1;\x0d\x0a}

用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;

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;rowRowOfFrame;row++)

line(frame.left+row*BlockWidth,frame.top,frame.left+row*BlockWidth,frame.bottom);

for(int column=1;columnColumnOfFrame;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-xrandy==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(speed100)

speed=100;

ClearKeyBuf();

break;

case PAGEDOWN:speed=speed+100;

if(speed500)

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.xheady==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(xframe.left||x=frame.right||yframe.top||y=frame.bottom)//hit the wall

return 1;

Node *p=snake.head-next;

for(int i=snake.length-1;i3;i–,p=p-next)//hit itself

if(x==p-xy==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(xx0||xxline_num)

{ inputerror();

continue;

}

if(yy0||yyline_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=1m4) {xx0–;m++;}

while(n9xx0=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=1m4){yy0–;m++;}

while(n9yy0=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=1m4){ xx0–; a++; m++;} m=0;

while(yy0=line_numm4){ yy0++; b++; m++;}

if(a=b)

{

xx0=x-a; yy0=y+a;

}

else

{

xx0=x-b; yy0=y+b;

}

while(xx0=line_numyy0=0n9)

{

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=0yy0=0n9)

{

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=1m4) {xx0–;m++;}

while(n9xx0=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=1m4){yy0–;m++;}

while(n9yy0=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=1m4){ xx0–; a++; m++;} m=0;

while(yy0=line_numm4){ yy0++; b++; m++;}

if(a=b)

{

xx0=x-a; yy0=y+a;

}

else

{

xx0=x-b; yy0=y+b;

}

while(xx0=line_numyy0=0n9)

{

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=0yy0=0n9)

{

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語言編寫簡單小遊戲

愛玩是人的天性,而C語言是我們計算機專業都要學習的一門基礎 學科.一般來說,是比較枯燥的.那麼,我們能不能通過編一些小遊戲來提高它的趣味性呢?這樣學習程序設計,就不會是一件艱苦 ,枯燥的事,它變得象電腦遊戲一樣充滿好奇,富有樂趣. 1, 總是從Hello,world開始 學習編程的第一個程序,一般就是打印一個親切的詞語——”Hell o,world!”.讓我們來看看這個最簡單的C程序:#incolude /*把輸入輸出函數的頭文件包含進來*/int main(){printf(“Hello, world!”);/*在屏幕上輸出字符串”Hello,world!”*/return 0;/*退出main函數,並返回0*/} 下面我們發現幾個值得改進的地方,1,程序的運行結果一閃而過 .2,每執行這個程序一次都能看見上次運行留下的字符.3,我們 還希望屏幕輸出一個笑臉來歡迎我們. 讓我們來改進一下這個程序吧!1,在return語句的前面加一句:getch ();,表示按任意鍵結束.2,在printf語句前用clrscr函數清屏,要使用這個函數和getch函數,需要在程序開頭再包含頭文件conio.h.3,ASCII碼也有 許多非常好玩的字符,比如ASCII碼值為2的就是一個笑臉,我們可 以用printf(“%c”, 2)來輸出一個笑臉. 現在我們把Hello,world程序改成一個更好看的Hello,world了.下面讓我們開始做遊戲吧! 2, 心動的開始,一個運動中的笑臉 大家小時侯喜歡看動畫片嗎?哈哈,我猜你們都喜歡吧!下面就讓我們來做一個小動畫吧.在屏幕上顯示一個運動的小笑臉,而且當它到達屏幕的邊緣時會自動彈回來.先在程序定義一個在屏幕中運動的點的結構:struct move_point{ int x, y;/*該點的位置,包括x坐標和y坐標*/ int xv, yv;/*該點在x軸,y軸的速度*/};運動的原理是,先擦去物體先前的軌跡,讓物體按其速度移動一段距離,再畫出該物體.讓我們看到以下代碼:gotoxy(man.x, man.y);/*把光標移到指定的坐標*/printf(” “);/*輸出一個空格,把先前的字符擦去*/然後我們讓物體按其速度運動:man.x += man.xv;/*水平方向按x軸的速度運動*/man.y += man.yv;/*垂直方向按y軸的速度運動*/運動後還要判斷物體是否出界,如果出了界,就令物體反彈,即讓 它下一刻的速度等於現在的速度的相反數.最後打印出這個笑臉:gotoxy(man.x, man.y);printf(“%c\b”, 2); /*輸出ASCII碼值為2的”笑臉”字符*/怎麼樣?是不是很有趣呢?不過這個笑臉一直是自己運動,能不能 讓我們來控制它運動呢?不過這個程序沒有什麼目的,也沒有什麼判斷勝負的條件.下面我們就利用這個能控制它移動的笑臉來做一個更有趣的遊戲吧! 4, 在迷宮中探索 小時侯,我常在一些小人書和雜誌上看見一些迷宮的遊戲,非常喜歡玩,還常到一些書上找迷宮玩呢.好的,現在我們用C語言來編個迷宮的遊戲,重溫一下童年的樂趣. 首先,我們定義一個二維數組map,用它來保存迷宮的地圖,其中map[x][y] == ‘#’表示在(x,y)坐標上的點是牆壁.DrawMap函數在屏幕上輸出迷宮的地圖和一些歡迎信息.在main函數里,我們定義了”小人”man的坐標和”目的地”des的 坐標.在遊戲循環中,我們增加了一些用來判斷勝負的語句:if (man.x == des.x man.y == des.y) /*如果人的坐標等於目的地的坐標*/{ gotoxy(35, 3); printf(“Ok! You win!”); /*輸出勝利信息*/….}在判斷按鍵時,如果玩家按的是方向鍵,我們還要先判斷前面是不是有”牆壁”,如果有的話,就不能往前移動了.好的,我們在判斷按鍵的switch語句的各個分支加上了判斷語句,如下:if (map[…][…] == ‘#’) break;/*如果前面是牆壁,就不執行下去*/哇噻!真棒,我們做出了一個完整的遊戲了.當然你還可以通過修改二維數組map來修改迷宮的地圖,讓它更有挑戰性.不過,我們要設計一個更好玩的遊戲—— 5, 聰明的搬運工 大家一定玩過”搬運工”的遊戲吧!這是在電腦和電子字典上較流行的益智遊戲,讓我們動手做一個屬於自己的”搬運工”吧!程序依然用數組map來保存地圖,數組元素如果為空格則表示什麼也沒有,’b’表示箱子,’#’表示牆壁,’*’表示目的地,’i’表示箱子在目的地.我們以後每推一下箱子,不但要改變屏幕的顯示,也要改變map相應元素的值.遊戲的主循環依然是接受按鍵.當接收一個方向鍵,需要判斷小人前面一格的狀態,如果是空地或目的地,則人物可以直接移動;如果是牆壁,則不可移動;如果是箱子或目的地上的箱子,則需要繼續判斷箱子前面一格的狀態:如果前一格是空地或目的地,則人推箱子前進,否則不可移動.好的,我們在switch中增加了這些判斷語句.程序還有一個重要的功能就是判斷勝利.數組Des用來記錄全部目的地的坐標,我們每執行一步操作後,程序就要通過Des數組判斷這些目的地上是否都有箱子了.真棒啊!我們可以做遊戲了.而且是一個老少皆宜,趣味十足的遊戲呢!當然,我們可以通過修改map數組來製作不同的遊戲地圖,我們還可以相互分享好的遊戲地圖呢. 尾聲: 在C++等高級語言還沒出來的時候,很多應用程序也是C語言開發的.C語言在與硬件聯繫緊密的編程中,也佔有重要地位.其實我覺得學習編程,可以通過一些小遊戲,實用的例子來學習.象學習音樂的人,不是要等到把全部樂理學完後才演奏一個完整的曲子.而是剛開始學時就有一些簡單的曲子讓你演奏,讓你立刻就有成就感,讓你很快就能賣弄出來在別人面前表現自己了.通過編遊戲來學習編程,把學習變成遊戲,不失為學習計算機的一種好方法. 好了,編遊戲就這麼簡單,希望大家也嘗試用C語言或其他的語言來做幾個自己喜歡的小遊戲.

怎樣用C語言編寫一個小遊戲?

「貪吃蛇」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;   //吃了食物的標誌(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;iH;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;isnk.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==72dir!=2)dir=1;  //72表示按下了向上方向鍵

         if(key==80dir!=1)dir=2;  //80為向下

         if(key==75dir!=4)dir=3;  //75為向左

         if(key==77dir!=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.speed150) 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 );

}   //用來設定顏色的函數

c語言小遊戲代碼

最基礎的貪吃蛇的代碼

#includestdio.h

#includewindows.h//基本型態定義。支援型態定義函數。使用者界面函數 圖形裝置界面函數。

#includeconio.h //用戶通過按鍵盤產生的對應操作 (控制台)

#includestdlib.h

#includetime.h //日期和時間頭文件

#define LEN 30

#define WID 25

int Snake[LEN][WID] = {0}; //數組的元素代表蛇的各個部位

char Sna_Hea_Dir = ‘a’;//記錄蛇頭的移動方向

int Sna_Hea_X, Sna_Hea_Y;//記錄蛇頭的位置

int Snake_Len = 3;//記錄蛇的長度

clock_t Now_Time;//記錄當前時間,以便自動移動

int Wait_Time ;//記錄自動移動的時間間隔

int Eat_Apple = 1;//吃到蘋果表示為1

int Level ;

int All_Score = -1;

int Apple_Num = -1;

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //獲取標準輸出的句柄 windows.h

//句柄 :標誌應用程序中的不同對象和同類對象中的不同的實例 方便操控,

void gotoxy(int x, int y)//設置光標位置

{

COORD pos = {x,y}; //定義一個字符在控制台屏幕上的坐標POS

SetConsoleCursorPosition(hConsole, pos); //定位光標位置的函數windows.h

}

void Hide_Cursor()//隱藏光標 固定函數

{

CONSOLE_CURSOR_INFO cursor_info = {1, 0};

SetConsoleCursorInfo(hConsole, cursor_info);

}

void SetColor(int color)//設置顏色

{

SetConsoleTextAttribute(hConsole, color);

//是API設置字體顏色和背景色的函數 格式:SetConsoleTextAttribute(句柄,顏色);

}

void Print_Snake()//打印蛇頭和蛇的脖子和蛇尾

{

int iy, ix, color;

for(iy = 0; iy WID; ++iy)

for(ix = 0; ix LEN; ++ix)

{

if(Snake[ix][iy] == 1)//蛇頭

{

SetColor(0xf); //oxf代表分配的內存地址 setcolor:34行自定義設置顏色的函數

gotoxy(ix*2, iy);

printf(“※”);

}

if(Snake[ix][iy] == 2)//蛇的脖子

{

color = rand()%15 + 1; //rand()函數是產生隨機數的一個隨機函數。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()//擦除貪吃蛇

{

int iy, ix;

for(iy = 0; iy WID; ++iy)

for(ix = 0; ix LEN; ++ix)

{

gotoxy(ix*2, iy);

if(Snake[ix][iy] == Snake_Len)

printf(” “);

}

}

void Rand_Apple()//隨機產生蘋果

{

int ix, iy;

do

{

ix = rand() % LEN;

iy = rand() % WID;

}while(Snake[ix][iy]);

Snake[ix][iy] = -1;

gotoxy(ix*2, iy);

printf(“⊙”);

Eat_Apple = 0;

}

void Game_Over()//蛇死掉了

{

gotoxy(30, 10);

printf(“Game Over”);

Sleep(3000);

system(“pause nul”);

exit(0);

}

void Move_Snake()//讓蛇動起來

{

int ix, iy;

for(ix = 0; ix LEN; ++ix)//先標記蛇頭

for(iy = 0; iy WID; ++iy)

if(Snake[ix][iy] == 1)

{

switch(Sna_Hea_Dir)//根據新的蛇頭方向標誌蛇頭

{

case ‘w’:

if(iy == 0)

Game_Over();

else

Sna_Hea_Y = iy – 1;

Sna_Hea_X = ix;

break;

case ‘s’:

if(iy == (WID -1))

Game_Over();

else

Sna_Hea_Y = iy + 1;

Sna_Hea_X = ix;

break;

case ‘a’:

if(ix == 0)

Game_Over();

else

Sna_Hea_X = ix – 1;

Sna_Hea_Y = iy;

break;

case ‘d’:

if(ix == (LEN – 1))

Game_Over();

else

Sna_Hea_X = ix + 1;

Sna_Hea_Y = iy;

break;

default:

break;

}

}

if(Snake[Sna_Hea_X][Sna_Hea_Y]!=1Snake[Sna_Hea_X][Sna_Hea_Y]!=0Snake[Sna_Hea_X][Sna_Hea_Y]!=-1)

Game_Over();

if(Snake[Sna_Hea_X][Sna_Hea_Y] 0)//吃到蘋果

{

++Snake_Len;

Eat_Apple = 1;

}

for(ix = 0; ix LEN; ++ix)//處理蛇尾

for(iy = 0; iy WID; ++iy)

{

if(Snake[ix][iy] 0)

{

if(Snake[ix][iy] != Snake_Len)

Snake[ix][iy] += 1;

else

Snake[ix][iy] = 0;

}

}

Snake[Sna_Hea_X][Sna_Hea_Y] = 1;//處理蛇頭

}

void Get_Input()//控制蛇的移動方向

{

if(kbhit())

{

switch(getch())

{

case 87:

Sna_Hea_Dir = ‘w’;

break;

case 83:

Sna_Hea_Dir = ‘s’;

break;

case 65:

Sna_Hea_Dir = ‘a’;

break;

case 68:

Sna_Hea_Dir = ‘d’;

break;

default:

break;

}

}

if(clock() – Now_Time = Wait_Time)//蛇到時間自動行走

{

Clear_Snake();

Move_Snake();

Print_Snake();

Now_Time = clock();

}

}

void Init()//初始化

{

system(“title 貪吃毛毛蛇”);

system(“mode con: cols=80 lines=25”);

Hide_Cursor();

gotoxy(61, 4);

printf(“You Score:”);

gotoxy(61, 6);

printf(“You Level:”);

gotoxy(61, 8);

printf(“The Lenght:”);

gotoxy(61, 10);

printf(“The Speed:”);

gotoxy(61, 12);

printf(“Apple Num:”);

int i;

for(i = 0; i Snake_Len; ++i)//生成蛇

Snake[10+i][15] = i+1;

int iy, ix;//打印蛇

for(iy = 0; iy WID; ++iy)

for(ix = 0; ix LEN; ++ix)

{

if(Snake[ix][iy])

{

SetColor(Snake[ix][iy]);

gotoxy(ix*2, iy);

printf(“■”);

}

}

}

void Pri_News()//打印信息

{

SetColor(0xe);

gotoxy(73,4);

All_Score += Level;

printf(“%3d”, All_Score);

gotoxy(73, 6);

printf(“%3d”, Level);

gotoxy(73, 8);

printf(“%3d”,Snake_Len);

gotoxy(73, 10);

printf(“0.%3ds”, Wait_Time/10);

gotoxy(73, 12);

printf(“%d”, Apple_Num);

}

void Lev_Sys()//等級系統

{

if(((Apple_Num-1) / 10) == Level)

{

++Level;

if(Wait_Time 50)

Wait_Time -= 50;

else

if(Wait_Time 10)

Wait_Time -= 10;

else

Wait_Time -= 1;

}

}

int main(void)

{

Init();

srand((unsigned)time(NULL));//設置隨機數的種子

Now_Time = clock();

int speed1=1000,speed2,a;

printf(“\n”);

printf(“請輸入你想要的速度\n”);

scanf(“%d”,speed2);

Level=1;

Wait_Time=speed1-speed2;

printf(“請輸入你想要的蘋果數\n”);

scanf(“%d”,a);

while(a–)

Rand_Apple();

while(1)

{

if(Eat_Apple)

{

++Apple_Num;

Rand_Apple();

Lev_Sys();

Pri_News();

}

Get_Input();

Sleep(10);

}

return 0;

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/307198.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2025-01-02 18:06
下一篇 2025-01-02 18:06

相關推薦

  • Python周杰倫代碼用法介紹

    本文將從多個方面對Python周杰倫代碼進行詳細的闡述。 一、代碼介紹 from urllib.request import urlopen from bs4 import Bea…

    編程 2025-04-29
  • Python字符串寬度不限制怎麼打代碼

    本文將為大家詳細介紹Python字符串寬度不限制時如何打代碼的幾個方面。 一、保持代碼風格的統一 在Python字符串寬度不限制的情況下,我們可以寫出很長很長的一行代碼。但是,為了…

    編程 2025-04-29
  • Python基礎代碼用法介紹

    本文將從多個方面對Python基礎代碼進行解析和詳細闡述,力求讓讀者深刻理解Python基礎代碼。通過本文的學習,相信大家對Python的學習和應用會更加輕鬆和高效。 一、變量和數…

    編程 2025-04-29
  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 倉庫管理系統代碼設計Python

    這篇文章將詳細探討如何設計一個基於Python的倉庫管理系統。 一、基本需求 在着手設計之前,我們首先需要確定倉庫管理系統的基本需求。 我們可以將需求分為以下幾個方面: 1、庫存管…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 寫代碼新手教程

    本文將從語言選擇、學習方法、編碼規範以及常見問題解答等多個方面,為編程新手提供實用、簡明的教程。 一、語言選擇 作為編程新手,選擇一門編程語言是很關鍵的一步。以下是幾個有代表性的編…

    編程 2025-04-29
  • Python實現簡易心形代碼

    在這個文章中,我們將會介紹如何用Python語言編寫一個非常簡單的代碼來生成一個心形圖案。我們將會從安裝Python開始介紹,逐步深入了解如何實現這一任務。 一、安裝Python …

    編程 2025-04-29

發表回復

登錄後才能評論