⑴ 求c語言大佬!!幫忙做一個成語接龍的程序!急用!要求如圖!
#include<stdio.h>
#include<string.h>
typedefstructcy
{
charidiom[9];
charstar[3];
charend[3];
}CY;
intmain()
{
inti,meNum,cont=0;
CYcy1,cy2;
charan,menu[10][11]={"胸有成竹","一心一意","花好月圓","風和日麗","豆蔻年華","學富五車","相輔相成","先發制人","興高采烈","自由輸入"};
printf("成語接龍游戲
");
while(1)
{
printf("請選擇開頭的成語,輸入序號1-9,自行輸入請選擇0:
");
for(i=0;i<9;i++)
printf("%d、--%s
",i+1,menu[i]);
printf("%d、--%s
",0,menu[i]);
scanf("%d",&meNum);
memset(cy1.idiom,0,9);
memset(cy1.end,0,3);
if(meNum==0)
{
printf("請輸入開頭的成語:");
scanf("%s",cy1.idiom);
}
else
strcpy(cy1.idiom,menu[meNum-1]);
cy1.end[0]=cy1.idiom[6];
cy1.end[1]=cy1.idiom[7];
cy1.end[2]=0;
printf("成語接龍開始,輸入0結束
");
printf(">>>>>>>>>>>>>>>>>>>>>>
");
printf("%s
",cy1.idiom);
while(1)
{
printf("-->");
memset(cy2.idiom,0,9);
memset(cy2.star,0,3);
scanf("%s",cy2.idiom);
if(cy2.idiom[0]=='0'&&cy2.idiom[1]==0)
break;
cy2.star[0]=cy2.idiom[0];
cy2.star[1]=cy2.idiom[1];
cy2.star[2]=0;
if(strcmp(cy1.end,cy2.star))
{
printf("接龍失敗!
");
break;
}
cont++;
memset(cy1.idiom,0,9);
strcpy(cy1.idiom,cy2.idiom);
cy1.end[0]=cy1.idiom[6];
cy1.end[1]=cy1.idiom[7];
cy1.end[2]=0;
}
printf("本次接龍結束!你共完成了%d個成語的接龍
",cont);
getchar();
while(1)
{
printf("再玩兒一次(Y/N)?");
scanf("%c",&an);
if(an=='N')
return0;
if(an=='Y')
break;
}
}
return0;
}
⑵ 用C語言編寫一個單詞接龍的小游戲
//囧,代碼寫好回來一看居然已經有推薦答案了.....
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#define MAX 80
char buff[MAX+1];
char first[4];
char last;
bool spellCheck()
{
int p = 0;
while(buff[p] != 0)
{
if(buff[p] > 'z'||buff[p] < 'a')
return false;
p++;
}
return true;
}
bool syntaxCheck()
{
int len = strlen(first);
if(len == 3)
{
if(strncmp(first,buff,3) == 0)
return true;
else if(strncmp(&first[1],buff,2) == 0)
return true;
else if(strncmp(&first[2],buff,1) == 0)
return true;
}
else if(len == 2)
{
if(strncmp(&first[0],buff,2) == 0)
return true;
else if(strncmp(&first[1],buff,1) == 0)
return true;
}
else if(len == 1)
{
if(strncmp(&first[0],buff,1) == 0)
return true;
}
return false;
}
void getWord()
{
do
{
printf("請輸入一個全小寫的單詞,和%s匹配\n",first);
scanf("%s",buff);
if(!spellCheck())
{
printf("拼寫錯誤,請輸入一個全小寫的單詞......\n");
continue;
}
if(strlen(buff) == 0)
{
printf("請輸入一個單詞......\n");
continue;
}
return;
}while(true);
}
void start()
{
FILE *fp = fopen("D:\\1.txt","w");//<--------這里改輸出文件的路徑
int len;
first[0] = rand()%26+'a';
first[1] = 0;
last = rand()%26+'a';
printf("a1:%c a2:%c\n",first[0],last);
while(true)
{
getWord();
if(!syntaxCheck())
{
printf("輸入的單詞不符合要求,請重新輸入......\n");
continue;
}
else
{
fprintf(fp,"%s\n",buff);
len = strlen(buff);
if(buff[len-1] == last)
{
printf("%s末尾和a2:%c匹配,所以游戲結束\n",buff,last);
break;
}
else
{
if(len >= 3)
strcpy(first,&buff[len-3]);
else
strcpy(first,buff);
printf("匹配成功,請繼續輸入......\n");
}
}
}
fclose(fp);
}
int main()
{
srand(GetTickCount());
start();
system("pause");
}
⑶ C語言的源代碼是什麼意思啊
C語言源代碼,就是依據C語言規則所寫出的程序代碼,常見的存儲文件擴展名為.c文件和.h文件,分別對應C源文件(source file)和C頭文件(header file)。
C語言是一門編程語言,簡單點說,就是由人類書寫按照一定規范書寫的字元,通過一定手段(編譯鏈接)轉換後,可以讓電腦或者其它電子晶元"讀懂",並按照其要求工作的語言。
在所有的編程語言中,C語言是相對古老而原始的,同時也是在同類語言中更接近硬體,最為高效的編程語言。
(3)紙牌接龍c語言源代碼擴展閱讀:
C語言廣泛應用於底層開發。它的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。
它能提供了許多低級處理的功能,可以保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。
其編譯器主要有Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C等。
⑷ 求一些C語言小游戲的源代碼,謝謝
學習一下數字版「拼圖」代碼寫法:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
inti,j,r,k; //i、j、r用於循環,k存放隨機數值
intm,n; //m、n是當前空位的下標
inta[4][4]; //存儲4×4共16個數字的數組
voidshow(void); //輸出界面
voidcsh(void); //初始化界面
intyes(void); //判斷排序是否成功(1是0否)
voip(void);//數字向上移動到空位(空位則下移)
voiddown(void); //數字向下移
voidleft(void); //數字向左移
voidrght(void); //數字向右移
voidinkey(void); //按鍵操作
voidgtxy(intx,inty); //控制游標位置的函數
intmain(void)
{while(1)
{csh();
while(1)
{inkey();
show();
if(yes())
{gtxy(6,12);printf("你成功了!再來一局y/n?");break;}
}
if(getch()=='n')break;
}
return0;
}
voidcsh(void) //初始化
{r=0;
CONSOLE_CURSOR_INFOcursor_info={1,0};//以下兩行是隱藏游標的設置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
for(i=0;i<4;i++)//給數組a依序賦值
for(j=0;j<4;j++)
{if(i==3&&j==3)a[i][j]=0;
elsea[i][j]=1+r++;
}
m=3; n=3; //記下空格(值為0)的下標
down( ); rght( ); rght( ); down( ); //預演4步
srand((unsigned)time(0)); //初始化隨機數發生器
for(r=0;r<500;r++)//將數組各值打亂
{k=rand()%(4);
switch(k)
{case0:{up();break;}
case1:{down();break;}
case2:{left();break;}
case3:{rght();break;}
}
}
system("cls");
printf(" 數字拼圖");
printf(" ┌──────┬──────┬──────┬──────┐");
printf(" │││││");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │││││");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │││││");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │││││");
printf(" └──────┴──────┴──────┴──────┘");
show();
}
voidshow(void)//輸出界面
{for(i=0;i<4;i++)
for(j=0;j<4;j++) //gtxy(7*j+9,2*i+4)是游標到指定位置輸出數字
{gtxy(7*j+9,2*i+4); if(a[i][j]==0)printf("│");
elseif(a[i][j]>9)printf("%d│",a[i][j]);
elseprintf("%d│",a[i][j]);
}
}
voidinkey(void) //按鍵操作
{intkey;
key=getch();
switch(key)
{case72:{up();break;}
case80:{down();break;}
case75:{left();break;}
case77:{rght();break;}
}
}
voip(void) //向上移動
{if(m!=3)//空位不得在下邊界
{a[m][n]=a[m+1][n];m++;a[m][n]=0;}
}
voiddown(void) //向下移動
{if(m!=0)//空位不得在上邊界
{a[m][n]=a[m-1][n];m--;a[m][n]=0;}
}
voidleft(void) //向左移動
{if(n!=3)//空位不得在右邊界
{a[m][n]=a[m][n+1];n++;a[m][n]=0;}
}
voidrght(void) //向右移動
{if(n!=0)//空位不得在左邊界
{a[m][n]=a[m][n-1];n--;a[m][n]=0;}
}
intyes(void)//判斷是否成功
{r=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{if(a[i][j]!=1+r++)return(r==16)?1:0;}
}
voidgtxy(intx,inty)//控制游標位置的函數
{COORDcoord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
⑸ c語言紙牌發牌程序源代碼(附註釋)
其實發牌問題里有個隨機的問題,就是模擬洗牌的問題,我來嘗試下這個程序吧(每個花色的代碼分別是:紅桃 \x3,方塊\x4,梅花\x5,黑桃\x6
#include <stdio.h>
#include <time.h>
char hua_se[4]={'\x3','\x4','\x5','\x6'}; //定義一個數組來存放花色
char *dight[14]={"Ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"};//定義一個指針型的數組來存放數字
int fa_pai[4][13]={0};//定義一個二維數組來發牌
void move(int fa_pai[4][13]);
void deal(int fa_pai[4][13],char huase[4],char *dight[4][13]);
int main(void){srand(time(NULL));
move(fa_pai);
deal(hua_se,dight,fa_pai);
printf("你是否想結束發牌?Y/N");
getch();return 0;}void move(int fa_pai[4][13]){int r,card,row,column;
for(card=1;card<=52;card++)
{
r=rand();
row=r%4;
r=rand();
column=r%13;
while(fa_pai[4][13]!=0)
{
r=rand();
row=r%4;
r=rand();
column=r%13;
}
fa_pai[row][column]=card;
}
}
void deal(int fapai[4][13],char hua_se[3],char *dight[13])
{
char c;int card,row,column;
for(card=1;card<=52;card++)
{
for(row=0;row<=3;row++)
{
for(column=0;column<=12;column++)
{
if(fapai[row][column]==card)
{
if(card%3=0)c='\n';
elsec='\t';
printf("%5sof%-8s%c",hua_se[row],dight[column],c);
}
}
}
}
}
⑹ 求C語言小游戲源程序
新手要方便寫代碼,可以收藏下面幾個自編函數:
gtxy (6, 3) //游標定位於窗口的第6列,第3行處(准備輸出,行與列都是從0算起)
Color (4, 0) //設置為紅字配黑底 如 Color (10, 0)則是淡綠字配黑底
yinc (1,0) //隱藏游標(第二個參數設為0就隱藏,沒有游標閃爍,yinc代表隱藏)
kou(80,25) //設定窗口緩沖區大小為80列,25行
下面幾個是庫函數,不需自己編寫,只要用#include包含就可以使用。
SetConsoleTitle("俄羅斯方塊"); //設置窗口左上角標題欄處出現"俄羅斯方塊"5個字
srand( (unsigned) time(NULL) ); //初始化隨機數發生器
n= rand( ) % 20; //產生隨機數0-19中的一個. 如 rand( )%5 就產生0-4中的一個數
SetConsoleTitle( )函數在<windows.h>里,srand( )函數與rand( )函數要配合用,
就是同時要用,在<stdlib.h>里。如果 rand( )%10+1 就產生1-10之中的一個數。
Sleep(300); //延時300毫秒(就是程序暫停300毫秒後繼續運行)
system("cls"); //清屏(把窗口裡的內容全部清除,游標定於(0,0)位置處)
這兩個函數都在<windows.h>里。開頭4個自編函數 編寫如下:
void gtxy (int x, int y) //控制游標位置的函數
{ COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );
}
void Color (short ForeColor= 7, short BackGroundColor= 0) //設定顏色的函數
{ HANDLE hl = GetStdHandle ( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute ( hl, ForeColor + BackGroundColor * 0x10 );
}
聲明時原型可寫 void Color (short x, short y);
void yinc (int x,int y) //隱藏游標的函數
{ CONSOLE_CURSOR_INFO gb={ x , y }; //gb代表游標
SetConsoleCursorInfo ( GetStdHandle(STD_OUTPUT_HANDLE), &gb );
}
void kou(int w,int h) //設置窗口大小的函數
{HANDLE hl=GetStdHandle ( STD_OUTPUT_HANDLE ) ;
COORD size={ w , h };
SetConsoleScreenBufferSize( hl , size );
SMALL_RECT rc={ 0, 0, w, h };
SetConsoleWindowInfo( hl, 1, &rc );
}
最後這個函數,參數w是寬h是高。里邊5行中第一行定義了句柄型變數hl,並給它賦值。
第二行定義了坐標型結構體變數size,它的取值決定了緩沖區的大小。第三行就是使用
size的值設置好緩沖區大小。第四行定義了變數rc,它的值決定當前窗口顯示的位置與
大小(不得超過緩沖區的大小)。前兩個0,0是從緩沖區左上角0列0行位置處開始,後兩
個參數可以小於w和h.比如rc={0,0,w-10,h-5}; 最後一行使用rc的值設置好窗口,中間
那個參數要為" 1 "或寫「 true 」才有效。