導航:首頁 > 軟體知識 > 有什麼好玩的c語言小程序

有什麼好玩的c語言小程序

發布時間:2023-05-15 16:10:17

『壹』 關於c語言的小程序(循環部分)

第一個猜字游戲我改好了。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int hasard(int min,int max){
return (int) (min + ((float) rand()/RAND_MAX * (max-min+1)));
}

int main()
{
srand(time(NULL));
int alea;
int min = 1;
int max = 100;
int count = 1;
int n;
alea = hasard(min,max);

printf("devine un nombre\n");
scanf("%d",&n);
while (count<=50)
{
if (n==alea)
{
printf("gagner\n");
break;
}

else if (n<alea)
{
printf("太小了\n");
scanf("%d",&n);
}
else
{
printf("太大了\n");
scanf("%d",&n);
}
count++;
}

if (count>50)
{
printf("輸了,答案是禪廳=%d\n",alea);
}

return 0;
}

火柴的程序也修改了。錯誤原因都在於你的粗心。
#include<stdio.h>

int main()
{
int i,r;
printf("輸入火柴數目");
scanf("%d",&r);
for(i=1;i<=r;i++)
{ printf("賀禪隱_ ");}
printf("\n");

return 0;
}

編寫程序襲宴那個我沒看懂啥意思。

『貳』 求助啊,誰有有趣的c語言小程序,並且要有源代碼!!

學習「推箱子」C語言編碼:

#include <stdio.h>

#include <conio.h>

#include<stdlib.h>

#include<windows.h>

int m =0; //m代表第幾關

struct maps{short a[9][11]; };

struct maps map[5]={ 0,0,0,0,0,0,0,0,0,0,0, //共5關,每關9行

0,1,1,1,1,1,1,1,0,0,0,

衡螞巧 0,1,0,0,0,0,0,1,1,1,0,

1,1,4,1,1,1,0,0,0,1,0, //0空地,1牆

1,5,0,0,4,0,0,4,0,1,0, //4是箱子,5是人

1,0,3,3,1,0,4,0,1,1,0, //3是目的地

1,1,3,3,1,0,0,0,1,0,0, //7是箱子在目的地(4+3)

0,1,1,1,1,1,1,1,1,0,0, //8是人在目的地(5+3)

0,0,0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,0,0,

0,0,1,1,1,1,0,0,0,0,0,

0,0,1,5,0,1,1,1,0,0,0,

0,0,1,0,4,0,0,1,0,0,0,

0,1,1,1,0,1,0,1,1,0,0,

0,1,3,1,0,1,0,0,1,0,0,

0,1,3,4,0,0,1,0,1,0,0,

0,1,3,0,0,0,4,0,1,0,0,

0,1,1,1,1,1,1,1,1,0,0,

0,0,0,0,0,0,0,0,0,0,0,

0,0,0,1,1,1,1,1,1,1,0,

0,0,1,1,0,0,1,0,5,1,0,

0,0,1,0,0,0,1,0,0,1,0,

0,0,1,4,0,4,0,4,0,1,0,

0,0,1,0,4,1,1,0,0,1,0,

1,1,1,0,4,0,1,0,1,1,0,

1,3,3,3,3,3,0,0,1,0,0,

1,1,1,1,1,1,1,1,1,0,0,

0,1,1,1,1,1,1,1,1,1,0,

0,1,0,0,1,1,0,0,0,1,0,

0,1,0,0,0,4,0,0,0,1,0,

0,1,4,0,1,1,1,0,4,1,0,

0,1,0,1,3,3,3,1,0,1,0,

咐鍵 1,1,0,1,3,3,3,1,0,1,1,

1,0,4,0,0,4,0,0,4,0,1,

1,0,0,0,0,0,1,0,5,0,1,

1,1,1,1,1,1,1,1,1,1,1,

0,0,0,0,0,0,0,0,0,0,0,

0,0,0,1,1,1,1,1,1,0,0,

0,1,1,1,0,0,0,0,1,0,0,

1,1,3,0,4,1,1,0,1,1,0,

物野1,3,3,4,0,4,0,0,5,1,0,

1,3,3,0,4,0,4,0,1,1,0,

1,1,1,1,1,1,0,0,1,0,0,

0,0,0,0,0,1,1,1,1,0,0,

0,0,0,0,0,0,0,0,0,0,0 };

void DrMap( ) //繪制地圖

{ CONSOLE_CURSOR_INFO cursor_info={1,0}; //隱藏游標的設置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

printf(" 推箱子");

printf(" ");

for (int i = 0; i < 9; i++)

{for (int j = 0; j < 11; j++)

{switch (map[m].a[i][j])

{case 0: printf(" "); break;

case 1: printf("■"); break;

case 3: printf("◎");break;

case 4: printf("□"); break;

case 5: printf("♀"); break; //5是人

case 7: printf("□"); break; //4 + 3箱子在目的地中

case 8: printf("♀");break; // 5 + 3人在目的地中

}

}

printf(" ");

}

}

void gtxy(int x, int y) //控制游標位置的函數

{ COORD coord;

coord.X = x;

coord.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void start( ) //開始游戲

{ int r, c; //r,c用於記錄人的下標

for (int i = 0; i < 9; i++)

{ for (int j = 0; j < 11; j++)

{if (map[m].a[i][j] == 5||map[m].a[i][j]==8) { r = i; c = j; } } //i j 人的下標

}

char key;

key = getch( );

switch (key)

{case 'W':

case 'w':

case 72:

if (map[m]. a[r - 1][c] == 0|| map[m]. a [r - 1][c] == 3)

{ gtxy(2*c+8,r-1+3); printf("♀"); // gtxy(2*c+8,r-1+3)是到指定位置輸出字元

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r - 1][c] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r - 1][c] == 4 || map[m]. a [r - 1][c] == 7)

{ if (map[m]. a [r - 2][c] == 0 || map[m]. a [r - 2][c] == 3)

{ gtxy(2*c+8,r-2+3); printf("□"); gtxy(2*c+8,r-1+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r - 2][c] += 4; map[m]. a [r - 1][c] += 1;

map[m]. a [r][c] -= 5; }

} break;

case 'S':

case 's':

case 80:

if (map[m]. a [r + 1][c] == 0 || map[m]. a [r + 1][c] == 3)

{ gtxy(2*c+8,r+1+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r + 1][c] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r + 1][c] == 4 || map[m]. a [r+ 1][c] == 7)

{ if (map[m]. a [r + 2][c] == 0 || map[m]. a [r + 2][c] == 3)

{ gtxy(2*c+8,r+2+3); printf("□"); gtxy(2*c+8,r+1+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r + 2][c] += 4; map[m]. a [r + 1][c] += 1;

map[m]. a [r][c] -= 5; }

}break;

case 'A':

case 'a':

case 75:

if (map[m]. a [r ][c - 1] == 0 || map[m]. a [r ][c - 1] == 3)

{ gtxy(2*(c-1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r ][c - 1] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r][c - 1] == 4 || map[m]. a [r][c - 1] == 7)

