当前位置: 首页>>代码示例>>C++>>正文


C++ Human::getroll方法代码示例

本文整理汇总了C++中Human::getroll方法的典型用法代码示例。如果您正苦于以下问题:C++ Human::getroll方法的具体用法?C++ Human::getroll怎么用?C++ Human::getroll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Human的用法示例。


在下文中一共展示了Human::getroll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: move

/*******************************************************************************
                                    move
 *******************************************************************************
 * purpose: To move Player around the board
 * input:
 *      p1loc-> takes in the players location on the board
 *      p1->    to move computer around the board c1 times
 *      p1bal-> if passed go add $200
 *      pmove[]->sets new location for computer
 * output:
 *      p1bal->if passed go collect $200
 *      p1loc->if passed go starts at the beginning
 */
int move(Human &h,int pmove[]){
    //Used to make sure the board is set to 0
    for(int i=0;i<SIZE;i++){
        pmove[i]=0;
    }
    for(int i=0;i<=h.getroll();i++){
        if(h.getloc()>39){
            h.setloc(h.getloc()-39);
            cout<<"You passed 'Go' please collect $200\n";
            h.setmoney(h.getMoney()+200);
        }else{
            pmove[h.getloc()]=1;
        }
    }
}
开发者ID:espinozahector,项目名称:EspinozaHector_CIS17a_43950,代码行数:28,代码来源:main.cpp

示例2: main

//Execution Begins here
int main(int argc, char** argv) {
    //Set the random number seed and size the array
    srand(static_cast<unsigned int>(time(0)));
    
    //Declare Variables
    Human h;
    
//    int p1=0;//player dice ===== is now roll
//    int p1bal=1500;//player bank account === is now bal
//    int p1loc=0;//player location on the board ==== is now loc
    int c1=0; //The computer's dice 
    int c1bal=1500;//The computer's bank account
    int c1loc=0;//computer's location on the board
    
    bool who=true;//used to see who's turn it is
    bool prison=true;//If the player is in jail 
    bool cprison=true;//If the computer is in jail
    bool game=true;//to continue the game until there is a winner
    char check;//is the player would like to buy
    int play=0;//play the game or see rules
    int buyans;//If the user would like to buy the property
    int turn=1; //Turns if the player or computer land on jail
    
    House *board=new House[SIZE];//dynamic array to hold the name, buy and rent of the property
    string property[SIZE]={"Go","Mediterranean Avenue","Community Chest","Baltic Avenue"," Income Tax","Reading Railroad",
                         "Oriental Avenue","Chance","Vermont Avenue","Connecticut Avenue","In Jail or Just visiting","St. Charles Place",
                         "Electric Company","States Avenue"," Virginia Avenue","Pennsylvania RailRoad","St. James Place",
                         "Community Chest","Tennessee Avenue"," New York Avenue","Free Parking","Kentucky Avenue","Chance",
                         "Indiana Avenue","Illinois Avenue"," B. & O. Railroad","Atlantic Avenue","Ventnor Avenue",
                         "Water Works","Marvin Gardens","Go to Jail","Pacific Avenue","North Carolina Avenue",
                         "Community Chest","Pennsylvania Avenue","Short Line","Chance","Park Place","Luxury Tax","BoardWalk"};
    int buy[SIZE]={0,60,0,60,0,200,100,0,100,120,0,140,150,140,160,200,180,0,180,
                   200,0,220,0,220,240,200,260,260,150,280,0,300,300,0,320,200,0,350,0,400};
    int rent[SIZE]={0,20,0,40,0,25,60,0,60,80,0,100,75,100,120,250,140,0,140,160,
                    0,180,0,180,200,250,220,220,75,240,0,260,260,0,280,250,0,350,0,500};
     for(int i=0;i<SIZE;i++){
    board[i].setName(property[i]);
    board[i].setBuy(buy[i]);
    board[i].setRent(rent[i]);
    }
    
    bool avail[SIZE];//if the house is owned or available
    //sets the whole board to true available to buy
    
    for(int i=0;i<SIZE;i++){
        avail[i]=true;
        //Sets the chance,go,income tax, et. to not able to buy
        if (i==0 || i==2 || i==4 || i==7 ||i==10 || i==17 || i==20 || i==22 || i==30 || i==33 || i==36 || i==38){
            avail[i]=false;
        }
    }
    
    int pmove[SIZE];//is the player's board
    int cmove[SIZE];//the computers board
    vector <int> p1prop;
    vector <int> c1prop;
    //sets the whole array to 0
    for(int i=0;i<SIZE;i++){
        pmove[i]=0;
        cmove[i]=0;
    }
    
    do{
        do{
            cout<<"Welcome to the Monopoly game!!!\n";
            cout<<"Each player starts off with $1500\n";
            cout<<"1. To play the game\n2. To see the rules\n";
            cin>>play;
            if(play<1 || play>2){
                cout<<"ERROR: Invalid Input\n";
            }
        }while(play<1 || play>2);
        
        switch(play){
            case 1:{
                do{
                    if(game!=false){
                        if(cprison==false){
                            turn=2;  
                            cprison=true;      
                        }else{
                            turn=1;
                        }
                        for(int i=1;i<=turn;i++){
                            who=true;
                            h.setroll(roll(6,2));
                            cout<<"Player 1 you rolled your dice and got "<<h.getroll()<<endl;
                            cout<<"Move forward "<<h.getroll()<<" spaces."<<endl; 
                            pmove[h.getloc()]=0;
                            h.setloc(h.getloc()+h.getroll());

                            move(h,pmove);
                            
                            cout<<"You landed on "<<property[h.getloc()]<<endl;
                            if(h.getloc()==4 || h.getloc()==38){
                                pay(h,c1bal,c1loc,who);
                            }
                            if(h.getloc()==7 || h.getloc()==22 || h.getloc()==36){
                                chance(h,pmove,c1loc,cmove,c1,c1bal,prison,cprison,who);
//.........这里部分代码省略.........
开发者ID:espinozahector,项目名称:EspinozaHector_CIS17a_43950,代码行数:101,代码来源:main.cpp


注:本文中的Human::getroll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。