课程设计(大富翁)

源码:

player类的定义(land.h):

#pragma once
#include<string>
#include<vector>
#include"land.h"
#include"card.h"
using namespace std;
class land; 
class player{
private:
    string name;
    int money;
    vector<land*>pland;
    int location;
public:
    bool canmove;
    string get_name();
    int get_location();
    int get_money();
    friend class land;
    friend class card;
    void change_move();
    void change_money();
    void change_location();
    player(string s, int m,int l,bool can);
    player();//构造函数;
    void pay(player *p, land l);//支付过路费;
    void pay(land l);//重载支付函数,用于向银行支付;
    void move();//按点数移动;
    void buy(land* l);
    //判断是否破产;
    bool isbankrupt();
    void get_infor();

    ~player() {}

};

player类的实现(player.cpp):

#include "stdafx.h"
#include "player.h"
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
#include"land.h"
#include<iomanip>
using namespace std;
player::player(string s, int m, int l=1,bool can=true) :name(s), money(m),location(l),canmove(can){}
string player::get_name() {
    return name;
}
int player::get_location() {
    return location;
}
int player::get_money() {
    return money;
}
void player::pay(player *p, land l) {
    p->money += l.fee+l.num_house*1000;
    money -= l.fee;
}
void player::pay(land l) {
    money -= l.fee;
}
void player::get_infor() {
    cout << this->get_name() << "账户余额:" << this->get_money()<< "当前位置:" << this->get_location() << endl;
    cout << this->get_name() << "所拥有的土地,每个土地上的房子数量:"<<endl;
    for (int i = 0; i < pland.size(); i++) {
        cout << setiosflags(ios::left) << setw(12) << pland[i]->get_name() << setw(4) << pland[i]->get_num() << endl;
    }
}
void player::move() {
    srand((
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值