public void TryParse_should_not_move_offset_on_invalid_input() { var offset = 1; LevelFragment.TryParse(" %d", ref offset); offset.Should().Be(1); }
public void TryParse_should_move_offset_accordingly() { var offset = 1; LevelFragment.TryParse(" %l", ref offset); offset.Should().Be(3); }
private GameObject GenerateLevel(int level) { var newLevel = new GameObject("Level " + level); var t0 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; var reload = true; var frags = new LevelFragment[0]; float h; var nFrag = 0; float diff; float areaWidth; var maxDiff = GetMaxLevelDifficulty(level); var minDiff = GetMinLevelDifficulty(level); var nreload = 0; var nretry = 0; while (true) { nretry++; if (reload) { nreload++; foreach (var f in frags) { Destroy(f.gameObject); } nFrag = 1 + Utils.RandomChances(Constants.FragmentNumberChances); frags = new LevelFragment[nFrag]; } var area = new List <Tuple <float, float> >(); h = 0f; for (var i = 0; i < nFrag; i++) { if (reload) { var n = Utils.RandInt(LevelFragments.Length); frags[i] = Instantiate(LevelFragments[n], newLevel.transform); frags[i].gameObject.SetActive(false); } h += frags[i].Height; area = Utils.AreaOr(area, frags[i].Area); } reload = true; if (nFrag > 1) { h += (nFrag - 1) * Constants.LevelFragmentMaxMargin; } if (h > Constants.LevelMaxY - Constants.LevelMinY) { continue; } area = Utils.AreaNot(-Constants.LevelMaxX, Constants.LevelMaxX, area); areaWidth = Utils.AreaWidth(area); if (areaWidth < Constants.MinPathWidth) { continue; } if (Utils.AreaDistance(Ball.transform.position.x, area) > Constants.MaxAreaDistBall) { continue; } diff = GetDifficulty(frags, areaWidth); if (diff > maxDiff) { continue; } reload = false; if (diff >= minDiff) { break; } if (IncreaseDifficulty(frags)) { continue; } reload = true; } var endH = Constants.LevelMaxY - h; var startH = Constants.LevelMinY; foreach (var f in frags) { var fh = f.Height; endH += fh; var py = Random.Range(startH + fh / 2f, endH - fh / 2f); var frag = f.gameObject; frag.transform.position = new Vector3(0, py, 0); frag.SetActive(true); startH = py + fh / 2 + Random.Range(Constants.LevelFragmentMinMargin, Constants.LevelFragmentMaxMargin); endH += Constants.LevelFragmentMaxMargin; } var t1 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; var debugLog = ""; debugLog += String.Format("Finished generating level {0:d} ({1:f}<diff:{2:f}<{3:f}) in {4:d} ms ({5:d} retry with {6:d} reload)\n", level, minDiff, diff, maxDiff, t1 - t0, nretry, nreload); debugLog += "|Area width:" + areaWidth + "\n"; for (var k = 0; k < frags.Length; k++) { var frag = frags[k]; var fdiff = Constants.WallDifficulties[frag.WallType] * (frag.MovementSpeed + 1) * Constants.MovSpeedDifficulty + (frag.RotationSpeed + 1) * Constants.RotSpeedDifficulty; debugLog += "|Fragment " + k + " (diff:" + fdiff + ")\n"; debugLog += "||Type:" + frag.WallType + " => " + Constants.WallDifficulties[frag.WallType] + "\n"; debugLog += "||Movement:" + frag.MovementSpeed + " => " + (frag.MovementSpeed + 1) * Constants.MovSpeedDifficulty + "\n"; debugLog += "||Rotation:" + frag.RotationSpeed + " => " + (frag.RotationSpeed + 1) * Constants.RotSpeedDifficulty + "\n"; } Debug.Log(debugLog); return(newLevel); }
public void TryParse_should_be_case_insensitive() { var offset = 1; LevelFragment.TryParse(" %L", ref offset).Should().NotBeNull(); }
public void TryParse_should_return_null_on_invalid_input(string input) { var offset = 1; LevelFragment.TryParse(input, ref offset).Should().BeNull(); }
public void TryParse_should_parse_fragment() { var offset = 1; LevelFragment.TryParse(" %l", ref offset).Should().Be(new LevelFragment()); }