forked from plutoscarab/Rails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStateFrame.cs
56 lines (50 loc) · 1.78 KB
/
StateFrame.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// StateFrame.cs
/*
* This class stores the game state information for the current player only,
* so that the game can be restored to a previous state using the Undo feature.
*
*/
using System;
namespace Rails
{
public class StateFrame
{
public string Message; // reason for the frame (title of Undo menu item)
Player PlayerInfo; // current player's info
int[,,] Track; // track
int AccumCost; // money spent this turn
int AccumTime; // time spent this turn
RandomState ContractRandomState; // state of the random number generator for new contracts
bool[] CityIncentive; // which are incentive cities
bool[] CityWasVisited; // for first-to-city bonuses
int[] Availability; // for limited commodity option
bool[] UseTrack; // which track can be ridden
// make a copy of the current game state
public StateFrame(GameState state, string message)
{
Message = message;
PlayerInfo = new Player(state.ThisPlayer);
Track = (int[,,]) state.Track.Clone();
AccumCost = state.AccumCost;
AccumTime = state.AccumTime;
ContractRandomState = Contract.RandomState;
CityIncentive = (bool[]) state.CityIncentive.Clone();
CityWasVisited = (bool[]) state.CityWasVisited.Clone();
Availability = (int[]) state.Availability.Clone();
UseTrack = (bool[]) state.UseTrack.Clone();
}
// restore the game state from the copy
public void Restore(GameState state)
{
state.PlayerInfo[state.CurrentPlayer] = PlayerInfo;
state.Track = Track;
state.AccumCost = AccumCost;
state.AccumTime = AccumTime;
Contract.RandomState = ContractRandomState;
state.CityIncentive = CityIncentive;
state.CityWasVisited = CityWasVisited;
state.Availability = Availability;
state.UseTrack = UseTrack;
}
}
}