佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

楼主: Wongkokchoy

Asignment新的小问题。。。

[复制链接]
发表于 1-10-2008 08:02 PM | 显示全部楼层

回复 40# Wongkokchoy 的帖子

看看是不是
  1.    
  2. for( count = 0, i = 0;  i < no_player ; i++ )
  3.         if( gameover_flag == true )
  4.             count++;
复制代码
改成
  1.     for( count = 0, i = 0;  i < no_player ; i++ )
  2.         if( gameover_flag[i] == true )
  3.             count++;
复制代码
佳礼的 【code】 有问题的。。 编辑过后会少东西。

我upload 了, 直接下载来试试看

http://onlylonly88.googlepages.com/Untitled1.cpp
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 1-10-2008 08:10 PM | 显示全部楼层
这个更正你在36楼已经改了,然后我下载了你的file. argv 和argc的warning还是存在, 问题也没有改善。
回复

使用道具 举报

发表于 1-10-2008 08:16 PM | 显示全部楼层

回复 42# Wongkokchoy 的帖子

argc argv 可以不管他。

我懂你说什么了。

那个其他玩家吧? player1 gameover了, player2 还没有, 说一继续玩。

如果不是的话, 那么恕我无法帮你了, 我在 dev-c++ 上跑一切正常。。
回复

使用道具 举报

 楼主| 发表于 1-10-2008 08:22 PM | 显示全部楼层
讲的不是很清楚,让你看看他的显示:
" border="0">
" border="0">
回复

使用道具 举报

发表于 1-10-2008 08:31 PM | 显示全部楼层

回复 44# Wongkokchoy 的帖子

看来我真的是不懂 turbo c++ 5.02 了, 在我这里一切正常

[img] [/img]
回复

使用道具 举报

发表于 1-10-2008 08:32 PM | 显示全部楼层

回复 44# Wongkokchoy 的帖子

你有 turbo c++ 5.02 的installer ?
或许我可是试试看

---------------------

我将 assigment operation 修改了, 不知是不是 5.02 不支持, 你在试试看

http://onlylonly88.googlepages.com/Untitled1.cpp

[ 本帖最后由 onlylonly 于 1-10-2008 08:35 PM 编辑 ]
回复

使用道具 举报

Follow Us
 楼主| 发表于 1-10-2008 08:34 PM | 显示全部楼层
我要怎么send给你?
90++Mb





还是你帮我解决玩家交替的问题就好了。。。。。

[ 本帖最后由 Wongkokchoy 于 1-10-2008 08:36 PM 编辑 ]
回复

使用道具 举报

发表于 1-10-2008 08:35 PM | 显示全部楼层

回复 47# Wongkokchoy 的帖子

