|
|
发表于 1-10-2008 08:02 PM
|
显示全部楼层
回复 40# Wongkokchoy 的帖子
看看是不是-
- for( count = 0, i = 0; i < no_player ; i++ )
- if( gameover_flag == true )
- count++;
复制代码 改成- for( count = 0, i = 0; i < no_player ; i++ )
- if( gameover_flag[i] == true )
- count++;
复制代码 佳礼的 【code】 有问题的。。 编辑过后会少东西。
我upload 了, 直接下载来试试看
http://onlylonly88.googlepages.com/Untitled1.cpp |
|
|
|
|
|
|
|
|
|
|

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

楼主 |
发表于 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 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-10-2008 08:34 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 1-10-2008 08:35 PM
|
显示全部楼层
回复 47# Wongkokchoy 的帖子
也可以, 你将code 贴上来
用 【code】 【/code】 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-10-2008 08:42 PM
|
显示全部楼层
原帖由 onlylonly 于 1-10-2008 08:35 PM 发表 
也可以, 你将code 贴上来
用 【code】 【/code】 - #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++)
- {
- 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";
- }
- else if (A==2)
- {
- cout<<"\n . \n";
- cout<<" \n";
- cout<<" . \n";
- cout<<"\n\nYou get 2!!\n";
- }
- else if (A==3)
- {
- cout<<"\n. \n";
- cout<<" . \n";
- cout<<" .\n";
- cout<<"\n\nYou get 3!!\n";
- }
- else if (A==4)
- {
- cout<<"\n. .\n";
- cout<<" \n";
- cout<<". .\n";
- cout<<"\n\nYou get 4!!\n";
- }
- else if (A==5)
- {
- cout<<"\n. .\n";
- cout<<" . \n";
- cout<<". .\n";
- cout<<"\n\nYou get 5!!\n";
- }
- else if (A==6)
- {
- cout<<"\n. .\n";
- cout<<". .\n";
- cout<<". .\n";
- cout<<"\n\nYou get 6!!\n";
- }
- 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 09:04 PM
|
显示全部楼层
回复 49# Wongkokchoy 的帖子
不如索性upload 然后给我link? 我懒惰做indentation  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-10-2008 09:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 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 的了。。  - #include <iostream.h>
- #include <stdlib.h>
- #include <time.h>
- /************* Function Phototype BEGIN *******************/
- void initialize_player_info( int pos[], bool player_gameover_flag[] , int no_player );
- /* set player starting position
- argument: pos[] `player_position array`
- no_player ` variable that hole " number of player " `
- */
- int player_move( int position );
- /* Player roll dice and move
- If position > 100, reverse
- climb ladder or slide down the snake if any
- argument: position `Player current position`
- return : position `Player position`
- */
- int snake_and_ladder( int position );
- /* Change player position when player meets ladder or snake
- print out statement to inform player
- argument: position `Player current position`
- return : position `Player position after ladder and snake`
- */
- bool gameover( int position );
- /* Check is game over criteria meets?
- argument: position `Player current position`
- return : TRUE ` When game over`
- FALSE ` When not yet game over`
- */
- void print_ladder( int position );
- /* print the statement when player meets a ladder
- argument : position `Player position after meets a ladder`
- return : NONE
- */
- void print_snake( int position );
- /* print the statement when player meets a snake
- argument : position `Player position after meets a snake`
- return : NONE
- */
- void print_gameover( int player );
- /* print out game over statement . i.e who wins
- argument : player `Winning player`
- return : NONE
- */
- bool all_gameover( bool gameover_flag[], int no_player );
- /************** END FUNCTION PHOTOTYPE *****************/
- int main( int argc, char *argv[])
- {
- // randomize rand() seed
- srand( time(0));
- int no_player, *player_position, current_player;
- bool *player_gameover_flag;
- cout << "Enter Number of Players : ";
- cin >> no_player;
- cin.get(); // get rid of enter key "line break"
- player_position = new int[ no_player ];
- player_gameover_flag = new bool [ no_player];
- initialize_player_info( player_position, player_gameover_flag, no_player );
- while( all_gameover( player_gameover_flag, no_player) == false )
- {
- for( current_player = 0; current_player < no_player; current_player++)
- {
- if( player_gameover_flag[ current_player ] == false )
- {
- cout << "\n\nPlayer " << (current_player + 1) << " turn : " << endl;
- player_position[ current_player ] = player_move( player_position[ current_player ]);
- }
- else
- continue;
- if (gameover( player_position[ current_player ] ))
- {
- print_gameover( current_player );
- player_gameover_flag[current_player] = true;
- }
- }
- }
- return 0;
- }
- // set starting position of all player
- void initialize_player_info( int pos[], bool player_gameover_flag[], int no_player )
- {
- while( --no_player >= 0 )
- {
- player_gameover_flag[ no_player ] = false;
- pos[ no_player ] = 1 ;
- }
- return;
- }
-
- int player_move( int position )
- {
- int dice;
- // roll dice and move
- cout << "Rolling dice .. .. "
- << "Press ENTER to continue ...";
- cin.get();
- dice = rand() % 6 + 1;
- cout << "\n . . \n"
- << ". . \n"
- << ". . \n"
- << "\n\nyou get " << dice << " !!" << endl
- << "\nMoving forward !! " << endl;
-
- position += dice;
- if( position > 100 )
- {
- cout << "OPPS!! \n"
- << "You got to the wall , more than 100 !! \n"
- << "Moving " << (position - 100) << " steps backward " << endl;
- position = 100 - ( position - 100 );
- }
- cout << "You are now in position " << position << "!!" << endl;
- position = snake_and_ladder( position );
- return position;
- }
- int snake_and_ladder( int position )
- {
- // put your snake and ladder information here
- // e.g a ladder at position 4, goes to position 16
- // case 4:
- // return 16;
- switch( position )
- {
- case 4:
- print_ladder(16);
- return 16;
- default:
- return position;
- }
- }
- bool gameover( int position )
- {
- if (position == 100)
- return true;
- else
- return false;
- }
- void print_gameover( int player )
- {
- cout << "Player " << (player + 1) << " WINS!! " << endl
- << "Congratulation " << endl;
- }
- void print_ladder( int position )
- {
- cout << "Congratulation !! \n"
- << "You climb up a ladder \n"
- << "You are now at position " << position << " !!" << endl;
- }
- void print_snake( int position )
- {
- cout << "OPPS!! \n"
- << "You meets a snake \n"
- << "You are now at position " << position << " !!" << endl;
- }
- bool all_gameover( bool gameover_flag[], int no_player )
- {
- int count, i;
- for( count = 0, i = 0; i < no_player ; i++ )
- if( gameover_flag[i] == true )
- count++;
- if( count < no_player )
- return false;
- else
- return true;
- }
复制代码 直接下载
http://onlylonly88.googlepages.com/ladder2.cpp |
|
|
|
|
|
|
|
|
|
|
发表于 1-10-2008 10:17 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-10-2008 10:23 PM
|
显示全部楼层
你的code可以run乐,谢谢你!!!
不过我的code真的不能够用了吗?不想枉费我一个礼拜的努力。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 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-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 编辑 ] |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|