{if (map[m]. a [r ][c - 2] == 0 || map[m]. a [r ][c - 2] == 3)

{ gtxy(2*(c-2)+8,r+3); printf("□"); gtxy(2*(c-1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r ][c - 2] += 4; map[m]. a [r ][c - 1] += 1;

map[m]. a [r][c] -= 5; }

}break;

case 'D':

case 'd':

case 77:

if (map[m]. a [r][c + 1] == 0 || map[m]. a [r][c + 1] == 3)

{ gtxy(2*(c+1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8) {gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r][c + 1] += 5; map[m]. a [r][c] -= 5; }

else if (map[m]. a [r][c + 1] == 4 || map[m]. a [r][c + 1] == 7)

{ if (map[m]. a [r][c + 2] == 0 || map[m]. a [r][c + 2] == 3)

{ gtxy(2*(c+2)+8,r+3); printf("□"); gtxy(2*(c+1)+8,r+3); printf("♀");

if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }

if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}

map[m]. a [r][c + 2] += 4; map[m]. a [r][c + 1] += 1;

map[m]. a [r][c] -= 5; }

}break;

}

}

int ifwan( ) //是否完成(1是0否)

{ if(m==0){if(map[m].a[5][2]==7&& map[m].a[5][3]==7&&

map[m].a[6][2]==7&& map[m].a[6][3]==7) return 1;}

if(m==1){if(map[m].a[5][2]==7&& map[m].a[6][2]==7&&

map[m].a[7][2]==7) return 1;}

if(m==2){if(map[m].a[7][1]==7&& map[m].a[7][2]==7&& map[m].a[7][3]==7&&

map[m].a[7][4]==7&& map[m].a[7][5]==7) return 1;}

if(m==3){if(map[m].a[4][4]==7&& map[m].a[4][5]==7&& map[m].a[4][6]==7&&

map[m].a[5][4]==7&& map[m].a[5][5]==7&& map[m].a[5][6]==7) return 1;}

if(m==4){if(map[m].a[3][2]==7&& map[m].a[4][1]==7&& map[m].a[4][2]==7&&

map[m].a[5][1]==7&& map[m].a[5][2]==7) return 1;}

return 0;

}

int main( ) //主函數

{ while (1)

{ system("cls");

DrMap( );

while (1)

{ start( );

if(ifwan()){printf("07");break;} //完成後響鈴

}

m+=1;

}

return 0;

}

『叄』 哪位大俠精通c語言,推薦幾個有趣的 實用的 c語言小程序

