用C语言编一个小游戏,注明编码,(简单易懂的游戏,不要复杂) 求助,用C语言做一个小游戏(不要太复杂),最最最基础的C语言...
\u7528C\u8bed\u8a00\u7f16\u4e00\u4e2a\u5c0f\u6e38\u620f\uff0c\u6ce8\u660e\u7f16\u7801\uff0c\uff08\u7b80\u5355\u6613\u61c2\u7684\u6e38\u620f\uff0c\u4e0d\u8981\u590d\u6742\uff09//C\u8bed\u8a00\u5199\u7684\uff0c\u4e00\u4e2a\u73a9\u77f3\u5934\u3001\u526a\u5200\u3001\u5e03\u7684\u5c0f\u6e38\u620f\u3002\u4e0b\u9762\u662f\u6e90\u7801\u3002
#include
#include
int main()
{
char cq[][10]={"\u77f3\u5934","\u526a\u5200","\u5e03"};
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);
printf("0\u3001\u77f3\u5934\n1\u3001\u526a\u5200\n2\u3001\u5e03\n3\u3001\u9000\u51fa\n\u6211\u5df2\u51fa\uff0c\u8bf7\u4f60\u51fa\uff1a");
scanf("%d",&guess);
if(3==guess)
{
break;
}
else
{
total++;
printf("\u8fd9\u4e00\u6b21\u4f60\u51fa\u7684\u662f%s,\u6211\u51fa\u7684\u662f%s\uff0c\u6240\u4ee5",cq[guess],cq[r]);
if(0==guess&&1==r || 1==guess&&2==r || 2==guess&&0==r)
{
youwin++;
printf("\u4f60\u8d62\u4e86\uff01\n");
}
else if(guess==r)
{
daping++;
printf("\u6211\u4eec\u6253\u5e73\u4e86\uff01\n");
}
else
{
mewin++;
printf("\u6211\u8d62\u4e86\uff01\n");
}
}
}
printf("\u603b\u5171\u73a9\u4e86%d\u6b21\uff0c\u4f60\u8d62\u4e86%d\u6b21\uff0c\u6211\u8d62\u4e86%d\u6b21\uff0c\u6253\u5e73%d\u6b21\uff01\n",total,youwin,mewin,daping);
system("PAUSE");
return EXIT_SUCCESS;
}
\u731c\u6570\u5b57 \u8d85\u7b80\u5355 \u53bb\u6389\u8bf4\u660e\u6587\u5b57\uff0c\u4e5f\u5c31\u5341\u51e0\u884c
\u7b80\u5355\u8bf4\u660e\u89c1\u6ce8\u91ca
#include
#include
#include
int main()
{
int i;
int a;
int t;
printf("\u6b22\u8fce\u73a9\u731c\u6570\u5b57\u5c0f\u6e38\u620f!\n");
printf("\u73a9\u6cd5\u4ecb\u7ecd:\n");
printf("\u6bcf\u6b21\u6e38\u620f\u4f1a\u8bbe\u7f6e\u4e00\u4e2a\u6570\u5b57(1-100)\uff0c\u8bf7\u8f93\u5165\u4f60\u731c\u7684\u6570\u5b57\n");
printf("\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165\u7684\u6570\u5b57\u6bd4\u7b54\u6848\u5927\u6216\u8005\u5c0f\n");
printf("\u5f53\u8f93\u5165\u6570\u5b57\u548c\u7b54\u6848\u76f8\u540c\u65f6\u80dc\u5229\n");
printf("\u597d\u8fd0\u54e6!\n");
srand(time(NULL));//\u8bbe\u7f6e\u968f\u673a\u6570\u79cd\u5b50
while(1)
{
a = rand()%100+1;//\u83b7\u53d61-100\u95f4\u968f\u673a\u6570\u5b57
printf("\u6211\u60f3\u597d\u4e86\u4e00\u4e2a\u6570\u5b57\uff0c1-100\u4e4b\u95f4\uff0c\u4f60\u6765\u731c\u5427\n");
t = 0;
while(1)
{
scanf("%d", &i);//\u8f93\u5165\u6570\u5b57
t++;
//\u5224\u65ad\u5408\u6cd5\u6027
if(i 100)
{
printf("\u7b28\u86cb\uff0c\u4e0d\u662f\u544a\u8bc9\u4f60\u662f1-100\u4e4b\u95f4\u7684\u5417!\n");
continue;
}
//\u5224\u65ad\u5927\u5c0f
if(i > a) printf("\u6bd4\u6211\u60f3\u7684\u8981\u5927\u54e6\n");
else if(i < a) printf("\u6bd4\u6211\u60f3\u7684\u8981\u5c0f\u54e6\n");
else
{
printf("\u731c\u5bf9\u4e86\uff0c\u5c31\u662f%d\uff0c\u4f60\u7528\u4e86%d\u6b21\n", i,t);
break;//\u6210\u529f \u7ed3\u675f\u672c\u6b21\u6e38\u620f
}
}
printf("\u8fd8\u8981\u7ee7\u7eed\u73a9\u5417? \u7ee7\u7eed\u8bf7\u8f93\u51651\n");
scanf("%d", &i);
if(i != 1) break;
}
printf("\u518d\u89c1\u5566!\n");
return 0;
}
这是个汉诺塔程序,在调试的时候,输入的数字最好不要大于15,因为每大一个数
所得的结果的步骤都会多一倍。如果你有耐心等待结果的话除外。汉诺塔是在欧洲
流行的一种游戏,有a,b,c三个竿。a竿上有若干个由大到小的圆盘,大的在下面,
小的在上面,b,c都是空杆,请你把a杆上的圆盘都倒到别的杆上,或b或c,在倒盘
的过程中不可以大的压小的,实例程序如下:
#include <stdio.h>
int i=0;
main()
{
unsigned n;
printf("Please enter the number of discs: ");
scanf("%d",&n);
printf("\tneedle:\ta\t b\t c\n");
movedisc(n,'a','c','b');
printf("\t Total: %d\n",i);
getch();
}
movedisc(n,fromneedle,toneedle,usingneedle)
unsigned n;
char fromneedle,toneedle,usingneedle;
{
if(n>0)
{
movedisc(n-1,fromneedle,usingneedle,toneedle);
i++;
switch(fromneedle)
{
case 'a':switch(toneedle)
{
case 'b':printf("\t[%d]:\t%2d------>%2d\n",i,n,n);
break;
case 'c':printf("\t[%d]:\t%2d------------->%2d\n",i,n,n);
break;
}
break;
case 'b':switch(toneedle)
{
case 'a':printf("\t[%d]:\t%2d<----------%2d\n",i,n,n);
break;
case 'c':printf("\t[%d]:\t\t%2d------>%2d\n",i,n,n);
break;
}
break;
case 'c':switch(toneedle)
{
case 'a':printf("\t[%d]:\t%2d<--------------%2d\n",i,n,n);
break;
case 'b':printf("\t[%d]:\t\t%2d<--------%2d\n",i,n,n);
break;
}
break;
}
movedisc(n-1,usingneedle,toneedle,fromneedle);
}
}
绛旓細sprintf(p[i], "%c", question[i]);} switch(type){ case 0:sprintf(answer, "%s %c (%s %c (%s %c %s))",
绛旓細//C璇█鍐欑殑锛屼竴涓鐜╃煶澶淬佸壀鍒銆佸竷鐨灏忔父鎴銆備笅闈㈡槸婧愮爜銆俰nclude<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)...
绛旓細/*鑷畾涔夊彉閲*/srand((int)time(NULL)); /*鍚姩闅忔満鏁板彂鐢熷櫒*/leb1: /*閫夋嫨妯″紡*/printf("\n 璇烽夋嫨妯″紡锛歕n 1.鏍囧噯 2.鑷畾涔塡n");scanf("%d",&mo);if(mo==2) /*鑻ラ夋嫨鑷畾涔夋ā寮忥紝瑕佽緭鍏ヤ笁涓弬鏁*/{do{t=0; printf("璇疯緭鍏n琛屾暟 鍒楁暟 闆风殑涓暟\n");scanf...
绛旓細/*涔熶笉鐭ラ亾浣犳槸浠涔堢骇鍒殑,鎴戞槸涓涓柊鎵,鍒氭帴瑙︾紪绋嬭瑷,浠ヤ笅鏄垜鑷繁鍙樺緱涓涓皬绋嬪簭,鍦ㄦ墍鏈c璇█鐨勭紪璇戝櫒(vc++6.0銆乼urbo???)涓婇兘鑳借繍琛,浣犺繕鍙互杩涗竴姝ユ敼杩涖傝繖鏄竴涓被浼艰椽鍚冭泧鐨灏忔父鎴銆傜浣犲ソ杩*/\x0d\x0a/*璐悆铔*/\x0d\x0a#include\x0d\x0a#include\x0d\x0a#include\x0d\x0a#includ...
绛旓細鈥滅寽鏁板瓧灏忔父鎴鈥濓紝姣忎釜鏁板瓧鍚庢寜绌烘牸锛屾渶鍚庢寜鍥炶溅纭 include<stdio.h> include<stdlib.h> include int a[4],b[4];int count=0; //璁$畻鐚滄祴娆℃暟 void csh( ); //鍒濆鍖 void start( ); //寮濮嬫父鎴 int main( ){ csh( );start( );} void csh( ) //鍒濆鍖 { printf("\...
绛旓細杩欐牱瀛︿範绋嬪簭璁捐,灏变笉浼氭槸涓浠惰壈鑻 ,鏋嚗鐨勪簨,瀹冨彉寰楄薄鐢佃剳娓告垙涓鏍峰厖婊″ソ濂,瀵屾湁涔愯叮. 1, 鎬绘槸浠嶩ello,world寮濮 瀛︿範缂栫▼鐨勭涓涓▼搴,涓鑸氨鏄墦鍗颁竴涓翰鍒囩殑璇嶈鈥斺"Hell o,world!".璁╂垜浠潵鐪嬬湅杩欎釜鏈绠鍗曠殑C绋嬪簭:#incolude <stdio.h> /*鎶婅緭鍏ヨ緭鍑哄嚱鏁扮殑澶存枃浠跺寘鍚繘鏉*/int main(){...
绛旓細涓銆佹暟瀛︾煡璇嗭細闀挎柟褰㈢殑闈㈢НS=a*b 闀挎柟褰㈠懆闀縇=2*锛坅+b锛夊叾涓璦 b鍒嗗埆涓洪暱鏂瑰舰鐨勫鍜岄珮銆備簩銆佺畻娉曞垎鏋愶細闀挎柟褰㈤潰绉強鍛ㄩ暱鍧囦緷璧栦簬瀹藉拰楂橈紝鎵浠ュ厛瑕佽緭鍏ュ楂樺硷紝鐒跺悗鏍规嵁鍏紡璁$畻锛岃緭鍑虹粨鏋滃嵆鍙備笁銆佸弬鑰冧唬鐮侊細include <stdio.h>void main(){ double a,b; double L,S; scanf("%l...
绛旓細printf("杩欐槸涓涓寽鎷崇殑灏忔父鎴忥紝璇疯緭鍏ヤ綘瑕佸嚭鐨勬嫵澶达細\n");printf("A:鍓垁\nB:鐭冲ご\nC:甯僜nD:涓嶇帺浜哱n");scanf("%c%*c",&gamer);switch (gamer){ case 65: //A case 97: //a gamer=4;break;case 66: //B case 98: //b gamer=7;break;case 67: //C case 99: //c g...
绛旓細娉ㄦ剰锛氫笂闈㈡彁鍒颁簡缂撳啿鍖虹殑姒傚康锛屽湪C璇█缂栫▼涓粡甯镐細鐢ㄥ埌缂撳啿鍖猴紝涓瀹氳寰堝ソ鐨勭悊瑙e畠銆俫etchar鍑芥暟涓巔utchar鍑芥暟缁忓父闇瑕佸尮閰浣跨敤锛鍙互鐢ㄦ潵瀹炵幇寰堝鐨勫皬鍔熻兘锛屼緥濡傦紝鍙互鍐欎釜C绋嬪簭缁勫悎瀹冧滑瀹炵幇鍥炴樉鍔熻兘銆佺畝鍗曠殑鏂囦欢鎷疯礉鍔熻兘銆佺敋鑷充竴浜灏忔父鎴绛夈4銆乻canf鍑芥暟杩欎釜鍑芥暟浼拌鏄敤鐨勬渶澶氱殑杈撳叆鍑芥暟浜嗭紝瀹冨彲浠ヤ粠...
绛旓細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(...