public void SubmitAnswer(RoundAction roundAction, PlayerAnswer playerAnswer) { //This is important to compare to the question start time to see if the player answered in time. playerAnswer.PlayerAnswerTime = DateTime.Now; db.Players.Attach(playerAnswer.Player); db.Answers.Attach(playerAnswer.AnswerGiven); RoundAction raEntity = db.RoundActions.Where(ra => ra.Id == roundAction.Id).FirstOrDefault(); // Check is the list has been initialised, if not intialise it if (raEntity.PlayerAnswers == null) { raEntity.PlayerAnswers = new List <PlayerAnswer>(); } //Checking if the player answers in time and that they haven't already submitted an answer int elapsedSeconds = (int)(playerAnswer.PlayerAnswerTime - raEntity.QuestionStartTime).TotalSeconds; bool playerHasntAnswered = true; if (raEntity.PlayerAnswers.Where(pa => pa.Player.Id == playerAnswer.Player.Id).FirstOrDefault() != null) { playerHasntAnswered = false; } //Saves the player's answer to the database if (elapsedSeconds <= 35 && playerHasntAnswered) { raEntity.PlayerAnswers.Add(playerAnswer); db.Entry(raEntity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public async Task <ActionResult> SavePlayerAnswer([FromBody] PlayerAnswer playerAnswer) { PlayerAnswerBE answerBE = base.Mapper.Map <PlayerAnswerBE>(playerAnswer); await base.Adapter.SavePlayerAnswer(answerBE); return(Ok()); }
private void StartGame_Click(object sender, RoutedEventArgs e) { try { if (StartGame.Content.Equals("Start Game")) { // set operands LeftOperand.Content = game.GetLeftOperand(); RightOperand.Content = game.GetRightOperand(); // start timer and focus input myTimer.Start(); PlayerAnswer.Focus(); // update button StartGame.Content = "Submit Answer"; PlayerAnswer.IsEnabled = true; PlayerAnswer.Focus(); } else { SubmitAnswer(); } } catch (Exception ex) { throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
public async Task SubmitAnswer(PlayerAnswer answer, int currentSessionId) { var currentSession = _db.SingleById <GameSession>(currentSessionId); _db.Insert(answer); await Clients.Groups("Players" + currentSession.JoinCode, "Server" + currentSession.JoinCode) .SendAsync("PlayerCountUpdated", _db.Fetch <Player>().Count(p => p.GameSession.Id == currentSessionId)); }
/// <summary> /// send the change of player's pos to server /// </summary> /// <param name="step"></param> void SendServerNotify(int index) { Debug.Log("Commit:" + index); PlayerAnswer data = new PlayerAnswer(); data.answerIndex = index; string jsonData = SimpleJson.SimpleJson.SerializeObject(data); NetworkManager.StarXService.Notify("Room.CommitAnswer", Encoding.UTF8.GetBytes(jsonData)); }
public void InitPlayerAnswers(List <UserReplica> replics) { m_lastAnswers.Clear(); foreach (UserReplica replica in replics) { PlayerAnswer answer = Instantiate(m_answer); answer.Init(replica, AddPlayerMessage); m_lastAnswers.Add(answer); } UpdateAnswersBox(); }
public Question(List <StringEmotion> inBreadText, PlayerAnswer inExpectedAnswer, List <StringEmotion> inWrongAnswer, List <StringEmotion> inRightAnswer) { breadText = inBreadText; this.expectedAnswer = inExpectedAnswer; this.wrongAnswer = inWrongAnswer; this.rightAnswer = inRightAnswer; allDone = false; questionState = 0; currentElement = 0; correct_happiness_boost = 0.1f; incorrect_happiness_loss = -0.1f; happiness_min = -1.0f; happiness_max = 1.0f; }
public async Task <int> CreatePlayerAnswer(CreatePlayerAnswerModel model) { var newAnswer = new PlayerAnswer { AnswerCardId = model.AnswerCardId, SecondaryAnswerCardId = model.SecondaryAnswerCardId, GameRoundId = model.GameRoundId, PlayerId = model.PlayerId, IsSelectedAnswer = false }; context.PlayerAnswers.Add(newAnswer); await context.SaveChangesAsync(); return(newAnswer.PlayerAnswerId); }
public void AddplayerAnswers(PlayerModel model) { var answers = new List <PlayerAnswer>(); foreach (var item in model.playerMovies) { var dbModel = new PlayerAnswer { gameId = model.gameId, playerId = model.playerId, movieRank = item.rank, year = item.year }; answers.Add(dbModel); } context.PlayerAnswers.AddRange(answers); context.SaveChanges(); }
public void SubmitAnswer(Round round, PlayerAnswer playerAnswer) { using (var db = new ConquestionDBContext()) { //This is important to compare to the question start time to see if the player answered in time. playerAnswer.PlayerAnswerTime = DateTime.Now; var playerEntity = db.Players.Where(p => p.Name.Equals(playerAnswer.Player.Name)).FirstOrDefault(); playerAnswer.Player = playerEntity; var answerEntity = db.Answers.Where(a => a.Id == playerAnswer.AnswerGiven.Id).FirstOrDefault(); playerAnswer.AnswerGiven = answerEntity; Round rEntity = db.Rounds.Include("PlayerAnswers.Player").Include("RoundWinner").Where(r => r.Id == round.Id).FirstOrDefault(); // Check is the list has been initialised, if not intialise it if (rEntity.PlayerAnswers == null) { rEntity.PlayerAnswers = new List <PlayerAnswer>(); } //Checking if the player answers in time and that they haven't already submitted an answer int elapsedSeconds = (int)(playerAnswer.PlayerAnswerTime - rEntity.QuestionStartTime).TotalSeconds; bool playerHasntAnswered = true; if (rEntity.PlayerAnswers.Where(pa => pa.Player.Id == playerAnswer.Player.Id).FirstOrDefault() != null) { playerHasntAnswered = false; } //Saves the player's answer to the database if (elapsedSeconds <= 35 && playerHasntAnswered) { rEntity.PlayerAnswers.Add(playerAnswer); if (ValidateAnswer(playerAnswer.AnswerGiven) && rEntity.RoundWinner == null) { rEntity.RoundWinner = playerAnswer.Player; } db.Entry(rEntity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } }
public void SubmitAnswer(RoundAction roundAction, PlayerAnswer playerAnswer) { roundCtr.SubmitAnswer(roundAction, playerAnswer); }
public PlayerAnswer GetAnswer() { PlayerAnswer ret_value = PlayerAnswer.Nothing; if (wait > 0) { wait -= Time.deltaTime; return(PlayerAnswer.Nothing); } else { if (Math.Abs(InputManager.GetX()) <= 0.0f && Math.Abs(InputManager.GetY()) <= 0.0f) { stayStileTime += Time.deltaTime; if (stayStileTime > 1) { shakeCount = 0; } } else { stayStileTime = 0; // Debug.Log("IN HERE"); //YES if (Math.Abs(InputManager.GetX()) > Math.Abs(InputManager.GetY())) { if (!isHorizontal) { shakeCount = 0; } isHorizontal = true; direction = InputManager.GetX(); if (shakeCount >= 4) { shakeCount = 0; wait = 1; ret_value = PlayerAnswer.No; } } //NO else { if (isHorizontal) { shakeCount = 0; } isHorizontal = false; direction = InputManager.GetY(); if (shakeCount >= 4) { wait = 1; shakeCount = 0; ret_value = PlayerAnswer.Yes; } } if (ret_value == PlayerAnswer.Nothing) { if ((direction + lastDirection) == 0) { shakeCount++; } lastDirection = direction; } } } if (ret_value == PlayerAnswer.Nothing) { if (Gameplay.INSTANCE.joystick.activeSelf == false) { Gameplay.INSTANCE.joystick.SetActive(true); } } else { if (Gameplay.INSTANCE.joystick.activeSelf == true) { Gameplay.INSTANCE.joystick.SetActive(false); } } return(ret_value); }
// Update is called once per frame void Update() { //if(Input.GetKeyDown(KeyCode.F8)) { // game_mode = GameMode.Minigame; // game_sequence = GameSequence.Balcony; // cheers_game.SetActive(true); //} //if(Input.GetKeyDown(KeyCode.F9)) { // game_mode = GameMode.Talking; // game_sequence = GameSequence.Livingroom; // cheers_game.SetActive(false); //} if (Input.GetKeyDown(KeyCode.F6)) { AndroidStatus.happiness -= 0.1f; } if (Input.GetKeyDown(KeyCode.F7)) { AndroidStatus.happiness += 0.1f; } if (Input.GetKeyDown(KeyCode.F5)) { if (mood_debug != null) { mood_debug.gameObject.SetActive(true); } if (happiness_debug != null) { happiness_debug.gameObject.SetActive(true); } } if (Input.GetKeyDown(KeyCode.F4)) { if (mood_debug != null) { mood_debug.gameObject.SetActive(false); } if (happiness_debug != null) { happiness_debug.gameObject.SetActive(false); } } if (Input.GetKeyDown(KeyCode.Escape)) { if (game_mode == GameMode.Talking) { SetDialogue(new Question.StringEmotion { breadText = "Are you leaving me?", emotionState = FaceSystem.Emotion.sad }); game_mode = GameMode.Leave; } else { Application.Quit(); } } outputDia.text = readLine; readLine = ReadCurrentDialogue(); if (fullLine != readLine) { return; } if (happiness_debug != null) { happiness_debug.text = "" + AndroidStatus.happiness; } if (game_mode == GameMode.Leave) { PlayerAnswer pa = InputManager.yesAndNo.GetAnswer(); if (pa == PlayerAnswer.Yes) { Application.Quit(); } else if (pa == PlayerAnswer.No) { game_mode = GameMode.Talking; } } if (game_mode == GameMode.Talking) { if (AndroidStatus.happiness >= 1.0f) { if (game_sequence == GameSequence.Livingroom) { currentTalkingElement = null; SetDialogue(new Question.StringEmotion { breadText = "Let's head out to the balcony?", emotionState = FaceSystem.Emotion.happy }); game_mode = GameMode.Minigame; } if (game_sequence == GameSequence.Balcony) { currentTalkingElement = null; SetDialogue(new Question.StringEmotion { breadText = "A toast, to us!", emotionState = FaceSystem.Emotion.happy }); cheers_game.SetActive(true); game_mode = GameMode.Minigame; } if (game_sequence == GameSequence.Bedroom) { currentTalkingElement = null; SetDialogue(new Question.StringEmotion { breadText = "Let's take this all the way", emotionState = FaceSystem.Emotion.blush }); sex_game.SetActive(true); game_mode = GameMode.Minigame; } } else if (AndroidStatus.happiness <= -1.0f) { game_mode = GameMode.Failure; } } if (game_mode == GameMode.Minigame) { if (game_sequence == GameSequence.Livingroom) { PlayerAnswer pa = InputManager.yesAndNo.GetAnswer(); if (pa == PlayerAnswer.Yes) { SetDialogue(new Question.StringEmotion { breadText = "^^'", emotionState = FaceSystem.Emotion.blush }); game_mode = GameMode.BackToTalking; } else if (pa == PlayerAnswer.No) { game_mode = GameMode.Failure; } } else if (game_sequence == GameSequence.Balcony) { CheersGame cg = cheers_game.GetComponent <CheersGame>(); if (cg.won) { SetDialogue(new Question.StringEmotion { breadText = "Shall take this to the bedroom", emotionState = FaceSystem.Emotion.blush }); game_mode = GameMode.BackToTalking; } else if (cg.lost) { SetDialogue(new Question.StringEmotion { breadText = "Why do you have to ruin every special moment we have?", emotionState = FaceSystem.Emotion.sad }); game_mode = GameMode.Failure; } else if (cg.won == false && cg.lost == false && cg.attempts != prev_cheer_attempts) { SetDialogue(new Question.StringEmotion { breadText = "Can't you aim!?", emotionState = FaceSystem.Emotion.angry }); prev_cheer_attempts = cg.attempts; } } else if (game_sequence == GameSequence.Bedroom) { SexHandler sh = sex_game.GetComponent <SexHandler>(); if (sh.finalized) { SetDialogue(new Question.StringEmotion { breadText = "You do care!", emotionState = FaceSystem.Emotion.happy }); game_mode = GameMode.BackToTalking; } } } if (game_mode == GameMode.Failure) { if (fail_state.active == false) { fail_state.SetActive(true); SetDialogue(new Question.StringEmotion { breadText = "...", emotionState = FaceSystem.Emotion.serious }); } } if (game_mode == GameMode.BackToTalking) { if (InputManager.PushToTalk()) { if (game_sequence == GameSequence.Livingroom) { change_scene.NextScene(); game_sequence = GameSequence.Balcony; game_mode = GameMode.Talking; AndroidStatus.happiness = 0.0f; } else if (game_sequence == GameSequence.Balcony) { change_scene.NextScene(); cheers_game.SetActive(false); game_sequence = GameSequence.Bedroom; game_mode = GameMode.Talking; AndroidStatus.happiness = 0.0f; } else if (game_sequence == GameSequence.Bedroom) { AndroidStatus.happiness = 100000000.0f; } } } if (game_mode == GameMode.Talking) { if (!currentTalkingElement || currentTalkingElement.GoNext()) { //Debug.Log("HEREH: "); if (currentTalkingElement is Question) { TalkingElement nextElement = null; if (currentTalkingElement.correctlyAnswered) { if (currentTalkingElement.GetType() == typeof(Question)) { Question q = (Question)currentTalkingElement; AndroidStatus.happiness += q.correct_happiness_boost; } nextElement = currentTalkingElement.rightAnswerNode; } else { if (currentTalkingElement.GetType() == typeof(Question)) { Question q = (Question)currentTalkingElement; AndroidStatus.happiness += q.incorrect_happiness_loss; } nextElement = currentTalkingElement.wrongAnswerNode; } if (nextElement != null) { SetTalkingElement(nextElement); Debug.Log("Not nUll"); } else { SetTalkingElement(AndroidStatus.GetTalkingElement()); Debug.Log("Next Element"); } } else { SetTalkingElement(AndroidStatus.GetTalkingElement()); } } } androidState.Update(); if (game_mode == GameMode.Talking) { if (currentTalkingElement) { var next = currentTalkingElement.GetText(); if (next != null && next.breadText != originalFullLine) { SetDialogue(next); } } } }
public void SubmitAnswer(Round round, PlayerAnswer playerAnswer) { playerAnswer.Player = playerCtr.RetrievePlayer(Thread.CurrentPrincipal.Identity.Name); roundCtr.SubmitAnswer(round, playerAnswer); }
public override bool GoNext() { //Debug.Log("GoNext() starting at " + questionState); allDone = false; switch (questionState) { case 0: if (currentElement == breadText.Count - 1) { currentElement++; } else if (currentElement < breadText.Count) { if (InputManager.PushToTalk()) { currentElement++; } } if (currentElement >= breadText.Count) { currentElement = breadText.Count - 1; questionState = 1; } if (currentElement < 0) { allDone = true; } break; case 1: PlayerAnswer answer = InputManager.yesAndNo.GetAnswer(); if (answer != PlayerAnswer.Nothing) { if (expectedAnswer != answer) { questionState = 2; correctlyAnswered = false; } else { questionState = 3; correctlyAnswered = true; } currentElement = 0; } break; case 2: //WRONG ANSWER if (currentElement < wrongAnswer.Count) { if (InputManager.PushToTalk()) { currentElement++; } } else { currentElement = 0; allDone = true; } break; case 3: //RIGHT ANSWER if (currentElement < rightAnswer.Count) { if (InputManager.PushToTalk()) { currentElement++; } } else { currentElement = 0; allDone = true; } break; } if (allDone) { currentElement = 0; questionState = 0; } //Debug.Log("Ended at " + questionState); return(allDone); }
public Task SubmitAnswer(PlayerAnswer answer) { return(_client.InvokeAsync(nameof(SubmitAnswer), answer)); }
void Load() { scrollRect.gameObject.SetActive(true); if (lastName == fileName) // проверка, чтобы не загружать уже загруженный файл { BuildDialogue(0, 0, 0, 0); return; } node = new List <Dialogue>(); try // чтение элементов XML и загрузка значений атрибутов в массивы { TextAsset binary = Resources.Load <TextAsset>(folder + "/" + fileName); XmlTextReader reader = new XmlTextReader(new StringReader(binary.text)); int index = 0; while (reader.Read()) { if (reader.IsStartElement("node")) { dialogue = new Dialogue(); dialogue.answer = new List <PlayerAnswer>(); dialogue.npcText = reader.GetAttribute("npcText"); node.Add(dialogue); XmlReader inner = reader.ReadSubtree(); while (inner.ReadToFollowing("answer")) { answer = new PlayerAnswer(); answer.text = reader.GetAttribute("text"); int number; if (int.TryParse(reader.GetAttribute("toNode"), out number)) { answer.toNode = number; } else { answer.toNode = 0; } bool result; if (bool.TryParse(reader.GetAttribute("exit"), out result)) { answer.exit = result; } else { answer.exit = false; } int reputation; if (int.TryParse(reader.GetAttribute("reputation"), out reputation)) { answer.reputation = reputation; } else { answer.reputation = 0; } int power; if (int.TryParse(reader.GetAttribute("power"), out power)) { answer.power = power; } else { answer.power = 0; } int money; if (int.TryParse(reader.GetAttribute("money"), out money)) { answer.money = money; } else { answer.money = 0; } bool end; if (bool.TryParse(reader.GetAttribute("end"), out end)) { answer.end = end; } else { answer.end = false; } node[index].answer.Add(answer); } inner.Close(); index++; } } lastName = fileName; reader.Close(); } catch (System.Exception error) { Debug.Log(this + " Ошибка чтения файла диалога: " + fileName + ".xml >> Error: " + error.Message); scrollRect.gameObject.SetActive(false); lastName = string.Empty; } BuildDialogue(0, 0, 0, 0); }