private static BoardCell[][] Generate(BdtBoard board, Dictionary <TrenElementButtonType, BoardCell> buttonDimensions) { // convert to cells var cells = new BoardCell[board.GetLength()][]; for (int row = 0; row < cells.Length; row++) { // create column cells[row] = new BoardCell[board.GetLength(row)]; for (int col = 0; col < cells[row].Length; col++) { var elem = board.GetAt(row, col); BoardCell dim = null; // create the array switch (elem.Type) { case TrenElementType.City: dim = elem.Dimension; break; case TrenElementType.Track: // construct the track that connects the two cities // get the bounds var top = Single.MaxValue; var endTop = 0f; var left = Single.MaxValue; var endLeft = 0f; var elemWidth = 0f; var elemHeight = 0f; foreach (var city in elem.Connections) { top = Math.Min(top, city.Dimension.Top); endTop = Math.Max(endTop, city.Dimension.Top); left = Math.Min(left, city.Dimension.Left); endLeft = Math.Max(endLeft, city.Dimension.Left); elemWidth += city.Dimension.Width; elemHeight += city.Dimension.Height; } elemWidth /= ((float)elem.Connections.Count); elemHeight /= ((float)elem.Connections.Count); // add tracks between var xgap = (endLeft - left) / cells[row].Length; var ygap = (endTop - top) / cells[row].Length; var trackWidth = 10f; var trackHeight = 10f; // adjust to the edge and column number left += (elemWidth) + (xgap * col); top += (elemHeight) + (ygap * col); dim = new BoardCell( points: new engine.Common.Point[] { new engine.Common.Point(x: left, y: top, z: 0), new engine.Common.Point(x: left, y: top + trackHeight, z: 0), new engine.Common.Point(x: left + trackWidth, y: top + trackHeight, z: 0), new engine.Common.Point(x: left + trackWidth, y: top, z: 0) } ); break; case TrenElementType.Destination: case TrenElementType.Button: if (!buttonDimensions.TryGetValue(elem.ButtonType, out dim)) { throw new Exception("Unknow button type : " + elem.ButtonType); } break; default: throw new Exception("Unknown TrenElementType : " + elem.Type); } // case // set if (dim == null) { throw new Exception("Failed to determine dimensions"); } cells[row][col] = dim; } // for } // for return(cells); }
private void UpdateCell(int row, int col) { var cell = Cells[row][col]; var elem = BdtBoard.GetAt(row, col); Board.UpdateCell(row, col, (img) => { img.Graphics.Clear(RGBA.White); img.MakeTransparent(RGBA.White); var color = RGBA.White; switch (elem.Type) { case TrenElementType.City: color = RGBA.Black; break; case TrenElementType.Track: if (elem.InUse) { switch (elem.Color) { case TrenColor.Black: color = RGBA.Black; break; case TrenColor.Blue: color = new RGBA() { B = 255, A = 255 }; break; case TrenColor.Green: color = new RGBA() { G = 255, A = 255 }; break; case TrenColor.Orange: color = new RGBA() { R = 255, G = 150, A = 255 }; break; case TrenColor.Pink: color = new RGBA() { R = 200, G = 50, B = 50, A = 255 }; break; case TrenColor.Red: color = new RGBA() { R = 255, A = 255 }; break; case TrenColor.White: color = RGBA.White; break; case TrenColor.Yellow: color = new RGBA() { R = 255, G = 255, A = 255 }; break; default: throw new Exception("Unknown track color : " + elem.Color); } } else { color = new RGBA() { R = 150, G = 150, B = 150, A = 255 } }; break; case TrenElementType.Button: color = RGBA.Black; break; case TrenElementType.Destination: break; default: throw new Exception("Unknow tren type : " + elem.Type); } img.Graphics.Polygon(color, cell.NormalizedPoints, fill: true, border: true); }); }