public WellSelectionDialog(int rows, int cols, string title, bool allowEmptySelectionList, ObservableCollection <Tuple <int, int> > wellList = null) { InitializeComponent(); vm = new WellSelectionDialog_ViewModel(); vm.DialogTitle = title; DataContext = vm; m_wellList = new ObservableCollection <Tuple <int, int> >(); if (wellList == null) { for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { m_wellList.Add(Tuple.Create <int, int>(r, c)); } } } else { foreach (Tuple <int, int> well in wellList) { m_wellList.Add(well); } } WellControl.Init(rows, cols, m_wellList); WellControl.NewWellSetSelected += WellControl_NewWellSetSelected; m_accepted = false; }
/// <summary> /// Falling /// </summary> /// <param name="well">Well.</param> public void OnTurn(WellControl well) { //if can move bottom bool canMoveBottom = true; foreach (GameObject go in this.inner) { Vector2 check = new Vector2( this.transform.localPosition.x + go.transform.localPosition.x, this.transform.localPosition.y + go.transform.localPosition.y - 1 ); if (well.PositionTaken(Mathf.RoundToInt(check.x), Mathf.RoundToInt(check.y))) { //boom canMoveBottom = false; } } if (canMoveBottom) { this.transform.localPosition = new Vector2(this.transform.localPosition.x, this.transform.localPosition.y - 1); } else { this.Dissolve(BlockControl.Instance.well); } }
public void TryMoveRight(WellControl well) { bool canMoveRight = true; foreach (GameObject go in this.inner) { Vector2 check = new Vector2( this.transform.localPosition.x + go.transform.localPosition.x + 1, this.transform.localPosition.y + go.transform.localPosition.y ); if (well.PositionTaken(Mathf.RoundToInt(check.x), Mathf.RoundToInt(check.y))) { canMoveRight = false; } } if (canMoveRight) { this.transform.localPosition = new Vector2(this.transform.localPosition.x + 1, this.transform.localPosition.y); } }
void Dissolve(WellControl well) { foreach (GameObject g in this.inner) { try { well.AddBlock( Mathf.FloorToInt(this.transform.position.x + g.transform.localPosition.x), Mathf.FloorToInt(this.transform.position.y + g.transform.localPosition.y) ); //well.Well[Mathf.FloorToInt(this.transform.position.x + g.transform.localPosition.x), Mathf.FloorToInt(this.transform.position.y + g.transform.localPosition.y)] = 1; } catch (IndexOutOfRangeException) { //GameOver! } } well.WhenDropped(); GameObject.Destroy(this.gameObject); BlockControl.Instance.CurrentBlock = BlockControl.Instance.NextBlock().GetComponent <BlockBehaviour>(); }
/// <summary> /// Rotates /// </summary> public void Rotate(WellControl well) { bool CanRotate = true; if (well != null) { foreach (GameObject g in inner) { if (g.transform.localPosition.x == 0) { if (well.PositionTaken(Mathf.FloorToInt(this.transform.localPosition.x + g.transform.localPosition.y), Mathf.FloorToInt(this.transform.localPosition.y + 3))) { CanRotate = false; } } else if (g.transform.localPosition.x == 1) { if (alterRotation) { if (well.PositionTaken(Mathf.FloorToInt(this.transform.localPosition.x + g.transform.localPosition.y), Mathf.FloorToInt(this.transform.localPosition.y + 1))) { CanRotate = false; } } else { if (well.PositionTaken(Mathf.FloorToInt(this.transform.localPosition.x + g.transform.localPosition.y), Mathf.FloorToInt(this.transform.localPosition.y + 2))) { CanRotate = false; } } } else if (g.transform.localPosition.x == 3) { if (well.PositionTaken(Mathf.FloorToInt(this.transform.localPosition.x + g.transform.localPosition.y), Mathf.FloorToInt(this.transform.localPosition.y))) { CanRotate = false; } } else if (g.transform.localPosition.x == 2) { if (alterRotation) { if (well.PositionTaken(Mathf.FloorToInt(this.transform.localPosition.x + g.transform.localPosition.y), Mathf.FloorToInt(this.transform.localPosition.y + 2))) { CanRotate = false; } } else { if (well.PositionTaken(Mathf.FloorToInt(this.transform.localPosition.x + g.transform.localPosition.y), Mathf.FloorToInt(this.transform.localPosition.y + 1))) { CanRotate = false; } } } } } if (CanRotate) { foreach (GameObject g in inner) { if (g.transform.localPosition.x == 0) { g.transform.localPosition = new Vector2(g.transform.localPosition.y, 3); } else if (g.transform.localPosition.x == 1) { if (alterRotation) { g.transform.localPosition = new Vector2(g.transform.localPosition.y, 1); } else { g.transform.localPosition = new Vector2(g.transform.localPosition.y, 2); } } else if (g.transform.localPosition.x == 3) { g.transform.localPosition = new Vector2(g.transform.localPosition.y, 0); } else if (g.transform.localPosition.x == 2) { if (alterRotation) { g.transform.localPosition = new Vector2(g.transform.localPosition.y, 2); } else { g.transform.localPosition = new Vector2(g.transform.localPosition.y, 1); } } } } }