void CheckPos() { numberCorrectPos = 0; for (int i = 1; i < 9; i++) { if (Board.instance.slots[i].content && Board.instance.slots[i].content.numberCode == i) { numberCorrectPos++; } if (i == 3 && i == numberCorrectPos && firstStop) {//start first stop firstStop = false; inGame = false; OnFirstStop?.Invoke(this, EventArgs.Empty); } } if (numberCorrectPos == 8) { inGame = false; OnQuestion?.Invoke(this, EventArgs.Empty); } }
/// <summary> /// When user input is needed anywhere during using uppm this method should be called. /// It invokes <see cref="OnQuestion"/> where the implementer can either block uppm with user query or use the default value. /// </summary> /// <param name="question">Question to be asked from user</param> /// <param name="possibilities">If null any input will be accepted. Otherwise input is compared to these possible entries ignoring case. If no match is found question will be asked again.</param> /// <param name="defaultValue">This value is used when user submits an empty input or in a potential unattended mode.</param> /// <param name="source">Optional logger which asks the question</param> /// <returns>User answer or default</returns> public static string AskUser( string question, IEnumerable <string> possibilities = null, string defaultValue = "", ILogging source = null) { var possarray = possibilities?.ToArray(); L.Information(question); L.Information(" ({Possibilities})", possarray.Humanize("or")); L.Information(" (default is {DefaultValue})", defaultValue); var args = new AskUserEventArgs { Question = question, Default = defaultValue }; OnQuestion?.Invoke(source, args); if (possarray != null && !possarray.Any(p => p.EqualsCaseless(args.Answer))) { L.Warning("Invalid answer submitted for question: {Answer}\n Asking again.", args.Answer); AskUser(question, possarray, defaultValue, source); } var res = string.IsNullOrWhiteSpace(args.Answer) ? defaultValue : args.Answer; L.Debug("{Answer} is answered", res); return(res); }
/// <summary> /// Ask a question using the given pipeline. /// </summary> /// <param name="question">The text of the question.</param> /// <param name="callback">The callback to receive the response.</param> /// <returns>Returns true if the request was submitted.</returns> public bool AskQuestion(string question, OnQuestion callback, int evidenceItems = 1, bool useCache = true) { if (string.IsNullOrEmpty(question)) { throw new ArgumentNullException("question"); } if (callback == null) { throw new ArgumentNullException("callback"); } string questionId = Utility.GetMD5(question); if (!DisableCache && useCache) { Question q = FindQuestion(questionId); if (q != null) { callback(q); return(true); } } RESTConnector connector = RESTConnector.GetConnector(m_ServiceId, ASK_QUESTION); if (connector == null) { return(false); } Dictionary <string, object> questionJson = new Dictionary <string, object>(); questionJson["question"] = new Dictionary <string, object>() { { "questionText", question }, { "formattedAnswer", "true" }, { "evidenceRequest", new Dictionary <string, object>() { { "items", evidenceItems }, { "profile", "NO" } } } }; string json = MiniJSON.Json.Serialize(questionJson); AskQuestionReq req = new AskQuestionReq(); req.QuestionID = questionId; req.Callback = callback; req.Headers["Content-Type"] = "application/json"; req.Headers["X-Synctimeout"] = "-1"; req.Send = Encoding.UTF8.GetBytes(json); req.OnResponse = OnAskQuestionResp; return(connector.Send(req)); }