Add suport of color into Tetrominoe parser
This commit is contained in:
parent
00dd266cf6
commit
3f03709cea
2 changed files with 41 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
@ -18,11 +19,11 @@ public class TetrominoeParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool[,] Get(String name) {
|
public static bool[,] GetShape(String name) {
|
||||||
if (!content.ContainsKey(name))
|
if (!content.ContainsKey(name))
|
||||||
throw new Exception("Invalid name");
|
throw new Exception("Invalid name");
|
||||||
|
|
||||||
String s = content.GetValue(name).ToString();
|
String s = content[name]["shape"].ToString();
|
||||||
|
|
||||||
int width = s.IndexOf('\n');
|
int width = s.IndexOf('\n');
|
||||||
if (width < 0)
|
if (width < 0)
|
||||||
|
@ -48,6 +49,15 @@ public class TetrominoeParser {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Color GetColor(String name) {
|
||||||
|
if (!content.ContainsKey(name))
|
||||||
|
throw new Exception("Invalid name");
|
||||||
|
|
||||||
|
String s = content[name]["color"].ToString();
|
||||||
|
|
||||||
|
return ColorTranslator.FromHtml(s);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> List() {
|
public static List<String> List() {
|
||||||
return content.Properties().Select(p => p.Name).ToList();
|
return content.Properties().Select(p => p.Name).ToList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,30 @@
|
||||||
{
|
{
|
||||||
"I": "xxxx",
|
"I": {
|
||||||
"J": "x--\nxxx",
|
"shape": "xxxx",
|
||||||
"L": "--x\nxxx",
|
"color": "#55ffff"
|
||||||
"O": "xx\nxx",
|
},
|
||||||
"S": "-xx\nxx-",
|
"J": {
|
||||||
"T": "-x-\nxxx",
|
"shape": "x--\nxxx",
|
||||||
"Z": "xx-\n-xx"
|
"color": "#0000ff"
|
||||||
|
},
|
||||||
|
"L": {
|
||||||
|
"shape": "--x\nxxx",
|
||||||
|
"color": "#ff5500"
|
||||||
|
},
|
||||||
|
"O": {
|
||||||
|
"shape": "xx\nxx",
|
||||||
|
"color": "#ffff00"
|
||||||
|
},
|
||||||
|
"S": {
|
||||||
|
"shape": "-xx\nxx-",
|
||||||
|
"color": "#00ff00"
|
||||||
|
},
|
||||||
|
"T": {
|
||||||
|
"shape": "-x-\nxxx",
|
||||||
|
"color": "#ff00ff"
|
||||||
|
},
|
||||||
|
"Z": {
|
||||||
|
"shape": "xx-\n-xx",
|
||||||
|
"color": "#aa0000"
|
||||||
|
}
|
||||||
}
|
}
|
Reference in a new issue