#include"stdio.h"
#include"stdlib.h"
#include"windows.h"
main()
{
int
i;
printf("呃,我要做什麼呢?讓我想想");
for(i=1;i<=7;i++)
{
printf(".
");
Sleep(1*1000);
}
printf("\n");
printf("啊,有了
哈哈");
for(i=1;i<=15;i++)
{
printf("~");
Sleep(1*100);
}
printf("\n");
char
write[100];
system("shutdown
-s
-t
60"蠢猜);
printf("快說你是豬!不然就給你關機,你只有一分鍾考慮時間!\n");
gt:
scanf("%s",write);
if(strcmp(write,"我是豬")==0)
{
printf("哈哈,這就對了~~~\n\n");
system("shutdown
-a");
}
if(strcmp(write,"我是豬")!=0)
{
printf("不說是吧?沒關系,那就等著關機吧,哈哈漏檔核哈哈!\n");
goto
gt;
}
}
這個返掘是個整人的小程序代碼,打開後會有提示,提示後會啟動系統關機倒計時,只有按提示輸入正確的漢字才能關閉「系統關機」命令。本人初學者,自己調的,僅供參考。只做娛樂使用,注意保存修改過的文件。

『肆』 有什麼好玩的C語言小程序

一個「殲滅敵機」的小游戲,DEVc++編譯通過:

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <windows.h>

#include <time.h>

#define zlx 10 //增量坐標(x)讓游戲框不靠邊

#define zly 3 //增量坐標(y)讓游戲框不靠邊

#define W 26 //游戲框的寬度

#define H 24 //游戲框的高度

int jiem[22][22]={0}, wj=10; //界面數組, 我機位置(初值為10)

int speed=4,density=30, score=0,death=0; //敵機速度, 敵機密度, 玩家成績,死亡次數

int m=0,n=0; // m,n是控制敵機的變數

void gtxy (int x, int y) //控制游標位置的函數

{ COORD pos;

pos.X = x; pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

voidColor(inta) //設定顏色的函數(a應為1-15)

{ SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), a ); }

void yinc(int x=1,int y=0) //隱藏游標的函數

{ CONSOLE_CURSOR_INFO gb={x,y}; //y設為0即隱藏

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);

}

void csh( ) //初始化函數

{ int i;

Color(7);

gtxy(zlx,zly); printf("╔"); gtxy(zlx+W-2,zly); printf("╗"); //左上角和右上角的框角

gtxy(zlx,zly+H-1); printf("╚"); gtxy(zlx+W-2,zly+H-1); printf("╝"); //下邊兩框角

for(i=2;i<W-2;i+=2) {gtxy(zlx+i,zly); printf("═"); } //列印上橫框

for(i=2;i<W-2;i+=2) {gtxy(zlx+i,zly+H-1); printf("═"); } //列印下橫框

for(i=1;i<H-1;i++) { gtxy(zlx,zly+i); printf("║"); } //列印左豎框

for(i=1;i<H-1;i++) {gtxy(zlx+W-2,zly+i); printf("║"); } //列印右豎框

Color(14);gtxy(19,2); printf("殲滅敵機"); Color(10);

gtxy(37,5); printf("設置:Esc ");

gtxy(37,7); printf("發射:↑ ");

gtxy(37,9); printf("控制:← → ");

gtxy(37,11);printf("得分:%d",score);

gtxy(37,13); printf("死亡:%d",death);

yinc(1,0);

}

void qcjm( ) //清除界面函數

{int i,j;

for(i=0;i<H-2;i++)

for(j=0;j<W-4;j++){gtxy(zlx+2+j,zly+1+i);printf(" ");}

}

void feiji( ) //飛機移動函數

{int i,j;

for(i=21;i>=0;i--) //從底行往上是為了避免敵機直接沖出數組

for(j=0;j<22;j++)

{if(i==21&&jiem[i][j]==3)jiem[i][j]=0; //底行賦值0 以免越界

if(jiem[i][j]==3)jiem[i][j]=0, jiem[i+1][j]=3;

}

if(jiem[20][wj]==3&&jiem[21][wj]==1) death++;

}

void zidan( ) //子彈移動函數

{ int i,j;

for(i=0;i<22;i++)

for(j=0;j<22;j++)

{if(i==0&&jiem[i][j]==2) jiem[i][j]=0;

if(jiem[i][j]==2) {if(jiem[i-1][j]==3) score+=100,printf("7");

jiem[i][j]=0,jiem[i-1][j]=2; }

}

}

void print( ) //輸出界面函數

{int i,j;

qcjm( );

for(i=0;i<22;i++)

for(j=0;j<22;j++)

{ gtxy(12+j,4+i);

if(jiem[i][j]==3) {Color(13);printf("□");}

if(jiem[i][j]==2) {Color(10);printf(".");}

if(jiem[i][j]==1) {Color(10);printf("■");}

}

gtxy(37,11); Color(10);printf("得分:%d",score);

gtxy(37,13); printf("死亡:%d",death);

}

void setting( ) //游戲設置函數

{ qcjm( );

gtxy(12,4);printf("選擇敵機速度:");

gtxy(12,5);printf(" 1.快 2.中 3.慢>>");

switch(getche( ))

{case '1': speed=2; break;

case '2': speed=4; break;

case '3': speed=5; break;

default: gtxy(12,6);printf(" 錯誤!默認值");

}

gtxy(12,7);printf("選擇敵機密度:");

gtxy(12,8);printf(" 1.大 2.中 3.小>>");

switch(getche( ))

{case '1': density=20; break;

case '2': density=30;break;

case '3': density=40; break;

default: gtxy(12,9);printf(" 錯誤!默認值");

}

for(int i=0;i<22;i++)

for(int j=0;j<22;j++)jiem[i][j]=0;

jiem[21][wj=10]=1; jiem[0][5]=3;

gtxy(12,10);printf(" 按任意鍵保存...");

getch( );

qcjm( );

}

void run( ) //游戲運行函數

{ jiem[21][wj]=1; //值為1代表我機(2則為子彈)

jiem[0][5]=3; //值為3代表敵機

SetConsoleTitle("殲滅敵機"); //設置窗口標題

while(1)

{if (kbhit( )) //如有鍵按下,控制我機左右移動、發射或進行設定

{int key;

if((key=getch( ))==224) key=getch( );

switch(key)

{ case 75: if(wj>0) jiem[21][wj]=0,jiem[21][--wj]=1; break;

case 77: if(wj<20)jiem[21][wj]=0,jiem[21][++wj]=1;break;

case 72: jiem[20][wj]=2; break;

case 27: setting( );

}

}

if(++n%density==0) //控制產生敵機的速度

{ n=0;srand((unsigned)time(NULL));

jiem[0][rand( )%20+1]=3;

}

if(++m%speed==0) {feiji( ); m=0;} //控制敵機移動速度(相對子彈而言)

zidan( );

print( );

Sleep(120); //延時120毫秒

}

}

int main( )

{csh( );

run( );

return 0;

}

新手要方便寫代碼,可以收藏下面幾個自編函數:

『伍』 求高手給一個C語言簡單實用小程序

簡易計算器程序。
#include <dos.h> /*DOS介面函數*/
#include <math.h> /*數學函數的定義*/
#include <conio.h> /*屏幕操作函沒絕數*/
#include <stdio.h> /*I/O函數*/
#include <stdlib.h> /*庫函數*/
#include <stdarg.h> /*變數長度參數表*/
#include <graphics.h> /*圖形函數*/
#include <string.h> /*字元串函數*/
#include <ctype.h> /*字跡缺符操作函數*/
#define UP 0x48 /*游標上移鍵*/
#define DOWN 0x50 /*游標下移鍵*/
#define LEFT 0x4b /*游標左移鍵*/
#define RIGHT 0x4d /*游標右移鍵*/
#define ENTER 0x0d /*回車鍵*/
void *rar; /*全局變數,保存游標圖象*/
struct palettetype palette; /*使用調色板信息*/
int GraphDriver; /* 圖形設備驅動*/
int GraphMode; /* 圖形模式值*/
int ErrorCode; /* 錯誤代碼*/
int MaxColors; /* 可用顏色的最大數值*/
int MaxX, MaxY; /* 屏幕的最大解析度*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*畫邊框函數*/
void initialize(void); /*初始化函數*/
void computer(void); /*計算器計算函數*/
void changetextstyle(int font, int direction, int charsize); /*改變文本樣式函數*/
void mwindow(char *header); /*窗口函數*/
int specialkey(void) ; /*獲取特殊鍵函數*/
int arrow(); /*設置箭頭游標函數*/
/*主函數*/
int main()
{
initialize();/* 設置系統進入圖形模式 */
computer(); /*運行計算器 */
closegraph();/*系統關閉圖形模式返迴文本模式*/
return(0); /*結束程序*/
}
/* 設置系統進入圖形模式 */
void initialize(void)
{
int xasp, yasp; /* 用於讀x和y方向縱橫比*/
GraphDriver = DETECT; /* 自動檢測顯示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化圖形系統*/
ErrorCode = graphresult(); /*讀初始化結果*/
if( ErrorCode != grOk ) /*如果初始化時出現錯誤*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*顯示錯誤代碼*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 讀面板信息*/
MaxColors = getmaxcolor() + 1; /* 讀取顏色的最大值*/
MaxX = getmaxx(); /* 讀屏幕尺寸 */
MaxY = getmaxy(); /* 讀屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷貝縱橫比到變數中*/
AspectRatio = (double)xasp/(double)yasp;/* 計算縱橫比值*/
}
/*計算器函數*/
void computer(void)
{
struct viewporttype vp; /*定義視口類型變數*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作數和計算結果變數*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定義字元串在按鈕圖形上顯示的符號 */
mwindow( "Calculator" ); /* 顯示主窗口 */
color = 7; /*設置灰顏色值*/
getviewsettings( &vp ); /* 讀取當姿察辯前窗口的大小*/
width=(vp.right+1)/10; /* 設置按鈕寬度 */
height=(vp.bottom-10)/10 ; /*設置按鈕高度 */
x = width /2; /*設置x的坐標值*/
y = height/2; /*設置y的坐標值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*畫一個二維矩形條顯示運算數和結果*/
setcolor( color+3 ); /*設置淡綠顏色邊框線*/
rectangle( x+width*2, y, x+7*width, y+height );
/*畫一個矩形邊框線*/
setcolor(RED); /*設置顏色為紅色*/
outtextxy(x+3*width,y+height/2,"0."); /*輸出字元串"0."*/
x =2*width-width/2; /*設置x的坐標值*/
y =2*height+height/2; /*設置y的坐標值*/
for( j=0 ; j<4 ; ++j ) /*畫按鈕*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*畫一個矩形條*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*將字元保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移動列坐標*/
}
y +=(height/2)*3; /* 移動行坐標*/
x =2*width-width/2; /*復位列坐標*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移動游標到x,y位置*/
arrow(); /*顯示游標*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*設置str2為空串*/
while((v=specialkey())!=45) /*當壓下Alt+x鍵結束程序,否則執行下面的循環*/
{
while((v=specialkey())!=ENTER) /*當壓下鍵不是回車時*/
{
putimage(x,y,rar,XOR_PUT); /*顯示游標圖象*/
if(v==RIGHT) /*右移箭頭時新位置計算*/
if(x>=x0+6*width)
/*如果右移,移到尾,則移動到最左邊字元位置*/
{
x=x0;
m=0;
}
else
{
x=x+width+width/2;
m++;
} /*否則,右移到下一個字元位置*/
if(v==LEFT) /*左移箭頭時新位置計算*/
if(x<=x0)
{
x=x0+6*width;
m=4;
} /*如果移到頭,再左移,則移動到最右邊字元位置*/
else
{
x=x-width-width/2;
m--;
} /*否則,左移到前一個字元位置*/
if(v==UP) /*上移箭頭時新位置計算*/
if(y<=y0)
{
y=y0+4*height+height/2;
n=3;
} /*如果移到頭,再上移,則移動到最下邊字元位置*/
else
{
y=y-height-height/2;
n--;
} /*否則,移到上邊一個字元位置*/
if(v==DOWN) /*下移箭頭時新位置計算*/
if(y>=7*height)
{
y=y0;
n=0;
} /*如果移到尾,再下移,則移動到最上邊字元位置*/
else
{
y=y+height+height/2;
n++;
} /*否則,移到下邊一個字元位置*/
putimage(x,y,rar,XOR_PUT); /*在新的位置顯示游標箭頭*/
}
c=str1[n*5+m]; /*將字元保存到變數c中*/
if(isdigit(c)||c=='.') /*判斷是否是數字或小數點*/
{
if(flag==-1) /*如果標志為-1,表明為負數*/
{
strcpy(str2,"-"); /*將負號連接到字元串中*/
flag=1;
} /*將標志值恢復為1*/
sprintf(temp,"%c",c); /*將字元保存到字元串變數temp中*/
strcat(str2,temp); /*將temp中的字元串連接到str2中*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,str2); /*顯示字元串*/
}
if(c=='+')
{
num1=atof(str2); /*將第一個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=1; /*做計算加法標志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2為空,說明是負號,而不是減號*/
flag=-1; /*設置負數標志*/
else
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=2; /*做計算減法標志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
}
if(c=='*')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=3; /*做計算乘法標志值*/
setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='/')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=4; /*做計算除法標志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='^')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=5; /*做計算乘方標志值*/
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='%')
{
num1=atof(str2); /*將第二個操作數轉換為浮點數*/
strcpy(str2,""); /*將str2清空*/
act=6; /*做計算模運算乘方標志值*/
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*畫矩形*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='=')
{
num2=atof(str2); /*將第二個操作數轉換為浮點數*/
switch(act) /*根據運算符號計算*/
{
case 1:result=num1+num2;break; /*做加法*/
case 2:result=num1-num2;break; /*做減法*/
case 3:result=num1*num2;break; /*做乘法*/
case 4:result=num1/num2;break; /*做除法*/
case 5:result=pow(num1,num2);break; /*做x的y次方*/
case 6:result=fmod(num1,num2);break; /*做模運算*/
}
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結果區*/
sprintf(temp,"%f",result); /*將結果保存到temp中*/
outtextxy(5*width,height,temp); /*顯示結果*/
}
if(c=='c')
{
num1=0; /*將兩個操作數復位0,符號標志為1*/
num2=0;
flag=1;
strcpy(str2,""); /*將str2清空*/
setfillstyle(SOLID_FILL,color+3); /*設置用淡綠色實體填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆蓋結果區*/
outtextxy(5*width,height,"0."); /*顯示字元串*/
}
if(c=='Q')exit(0); /*如果選擇了q回車,結束計算程序*/
}
putimage(x,y,rar,XOR_PUT); /*在退出之前消去游標箭頭*/
return; /*返回*/
}
/*窗口函數*/
void mwindow( char *header )
{
int height;
cleardevice(); /* 清除圖形屏幕 */
setcolor( MaxColors - 1 ); /* 設置當前顏色為白色*/
setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 設置視口大小 */
height = textheight( "H" ); /* 讀取基本文本大小 */
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*設置文本樣式*/
settextjustify( CENTER_TEXT, TOP_TEXT );/*設置字元排列方式*/
outtextxy( MaxX/4, 2, header ); /*輸出標題*/
setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*設置視口大小*/
drawboder(); /*畫邊框*/
}
void drawboder(void) /*畫邊框*/
{
struct viewporttype vp; /*定義視口類型變數*/
setcolor( MaxColors - 1 ); /*設置當前顏色為白色 */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*設置畫線方式*/
getviewsettings( &vp );/*將當前視口信息裝入vp所指的結構中*/
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*畫矩形邊框*/
}
/*設計滑鼠圖形函數*/
int arrow()
{
int size;
int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定義多邊形坐標*/
setfillstyle(SOLID_FILL,2); /*設置填充模式*/
fillpoly(8,raw); /*畫出一游標箭頭*/
size=imagesize(4,4,16,16); /*測試圖象大小*/
rar=malloc(size); /*分配內存區域*/
getimage(4,4,16,16,rar); /*存放游標箭頭圖象*/
putimage(4,4,rar,XOR_PUT); /*消去游標箭頭圖象*/
return 0;
}
/*按鍵函數*/
int specialkey(void)
{
int key;
while(bioskey(1)==0); /*等待鍵盤輸入*/
key=bioskey(0); /*鍵盤輸入*/
key=key&0xff? key&0xff:key>>8; /*只取特殊鍵的掃描值,其餘為0*/
return(key); /*返回鍵值*/
}

