// ----- // Interactions, etc // ----- bool VexTargetInteract(int pressed) { if (moduleSolved) { return(false); } VexBlock target = VexAtPosition(pressed); // Pressed the empty square? if (target == null) { bombAudio.PlaySoundAtTransform("ClickDown", vexButtonTargets[pressed].transform); currentlyHeldVex.SetPosition(openPosition); currentlyHeldVex = null; openPosition = -1; return(false); } // Already holding something? Set it down before picking up. if (currentlyHeldVex != null) { currentlyHeldVex.SetPosition(pressed); bombAudio.PlaySoundAtTransform("ClickDown", vexButtonTargets[pressed].transform); } else { openPosition = target.GetPosition(); } target.PickUp(); currentlyHeldVex = target; return(false); }
// For logging static public string[] BlockLineToStrings(VexBlock a, VexBlock b, VexBlock c) { return(new string[] { String.Format(" {0} │ {1} │ {2} ", a.digits[2], b.digits[2], c.digits[2]), String.Format("{0} {1}│{2} {3}│{4} {5}", a.digits[1], a.digits[3], b.digits[1], b.digits[3], c.digits[1], c.digits[3]), String.Format(" {0} │ {1} │ {2} ", a.digits[0], b.digits[0], c.digits[0]), }); }
// ----- // Puzzle generation // ----- void GeneratePuzzle() { int digit; for (int x = 0; x < 3; ++x) { digit = RNG.Range(0, 8); vexes[x].SetFace(2, digit, colorMeshes[digit]); digit = RNG.Range(0, 8); vexes[x].SetFace(0, digit, colorMeshes[digit]); vexes[x + 3].SetFace(2, digit, colorMeshes[digit]); digit = RNG.Range(0, 8); vexes[x + 3].SetFace(0, digit, colorMeshes[digit]); vexes[x + 6].SetFace(2, digit, colorMeshes[digit]); digit = RNG.Range(0, 8); vexes[x + 6].SetFace(0, digit, colorMeshes[digit]); } for (int y = 0; y < 9; y += 3) { digit = RNG.Range(0, 8); vexes[y].SetFace(1, digit, colorMeshes[digit]); digit = RNG.Range(0, 8); vexes[y].SetFace(3, digit, colorMeshes[digit]); vexes[y + 1].SetFace(1, digit, colorMeshes[digit]); digit = RNG.Range(0, 8); vexes[y + 1].SetFace(3, digit, colorMeshes[digit]); vexes[y + 2].SetFace(1, digit, colorMeshes[digit]); digit = RNG.Range(0, 8); vexes[y + 2].SetFace(3, digit, colorMeshes[digit]); } // Scramble the pieces now that we've generated the solution. List <int> vexPositions = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; vexPositions.Shuffle(); for (int i = 0; i < 9; ++i) { vexes[i].idealPosition = i; vexes[i].SetPosition(vexPositions[i]); } // Logging Debug.LogFormat("[TetraVex #{0}] Intended solution:", thisLogID); for (int i = 0; i < 9; i += 3) { string[] log = VexBlock.BlockLineToStrings(vexes[i], vexes[i + 1], vexes[i + 2]); Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[0]); Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[1]); Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[2]); if (i < 6) { Debug.LogFormat("[TetraVex #{0}] ───┼───┼───", thisLogID); } } }
public bool IsPositionOkay(VexBlock down, VexBlock right) { if (down != null && down.digits[2] != digits[0]) { return(false); } if (right != null && right.digits[1] != digits[3]) { return(false); } return(true); }
bool CheckButtonPress() { bombAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.ButtonPress, checkButton.transform); checkButton.AddInteractionPunch(0.4f); checkButton.GetComponent <Animator>().Play("ZButtonPress", 0, 0); if (moduleSolved) { return(false); } List <VexBlock> shownOrder = VexesInDisplayOrder(); if (shownOrder[0].GetPosition() == -1) { Debug.LogFormat("[TetraVex #{0}] STRIKE: Submitted when a piece wasn't in place.", thisLogID); bombModule.HandleStrike(); return(false); } // Logging Debug.LogFormat("[TetraVex #{0}] Submitted solution:", thisLogID); for (int i = 0; i < 9; i += 3) { string[] log = VexBlock.BlockLineToStrings(shownOrder[i], shownOrder[i + 1], shownOrder[i + 2]); Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[0]); Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[1]); Debug.LogFormat("[TetraVex #{0}] {1}", thisLogID, log[2]); if (i < 6) { Debug.LogFormat("[TetraVex #{0}] ───┼───┼───", thisLogID); } } // We only check DOWN and RIGHT for each block, because left and up for each block are already checked by previous blocks. // We don't even bother extending the loop to hit the bottom-right block, because if we did hit it it is a guaranteed solve. for (int i = 0; i < 8; ++i) { if (!shownOrder[i].IsPositionOkay(i < 6 ? shownOrder[i + 3] : null, i % 3 < 2 ? shownOrder[i + 1] : null)) { Debug.LogFormat("[TetraVex #{0}] STRIKE: The block in the {1} position has an incorrect connection.", thisLogID, __positionText[i]); bombModule.HandleStrike(); return(false); } } Debug.LogFormat("[TetraVex #{0}] SOLVE: All connections okay; this is a valid solution.", thisLogID); bombAudio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.CorrectChime, bombModule.transform); bombModule.HandlePass(); moduleSolved = true; return(false); }