Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
NPBruce committed Apr 5, 2017
2 parents a736d1e + 012ee6c commit 9167363
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 30 deletions.
242 changes: 242 additions & 0 deletions Assets/Resources/slidepuzzles.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@

[PuzzleSlide11]
moves=1
block0=False,1,0,0,2,True
block2=True,0,1,1,3,False

[PuzzleSlide21]
moves=2
block0=False,1,0,0,2,True
block1=True,0,2,2,1,False
block2=True,0,1,1,3,False

[PuzzleSlide22]
moves=2
block0=False,1,0,0,2,True
block1=False,2,0,0,5,False
block2=True,0,2,5,1,False

[PuzzleSlide23]
moves=2
block0=False,1,0,0,2,True
block1=True,0,1,1,4,False
block2=True,0,2,4,1,False

[PuzzleSlide31]
moves=3
block0=False,1,0,0,2,True
block1=False,4,0,1,1,False
block2=False,2,0,2,0,False
block3=True,0,1,2,2,False
block4=False,4,0,0,5,False
block5=False,2,0,2,4,False

[PuzzleSlide32]
moves=3
block0=False,1,0,0,2,True
block1=False,2,0,3,4,False
block2=False,2,0,0,3,False
block3=True,0,1,5,1,False
block4=False,1,0,3,3,False
block5=False,1,0,0,0,False
block6=False,3,0,0,1,False
block7=False,4,0,1,5,False
block8=False,1,0,2,0,False
block9=True,0,1,4,1,False

[PuzzleSlide33]
moves=3
block0=False,1,0,0,2,True
block1=False,1,0,2,1,False
block2=False,3,0,0,3,False
block3=False,1,0,0,0,False
block4=False,2,0,3,5,False
block5=True,0,2,4,1,False

[PuzzleSlide34]
moves=3
block0=False,1,0,0,2,True
block1=False,1,0,3,0,False
block2=True,0,1,1,0,False
block3=True,0,2,2,0,False
block4=True,0,1,5,2,False

[PuzzleSlide35]
moves=3
block0=False,1,0,0,2,True
block1=True,0,2,1,3,False
block2=True,0,2,4,3,False
block3=False,1,0,1,0,False
block4=True,0,2,3,0,False
block5=True,0,2,2,1,False

[PuzzleSlide41]
moves=4
block0=False,1,0,0,2,True
block1=False,3,0,2,3,False
block2=True,0,1,3,0,False
block3=True,0,1,0,0,False
block4=True,0,1,1,4,False
block5=True,0,1,1,0,False
block6=False,1,0,4,4,False
block7=True,0,2,5,0,False

[PuzzleSlide42]
moves=4
block0=False,1,0,0,2,True
block1=False,3,0,0,4,False
block2=False,3,0,1,3,False
block3=False,3,0,0,1,False
block4=True,0,2,5,0,False
block5=False,1,0,2,0,False
block6=True,0,2,4,0,False

[PuzzleSlide43]
moves=4
block0=False,1,0,0,2,True
block1=False,2,0,2,5,False
block2=False,3,0,0,1,False
block3=False,3,0,1,4,False
block4=False,2,0,1,0,False
block5=True,0,2,4,0,False

[PuzzleSlide44]
moves=4
block0=False,1,0,0,2,True
block1=False,2,0,3,4,False
block2=False,2,0,0,1,False
block3=False,3,0,2,3,False
block4=True,0,2,4,0,False

[PuzzleSlide45]
moves=4
block0=False,1,0,0,2,True
block1=False,1,0,1,3,False
block2=False,2,0,0,5,False
block3=True,0,1,5,4,False
block4=False,1,0,2,0,False
block5=False,2,0,0,4,False
block6=False,1,0,0,1,False
block7=False,1,0,3,3,False
block8=False,1,0,0,0,False
block9=True,0,1,3,1,False
block10=True,0,1,5,2,False

