public void Init() { this.Children.Clear(); HumanList = new Human[ROW_NUM][]; for (int i = 0; i < ROW_NUM; i++) { HumanList[i] = new Human[COL_NUM]; for (int j = 0; j < COL_NUM; j++) { HumanList[i][j] = new Human() { RowIndex = i, ColIndex = j }; } } InitBaseGrid(); }
public void UpdateHumanLiveDead() { int row, col; int liveCount; int count = 0; Human human = new Human(); for (int i = 0; i < ROW_NUM; i++) { for (int j = 0; j < COL_NUM; j++) { liveCount = 0; //検索 for (int s = -1; s < 2; s++) { for (int t = -1; t < 2; t++) { //自身は数えない if (s == 0 && t == 0) { continue; } row = i + s; col = j + t; //はみ出さない if (row >= 0 && row < ROW_NUM && col >= 0 && col < COL_NUM) { count++; if (HumanList[row][col].Visibility == Visibility.Visible) { liveCount++; } } } } human = HumanList[i][j]; if (human.Visibility == Visibility.Visible && (liveCount == 2 || liveCount == 3)) { human.IsLive = true; } else if (human.Visibility == Visibility.Hidden && (liveCount == 3)) { human.IsLive = true; } else { human.IsLive = false; } } } //tempから移す for (int i = 0; i < ROW_NUM; i++) { for (int j = 0; j < COL_NUM; j++) { human = HumanList[i][j]; if (human.IsLive == true) { human.Visibility = Visibility.Visible; } else { human.Visibility = Visibility.Hidden; } } } }