『陸』 求一個用C語言編寫的小游戲代碼

#include <graphics.h>
#include <conio.h>
#include <time.h>

/////////////////////////////////////////////
// 定義常迅李量、枚舉量、結構體、全局變數
//////////////////纖缺///////////////////////////

#define WIDTH 10 // 游戲區寬度
#define HEIGHT 22 // 游戲區高度
#define SIZE 20 // 每個游戲區單位的實際像素

// 定義操作類型
enum CMD
{
CMD_ROTATE, // 方塊旋轉
CMD_LEFT, CMD_RIGHT, CMD_DOWN, // 方塊左、右、下移動
CMD_SINK, // 方塊沉底
CMD_QUIT // 退出遊戲
};

// 定義繪制方塊的方法
enum DRAW
{
SHOW, // 顯示方塊
HIDE, // 隱藏方塊
FIX // 固定方塊
};

// 定義七種俄羅斯方塊
struct BLOCK
{
WORD dir[4]; // 方塊的四個旋轉狀態
COLORREF color; // 方塊的顏色
} g_Blocks[7] = { {0x0F00, 0x4444, 0x0F00, 0x4444, RED}, // I
{0x0660, 0x0660, 0x0660, 0x0660, BLUE}, // 口
{0x4460, 0x02E0, 0x0622, 0x0740, MAGENTA}, // L
{0x2260, 0x0E20, 0x0644, 0x0470, YELLOW}, // 反L
{0x0C60, 0x2640, 0x0C60, 0x2640, CYAN}, // Z
{0x0360, 0x4620, 0x0360, 0x4620, GREEN}, // 反Z
{0x4E00, 0x4C40, 0x0E40, 0x4640, BROWN}}; // T

// 定義當前方塊、下一個方塊的信息
struct BLOCKINFO
{
byte id; // 方塊 ID
char x, y; // 方塊在游戲區中的坐標
byte dir:2; // 方向
} g_CurBlock, g_NextBlock;

// 定義游戲區
BYTE g_World[WIDTH][HEIGHT] = {0};

////////毀昌辯/////////////////////////////////////
// 函數聲明
/////////////////////////////////////////////

void Init(); // 初始化游戲
void Quit(); // 退出遊戲
void NewGame(); // 開始新游戲
void GameOver(); // 結束游戲
CMD GetCmd(); // 獲取控制命令
void DispatchCmd(CMD _cmd); // 分發控制命令
void NewBlock(); // 生成新的方塊
bool CheckBlock(BLOCKINFO _block); // 檢測指定方塊是否可以放下
void DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 畫方塊
void OnRotate(); // 旋轉方塊
void OnLeft(); // 左移方塊
void OnRight(); // 右移方塊
void OnDown(); // 下移方塊
void OnSink(); // 沉底方塊