也可以, 你将code 贴上来
用 【code】 【/code】
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 1-10-2008 08:42 PM | 显示全部楼层
原帖由 onlylonly 于 1-10-2008 08:35 PM 发表
也可以, 你将code 贴上来
用 【code】 【/code】
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #define m 50
  6. void Line()
  7. {
  8. cout<<"-------------------------------------------------------------------------------\n";
  9. }
  10. void main()
  11. {
  12. char dice;
  13. int A, n, number, next;
  14. int player[m];
  15. Line();
  16. cout<<"\t\tWelcome to Snake and Ladder Game!!\n\n";
  17. cout<<"Introduction: if a player reach a point where there is a ladder, he/she will \nraise to a higher location.\n";
  18. cout<<"\nOn the other hand, if the player reach a spot where there is a snake over there,the player will drop to a lower location.\n";
  19. Line();
  20. cout<<"\nNow please enter the numbers of players:\n";
  21. cin>>n;
  22. cout<<"\nSo there will be "<<n<<" player(s) in the game.\n";
  23. cout<<"Good Luck and Have Fun!!!\n\n";
  24. cout<<"(All players start at 0)\n\n\n";
  25. for (int x=0; x<n; x++)
  26. {
  27. player[x]=0;
  28. while (player[x]<=100)
  29. {
  30. srand(time(0));
  31. cout<<"ress 'T' to throw a dice!\n";
  32. cin>>dice;
  33. if (dice=='T')
  34. {
  35. A=(rand()%6)+1;
  36. if (A==1)
  37. {
  38. cout<<"\n   \n";
  39. cout<<" . \n";
  40. cout<<"   \n";
  41. cout<<"\n\nYou get 1!!\n";
  42. }
  43. else if (A==2)
  44. {
  45. cout<<"\n . \n";
  46. cout<<"   \n";
  47. cout<<" . \n";
  48. cout<<"\n\nYou get 2!!\n";
  49. }
  50. else if (A==3)
  51. {
  52. cout<<"\n.  \n";
  53. cout<<" . \n";
  54. cout<<"  .\n";
  55. cout<<"\n\nYou get 3!!\n";
  56. }
  57. else if (A==4)
  58. {
  59. cout<<"\n. .\n";
  60. cout<<"   \n";
  61. cout<<". .\n";
  62. cout<<"\n\nYou get 4!!\n";
  63. }
  64. else if (A==5)
  65. {
  66. cout<<"\n. .\n";
  67. cout<<" . \n";
  68. cout<<". .\n";
  69. cout<<"\n\nYou get 5!!\n";
  70. }
  71. else if (A==6)
  72. {
  73. cout<<"\n. .\n";
  74. cout<<". .\n";
  75. cout<<". .\n";
  76. cout<<"\n\nYou get 6!!\n";
  77. }
  78. player[x]+=A;
  79. number=x+1;
  80. cout<<"layer "<<number<<" had reached "<<player[x]<<"\n";
  81. cout<<"\n";
  82. }
  83. }
  84. if (x==n-1)
  85. continue;
  86. next=number+1;
  87. cout<<"\n\nPlayer "<<next<<"'s turn!!!\n";
  88. }
  89. }
复制代码



蛇和梯子我还没放,应该没问题吧!
回复

使用道具 举报

发表于 1-10-2008 09:04 PM | 显示全部楼层

回复 49# Wongkokchoy 的帖子

不如索性upload 然后给我link? 我懒惰做indentation
回复

使用道具 举报

 楼主| 发表于 1-10-2008 09:29 PM | 显示全部楼层
我的code:
http://www.badongo.com/file/11567117

你需要Borland C++ 的installer吗?
我在upload-ing......
回复

使用道具 举报

发表于 1-10-2008 10:05 PM | 显示全部楼层

回复 51# Wongkokchoy 的帖子

唉, 你的condition 放错了。 整个structure 必须要更换。

你不因该让一个player玩到玩才转换。

而是转换后才check condition。

----------------------

我将那 n 年前的 borland c++ 挖出来了。。 ^^ 居然还收着

