源码:
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((