Skip to content

Commit

Permalink
update stock everyday
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonly committed Apr 30, 2016
1 parent f7f8044 commit a06bf27
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Monopoly/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ namespace monopoly {
// TODO: test
gs.message += "新闻事件:\n";
int r0 = rand() % 5;
r0 = 3;
vector<Player>::iterator it, itMax, itMin;
switch (r0)
{
Expand Down Expand Up @@ -530,8 +531,10 @@ namespace monopoly {
p.done = false;
}
gs.today.nextDay();
gs.stockMarket.update();
}
if (gs.today.d[2] == 1) { // 月初发钱
if (gs.today.d[2] == 1) {
// 月初发钱
vector<Player>::iterator it;
for (it = gs.players.begin(); it != gs.players.end(); it++) {
it->deposit *= 1.1;
Expand Down
8 changes: 8 additions & 0 deletions Monopoly/Stock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ namespace monopoly {
playerMap[playerName][serial] -= n;
if (playerMap[playerName][serial] < 0) playerMap[playerName][serial] = 0;
}

void StockMarket::update() {
double ratio;
for (vector<Stock>::iterator it = stocks.begin(); it != stocks.end(); it++) {
ratio = static_cast<double>(rand() % 100) / 1000;
it->price *= (1 + ratio);
}
}
}
2 changes: 2 additions & 0 deletions Monopoly/Stock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string>
#include <vector>
#include <map>
#include <cstdlib>

namespace monopoly {

Expand All @@ -38,6 +39,7 @@ namespace monopoly {
Stock find(string);
void buy(string, string, int);
void sell(string, string, int);
void update();
};

}
Expand Down

0 comments on commit a06bf27

Please sign in to comment.