private int PushIntoSlots(CmpButton[] aControls, AnimalAge eAge, int nFillCount, ref Random randGenerator) { bool[] abUsedSlots = new bool[3]; int nIDCount, nCurrent; Array.Clear(abUsedSlots, 0, abUsedSlots.Length); nIDCount = 3; for (int i = 0; i < 3; i++) { nCurrent = randGenerator.Next() % (nIDCount--); for (int j = 0, q = 0; j < 3; j++) { if (abUsedSlots[j]) { continue; } if (q == nCurrent) { abUsedSlots[j] = true; m_aAnimals[nFillCount++] = new CmpAnimal(this, aControls[j], m_aLastTypes[i], eAge); break; } q++; } } return(nFillCount); }
private void TestSelected() { CmpAnimal[] aSelectedAnimals = new CmpAnimal[2]; for (int i = 0, q = 0; i < m_aAnimals.Length; i++) { if (m_aAnimals[i].IsEnabled() && m_aAnimals[i].IsChecked()) { aSelectedAnimals[q++] = m_aAnimals[i]; } } if (aSelectedAnimals[0].GetAnimal().GetAnimalType() != aSelectedAnimals[1].GetAnimal().GetAnimalType()) { //MessageBox.Show("Wrong!"); aSelectedAnimals[0].Uncheck(); aSelectedAnimals[1].Uncheck(); aSelectedAnimals[0].PlayWrongAnimation(); aSelectedAnimals[1].PlayWrongAnimation(); } else { aSelectedAnimals[0].Uncheck(); aSelectedAnimals[1].Uncheck(); aSelectedAnimals[0].Disable(); aSelectedAnimals[1].Disable(); //MessageBox.Show("Right!"); aSelectedAnimals[0].PlayRightAnimation(); aSelectedAnimals[1].PlayRightAnimation(); m_nPairsLeft--; m_Parent.PlayMessageAnimation(aSelectedAnimals[0].GetAnimal().GetCompareSuccessImage()); } if (m_nPairsLeft == 0) { m_eState = CmpGameState.CGS_COMPLETED; m_Parent.nextButton.Visibility = Visibility.Visible; m_Parent.restartButton.Visibility = Visibility.Visible; //MessageBox.Show("Game completed."); } else { m_eState = CmpGameState.CGS_WAITING; } }