-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameState.cs
101 lines (83 loc) · 3.35 KB
/
GameState.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace Monopoly
{
public class GameState
//contains the majority of the game logic, as well as the game elements
//creates the board, deck, and players
{
private Board mBoard;
private int mTurnCount;
private Player[] mPlayers;
private int mActivePlayerID;
private Deck[] mDecks;
private DoublesQueue[] mDoublesQueues;
public GameState()
{
SetState();
}//Game()
//PROPERTIES
public Deck[] Decks { get { return mDecks; } set { mDecks = value; } }
public Player[] Players { get { return mPlayers; } private set { mPlayers = value; } }
public Board Board { get { return mBoard; } private set { mBoard = value; } }
public int ActivePlayerID { get { return mActivePlayerID; } set { mActivePlayerID = value; } }
public int TurnCount { get { return mTurnCount; } set { mTurnCount = value; } }
public DoublesQueue[] Doubles { get { return mDoublesQueues; } set { mDoublesQueues = value; } }
public int LastRoll { get; set; }
public bool IsOver { get; set; }
public int WinnerID { get; set; }
public RollState RollState { get; set; }
public bool IsStarted { get; set; }
public int[] StartingRolls { get; set; }
public List<String> GameLog { get; set; }
//METHODS
public Player GetActivePlayer()
{
Player thisPlayer = this.Players[this.ActivePlayerID];
return thisPlayer;
}//GetActivePlayer()
public Tiles.BoardSpace GetActiveTile()
{
Player thisPlayer = this.GetActivePlayer();
Tiles.BoardSpace thisTile = this.Board.BoardSpaces[thisPlayer.Position];
return thisTile;
}//GetActiveTile()
public void SetState()
//Used as both the constructor and a publicly callable function to reset the state of the game
{
this.Board = new Board();
this.Players = new Player[2];
this.Decks = new Deck[2];
TurnCount = 1;
ActivePlayerID = 0;
Players[0] = new Player(0);
Players[1] = new Player(1);
Decks[0] = new Deck(1, DeckType.CommunityChest);
Decks[1] = new Deck(2, DeckType.Chance);
BoardfileReader reader = new BoardfileReader("Boards\\DefaultBoard.csv");
Board = reader.CreateBoard();
//Create an array of queues for each player. This will be used to hold a boolean for
//the last three rolls, representing if it was a double.
mDoublesQueues = new DoublesQueue[Players.Length];
for (int i = 0; i <= Players.Length - 1; i++)
{
mDoublesQueues[i] = new DoublesQueue(new Queue<bool>());
}//for
this.LastRoll = 0;
IsOver = false;
IsStarted = false;
StartingRolls = new int[2];
StartingRolls[0] = 0;
StartingRolls[1] = 0;
}//SetState()
public void Log(String logMessage)
{
GameLog.Add(logMessage);
}//Log()
}//class Game
}//Monopoly