[PuzzleSlide51]
moves=5
block0=False,1,0,0,2,True
block1=False,2,0,0,0,False
block2=True,0,1,4,4,False
block3=True,0,2,2,1,False
block4=True,0,1,4,0,False
block5=True,0,2,3,2,False
block6=False,1,0,0,1,False
block7=True,0,1,5,1,False
block8=True,0,1,5,4,False
block9=False,1,0,1,4,False

[PuzzleSlide52]
moves=5
block0=False,1,0,0,2,True
block1=False,1,0,4,0,False
block2=False,2,0,0,3,False
block3=False,1,0,2,0,False
block4=False,3,0,1,1,False
block5=False,4,0,0,4,False
block6=True,0,1,4,2,False

[PuzzleSlide53]
moves=5
block0=False,1,0,0,2,True
block1=False,3,0,1,4,False
block2=False,1,0,1,1,False
block3=False,2,0,0,5,False
block4=False,1,0,0,3,False
block5=True,0,2,5,1,False
block6=False,1,0,4,0,False
block7=False,1,0,3,3,False
block8=False,1,0,2,0,False
block9=True,0,1,2,2,False

[PuzzleSlide54]
moves=5
block0=False,1,0,0,2,True
block1=False,2,0,2,5,False
block2=True,0,1,4,1,False
block3=False,1,0,3,4,False
block4=False,3,0,0,0,False
block5=True,0,2,5,1,False
block6=False,1,0,0,5,False
block7=False,1,0,0,4,False
block8=True,0,1,2,1,False
block9=False,1,0,2,3,False

[PuzzleSlide55]
moves=5
block0=False,1,0,0,2,True
block1=False,2,0,1,0,False
block2=False,1,0,2,5,False
block3=True,0,1,5,0,False
block4=False,1,0,4,5,False
block5=False,2,0,3,3,False
block6=True,0,1,0,0,False
block7=True,0,2,4,0,False

[PuzzleSlide61]
moves=6
block0=False,1,0,0,2,True
block1=False,1,0,4,4,False
block2=False,3,0,0,5,False
block3=False,1,0,2,4,False
block4=False,2,0,1,0,False
block5=False,1,0,4,5,False
block6=False,1,0,3,1,False
block7=True,0,1,2,1,False
block8=True,0,1,5,0,False
block9=False,3,0,0,3,False

[PuzzleSlide62]
moves=6
block0=False,1,0,0,2,True
block1=True,0,1,4,1,False
block2=False,3,0,1,4,False
block3=True,0,1,0,3,False
block4=False,2,0,0,5,False
block5=False,1,0,2,1,False
block6=False,3,0,1,3,False
block7=False,4,0,0,0,False

[PuzzleSlide63]
moves=6
block0=False,1,0,0,2,True
block1=True,0,1,2,0,False
block2=False,1,0,0,3,False
block3=True,0,1,1,4,False
block4=False,2,0,3,4,False
block5=True,0,1,0,0,False
block6=True,0,2,5,1,False
block7=True,0,1,2,4,False
block8=True,0,1,3,2,False

[PuzzleSlide64]
moves=6
block0=False,1,0,0,2,True
block1=False,1,0,3,0,False
block2=True,0,1,0,4,False
block3=True,0,1,2,4,False
block4=True,0,2,4,1,False
block5=False,1,0,1,1,False
block6=False,1,0,3,4,False
block7=True,0,1,5,2,False

[PuzzleSlide71]
moves=7
block0=False,1,0,0,2,True
block1=True,0,1,2,0,False
block2=True,0,1,5,0,False
block3=True,0,1,5,2,False
block4=True,0,1,2,4,False
block5=True,0,2,3,0,False
block6=False,1,0,4,4,False
block7=True,0,2,4,0,False

