Revert "Removing byte order...
Dev Ghai authored 11 years ago
|
2) using System.Text;
3)
4) namespace Boggle
5) {
6) public class BoggleBoard
7) {
8) private readonly Tile[,] _Tiles;
9) /// <summary>
10) /// A 2D array containing all the tles in the board.
11) /// This is a read only propert
12) /// </summary>
13) public Tile[,] Tiles
14) {
15) get
16) {
17) return _Tiles;
18) }
19) }
20)
21) private readonly int _SideLength;
22) /// <summary>
23) /// Number of tiles in one side of the square board.
24) /// This is a read only property.
25) /// </summary>
26) public int SideLength
27) {
28) get
29) {
30) return _SideLength;
31) }
32) }
33)
34) /// <summary>
35) /// BoggleBoard constructor.
36) /// </summary>
37) /// <param name="sideLength">Number of TILES that make up the side of the board.</param>
38) /// <param name="letters">String containing alphabets in row first order.</param>
39) public BoggleBoard(int sideLength, string letters)
40) {
41) if (sideLength < Constants.MIN_SIDE_LENGTH)
42) {
43) throw new ArgumentException(string.Format("Length of side of board has to be greater than or equal to {0}", Constants.MIN_SIDE_LENGTH));
44) }
45)
46) int numTiles = sideLength * sideLength;
47)
48) if (letters.Length != numTiles)
49) {
50) throw new ArgumentException(string.Format("Board's initialization string contains {0} characters. {1} characters were expected. 'Q' tranlates to 'QU' internally and only 'Q' needs to be mentioned.", letters.Length, numTiles));
51) }
52) _SideLength = sideLength;
53) _Tiles = new Tile[_SideLength, _SideLength];
54)
55) //row-first addition = manner in which humans read.
56) string alphabet;
57) for (int i = 0; i < sideLength; i++)
58) {
59) for (int j = 0; j < sideLength; j++)
60) {
61) alphabet = letters.Substring(i * sideLength + j, 1);
62) //the special condition
63) if (alphabet == "Q")
64) alphabet += "U";
65) _Tiles[j, i] = new Tile(j, i, alphabet);
66) }
67) }
68) }
69)
70) /// <summary>
71) /// Copy constructor.
72) /// </summary>
73) /// <param name="orignalBoard">Board to copy.</param>
74) public BoggleBoard(BoggleBoard orignalBoard)
75) {
76) _SideLength = orignalBoard._SideLength;
77) _Tiles = new Tile[_SideLength, _SideLength];
78) for (int i = 0; i < _SideLength; i++)
79) {
80) for (int j = 0; j < _SideLength; j++)
81) {
82) _Tiles[i, j] = new Tile(i, j, orignalBoard.Tiles[i, j].Alphabet);
83) }
84) }
85) }
86)
87) /// <summary>
88) /// Indexer to allow more natural access to tiles in the board.
89) /// </summary>
90) /// <param name="x">X co-ordinate of the tile in the board.</param>
91) /// <param name="y">Y co-ordinate of the tile in the board.</param>
92) /// <returns>Tile at x, y co-ordinate.</returns>
93) public Tile this[int x, int y]
94) {
95) get
96) {
97) return _Tiles[x, y];
98) }
99) }
100)
101) /// <summary>
102) /// Prints out the board on console.
103) /// </summary>
104) public void Print()
105) {
|
Revert "Removing byte order...
Dev Ghai authored 11 years ago
|
107) StringBuilder line = new StringBuilder(horizontalLength);
108) string horizontalSeparator = string.Empty;
109) for (int i = 0; i < horizontalLength; i++)
110) {
111) horizontalSeparator += "\u2550";
112) }
113)
114) for (int i = 0; i < _SideLength; i++)
115) {
116) Console.WriteLine(horizontalSeparator);
117) line.Clear();
118) line.Append("\u2551");
119) for (int j = 0; j < _SideLength; j++)
120) {
|