返回列表 回覆 發帖

[原創作品] Matches game

本帖最後由 qwert 於 2009/1/17 09:36 編輯

a quite boring game...
I finish it in 2hrs.
In fact, how to upload the game?
No link?
yes, i can't see the botton of upload
# include <stdlib.h>
# 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("layer 1: Input the first and last matches you want to take(e.g. 3 5): ");
      scanf("%d%d",&p, &q);}
      else {
      printf("layer 2: Input the first and last matches you want to take(e.g. 3 5): ");
      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("layer 1 wins!\n");
      else
      printf("Player 2 wins!\n");
      
      system("pause");
}
If you're interest in it, you can try to run this program.
本帖最後由 qwert 於 2009/1/19 18:16 編輯

why I can't show the whole program??
= P

PS: you can download C - language software to run it.
:怒:why I can't show the whole program??
;P= P

PS: you can download C - language software to run it.
qwert 發表於 2009/1/19 18:14

更多設定 -> 禁用Smilies
支持鼓勵每位離教者
4# qwert

{:4_180:} ......看不明白!
我命由我不由天!
祢所說的平安裡沒有平安,祢所在的地方並沒有烏托邦!
7# 鹿鳴
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 into P!
7# 鹿鳴
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 pla ...
qwert 發表於 2009/1/20 17:19


ThANKs





exChristian.info前基督徒,主力:淚儿/泪儿,WEIYAN,龙井树。。。。。。。。。。。。。。。。。。。。。。。。警告 基督徒:你们一定不够他们玩
realChristianities.com雪龙坛
本帖最後由 qwert 於 2009/1/23 18:45 編輯

改良版的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有時仍會死機
高手指點下...
# include
# include
# include
# include
main()
{
      int size,qw;
      srand(time(NULL));
      printf("Enter the number of matches:  ...
qwert 發表於 2009/1/23 18:42


ThANKs again

ThANKing
good year
good year greeting
good        morning





exChristian.info前基督徒,主力:淚儿/泪儿,WEIYAN,龙井树。。。。。。。。。。。。。。。。。。。。。。。。警告 基督徒:你们一定不够他们玩
realChristianities.com雪龙坛
返回列表
高級模式 | 發新話題
B Color Image Link Quote Code Smilies
換一個