public void PrintErrorMessege(eResponseCode i_Error) { switch (i_Error) { case eResponseCode.CellIsInvalid: Console.WriteLine("The chosen cell is invalid, please choose another cell:"); break; case eResponseCode.NoValidCellsForPlayer: Console.WriteLine("You have no valid cells. The turn will be moved to the second player"); break; case eResponseCode.NoValidCellsForBothPlayers: Console.WriteLine("Both players have no valid cells"); break; case eResponseCode.InvalidMove: Console.WriteLine("The cell you chose doesn't block the competitor's coins, please try again:"); break; case eResponseCode.NotEmpty: Console.WriteLine("The chosen cell is not empty, please try again:"); break; case eResponseCode.OutOfRange: Console.WriteLine("The chosen cell is out of range, please try again:"); break; default: break; } }
public void AddErrorMessage(eResponseCode responseCode) { if (ErrorMessages == null) { ErrorMessages = new List <string>(); } ErrorMessages.Add(responseCode.Message()); }
public override bool ProcessError(Response response, eResponseCode errCode) { if (!mProcessErrorMethodGot) { mProcessErrorMethod = instance.Type.GetMethod("ProcessError", 2); mProcessErrorMethodGot = true; } if (mProcessErrorMethod != null) { return((bool)appdomain.Invoke(mProcessErrorMethod, instance, response, errCode)); } return(base.ProcessError(response, errCode)); }
private eResponseCode locationInputValidation(string i_InputLocation) { eResponseCode sendResponse = eResponseCode.OK; int boardSize = m_GameBoard.Matrix.GetLength(0); if (i_InputLocation.Length != 2) { sendResponse = eResponseCode.CellIsInvalid; } else if (i_InputLocation[0] < 'A' || i_InputLocation[0] > ('A' + boardSize) || i_InputLocation[1] < '1' || i_InputLocation[1] >= '1' + boardSize) { sendResponse = eResponseCode.OutOfRange; } return(sendResponse); }
private void playTurns() { while (m_GameManager.Winner == null) { eResponseCode availableCells = m_GameManager.CheckValidCellsForBothPlayers(); if (availableCells == eResponseCode.NoValidCellsForBothPlayers) { Player looser = m_GameManager.CalculateWinnerAndLooser(); PrintErrorMessege(availableCells); GameOverMessege(m_GameManager.Winner, looser, m_GameManager.Player1.Score, m_GameManager.Player2.Score); FinishGame(); } else if (availableCells == eResponseCode.NoValidCellsForPlayer) { PrintErrorMessege(availableCells); } else { if (m_GameManager.CurrentPlayer.PlayerID == Player.ePlayerID.Computer) { m_GameManager.MakeAiMove(); } else { string inputLocation = GetMoveFromUser(m_GameManager.CurrentPlayer.PlayerID); Cell.Location location = m_GameManager.ParseLocation(inputLocation); eResponseCode moveResponse = m_GameManager.ExecuteMove(location); while (moveResponse != eResponseCode.OK) { PrintErrorMessege(moveResponse); inputLocation = GetInputFromUser(); location = m_GameManager.ParseLocation(inputLocation); moveResponse = m_GameManager.ExecuteMove(location); } } PrintTheBoardAfterTurn(); } m_GameManager.ChangeCurrentPlayer(); } }
public eResponseCode PlayTurn(int i_X, int i_Y) { eResponseCode response = eResponseCode.OK; Cell.Location location = parseLocation(i_X, i_Y); executeMove(location); changeCurrentPlayer(); response = CheckValidCellsForBothPlayers(); if (response == eResponseCode.OK) { if (m_CurrentPlayer.PlayerID == Player.ePlayerID.Computer) { response = makeAiMove(); changeCurrentPlayer(); } } return(response); }
private eResponseCode checkValidCellsForPlayer(Cell.eType i_Type) { List <Cell> availableCells = new List <Cell>(); eResponseCode response = eResponseCode.NoValidCellsForPlayer; foreach (Cell cell in m_GameBoard.Matrix) { if (cell.CellType == Cell.eType.Empty) { availableCells = findCellsToFlip(cell.CellLocation, i_Type); if (availableCells.Count > 0) { response = eResponseCode.OK; break; } } } return(response); }
public Cell.Location ParseLocation(string i_InputLocation) { if (i_InputLocation == "Q") // Quit game { OnExit.Invoke(); } eResponseCode response = locationInputValidation(i_InputLocation); while (response != eResponseCode.OK) { OnPrintErrorMessage.Invoke(response); i_InputLocation = OnGetUserInput.Invoke(); response = locationInputValidation(i_InputLocation); } Cell.Location chosenLocation = new Cell.Location(); chosenLocation.Y = i_InputLocation[0] - 65; // convert letter to number chosenLocation.X = int.Parse((i_InputLocation[1]).ToString()) - 1; return(chosenLocation); }
public ResponseInfo(eResponseCode code, String message) { ResponseCode = (int)code; ResponseMessage = message; }
public static ResponseInfo getDefaultResponseInfo(eResponseCode errorCode, String errorMessage) { return new ResponseInfo(errorCode, errorMessage); }
public static ResponseInfo getDefaultResponseInfo(eResponseCode errorCode) { return getDefaultResponseInfo((int)errorCode); }
private bool ErrorHandler(Response response, eResponseCode errCode) { return(false); }
/// <summary> /// Get the resource message based on eResponseCode enum. /// </summary> /// <param name="value">The eResponseCode enum.</param> /// <returns> /// The Message of the code. /// </returns> public static string Message(this eResponseCode value) { var code = value.Code(); return(ResourcesManager.GetMessage(code)); }
/// <summary> /// Convert arduino response code to state /// </summary> /// <param name="code">Arduino response code</param> /// <returns>Servo state</returns> private eRotationalMove ResponseCodeToServoState(eResponseCode code) { eRotationalMove state = eRotationalMove.NA; switch (code) { case eResponseCode.SERVO_STATE_KICK: state = eRotationalMove.KICK; break; case eResponseCode.SERVO_STATE_RISE: state = eRotationalMove.RISE; break; case eResponseCode.SERVO_STATE_DEFENCE: state = eRotationalMove.DEFENCE; break; } return state; }
/// <summary> /// Print received code to log /// </summary> /// <param name="code">Received code</param> /// <param name="category">Print category</param> private void PrintArduinoResponse(eResponseCode code, eCategory category, [CallerMemberName]string method = "", [CallerFilePath] string sourceFile = "", [CallerLineNumber] int lineNumber = 0) { if (code != eResponseCode.NO_DATA) { String message = String.Format("[Remote: {0}]: {1}", ComPortName, code.ToString()); Log.Print(message, category, LogTag.ARDUINO, method, sourceFile, lineNumber); } }
/// <summary> /// Update last arduino servo state /// </summary> /// <param name="newState">Servo state as arduino response code</param> public void SetLastServoState(eResponseCode newState) { eRotationalMove state = ResponseCodeToServoState(newState); if (!state.Equals(eRotationalMove.NA)) { _lastServo = state; if (OnServoChangeState != null) { OnServoChangeState(RodType, _lastServo); } } }