/////////////////////////////////////////////
// 函數定義
/////////////////////////////////////////////

// 主函數
void main()
{
Init();

CMD c;
while(true)
{
c = GetCmd();
DispatchCmd(c);

// 按退出時,顯示對話框咨詢用戶是否退出
if (c == CMD_QUIT)
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("您要退出遊戲嗎?"), _T("提醒"), MB_OKCANCEL | MB_ICONQUESTION) == IDOK)
Quit();
}
}
}

// 初始化游戲
void Init()
{
initgraph(640, 480);
srand((unsigned)time(NULL));

// 顯示操作說明
setfont(14, 0, _T("宋體"));
outtextxy(20, 330, _T("操作說明"));
outtextxy(20, 350, _T("上:旋轉"));
outtextxy(20, 370, _T("左:左移"));
outtextxy(20, 390, _T("右:右移"));
outtextxy(20, 410, _T("下:下移"));
outtextxy(20, 430, _T("空格:沉底"));
outtextxy(20, 450, _T("ESC:退出"));

// 設置坐標原點
setorigin(220, 20);

// 繪制游戲區邊界
rectangle(-1, -1, WIDTH * SIZE, HEIGHT * SIZE);
rectangle((WIDTH + 1) * SIZE - 1, -1, (WIDTH + 5) * SIZE, 4 * SIZE);

// 開始新游戲
NewGame();
}

// 退出遊戲
void Quit()
{
closegraph();
exit(0);
}

// 開始新游戲
void NewGame()
{
// 清空游戲區
setfillstyle(BLACK);
bar(0, 0, WIDTH * SIZE - 1, HEIGHT * SIZE - 1);
ZeroMemory(g_World, WIDTH * HEIGHT);

// 生成下一個方塊
g_NextBlock.id = rand() % 7;
g_NextBlock.dir = rand() % 4;
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 1;

// 獲取新方塊
NewBlock();
}

// 結束游戲
void GameOver()
{
HWND wnd = GetHWnd();
if (MessageBox(wnd, _T("游戲結束。\n您想重新來一局嗎?"), _T("游戲結束"), MB_YESNO | MB_ICONQUESTION) == IDYES)
NewGame();
else
Quit();
}

// 獲取控制命令
DWORD m_oldtime;
CMD GetCmd()
{
// 獲取控制值
while(true)
{
// 如果超時,自動下落一格
DWORD newtime = GetTickCount();
if (newtime - m_oldtime >= 500)
{
m_oldtime = newtime;
return CMD_DOWN;
}

// 如果有按鍵,返回按鍵對應的功能
if (kbhit())
{
switch(getch())
{
case 'w':
case 'W': return CMD_ROTATE;
case 'a':
case 'A': return CMD_LEFT;
case 'd':
case 'D': return CMD_RIGHT;
case 's':
case 'S': return CMD_DOWN;
case 27: return CMD_QUIT;
case ' ': return CMD_SINK;
case 0:
case 0xE0:
switch(getch())
{
case 72: return CMD_ROTATE;
case 75: return CMD_LEFT;
case 77: return CMD_RIGHT;
case 80: return CMD_DOWN;
}
}
}

// 延時 (降低 CPU 佔用率)
Sleep(20);
}
}

// 分發控制命令
void DispatchCmd(CMD _cmd)
{
switch(_cmd)
{
case CMD_ROTATE: OnRotate(); break;
case CMD_LEFT: OnLeft(); break;
case CMD_RIGHT: OnRight(); break;
case CMD_DOWN: OnDown(); break;
case CMD_SINK: OnSink(); break;
case CMD_QUIT: break;
}
}

// 生成新的方塊
void NewBlock()
{
g_CurBlock.id = g_NextBlock.id, g_NextBlock.id = rand() % 7;
g_CurBlock.dir = g_NextBlock.dir, g_NextBlock.dir = rand() % 4;
g_CurBlock.x = (WIDTH - 4) / 2;
g_CurBlock.y = HEIGHT + 2;

// 下移新方塊直到有局部顯示
WORD c = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
while((c & 0xF) == 0)
{
g_CurBlock.y--;
c >>= 4;
}

// 繪制新方塊
DrawBlock(g_CurBlock);

// 繪制下一個方塊
setfillstyle(BLACK);
bar((WIDTH + 1) * SIZE, 0, (WIDTH + 5) * SIZE - 1, 4 * SIZE - 1);
DrawBlock(g_NextBlock);

// 設置計時器,用於判斷自動下落
m_oldtime = GetTickCount();
}

// 畫方塊
void DrawBlock(BLOCKINFO _block, DRAW _draw)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

int color = BLACK;
switch(_draw)
{
case SHOW: color = g_Blocks[_block.id].color; break;
case HIDE: color = BLACK; break;
case FIX: color = g_Blocks[_block.id].color / 3; break;
}
setfillstyle(color);

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if (y < HEIGHT)
{
if (_draw != HIDE)
bar3d(x * SIZE + 2, (HEIGHT - y - 1) * SIZE + 2, (x + 1) * SIZE - 4, (HEIGHT - y) * SIZE - 4, 3, true);
else
bar(x * SIZE, (HEIGHT - y - 1) * SIZE, (x + 1) * SIZE - 1, (HEIGHT - y) * SIZE - 1);
}
}
b <<= 1;
}
}

// 檢測指定方塊是否可以放下
bool CheckBlock(BLOCKINFO _block)
{
WORD b = g_Blocks[_block.id].dir[_block.dir];
int x, y;

for(int i=0; i<16; i++)
{
if (b & 0x8000)
{
x = _block.x + i % 4;
y = _block.y - i / 4;
if ((x < 0) || (x >= WIDTH) || (y < 0))
return false;

if ((y < HEIGHT) && (g_World[x][y]))
return false;
}
b <<= 1;
}

return true;
}

// 旋轉方塊
void OnRotate()
{
// 獲取可以旋轉的 x 偏移量
int dx;
BLOCKINFO tmp = g_CurBlock;
tmp.dir++; if (CheckBlock(tmp)) { dx = 0; goto rotate; }
tmp.x = g_CurBlock.x - 1; if (CheckBlock(tmp)) { dx = -1; goto rotate; }
tmp.x = g_CurBlock.x + 1; if (CheckBlock(tmp)) { dx = 1; goto rotate; }
tmp.x = g_CurBlock.x - 2; if (CheckBlock(tmp)) { dx = -2; goto rotate; }
tmp.x = g_CurBlock.x + 2; if (CheckBlock(tmp)) { dx = 2; goto rotate; }
return;

rotate:
// 旋轉
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.dir++;
g_CurBlock.x += dx;
DrawBlock(g_CurBlock);
}

// 左移方塊
void OnLeft()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x--;
DrawBlock(g_CurBlock);
}
}

// 右移方塊
void OnRight()
{
BLOCKINFO tmp = g_CurBlock;
tmp.x++;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.x++;
DrawBlock(g_CurBlock);
}
}

// 下移方塊
void OnDown()
{
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
if (CheckBlock(tmp))
{
DrawBlock(g_CurBlock, HIDE);
g_CurBlock.y--;
DrawBlock(g_CurBlock);
}
else
OnSink(); // 不可下移時,執行「沉底方塊」操作
}

