Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1525|回复: 1
打印 上一主题 下一主题

C++ 求救

[复制链接]

27

主题

1

好友

2288

积分

白金长老

Rank: 10

跳转到指定楼层
1#
发表于 2012-1-7 07:41 PM |只看该作者 |倒序浏览
这是是小弟我的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);
                }
        }




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 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



應用例子 :

  1. #include <stdio.h>
  2. #include <math.h>


  3. short dice()
  4. {
  5.         srand(time(0));
  6.         return rand() % 6 + 1;
  7. }

  8. int main()
  9. {
  10.       unsigned short round = 0; total = 0;

  11.       while( 1 )
  12.       {
  13.            total += dice();
  14.            round ++;

  15.            printf( "Round %u : %u\n", round, total );

  16.            if( round >= 10 )
  17.                 break;
  18.       }

  19.       return 0;
  20. }
复制代码


回复

使用道具 举报

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

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-26 07:29 AM , Processed in 0.102095 second(s), 27 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部