/// <summary> /// Creates the start and finish points /// Note: No path checks have been implemented to make the game more interesting, the finish can spawn very close to the start. /// With more time, algoritims can be put into place to improve the quaity and consistency of the games. /// </summary> void CreateStartAndFinishPoints() { int iRandomStartX = Random.Range(0, m_iBoardWidth); int iRandomStartY = Random.Range(0, m_iBoardHeight); GameBoardElement cStartEle = m_acGameBoardData[iRandomStartX, iRandomStartY]; m_gStartLocation = cStartEle; cStartEle.m_eElementType = EGameBoardType.Start; GameBoardElement cCurrentSquare = cStartEle; //Dirty method of finding path, possible infinite loop danger for (int iCurrentStep = 0; iCurrentStep < m_iOptimalStepCount; iCurrentStep++) { cCurrentSquare = RandomiseNextSquare(cCurrentSquare); if (cCurrentSquare == null) { ResetPath(); iCurrentStep = 0; cCurrentSquare = cStartEle; } else { cCurrentSquare.m_bIsPath = true; } } cCurrentSquare.m_eElementType = EGameBoardType.Finish; }
public void MarkElement_SettingFirstValue_StateReturnThatValue(ElementState startingState) { // Setup var element = new GameBoardElement(0, 0); // Call element.MarkElement(startingState); // Assert Assert.AreEqual(startingState, element.State); }
public void MarkElement_FromYesToAnyNotStates_StateReturnsNewNotState(ElementState newNotState) { // Setup var element = new GameBoardElement(0, 0); element.MarkElement(ElementState.Yes); // Call element.MarkElement(newNotState); // Assert Assert.AreEqual(newNotState, element.State); }
public void MarkElement_FromAnyStateToEmpty_StateReturnsEmpty(ElementState startingState) { // Setup var element = new GameBoardElement(0, 0); element.MarkElement(startingState); // Call element.MarkElement(ElementState.Empty); // Assert Assert.AreEqual(ElementState.Empty, element.State); }
public void ParameteredConstructor_ExpectedValues( [Random(0, int.MaxValue, 3)]int horizontalIndex, [Random(0, int.MaxValue, 3)]int verticalIndex) { // Call var element = new GameBoardElement(horizontalIndex, verticalIndex); // Assert Assert.IsInstanceOf<IObservable<ElementState>>(element); Assert.AreEqual(horizontalIndex, element.ElementValue); Assert.AreEqual(verticalIndex, element.SecondaryElementValue); Assert.AreEqual(ElementState.Empty, element.State); }
/// <summary> /// Places enemies in empty spaces /// </summary> void CreateEnemies() { for (int iCurrentEnemies = 0; iCurrentEnemies < m_iNumberOfEnemies;) { int iRandomEnemyX = Random.Range(0, m_iBoardWidth); int iRandomEnemyY = Random.Range(0, m_iBoardHeight); GameBoardElement cPossibleEnemyPlacement = m_acGameBoardData[iRandomEnemyX, iRandomEnemyY]; if (!cPossibleEnemyPlacement.m_bIsPath && cPossibleEnemyPlacement.m_eElementType == EGameBoardType.Empty) { cPossibleEnemyPlacement.m_eElementType = EGameBoardType.Enemy; iCurrentEnemies++; } } }
/// <summary> /// Gets a valid random square /// </summary> /// <param name="_cEle"></param> /// <returns></returns> GameBoardElement RandomiseNextSquare(GameBoardElement _cEle) { List <GameBoardElement> lValidSquares = new List <GameBoardElement>(); if (_cEle.m_cTopElement != null) { if (!_cEle.m_cTopElement.m_bIsPath && _cEle.m_cTopElement.m_eElementType == EGameBoardType.Empty) { lValidSquares.Add(_cEle.m_cTopElement); } } if (_cEle.m_cBotElement != null) { if (!_cEle.m_cBotElement.m_bIsPath && _cEle.m_cBotElement.m_eElementType == EGameBoardType.Empty) { lValidSquares.Add(_cEle.m_cBotElement); } } if (_cEle.m_cLeftElement != null) { if (!_cEle.m_cLeftElement.m_bIsPath && _cEle.m_cLeftElement.m_eElementType == EGameBoardType.Empty) { lValidSquares.Add(_cEle.m_cLeftElement); } } if (_cEle.m_cRightElement != null) { if (!_cEle.m_cRightElement.m_bIsPath && _cEle.m_cRightElement.m_eElementType == EGameBoardType.Empty) { lValidSquares.Add(_cEle.m_cRightElement); } } if (lValidSquares.Count > 0) { return(lValidSquares[Random.Range(0, lValidSquares.Count - 1)]); } return(null); }
/// <summary> /// Initialises Board Data /// </summary> void FormBoardData() { m_acGameBoardData = new GameBoardElement[m_iBoardWidth, m_iBoardHeight]; for (int i = 0; i < m_iBoardWidth; i++) { for (int j = 0; j < m_iBoardHeight; j++) { //Initialises the Class to store data GameBoardElement cNewElement = new GameBoardElement(i, j) { m_eElementType = EGameBoardType.Empty }; if (j - 1 >= 0 && m_acGameBoardData[i, j - 1] != null) { cNewElement.m_cTopElement = m_acGameBoardData[i, j - 1]; m_acGameBoardData[i, j - 1].m_cBotElement = cNewElement; } if (j + 1 < m_iBoardHeight && m_acGameBoardData[i, j + 1] != null) { cNewElement.m_cBotElement = m_acGameBoardData[i, j + 1]; m_acGameBoardData[i, j + 1].m_cTopElement = cNewElement; } if (i - 1 >= 0 && m_acGameBoardData[i - 1, j] != null) { cNewElement.m_cLeftElement = m_acGameBoardData[i - 1, j]; m_acGameBoardData[i - 1, j].m_cRightElement = cNewElement; } if (i + 1 < m_iBoardWidth && m_acGameBoardData[i + 1, j] != null) { cNewElement.m_cRightElement = m_acGameBoardData[i + 1, j]; m_acGameBoardData[i + 1, j].m_cLeftElement = cNewElement; } m_acGameBoardData[i, j] = cNewElement; } } }
private void GenerateElements() { elements = new GameBoardElement[size, size]; string name = GetType().Assembly.GetManifestResourceNames().First(n => n.EndsWith("BrainFreezeBoard.txt")); Stream boardInitStream = GetType().Assembly.GetManifestResourceStream(name); using(var reader = new StreamReader(boardInitStream)) { for (int i = 0; i < size; i++) { var textElements = reader.ReadLine().Split(new[] { ' ' }); for (int j = 0; j < size; j++) { var elementCode = textElements[j]; int primaryValue = int.Parse(string.Format("{0}", elementCode[0])); int secondaryValue = GetValueFromChar(elementCode[1]); elements[i, j] = new GameBoardElement(primaryValue, secondaryValue); } } } }
public void MarkElement_WithObserverUnsubscribedAndChangingValue_ObserverNotNotified() { // Setup var mocks = new MockRepository(); var observer = mocks.StrictMock<IObserver<ElementState>>(); mocks.ReplayAll(); var element = new GameBoardElement(0, 0); using (element.Subscribe(observer)) { } // Call element.MarkElement(ElementState.NotRow); // Assert mocks.VerifyAll(); }
public void MarkElement_FromNeitherRowNorColumnToAnyOtherNotStates_StateKeepsReturningNeitherRowNorColumn(ElementState newNotState) { // Setup var element = new GameBoardElement(0, 0); element.MarkElement(ElementState.NeitherRowNorColumn); // Call element.MarkElement(newNotState); // Assert Assert.AreEqual(ElementState.NeitherRowNorColumn, element.State); }
public void MarkElement_FromNotColumnToNotValue_StateRemainsNotColumn() { // Setup var element = new GameBoardElement(0, 0); element.MarkElement(ElementState.NotColumn); // Call element.MarkElement(ElementState.NotValue); // Assert Assert.AreEqual(ElementState.NotColumn, element.State); }
public void MarkElement_FromNotRowToSomeOtherNotStates_StateReturnsNeitherRowNorColumn(ElementState newNotState) { // Setup var element = new GameBoardElement(0, 0); element.MarkElement(ElementState.NotRow); // Call element.MarkElement(newNotState); // Assert Assert.AreEqual(ElementState.NeitherRowNorColumn, element.State); }
public void MarkElement_FromAnyNotToYes_DoNotChangeState(ElementState notState) { // Setup var element = new GameBoardElement(0, 0); element.MarkElement(notState); // Call element.MarkElement(ElementState.Yes); // Assert Assert.AreEqual(notState, element.State); }