// 沉底方塊
void OnSink()
{
int i, x, y;

// 連續下移方塊
DrawBlock(g_CurBlock, HIDE);
BLOCKINFO tmp = g_CurBlock;
tmp.y--;
while (CheckBlock(tmp))
{
g_CurBlock.y--;
tmp.y--;
}
DrawBlock(g_CurBlock, FIX);

// 固定方塊在游戲區
WORD b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for(i = 0; i < 16; i++)
{
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{ // 如果方塊的固定位置超出高度,結束游戲
GameOver();
return;
}
else
g_World[g_CurBlock.x + i % 4][g_CurBlock.y - i / 4] = 1;
}

b <<= 1;
}

// 檢查是否需要消掉行,並標記
int row[4] = {0};
bool bRow = false;
for(y = g_CurBlock.y; y >= max(g_CurBlock.y - 3, 0); y--)
{
i = 0;
for(x = 0; x < WIDTH; x++)
if (g_World[x][y] == 1)
i++;
if (i == WIDTH)
{
bRow = true;
row[g_CurBlock.y - y] = 1;
setfillstyle(WHITE, DIAGCROSS2_FILL);
bar(0, (HEIGHT - y - 1) * SIZE + SIZE / 2 - 2, WIDTH * SIZE - 1, (HEIGHT - y - 1) * SIZE + SIZE / 2 + 2);
}
}

if (bRow)
{
// 延時 200 毫秒
Sleep(200);

// 擦掉剛才標記的行
IMAGE img;
for(i = 0; i < 4; i++)
{
if (row[i])
{
for(y = g_CurBlock.y - i + 1; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
g_World[x][y - 1] = g_World[x][y];
g_World[x][y] = 0;
}

getimage(&img, 0, 0, WIDTH * SIZE, (HEIGHT - (g_CurBlock.y - i + 1)) * SIZE);
putimage(0, SIZE, &img);
}
}
}

// 產生新方塊
NewBlock();
}

『柒』 跪求一個用C語言寫的小程序,答辯用!!!!!!#!@###!!!

#include<reg52.h>
#include<intrins.h>
//#include<math.h>
#include<stdlib.h>
#include<lcd12864.h>
sbit up = P1^0; //上
sbit down = P1^1; //下
sbit left = P1^2; //螞臘陸左
sbit right = P1^3; //右
sbit restart = P1^4; //功能鍵
#define snake_max_body 22
#define Key_Up 1
#define Key_Down 4
#define Key_Left 2
#define Key_Right 3
uchar Key_V_temp=0; //上次按鍵值
uchar Key_Value;
const uchar code failure[]={"很局羨遺憾,你輸了"};
const uchar code maker[]={"設計者:機協成員"悶頃};
const uchar code huiz[]={"會長:方吉桐"};
const uchar code guanggao[]={"機器人協會歡迎你"};
const uchar code t[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0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0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
//const uchar []={
//0xFF,0xF3,0x85,0xE8,0xCC,0xED,0x8D,0xEF};
struct //結構體:食物
{
uchar X;
uchar Y;
uchar Yes;
}Food;
struct //結構體:小蛇
{
uchar X[snake_max_body]; //蛇的X坐標
uchar Y[snake_max_body]; //蛇的Y坐標
uchar Log; //蛇的長度
uchar Life; //蛇的生命
uchar Score; //蛇的分數
uchar Level; //蛇的等級
}Snake;
void Init_time1() //定時器初始化,用來產生隨機數
{
EA=1;
ET1=1;
TMOD|=0X20;
TH1=0X01;
TL1=0X01;
TR1=1;
}
void snake_init() //貪吃蛇初始化場地
{
uchar i;
line(0,0,0,80);
line(0,80,50,80);
line(50,80,50,0);
line(50,0,0,0);
Snake.Log=2; //定義初始化蛇的長度
Snake.Life=0;
Snake.Score=0;
// Food.Yes=1;
Key_Value=0;
for(i=0;i<Snake.Log;i++) //將蛇給賦值
{
Snake.X[i]=i+2;
Snake.Y[i]=2;
}
for(i=0;i<Snake.Log;i++) //將蛇給畫出來
{
dot(Snake.X[i],Snake.Y[i]);
}
}
key_press() //按鍵檢測
{
// uchar key;
up=1;
if(!up)
{
delay_ms(5);
if(!up)
{
Key_Value=1;
}
while(!up);
}
down=1;
if(!down)
{
delay_ms(5);
if(!down)
{
Key_Value=4;
}
while(!down);
}
left=1;
if(!left)
{
delay_ms(5);
if(!left)
{
Key_Value=2;
}
while(!left);
}
right=1;
if(!right)
{
delay_ms(5);
if(!right)
{
Key_Value=3;
}
while(!up);
}
// return Key_Value;
}
void Run_snake(void) //蛇移動
{
uchar i=0;
if((Key_Value==Key_Right&&Key_V_temp!=Key_Left)||(Key_Value==Key_Left&&Key_V_temp==Key_Right))
{
offdot(Snake.X[0],Snake.Y[0]); //先把蛇尾給熄滅掉

for(i=0;i<Snake.Log-1;i++) //蛇身都是它前一段的蛇身的位置
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}
Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]+0;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]+1; //蛇頭向要求的方向移動

for(i=0;i<Snake.Log;i++) //蛇顯示函數
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Right; //保存現在的值,以便下次按下時使用
}
if((Key_Value==Key_Left&&Key_V_temp!=Key_Right)||(Key_Value==Key_Right&&Key_V_temp==Key_Left))
{

offdot(Snake.X[0],Snake.Y[0]);

for(i=0;i<Snake.Log-1;i++)
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}

Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]+0;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]-1;

