JBTALKS.CC
标题:
C++ 求救
[打印本页]
作者:
Autistic紅毛丹
时间:
2012-1-7 07:41 PM
标题:
C++ 求救
这是是小弟我的code...
小弟我面对的问题是如何将dice 的号码加起来,然后显示和update 我的界面??
最后是如何重复的roll dice .... 谢谢...
int display()
{
string a[10][10] = {{"100","99","98","97","96","95","94","93","92","91"},
{"81","82","83","84","85","86","87","88","89","90"},
{"80","79","78","77","76","75","74","73","72","71"},
{"61","62","63","64","65","66","67","68","69","70"},
{"60","59","58","57","56","55","54","53","52","51"},
{"41","42","43","44","45","46","47","48","49","50"},
{"40","39","38","37","36","35","34","33","32","31"},
{"21","22","23","24","25","26","27","28","29","30"},
{"20","19","18","17","16","15","14","13","12","11"},
{"1","2","3","4","5","6","7","8","9","10"}};
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
cout << a[i][j] << "\t";
}
cout << endl;
}
}
void display_snake()
{
cout << "======================================" << endl;
cout << " SNAKE POSITION " << endl;
cout << "======================================" << endl;
cout << "\tFROM 18 TO 6" << endl;
cout << "\tFROM 36 TO 14" << endl;
cout << "\tFROM 52 TO 30" << endl;
cout << "\tFROM 65 TO 54" << endl;
cout << "\tFROM 72 TO 24" << endl;
cout << "\tFROM 92 to 48" << endl;
cout << "\tFROM 98 to 57" << endl << endl;
}
void display_ladder()
{
cout << "======================================" << endl;
cout << " LADDER POSITION " << endl;
cout << "======================================" << endl;
cout << "\tFROM 3 TO 25" << endl;
cout << "\tFROM 8 TO 34" << endl;
cout << "\tFROM 37 TO 67" << endl;
cout << "\tFROM 56 TO 78" << endl;
cout << "\tFROM 69 TO 87" << endl;
cout << "\tFROM 71 to 91" << endl;
cout << "\tFROM 80 to 99" << endl << endl;
}
void dice(int random)
{
srand(time(0));
random = (rand()%6 + 1);
cout << "Dice number: " << random << endl ;
}
int main()
{
int random;
int count;
int a[9][9];
string player1, player2;
system("cls");
cout << "=======================================" << endl;
cout << " SNAKE AND LADDER GAME " << endl;
cout << "=======================================" << endl;
cout << endl;
display();
display_snake();
display_ladder();
cout << "Enter Name of Player 1: ";
getline(cin,player1);
cout << endl << "Enter Name of Player 2: ";
getline(cin,player2);
for(int i = 1; i > 0; i++)
{
if(i % 2 == 1)
{
cout << "It's " << player1 << " turn to roll the dice." << endl;
system("pause");
dice(random);
}
else if(i % 2 == 0)
{
cout << "It's " << player2 << " turn to roll the dice." << endl;
system("pause");
dice(random);
}
}
作者:
Super-Tomato
时间:
2012-1-7 09:07 PM
本帖最后由 Super-Tomato 于 2012-1-7 09:12 PM 编辑
这是是小弟我的code...
小弟我面对的问题是如何将dice 的号码加起来,然后显示和update 我的界面??
最后 ...
Autistic紅毛丹 发表于 2012-1-7 07:41 PM
void dice(int random)
{
srand(time(0));
random = (rand()%6 + 1);
cout << "Dice number: " << random << endl ;
}
以上這样 random 参數的使用方式不對,要做累加就必須把亂數回傳
不懂你所說的顯示和 update 是甚麼意思
想不斷循环的話就使用 while
應用例子 :
#include <stdio.h>
#include <math.h>
short dice()
{
srand(time(0));
return rand() % 6 + 1;
}
int main()
{
unsigned short round = 0; total = 0;
while( 1 )
{
total += dice();
round ++;
printf( "Round %u : %u\n", round, total );
if( round >= 10 )
break;
}
return 0;
}
复制代码
欢迎光临 JBTALKS.CC (https://jbtalks.my/)
Powered by Discuz! X2.5