void ConnectedDiceWithValueRecursive(int value, Vector3 pos, List <Rollable> visited, List <Rollable> dice) { Rollable left = GetAtPosition(pos + Vector3.left); Rollable right = GetAtPosition(pos + Vector3.right); Rollable forward = GetAtPosition(pos + Vector3.forward); Rollable back = GetAtPosition(pos + Vector3.back); if (left && left.GetTopFace() == value && !visited.Contains(left)) { dice.Add(left); visited.Add(left); ConnectedDiceWithValueRecursive(value, pos + Vector3.left, visited, dice); } if (right && right.GetTopFace() == value && !visited.Contains(right)) { dice.Add(right); visited.Add(right); ConnectedDiceWithValueRecursive(value, pos + Vector3.right, visited, dice); } if (forward && forward.GetTopFace() == value && !visited.Contains(forward)) { dice.Add(forward); visited.Add(forward); ConnectedDiceWithValueRecursive(value, pos + Vector3.forward, visited, dice); } if (back && back.GetTopFace() == value && !visited.Contains(back)) { dice.Add(back); visited.Add(back); ConnectedDiceWithValueRecursive(value, pos + Vector3.back, visited, dice); } }
public void SpawnRollableOnTile(GameBoardTile tile) { GameObject obj = Instantiate(rollablePrefab, transform.Find("AllDice").transform); obj.transform.position = tile.transform.position; Rollable rollableComponent = obj.GetComponent <Rollable>(); rollableComponent.RandomiseRotation(); rollableComponent.BeginRiseing(); dice.Add(rollableComponent); }
public void TrySinkDice(int value, Vector3 pos) { Rollable r = GetAtPosition(pos); List <Rollable> visited = new List <Rollable>(); List <Rollable> dice = new List <Rollable>(); ConnectedDiceWithValueRecursive(value, pos, visited, dice); if (dice.Count >= value) { foreach (Rollable die in dice) { die.BeginSinking(); } } }
public void RemoveBlock(Rollable block) { dice.Remove(block); }
public Product(Rollable left, Rollable right) : base(left, right) { }
public static Product Of(Rollable left, Rollable right) => new Product(left, right);
public override Rollable With(Rollable left, Rollable right) => new Product(left, right);
// Use this for initialization void Start() { target = GetComponent <Rollable>(); target.SetProps(controllerProps); }
public static Difference Of(Rollable left, Rollable right) => new Difference(left, right);
public BlockController() { target = null; }
void DetectGroundBlock() { tileBounds.size = new Vector3(1, 1, 1); tileBounds.center = new Vector3( (int)((transform.position.x + (transform.position.x >= 0 ? 0.5f : -0.5f)) / 1.0f) * 1.0f, (int)((transform.position.y + (transform.position.y >= 0 ? 0.5f : -0.5f)) / 1.0f) * 1.0f, (int)((transform.position.z + (transform.position.z >= 0 ? 0.5f: -0.5f)) / 1.0f) * 1.0f); Ray ray = new Ray(transform.position, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, character.height * 0.75f)) { BoxCollider collider = hit.collider.GetComponent <BoxCollider>(); if (collider == null) { blockBounds = null; availableMovementBounds.Clear(); } else { Bounds b = collider.bounds; // check if the bounds are different... if so, update if (b != blockBounds) { blockBounds = b; availableMovementBounds.Clear(); availableMovementBounds.Add(b); if (IsBlockInPosition(b.center + Vector3.left)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.left, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.right)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.right, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.forward)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.forward, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.back)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.back, Vector3.one)); } if (rollable) { rollable.diceMesh.transform.localScale = Vector3.one; rollable.SetEmissiveness(0.0f); } rollable = hit.collider.GetComponent <Rollable>(); if (rollable) { rollable.diceMesh.transform.localScale -= new Vector3(0.1f, 0.1f, 0.1f); rollable.SetEmissiveness(0.4f); rollable.SetProps(props); } } } } if (rollable) { Bounds b = rollable.GetComponent <BoxCollider>().bounds; availableMovementBounds.Clear(); availableMovementBounds.Add(b); if (rollable.IsRolling() == false) { if (IsBlockInPosition(b.center + Vector3.left)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.left, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.right)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.right, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.forward)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.forward, Vector3.one)); } if (IsBlockInPosition(b.center + Vector3.back)) { availableMovementBounds.Add(new Bounds(b.center + Vector3.back, Vector3.one)); } } } }
public Sum(Rollable left, Rollable right) : base(left, right) { }
public static Sum Of(Rollable left, Rollable right) => new Sum(left, right);
public override Rollable With(Rollable left, Rollable right) => new Sum(left, right);
public Difference(Rollable left, Rollable right) : base(left, right) { }
public void SetTarget(Rollable obj) { target = obj; }
public override Rollable With(Rollable left, Rollable right) => new Difference(left, right);