using System; using System.Collections.Generic; using System.Text; namespace BoardGame { class PlayerPosition { // Attributes private int _position; private int _boardWidth; private int _boardHeight; private static Random _rnd = new Random(); // Constructor public PlayerPosition(int boardWidth, int boardHeight) { _position = 0; _boardWidth = boardWidth; _boardHeight = boardHeight; } // Properties // Methods public int GetX() { // Odd rows are traversed right to left return GetY() % 2 == 1 ? ((_boardWidth - 1) - _position % _boardWidth) : (_position % _boardWidth); } public int GetY() { return _position / _boardWidth; } public void ThrowDice() { // Random die value between 1 and 6 int diceValue = _rnd.Next(0, 6) + 1; Console.WriteLine("Dice thrown {0}", diceValue); if ((_position + diceValue) < (_boardWidth * _boardHeight)) { _position = _position + diceValue; } } } }