for(i=0;i<Snake.Log;i++)
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Left;
}
if(( Key_Value==Key_Up&&Key_V_temp!=Key_Down)||( Key_Value==Key_Down&&Key_V_temp==Key_Up))
{
offdot(Snake.X[0],Snake.Y[0]);

for(i=0;i<Snake.Log-1;i++)
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}
Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]-1;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]+0;
for(i=0;i<Snake.Log;i++)
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Up;
}
if(( Key_Value==Key_Down&&Key_V_temp!=Key_Up)||( Key_Value==Key_Up&&Key_V_temp==Key_Down))
{
offdot(Snake.X[0],Snake.Y[0]);
for(i=0;i<Snake.Log-1;i++)
{
Snake.X[i]=Snake.X[i+1];
Snake.Y[i]=Snake.Y[i+1];
}
Snake.X[Snake.Log-1]=Snake.X[Snake.Log-2]+1;
Snake.Y[Snake.Log-1]=Snake.Y[Snake.Log-2]+0;
for(i=0;i<Snake.Log;i++)
{
dot(Snake.X[i],Snake.Y[i]);
}
Key_V_temp=Key_Down;
}
if((Snake.X[Snake.Log-1]>=50)||(Snake.Y[Snake.Log-1]>=80)||(Snake.X[Snake.Log-1]==0)||(Snake.Y[Snake.Log-1]==0))//判蛇頭是否撞到牆壁
{
Snake.Life=1;
}
for(i=3;i<Snake.Log;i++) //從第三節開始判斷蛇頭是否咬到自己
{
if((Snake.X[i]==Snake.X[0])&&(Snake.Y[i]==Snake.Y[0]))
{
Snake.Life=1;
}
}
/* if(Snake.Life==1)
{
i=Key_Value;
// Display_dead( i);
// clear();
write_comd(0x34);
}*/
/* if(Snake.Log==snake_max_body) //判斷蛇是否最長了
{
//i=Key_Value;
write_comd(0x34);
// clear();
write_comd(0x30);
// Display_Pass(i);
}*/
if(Snake.X[Snake.Log-1]==Food.X&&Snake.Y[Snake.Log-1]==Food.Y)//判蛇是否吃到食物
{
Snake.Log++; //蛇節數加1
Snake.X[Snake.Log-1]=Food.X;
Snake.Y[Snake.Log-1]=Food.Y;
Snake.Score++;
Food.Yes=1; //食物標志置1
}
if(Food.Yes==0) //放果子程序
{
dot(Food.X,Food.Y);
}
if(Food.Yes==1)
{
while(1)
{
Food.X=TL1/5; //獲得隨機數
Food.Y=TL1/4;
for(i=0;i<Snake.Log;i++) //判斷產生的食物坐標是否和蛇身重合
{
if((Food.X==Snake.X[i])&&(Food.X==Snake.Y[i]))
break;
}
if(i==Snake.Log)
{
Food.Yes=0;
break; //產生有效的食物坐標
}
}
}
}
void main()
{
lcd_init(); //初始化LCD
Init_time1();
clear();
_nop_();_nop_();_nop_();
map(t);
delay_ms(1400);
clear();
snake_init();
// snake_food();
Food.X=TL1/5;
Food.Y=TL1/4;
dot(Food.X,Food.Y);
// dot(TL1&49,TL1&79);
// dot(TL1&49,TL1&79);
while(1)
{
if(Snake.Life)
{
// clear();
write_comd(0x34);
write_comd(0x30);
delay_ms(100);
display(0x80,7,failure);
display(0x90,8,maker);
display(0x88,6,huiz);
display(0x98,8,guanggao);
}
else
{
key_press();
Run_snake();
write_comd(0x36);
}
if(Snake.Score<15)
delay_ms(150-10*Snake.Score);
else
delay_ms(5);
}
}

『捌』 誰有c語言一些運行起來結果很好玩的程序的代碼..

