private List<CellControl> GetValidCells(CellControl cell, ImageBalls ball) { List<CellControl> result = new List<CellControl>(); int x = cell.ID / (int)level; int y = cell.ID % (int)level; for (int i = 0; i < 8; i++) result.AddRange(DoStepStuff(x, y, dx[i], dy[i], ball)); return result; }
public void Start() { ClearData(); //this.level = Game.GetLevel(); this.level = GameLevel.Standart; this.CellCount = (int)level * (int)level; this.style = Game.GetGameStyle(); for (int i = 0; i < CellCount; i++) { CellControl cc = new CellControl(i, this, ImageBalls.None); cellCollection.Add(cc); } SetDefault(); }
private bool DoStepStuff(CellControl cell, ImageBalls ball) { bool didStuff = false; List<CellControl> result = GetValidCells(cell, ball); if (result.Count > 0) { didStuff = true; cell.Ball = ball; switch (ball) { case ImageBalls.BlueBall: CountRedBalls -= result.Count; CountBlueBalls += result.Count + 1; break; case ImageBalls.RedBall: CountRedBalls += result.Count + 1; CountBlueBalls -= result.Count; break; default: break; } foreach (CellControl c in result) { c.Ball = ball; } } return didStuff; }
/* private void cellControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { CellControl c = (CellControl)sender; DoStepStuff(c); } */ public void DoStepStuff(CellControl c) { if (c.Ball == ImageBalls.None && !IsFinished) { bool result = false; switch (step) { case GameStep.Red: result = DoStepStuff(c, ImageBalls.RedBall); break; case GameStep.Blue: result = DoStepStuff(c, ImageBalls.BlueBall); break; default: break; } if (result) { Step = (GameStep)(((int)step + 1) % countStep); VerifyStep(); } } }