public void AnotherGrid() { NbGoodRes = 0; bool ok; do { Cells.Clear(); HorizontalTargets.Clear(); VerticalTargets.Clear(); InitializeResults(GridSize); ok = true; InitializeCells(GridSize); LinkCellsToResults(GridSize); foreach (var item in HorizontalTargets) { if (item.Result == 0) { ok = false; } } foreach (var item in VerticalTargets) { if (item.Result == 0) { ok = false; } } } while (!ok); SetBitsTo0(); _eventAggregator.GetEvent <OnStartTimerEvent>().Publish(new OnStartTimerEventArgs()); }
public void GenerateGrid(GenerateGridEventArgs args) { switch (args.DifficultyName) { case "Easy": GridSize = 4; cellSize = 50; fontSize = 22; resFontSize = 22; break; case "Normal": GridSize = 6; cellSize = 32; fontSize = 20; resFontSize = 18; break; case "Expert": GridSize = 8; cellSize = 23; fontSize = 14; resFontSize = 7; break; default: break; } NbGoodRes = 0; bool ok; do { Cells.Clear(); HorizontalTargets.Clear(); VerticalTargets.Clear(); InitializeResults(GridSize); ok = true; InitializeCells(GridSize); LinkCellsToResults(GridSize); foreach (var item in HorizontalTargets) { if (item.Result == 0) { ok = false; } } foreach (var item in VerticalTargets) { if (item.Result == 0) { ok = false; } } } while (!ok); SetBitsTo0(); }
private void InitializeResults(int n) { for (int i = 0; i < n; i++) { VerticalTargets.Add(new ResultBoxWrapper(new ResultBox { FontSize = resFontSize, Size = cellSize, Status = "#6D4C41" })); HorizontalTargets.Add(new ResultBoxWrapper(new ResultBox { FontSize = resFontSize, Size = cellSize, Status = "#6D4C41" })); } }
public void OnClick(OnClickEventArgs obj) { var cellsH = Cells.Where(c => c.Cell.HorizontalTarget == obj.Cell.HorizontalTarget); var cellsV = Cells.Where(c => c.Cell.VerticalTarget == obj.Cell.VerticalTarget); double VRes = 0; double HRes = 0; foreach (var item in cellsH) { HRes += int.Parse(item.Cell.Bit) * item.Cell.HorizontalValue; } foreach (var item in cellsV) { VRes += int.Parse(item.Cell.Bit) * item.Cell.VerticalValue; } var HTarget = HorizontalTargets.Single(c => obj.Cell.HorizontalTarget == c.Model); var VTarget = VerticalTargets.Single(c => obj.Cell.VerticalTarget == c.Model); string HTargetOldStatus = HTarget.Status; string VTargetOldStatus = VTarget.Status; HTarget.Status = HTarget.Result == HRes ? "#30D1D5" : "#6D4C41"; VTarget.Status = VTarget.Result == VRes ? "#30D1D5" : "#6D4C41"; if (HTarget.Status != HTargetOldStatus && HTargetOldStatus != "#30D1D5") { NbGoodRes++; } else if (HTarget.Status != HTargetOldStatus && HTargetOldStatus == "#30D1D5") { NbGoodRes--; } if (VTarget.Status != VTargetOldStatus && VTargetOldStatus != "#30D1D5") { NbGoodRes++; } else if (VTarget.Status != VTargetOldStatus && VTargetOldStatus == "#30D1D5") { NbGoodRes--; } if (NbGoodRes == GridSize * 2) { _eventAggregator.GetEvent <OnStopTimerEvent>().Publish(new OnStopTimerEventArgs()); } }