Matches game
a quite boring game... I finish it in 2hrs. In fact, how to upload the game? | |||||
| |||||
| |||||
# include <time.h> # include <math.h> # include <stdio.h> # define size 20 main() { printf("----------------------------------------\n"); printf("****************MATCHES*****************\n"); printf("Game rule:\n"); printf("1. There are 20 matches, the player who takes the last match will lose\n"); printf("2. You should take the max 5 consecutive matches\n"); printf("-----------------------------------------\n"); int i,p,q,no,match[size],count=0,end,score; for (i=0; i<20; i++) match= 1; printf("The matches are shown below:\n"); for (i=0; i<size; i++){ printf("%d",match); printf(" ");} printf("\n"); do { if (count%2 == 0 || count == 0){ printf(" scanf("%d%d",&p, &q);} else { printf(" scanf("%d%d",&p, &q);} if (p&&q>=1 && p&&q<=size){ if ((p-q>=-4 && q-p>=-4) && (p-q<=4 && q-p<=4)) { if (q>p){ for (no=p; no<=q; no++) match [no-1]=0;} if (p>q){ for (no=p; no>=q; no--) match [no-1]=0;} if (p==q) match [p-1]=0; }} printf("\n"); for (i=0; i<size; i++){ printf("%d",match); printf(" ");} printf("\n"); count++; end=0; for (i=0; i<size; i++){ end+=match;} if (end==0) score=-1; } while (score>=0); printf("----------------------------------\n"); printf("Game over.\n"); if (count%2==0) printf(" else printf("Player 2 wins!\n"); system("pause"); } If you're interest in it, you can try to run this program. | |||||
PS: you can download C - language software to run it. | |||||
:怒:why I can't show the whole program?? 更多設定 -> 禁用Smilies | |||||
{:4_180:} ......看不明白! | |||||
no need to understand this program you can download Dev-C++ from http://www.bloodshed.net/devcpp.html open this software, copy and paste the above program in it, press F9, finally you can play it. remember to change | |||||
7# 鹿鳴 ThANKs | |||||
改良版的game, but有時仍會死機 :唉: :哭著跑: 高手指點下... # include <stdlib.h> # include <time.h> # include <math.h> # include <stdio.h> main() { int size,qw; srand(time(NULL)); printf("Enter the number of matches: "); scanf("%d",&size); printf("Enter the matches you take once: "); scanf("%d",&qw); int match[size],i,p,q,no,count=0,end,score,temp,r,s,j,k,ace; printf("----------------------------------------\n"); printf("****************MATCHES*****************\n"); printf("Game rule:\n"); printf("1. There are %d matches, the player who takes the last match will lose\n",size); printf("2. You should take the max %d consecutive matches\n",qw); printf("-----------------------------------------\n"); for (i=0; i<size; i++) match= 1; printf("The matches are shown below:\n"); for (k=0; k<size; k++){ printf("%d",match[k]); printf(" ");} printf("\n"); do { if (count%2 == 0 ){ printf("Player 1: Input the first and last matches you want to take(e.g. 3,5): "); scanf("%d,%d",&p,&q); ace=0; if (p>q){ temp=p; p=q; q=temp;} if ((p&&q>=1) && (p&&q<=size)){ if (q-p>=0-qw+1 && q-p<=qw-1) { for (i=p; i<=q; i++) ace+=match[i-1]; if (ace==q-p+1){ if (q>p) for (no=p; no<=q; no++) match [no-1]=0; if (p==q) match [p-1]=0; } else continue;}else continue;} else continue;} else{ do{ r=0; s=0; ace=0; score=1; r=rand()%size; s=rand()%size; if (r>s){ temp=r; r=s; s=temp;} if ((r&&s>=1) && (r&&s<=size)){ if (s-r>=0-qw+1 && s-r<=qw-1){ if (match[r-1]==1 && match[s-1]==1){ for (i=r; i<=s; i++) ace+=match[i-1]; if (ace==q-p+1){ printf("computer: Input the first and last matches you want to take(e.g. 3 5):%d %d\n",r,s); score=0;} } } } }while (score==1); if (s>r){ for (no=r; no<=s; no++) match [no-1]=0;} if (r==s) match [r-1]=0; } count++; printf("\n"); for (k=0; k<size; k++){ printf("%d",match[k]); printf(" ");} printf("\n"); for(j=0;j<=size; j+=5){ printf("%d",j+1); printf("\t "); } printf("\n"); end=0; for (i=0; i<size; i++){ end+=match;} printf("Number of matches left: %d\n", end); if (end==0) end=-1; } while (end>0); printf("----------------------------------\n"); printf("Game over.\n"); if (count%2==0) printf("Player 1 wins!\n"); else printf("computer wins!\n"); system("pause"); } | |||||
改良版的game, but有時仍會死機 ThANKs again ThANKing good year good year greeting good morning |