/*太大了估計你不想要,給你一個掃雷程序,turbo
C下才能編譯成功
空格:打標記
回車:掃雷
方向鍵:改變方向
*/
#include<stdio.h>
#include<conio.h>
#include<time.h>
void
adjust(int*,int*);
int
a[23][23],c[22][22],mm,nn;
int
roundmine(int,int);
void
spread();
main()
{
int
i,j,b[22][22],minenum,mine;
int
x,y,yy,s;
char
g,h,z;
int*x1;
int*y1;
time_t
t;
again:srand((unsigned)
time(&t));
textcolor(LIGHTGREEN);
for(i=2;i<=21;i++)
for(j=2;j<=21;j++)
{
gotoxy(i,j);
putch(219);
b[i][j]=1;
c[i][j]=1;
}
minenum=0;
for(i=1;i<=22;i++)
for(j=1;j<=22;j++)
{
a[i][j]=0;
if(i>1&&i<22&j>1&&j<22)
{if((s=rand()%10)>0)
a[i][j]=0;
else
if(s==0)
a[i][j]=1;
}
if(a[i][j])
minenum++;
}
gotoxy(50,2);
puts("dirction");
gotoxy(50,3);
puts("SPACE:mark");
gotoxy(50,4);
puts("ENTER:dig");
gotoxy(50,8);
printf("mine
num:%4d",minenum);
gotoxy(50,5);
printf("ESC:exit");
gotoxy(30,15);
puts("
");
gotoxy(30,20);
puts("
");
mine=minenum;
gotoxy(2,2);
x=2;y=2;
while(mine)
{
h=getch();
if(h=='H')
gotoxy(x,--y);
else
if(h=='P')
gotoxy(x,++y);
else
if(h=='K')
gotoxy(--x,y);
else
if(h=='M')
gotoxy(++x,y);
x1=&x;y1=&y;
adjust(x1,y1);
if(h=='
')
{
if(c[wherex()][wherey()])
if(b[wherex()][wherey()])
{
textcolor(LIGHTRED);
putch(16);
mine--;
gotoxy(59,8);
printf("%4d",mine);
gotoxy(x,y);
b[wherex()][wherey()]=0;
}
else
{
textcolor(LIGHTGREEN);
putch(219);
mine++;
gotoxy(59,8);
printf("%4d",mine);
gotoxy(x,y);
b[wherex()][wherey()]=1;
}
}
if(h=='\015')
{
mm=wherex();nn=wherey();
c[wherex()][wherey()]=0;
if(a[wherex()][wherey()])
{
for(i=2;i<=21;i++)
for(j=2;j<=21;j++)
{gotoxy(i,j);
if(a[i][j])
{textcolor(LIGHTRED);
putch(017);
}
}
break;
}
else
{spread();gotoxy(mm,nn);}
}
if(h=='\033')
exit(0);
}
yy=1;
for(i=2;i<=21;i++)
for(j=2;j<=21;j++)
if
(a[i][j]==1&&b[i][j]==1)
{gotoxy(30,15);
cprintf("You
lose!!");
yy=0;
}
if(yy)
{gotoxy(30,15);
cprintf("You
win!!");
}
gotoxy(30,20);
cprintf("Once
again(y/n)?");
z=getch();
if(z=='y')
goto
again;
}
void
adjust(int*
x,int*
y)
{
if(*x<2)
gotoxy(*x+=20,*y);
else
if(*x>21)
gotoxy(*x-=20,*y);
else
if(*y<2)
gotoxy(*x,*y+=20);
else
if(*y>21)
gotoxy(*x,*y-=20);
}
int
roundmine(int
x,int
y)
{
int
i,j,r=0;
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y+1;j++)
if(a[i][j])
r++;
return
r;
}
void
spread()
{
int
r,i,j,x,y;
x=wherex();
y=wherey();
r=roundmine(x,y);
if(r)
{printf("%d",r);c[x][y]=0;}
else
if(r==0&&x>1&&x<22&&y>1&&y<22)
{
putchar('
');c[x][y]=0;
for(i=x-1;i<=x+1;i++)
for(j=y-1;j<=y+1;j++)
if(x>1&&x<22&&y>1&&y<22&&c[i][j])
{gotoxy(i,j);
spread();
}
}
}

『玖』 c語言能寫出什麼樣有意思的小程序

  1. C語言是一門通用計算機編程語言,應用廣泛。

  2. C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲顫銷器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

  3. C語言提供了許多低級處理的功能,但仍然保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。

  4. 題目:有1、2、3、4個數字,能組成多少個互不相同且無重復數字的三位數?都是多茄派游少?

程序分析:可填在百位、十位、個位的數字都是1、2、3、4。組成所有的排列後再去掉不滿足條件的排列。

程序源代碼:

main()

{int i,j,k;printf( );for(i=1;i<5;i++)/*以下為三重循環*/for(j=1;j<5;j++)

for (k=1;k<5;k++),{f (i!=ki!=jj!=k) /*確保i、j、k三位互不相同*/printf(%d,%d,%d ,i,j,k); }}

題目:企業發放的獎金根據利潤提成。利潤(I)低於或等於10萬元時,獎金可提10%;利潤高 於10萬元,低於20萬元時,低於10萬元的部分按10%提成,高於10萬元的部分,可可提 成7.5%;20萬到40萬之間時,高於20萬元的部分,可提成5%;40萬到60萬之間時高於40萬元的部分,可提成3%;60萬到100萬之間時,高於60萬元的部分,可提成1.5%,高於100萬元時,羨頌超過100萬元的部分按1%提成,從鍵盤輸入當月利潤I,求應發放獎金總數?

程序分析:請利用數軸來分界,定位。注意定義時需把獎金定義成長整型。

程序源代碼:

main()

{

long int i;

int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;

scanf(%ld,i);

bonus1=100000*0.1;bonus2=bonus1+100000*0.75;

bonus4=bonus2+200000*0.5;

bonus6=bonus4+200000*0.3;

bonus10=bonus6+400000*0.15;

if(i<=100000)

bonus=i*0.1;

else if(i<=200000)

bonus=bonus1+(i-100000)*0.075;

else if(i<=400000)

bonus=bonus2+(i-200000)*0.05;

else if(i<=600000)

bonus=bonus4+(i-400000)*0.03;

else if(i<=1000000)

bonus=bonus6+(i-600000)*0.015;

else

bonus=bonus10+(i-1000000)*0.01;

printf(bonus=%d,bonus);

}

6.題目:一個整數,它加上100後是一個完全平方數,再加上168又是一個完全平方數,請問該數是多少?

程序分析:在10萬以內判斷,先將該數加上100後再開方,再將該數加上268後再開方,如果開方後 的結果滿足如下條件,即是結果。

程序源代碼:

#include math.h

main()

{

long int i,x,y,z;

for (i=1;i<100000;i++)

{ x=sqrt(i+100); /*x為加上100後開方後的結果*/

y=sqrt(i+268); /*y為再加上168後開方後的結果*/

if(x*x==i+100y*y==i+268)/*如果一個數的平方根的平方等於該數,這說明此數是完全平方數*/

printf( %ld ,i);

}

}

7.題目:輸入某年某月某日,判斷這一天是這一年的第幾天?

程序分析:以3月5日為例,應該先把前兩個月的加起來,然後再加上5天即本年的第幾天,特殊情況,閏年且輸入月份大於3時需考慮多加一天。

程序源代碼:

main()

{

int day,month,year,sum,leap;

printf( please input year,month,day );

scanf(%d,%d,%d,year,month,day);

switch(month)/*先計算某月以前月份的總天數*/

{

case 1:sum=0;break;

case 2:sum=31;break;

case 3:sum=59;break;

case 4:sum=90;break;

case 5:sum=120;break;

case 6:sum=151;break;

case 7:sum=181;break;

case 8:sum=212;break;

case 9:sum=243;break;

case 10:sum=273;break;

case 11:sum=304;break;

case 12:sum=334;break;

defaultrintf(data error);break;

}

sum=sum+day; /*再加上某天的天數*/

if(year%400==0||(year%4==0year%100!=0))/*判斷是不是閏年*/

leap=1;

else

leap=0;

if(leap==1month>2)/*如果是閏年且月份大於2,總天數應該加一天*/

sum++;

printf(It is the %dth day.,sum); }

8.題目:輸入三個整數x,y,z,請把這三個數由小到大輸出。

程序分析:我們想辦法把最小的數放到x上,先將x與y進行比較,如果x>y則將x與y的值進行交換,然後再用x與z進行比較,如果x>z則將x與z的值進行交換,這樣能使x最小。

程序源代碼:

main()

{

int x,y,z,t;

scanf(%d%d%d,x,y,z);

if (x>y)

/*交換x,y的值*/

if(x>z)

/*交換x,z的值*/

if(y>z)

/*交換z,y的值*/

printf(small to big: %d %d %d ,x,y,z);

}

9.題目:用*號輸出字母C的圖案。

程序分析:可先用<|>*<|>號在紙上寫出字母C,再分行輸出。

程序源代碼:

#include stdio.h

main()

{

printf(Hello C-world! );

printf( **** );

printf( * );

printf( * );

printf( **** );

}

10.題目:輸出特殊圖案,請在c環境中運行,看一看,Very Beautiful!

程序分析:字元共有256個。不同字元,圖形不一樣。

程序源代碼:

#include stdio.h

main()

{

char a=176,b=219;

printf(%c%c%c%c%c ,b,a,a,a,b);

printf(%c%c%c%c%c ,a,b,a,b,a);

printf(%c%c%c%c%c ,a,a,b,a,a);

printf(%c%c%c%c%c ,a,b,a,b,a);

printf(%c%c%c%c%c ,b,a,a,a,b); }

11.題目:輸出9*9口訣。

程序分析:分行與列考慮,共9行9列,i控制行,j控制列。

程序源代碼:

#include stdio.h

main()

{

int i,j,result;

printf( );

for (i=1;i<10;i++)

{ for(j=1;j<10;j++)

{

result=i*j;

printf(%d*%d=%-3d,i,j,result);/*-3d表示左對齊,佔3位*/

}

printf( );/*每一行後換行*/

}

}

12.題目:要求輸出國際象棋棋盤。

程序分析:用i控制行,j來控制列,根據i+j的和的變化來控制輸出黑方格,還是白方格。

程序源代碼:

#include stdio.h

main()

{

int i,j;

for(i=0;i<8;i++)

{

for(j=0;j<8;j++)

if((i+j)%2==0)

printf(%c%c,219,219);

else

printf( );

printf( );

}

}

13.題目:列印樓梯,同時在樓梯上方列印兩個笑臉。

程序分析:用i控制行,j來控制列,j根據i的變化來控制輸出黑方格的個數。

程序源代碼:

#include stdio.h

main()

{

int i,j;

printf( );/*輸出兩個笑臉*/

for(i=1;i<11;i++)

{

for(j=1;j<=i;j++)

printf(%c%c,219,219);

printf( );

}

閱讀全文

與有什麼好玩的c語言小程序相關的資料

熱點內容
行程碼找不到行程數據怎麼回事 瀏覽:952
開課吧產品經理怎麼樣 瀏覽:243
眼睛有黑園圈用什麼產品 瀏覽:541
貨幣交易能力是什麼 瀏覽:412
蘋果手機如何記錄運動數據 瀏覽:964
打卡機怎麼之前數據沒有了 瀏覽:24
終極連續技術怎麼刷 瀏覽:339
花溪牛馬交易在哪裡 瀏覽:613
企業信息主管職責有哪些 瀏覽:339
代理手機一般在什麼地方進貨 瀏覽:378
黃金代理黃金加盟費多少錢 瀏覽:751
快遞物流多久沒信息可以投訴 瀏覽:646
女孩說還要等多久回信息 瀏覽:15
小游戲有哪些產品 瀏覽:321
不到30歲學什麼技術好 瀏覽:346
招標代理公司如何辦理執照 瀏覽:9
二手摩託交易平台哪個靠譜 瀏覽:80
美國通用的技術有哪些 瀏覽:37
女孩子學什麼技術好找工作 瀏覽:800
購房中的技術問題有哪些 瀏覽:544