8 changes: 8 additions & 0 deletions Assets/Resources/slidepuzzles.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.3
0.8.4
6 changes: 3 additions & 3 deletions Assets/Scripts/Content/ContentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// This class reads and stores all of the content for a base game and expansions
public class ContentData {

public List<string> loadedPacks;
public HashSet<string> loadedPacks;
public List<ContentPack> allPacks;
public Dictionary<string, PackTypeData> packTypes;
public Dictionary<string, TileSideData> tileSides;
Expand Down Expand Up @@ -37,7 +37,7 @@ public static string ContentPath()
public ContentData(string path)
{
// This is pack type for sorting packs
loadedPacks = new List<string>();
loadedPacks = new HashSet<string>();

// This is pack type for sorting packs
packTypes = new Dictionary<string, PackTypeData>();
Expand Down Expand Up @@ -182,7 +182,7 @@ public string GetContentName(string id)
// Return a list of id for all enbaled content packs
public List<string> GetLoadedPackIDs()
{
return loadedPacks;
return new List<string>(loadedPacks);
}

// This loads content from a pack by name
Expand Down
13 changes: 11 additions & 2 deletions Assets/Scripts/Content/IniRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,21 @@ public static IniData ReadFromStringArray(string[] lines, string path)
int equalsLocation = l.IndexOf('=');
// Add data as entry with no value
if (equalsLocation == -1)
entryData.Add(l.Trim(), "");
{
if (entryData.ContainsKey(l.Trim()))
{
ValkyrieDebug.Log("Warning: duplicate \"" + l.Trim() + "\" data in section \"" + entryName + "\" in " + path + " will be ignored.");
}
else
{
entryData.Add(l.Trim(), "");
}
}
// If there is an = add data as key and value
else
{
string key = l.Substring(0, equalsLocation).Trim();
if(entryData.ContainsKey(key))
if (entryData.ContainsKey(key))
{
ValkyrieDebug.Log("Warning: duplicate \"" + key + "\" data in section \"" + entryName + "\" in " + path + " will be ignored.");
}
Expand Down
64 changes: 48 additions & 16 deletions Assets/Scripts/Quest/PuzzleSlide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,54 @@ public class PuzzleSlide : Puzzle
public int moves = 0;

public PuzzleSlide(int depth)
{
if (depth < 1)
{
depth = 1;
}
if (depth > 7)
{
depth = 7;
}
List<Dictionary<string, string>> options = new List<Dictionary<string, string>>();
TextAsset textAsset = (TextAsset)Resources.Load("slidepuzzles");
string puzzleText = textAsset.text;
IniData puzzles = IniRead.ReadFromString(puzzleText);
foreach (Dictionary<string, string> p in puzzles.data.Values)
{
int moves = 1;
int.TryParse(p["moves"], out moves);
if (moves == depth)
{
options.Add(p);
}
}
Loadpuzzle(options[Random.Range(0, options.Count)]);
}

public PuzzleSlide(Dictionary<string, string> data)
{
Loadpuzzle(data);
}

public void Loadpuzzle(Dictionary<string, string> data)
{
puzzle = new List<Block>();
foreach (KeyValuePair<string, string> kv in data)
{
if (kv.Key.Equals("moves"))
{
int.TryParse(kv.Value, out moves);
}
else
{
puzzle.Add(new Block(kv.Value));
}
}
}

// Too slow and memory consuming
public void GeneratePuzzle(int depth)
{
puzzle = new List<Block>();
puzzle.Add(new Block());
Expand All @@ -34,22 +82,6 @@ public PuzzleSlide(int depth)
}
}

public PuzzleSlide(Dictionary<string, string> data)
{
puzzle = new List<Block>();
foreach (KeyValuePair<string, string> kv in data)
{
if (kv.Key.Equals("moves"))
{
int.TryParse(kv.Value, out moves);
}
else
{
puzzle.Add(new Block(kv.Value));
}
}
}

public bool Solved()
{
return (puzzle[0].xpos == 6);
Expand Down
4 changes: 1 addition & 3 deletions Assets/Scripts/Quest/PuzzleSlideWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public PuzzleSlideWindow(EventManager.Event e)
}
else
{
// FIXME: dynamic generation too slow
//puzzle = new PuzzleSlide(questPuzzle.puzzleLevel);
puzzle = new PuzzleSlide(PuzzleSlide.HardCodedPuzzle());
puzzle = new PuzzleSlide(questPuzzle.puzzleLevel);
}

CreateWindow();
Expand Down
Loading

0 comments on commit 9167363

Please sign in to comment.