コード例 #1
0
        private void FindHints()
        {
            TilePair hint = _field.GetHint();

            if (hint != null)
            {
                _hint1 = hint.Tile1;
                _hint2 = hint.Tile2;
            }
        }
コード例 #2
0
        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");
        }