protected override void OnPaint(PaintEventArgs e) { if (_field == null) { return; } if (_drawGrid) { DrawTileGrid(e.Graphics); } if (_showHint) { FindHints(); } // Draw sorted tile list from bottom left to top right Tile[] tiles = _field.GetSortedTiles(); foreach (Tile t in tiles) { DrawTile(e.Graphics, t); } if (_mode == PanelMode.Play) { e.Graphics.DrawString("Middle Mouse = Toggle Show Moveable Tiles\nRight Mouse = Toggle Show Hint", DefaultFont, Brushes.Black, 5, 5); } else { e.Graphics.DrawString("Left Mouse = Place Tile\nRight Mouse = Remove Tile", DefaultFont, Brushes.Black, 5, 5); } }
private string BuildFieldJson() { TilePair hintPair = null; if (_showHint) { hintPair = _field.GetHint(); } Tile[] tiles = _field.GetSortedTiles(); List <string> tilesJson = new List <string>(); foreach (Tile tile in tiles) { string selected = (tile == _selected) ? "true" : "false"; string disabled = !_field.CanMove(tile) && _showMoveable ? "true" : "false"; string hint = _showHint && hintPair != null && (tile == hintPair.Tile1 || tile == hintPair.Tile2) ? "true" : "false"; string type = (tile != null) ? tile.Type.Name : "empty"; string tileJson = " {\n"; tileJson += " \"x\": " + tile.X + ",\n"; tileJson += " \"y\": " + tile.Y + ",\n"; tileJson += " \"z\": " + tile.Z + ",\n"; tileJson += " \"type\": \"" + type + "\",\n"; tileJson += " \"selected\": " + selected + ",\n"; tileJson += " \"hint\": " + hint + ",\n"; tileJson += " \"disabled\": " + disabled + "\n"; tileJson += " }"; tilesJson.Add(tileJson); } return ("{\n" + " \"field\": {\n" + " \"fieldwidth\": " + Field.WIDTH + ",\n" + " \"fieldheight\": " + Field.HEIGHT + ",\n" + " \"tilewidth\": " + Tile.WIDTH + ",\n" + " \"tileheight\": " + Tile.HEIGHT + ",\n" + " \"tiles\": [\n" + string.Join(",\n", tilesJson.ToArray()) + "\n" + " ]\n" + " }\n" + "}\n"); }