コード例 #1
0
    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseConvergeNewAttempt response = new ResponseConvergeNewAttempt();

        using (BinaryReader br = new BinaryReader(dataStream, Encoding.UTF8)) {
            int    playerId    = br.ReadInt32();
            int    ecosystemId = br.ReadInt32();
            int    attemptId   = br.ReadInt32();
            bool   allowHints  = br.ReadBoolean();
            int    hintId      = br.ReadInt32();
            short  fldSize     = br.ReadInt16();
            String config      = System.Text.Encoding.UTF8.GetString(br.ReadBytes(fldSize));
            fldSize = br.ReadInt16();
            String csv = System.Text.Encoding.UTF8.GetString(br.ReadBytes(fldSize));
            //Debug.Log ("csv = " + csv);

            ConvergeAttempt attempt = new ConvergeAttempt(playerId,
                                                          ecosystemId,
                                                          attemptId,
                                                          allowHints,
                                                          hintId,
                                                          config,
                                                          csv
                                                          //null
                                                          );

            response.attempt = attempt;
        }

        return(response);
    }
コード例 #2
0
    public void ProcessConvergeNewAttempt(NetworkResponse response)
    {
        ConvergeAttempt            attempt;
        ResponseConvergeNewAttempt args = response as ResponseConvergeNewAttempt;

        attempt = args.attempt;

        //if the submission resulted in a valid attempt, add to attempt list and reinitialize
        //currAttempt for next attempt.  Otherwise, keep current attempt
        if (attempt != null && attempt.attempt_id != Constants.ID_NOT_SET)
        {
            currAttempt.attempt_id = attempt.attempt_id;
            currAttempt.SetCSV(attempt.csv_string);
            attemptList.Add(currAttempt);
            attemptCount = attemptList.Count;

            //calculate score and send back to server.
            CSVObject target = ecosystemList[ecosystem_idx].csv_target_object;
            int       score  = currAttempt.csv_object.CalculateScore(target);
            NetworkManager.Send(
                ConvergeNewAttemptScoreProtocol.Prepare(
                    player_id,
                    ecosystem_id,
                    attempt.attempt_id,
                    score
                    ),
                ProcessConvergeNewAttemptScore
                );

            //update pertinent variables with new data
            if (currAttempt.hint_id != Constants.ID_NOT_SET)
            {
                priorHintIdList.Add(currAttempt.hint_id);
            }
            //need to recalc reset slider config due to additional attempt
            isResetSliderInitialized = false;

            if (barGraph != null)
            {
                barGraph.InputToCSVObject(currAttempt.csv_string, manager);
            }

            currAttempt = new ConvergeAttempt(
                player_id,
                ecosystem_id,
                attempt.attempt_id + 1,
                allowHintsMaster,
                Constants.ID_NOT_SET,
                attempt.config,
                null,
                manager
                );

            FinalizeAttemptUpdate(attemptCount - 1, false);
        }
        else
        {
            Debug.LogError("Submission of new attempt failed to produce results.");
            SetIsProcessing(false);
        }
    }