⑴ 求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 ”才有效。