[ 本帖最后由 onlylonly 于 1-10-2008 10:08 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 1-10-2008 10:10 PM | 显示全部楼层
对。。。。。。

我怎样调换for 和while 的位置也无法找到一个适合的方法

然后,我能够去掉argv 和 argc吗? 会影响整个code吗?

[ 本帖最后由 Wongkokchoy 于 1-10-2008 10:12 PM 编辑 ]
回复

使用道具 举报

发表于 1-10-2008 10:17 PM | 显示全部楼层

回复 51# Wongkokchoy 的帖子

好了这次的事 borland c++ 5.02 compatable 的了。。
  1.                                                        #include <iostream.h>
  2. #include <stdlib.h>
  3. #include <time.h>



  4. /************* Function Phototype BEGIN *******************/

  5. void initialize_player_info( int pos[], bool player_gameover_flag[] , int no_player );
  6. /* set player starting position
  7.    argument: pos[] `player_position array`
  8.              no_player ` variable that hole " number of player " `
  9. */

  10. int player_move( int position );
  11. /* Player roll dice and move
  12.    If position > 100, reverse
  13.    climb ladder or slide down the snake if any

  14.    argument: position `Player current position`
  15.    return  : position `Player position`
  16. */


  17. int snake_and_ladder( int position );
  18. /* Change player position when player meets ladder or snake
  19.    print out statement to inform player

  20.    argument: position `Player current position`
  21.    return  : position `Player position after ladder and snake`
  22. */

  23. bool gameover( int position );
  24. /* Check is game over criteria meets?

  25.    argument: position `Player current position`
  26.    return  : TRUE  ` When game over`
  27.              FALSE ` When not yet game over`
  28. */

  29. void print_ladder( int position );
  30. /* print the statement when player meets a ladder
  31.    argument : position `Player position after meets a ladder`
  32.    return   : NONE
  33. */

  34. void print_snake( int position );
  35. /* print the statement when player meets a snake
  36.    argument : position `Player position after meets a snake`
  37.    return   : NONE
  38. */

  39. void print_gameover( int player );
  40. /* print out game over statement . i.e who wins
  41.    argument : player `Winning player`
  42.    return   : NONE
  43. */

  44. bool all_gameover( bool gameover_flag[], int no_player );

  45. /************** END FUNCTION PHOTOTYPE *****************/

  46. int main( int argc, char *argv[])
  47. {
  48.     // randomize rand() seed
  49.     srand( time(0));

  50.     int no_player, *player_position, current_player;
  51.     bool *player_gameover_flag;

  52.     cout << "Enter Number of Players : ";
  53.     cin >> no_player;
  54.     cin.get(); // get rid of enter key "line break"

  55.     player_position = new int[ no_player ];
  56.     player_gameover_flag = new bool [ no_player];

  57.     initialize_player_info( player_position, player_gameover_flag, no_player );


  58.     while( all_gameover( player_gameover_flag, no_player) == false )
  59.     {
  60.         for( current_player = 0; current_player < no_player; current_player++)
  61.         {
  62.             if( player_gameover_flag[ current_player ] == false )
  63.             {
  64.                 cout << "\n\nPlayer " << (current_player + 1) << " turn : " << endl;
  65.                 player_position[ current_player ] = player_move( player_position[ current_player ]);
  66.             }
  67.             else
  68.                 continue;

  69.             if (gameover( player_position[ current_player ] ))
  70.             {
  71.                     print_gameover( current_player );
  72.                     player_gameover_flag[current_player] = true;
  73.             }

  74.         }
  75.     }


  76.     return 0;

  77. }

  78. // set starting position of all player
  79. void initialize_player_info( int pos[], bool player_gameover_flag[], int no_player )
  80. {
  81.     while( --no_player >= 0 )
  82.     {
  83.         player_gameover_flag[ no_player ] = false;
  84.         pos[ no_player ] = 1 ;
  85.     }

  86.     return;
  87. }
  88.    
  89. int player_move( int position )
  90. {
  91.     int dice;
  92.     // roll dice and move

  93.     cout << "Rolling dice .. .. "
  94.          << "Press ENTER to continue ...";

  95.     cin.get();

  96.     dice = rand() % 6 + 1;

  97.     cout << "\n . . \n"
  98.          << ". . \n"
  99.          << ". . \n"
  100.          << "\n\nyou get " << dice << " !!" << endl
  101.          << "\nMoving forward !! " << endl;
  102.          
  103.     position += dice;

  104.     if( position > 100 )
  105.     {
  106.         cout << "OPPS!! \n"
  107.              << "You got to the wall , more than 100 !! \n"
  108.              << "Moving " << (position - 100) << " steps backward " << endl;

  109.         position = 100 - ( position - 100 );
  110.     }

  111.     cout << "You are now in position " << position << "!!" << endl;

  112.     position = snake_and_ladder( position );

  113.     return position;

  114. }


  115. int snake_and_ladder( int position )
  116. {
  117.     // put your snake and ladder information here
  118.     // e.g a ladder at position 4, goes to position 16
  119.     // case 4:
  120.     //    return 16;

  121.     switch( position )
  122.     {
  123.         case 4:
  124.             print_ladder(16);
  125.             return 16;

  126.         default:
  127.             return position;
  128.     }
  129. }

  130. bool gameover( int position )
  131. {
  132.     if (position == 100)
  133.         return true;
  134.     else
  135.         return false;
  136. }

  137. void print_gameover( int player )
  138. {
  139.     cout << "Player " << (player + 1) << " WINS!! " << endl
  140.          << "Congratulation " << endl;
  141. }

  142. void print_ladder( int position )
  143. {

  144.      cout << "Congratulation !! \n"
  145.           << "You climb up a ladder \n"
  146.           << "You are now at position " << position << " !!" << endl;
  147. }                                                            

  148. void print_snake( int position )
  149. {

  150.      cout << "OPPS!! \n"
  151.           << "You meets a snake \n"
  152.           << "You are now at position " << position << " !!" << endl;
  153. }

  154. bool all_gameover( bool gameover_flag[], int no_player )
  155. {
  156.     int count, i;

  157.     for( count = 0, i = 0;  i < no_player ; i++ )
  158.         if( gameover_flag[i] == true )
  159.             count++;

  160.     if( count < no_player  )
  161.         return false;
  162.     else
  163.         return true;


  164. }
复制代码
直接下载
http://onlylonly88.googlepages.com/ladder2.cpp
回复

使用道具 举报

发表于 1-10-2008 10:17 PM | 显示全部楼层

回复 53# Wongkokchoy 的帖子

可以去掉, 不会影响的
回复

使用道具 举报

 楼主| 发表于 1-10-2008 10:23 PM | 显示全部楼层
你的code可以run乐,谢谢你!!!

不过我的code真的不能够用了吗?不想枉费我一个礼拜的努力。。。
回复

使用道具 举报


ADVERTISEMENT

发表于 1-10-2008 10:28 PM | 显示全部楼层

回复 56# Wongkokchoy 的帖子

并非不能。 只是大部分的必须修改, 而且出现很多 redundant code ( repeat code )

基本上, 你一开始必须先将说有player 的 position 设定, 而不是在 run 这的时候设定。

然后再 for 哪里必须加入一个 gameover condition check
回复

使用道具 举报

 楼主| 发表于 1-10-2008 10:31 PM | 显示全部楼层
原帖由 onlylonly 于 1-10-2008 10:28 PM 发表


你一开始必须先将说有player 的 position 设定, 而不是在 run 这的时候设定。

然后再 for 哪里必须加入一个 gam ...



那里不时很明白。。。。。
回复

使用道具 举报

发表于 1-10-2008 11:04 PM | 显示全部楼层

回复 58# Wongkokchoy 的帖子

大概这样子 ( 我只是改了基本的, 很多logic error 我没有改)
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>

  5. #define m 50

  6. void Line()
  7. {
  8.     cout<<"-------------------------------------------------------------------------------\n";
  9. }

  10. int main()
  11. {
  12.     char dice;
  13.     int A, n, number, next, x;
  14.     int player[m];
  15.    
  16.     bool exit_flag = false;

  17.     Line();

  18.     cout<<"\t\tWelcome to Snake and Ladder Game!!\n\n";
  19.     cout<<"Introduction: if a player reach a point where there is a ladder, he/she will \nraise to a higher location.\n";
  20.     cout<<"\nOn the other hand, if the player reach a spot where there is a snake over there,the player will drop to a lower location.\n";
  21.     Line();
  22.     cout<<"\nNow please enter the numbers of players:\n";
  23.     cin>>n;
  24.     cout<<"\nSo there will be "<<n<<" player(s) in the game.\n";
  25.     cout<<"Good Luck and Have Fun!!!\n\n";
  26.     cout<<"(All players start at 0)\n\n\n";

  27.     for (x = 0; x < n; x++)
  28.         player[x] = 0;

  29.     while ( /*player[x]<=100*/ exit_flag == false )
  30.     {
  31.         for (x=0; x<n; x++)
  32.         {
  33.             srand(time(0));
  34.             cout<<"Press 'T' to throw a dice!\n";
  35.             cin>>dice;

  36.             if (dice=='T')
  37.             {
  38.                 A=(rand()%6)+1;
  39.                 if (A==1)
  40.                 {
  41.                     cout<<"\n   \n";
  42.                     cout<<" . \n";
  43.                     cout<<"   \n";
  44.                     cout<<"\n\nYou get 1!!\n";
  45.                 }
  46.                 else if (A==2)
  47.                 {
  48.                     cout<<"\n . \n";
  49.                     cout<<"   \n";
  50.                     cout<<" . \n";
  51.                     cout<<"\n\nYou get 2!!\n";
  52.                 }
  53.                 else if (A==3)
  54.                 {
  55.                     cout<<"\n.  \n";
  56.                     cout<<" . \n";
  57.                     cout<<"  .\n";
  58.                     cout<<"\n\nYou get 3!!\n";  
  59.                 }
  60.                 else if (A==4)
  61.                 {
  62.                     cout<<"\n. .\n";
  63.                     cout<<"   \n";
  64.                     cout<<". .\n";
  65.                     cout<<"\n\nYou get 4!!\n";
  66.                 }
  67.                 else if (A==5)
  68.                 {
  69.                     cout<<"\n. .\n";
  70.                     cout<<" . \n";
  71.                     cout<<". .\n";
  72.                     cout<<"\n\nYou get 5!!\n";
  73.                 }
  74.                 else if (A==6)
  75.                 {      
  76.                     cout<<"\n. .\n";
  77.                     cout<<". .\n";
  78.                     cout<<". .\n";
  79.                     cout<<"\n\nYou get 6!!\n";
  80.                 }

  81.                 player[x]+=A;
  82.                
  83.                 if( player[x] > 100 )
  84.                     player[x] = 100 - ( player[x] - 100 );
  85.                     
  86.                 number=x+1;
  87.                 cout<<"Player "<<number<<" had reached "<<player[x]<<"\n";
  88.                 cout<<"\n";
  89.             }
  90.             
  91.             if ( player[x]==100 )
  92.             {
  93.                 cout << "Player[" << x << "] wins" << endl;
  94.                 exit_flag = true;
  95.                 break;
  96.             }            
  97.         }

  98.         
  99.         if (x==n-1)
  100.             continue;

  101.         next=number+1;
  102.         cout<<"\n\nPlayer "<<next<<"'s turn!!!\n";
  103.         

  104.     }
  105. }
复制代码
回复

使用道具 举报

发表于 1-10-2008 11:06 PM | 显示全部楼层
老实说
onlyonly的coding level比较高
你不能直接抄, 老师会知道的

#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define m 50
void Line()
{
cout<<"-------------------------------------------------------------------------------\n";
}
void main()
{
char dice;
int A, n, number, next;
int player[m];
Line();
cout<<"\t\tWelcome to Snake and Ladder Game!!\n\n";
cout<<"Introduction: if a player reach a point where there is a ladder, he/she will \nraise to a higher location.\n";
cout<<"\nOn the other hand, if the player reach a spot where there is a snake over there,the player will drop to a lower location.\n";
Line();
cout<<"\nNow please enter the numbers of players:\n";
cin>>n;
cout<<"\nSo there will be "<<n<<" player(s) in the game.\n";
cout<<"Good Luck and Have Fun!!!\n\n";
cout<<"(All players start at 0)\n\n\n";
for (int x=0; x<n; x++)  你的program不能给player 轮流roll dice的问题, 就是这里
{
player[x]=0;
while (player[x]<=100)
{
srand(time(0));
cout<<"ress 'T' to throw a dice!\n";
cin>>dice;
if (dice=='T')
{
A=(rand()%6)+1;
if (A==1)
{
cout<<"\n   \n";
cout<<" . \n";
cout<<"   \n";
cout<<"\n\nYou get 1!!\n"; redundant code
}
else if (A==2)
{
cout<<"\n . \n";
cout<<"   \n";
cout<<" . \n";
cout<<"\n\nYou get 2!!\n"; redundant code
}
else if (A==3)
{
cout<<"\n.  \n";
cout<<" . \n";
cout<<"  .\n";
cout<<"\n\nYou get 3!!\n"; redundant code
}
else if (A==4)
{
cout<<"\n. .\n";
cout<<"   \n";
cout<<". .\n";
cout<<"\n\nYou get 4!!\n"; redundant code
}
else if (A==5)
{
cout<<"\n. .\n";
cout<<" . \n";
cout<<". .\n";
cout<<"\n\nYou get 5!!\n"; redundant code
}
else if (A==6)
{
cout<<"\n. .\n";
cout<<". .\n";
cout<<". .\n";
cout<<"\n\nYou get 6!!\n";
redundant code
}
player[x]+=A;
number=x+1;
cout<<"layer "<<number<<" had reached "<<player[x]<<"\n";
cout<<"\n";
}
}
if (x==n-1)
continue;
next=number+1;
cout<<"\n\nPlayer "<<next<<"'s turn!!!\n";
}
}

[ 本帖最后由 晨天 于 1-10-2008 11:08 PM 编辑 ]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 25-12-2025 04:20 AM , Processed in 0.140966 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表