You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
6.3 KiB
199 lines
6.3 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class GameRoot : MonoBehaviour
|
|
{
|
|
public static GameRoot Instance = null;
|
|
|
|
private float _score;
|
|
|
|
//记录选择题答案字典
|
|
public Dictionary<int, Dictionary<int, int>> _choiceDict = new Dictionary<int, Dictionary<int, int>>();
|
|
//记录多选题答案字典
|
|
public Dictionary<int, Dictionary<int, int[]>> _moreChoiceDict = new Dictionary<int, Dictionary<int, int[]>>();
|
|
//记录操作题答案字典
|
|
public Dictionary<int, Dictionary<int, bool>> _oprerationDict = new Dictionary<int, Dictionary<int, bool>>();
|
|
|
|
private void Awake()
|
|
{
|
|
DontDestroyOnLoad(this);
|
|
Instance = this;
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
int[] a = { 1,2,3,4,};
|
|
//SubmitChoiceAnswer(1,1,1);
|
|
//SubmitChoiceAnswer(1, 2, 2);
|
|
//SubmitChoiceAnswer(2, 1, 2);
|
|
//CheckChoiceAnswer();
|
|
SubmitMoreChoiceAnswer(5,1,a );
|
|
SubmitOprerationAnswer(5, 2, true);
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 答案管理方法
|
|
|
|
/// <summary>
|
|
/// 提交选择题答案函数
|
|
/// PassIndex:关卡索引
|
|
/// QuestionIndex:问题索引
|
|
/// answer:记录用户所选的答案(ABCD对应0123)
|
|
/// </summary>
|
|
/// <param name="PassIndex">关卡索引</param>
|
|
/// <param name="QuestionIndex">问题索引</param>
|
|
/// <param name="answer">记录用户所选的答案(ABCD对应0123)</param>
|
|
public static void SubmitChoiceAnswer(int PassIndex, int QuestionIndex, int answer)
|
|
{
|
|
if (GameRoot.Instance == null) return;
|
|
|
|
//如果不存在则创建并放入字典
|
|
if (!GameRoot.Instance._choiceDict.ContainsKey(PassIndex))
|
|
{
|
|
Dictionary<int, int> dict = new Dictionary<int, int>();
|
|
dict.Add(QuestionIndex, answer);
|
|
GameRoot.Instance._choiceDict.Add(PassIndex, dict);
|
|
Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + answer);
|
|
}
|
|
else
|
|
{
|
|
//继续记录
|
|
Dictionary<int, int> dict = new Dictionary<int, int>();
|
|
if (GameRoot.Instance._choiceDict.TryGetValue(PassIndex, out dict))
|
|
{
|
|
dict.Add(QuestionIndex, answer);
|
|
|
|
GameRoot.Instance._choiceDict[PassIndex] = dict;
|
|
|
|
Debug.Log("关卡字典已存在,更新" + QuestionIndex + "问题的答案为" + answer);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提交多选题答案函数
|
|
/// PassIndex:关卡索引
|
|
/// QuestionIndex:问题索引
|
|
/// answer:记录用户所选的答案(ABCD对应0123)
|
|
/// </summary>
|
|
/// <param name="PassIndex">关卡索引</param>
|
|
/// <param name="QuestionIndex">问题索引</param>
|
|
/// <param name="answer">记录用户所选的答案</param>
|
|
public static void SubmitMoreChoiceAnswer(int PassIndex, int QuestionIndex, int[] answer)
|
|
{
|
|
if (GameRoot.Instance == null) return;
|
|
|
|
//如果不存在则创建并放入字典
|
|
if (!GameRoot.Instance._moreChoiceDict.ContainsKey(PassIndex))
|
|
{
|
|
Dictionary<int, int[]> dict = new Dictionary<int, int[]>();
|
|
dict.Add(QuestionIndex, answer);
|
|
GameRoot.Instance._moreChoiceDict.Add(PassIndex, dict);
|
|
Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + ArrToString(answer));
|
|
}
|
|
else
|
|
{
|
|
//继续记录
|
|
Dictionary<int, int[]> dict = new Dictionary<int, int[]>();
|
|
if (GameRoot.Instance._moreChoiceDict.TryGetValue(PassIndex, out dict))
|
|
{
|
|
dict.Add(QuestionIndex, answer);
|
|
|
|
GameRoot.Instance._moreChoiceDict[PassIndex] = dict;
|
|
|
|
Debug.Log("关卡字典已存在,更新" + QuestionIndex + "问题的答案为" + answer);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提交操作题答案函数
|
|
/// PassIndex:关卡索引
|
|
/// QuestionIndex:问题索引
|
|
/// answer:记录用户所选的答案(ABCD对应0123)
|
|
/// </summary>
|
|
/// <param name="PassIndex">关卡索引</param>
|
|
/// <param name="QuestionIndex">问题索引</param>
|
|
/// <param name="answer">记录用户所选的答案</param>
|
|
public static void SubmitOprerationAnswer(int PassIndex, int QuestionIndex, bool answer)
|
|
{
|
|
if (GameRoot.Instance == null) return;
|
|
|
|
//如果不存在则创建并放入字典
|
|
if (!GameRoot.Instance._oprerationDict.ContainsKey(PassIndex))
|
|
{
|
|
Dictionary<int, bool> dict = new Dictionary<int, bool>();
|
|
dict.Add(QuestionIndex, answer);
|
|
GameRoot.Instance._oprerationDict.Add(PassIndex, dict);
|
|
Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + answer);
|
|
}
|
|
else
|
|
{
|
|
//继续记录
|
|
Dictionary<int, bool> dict = new Dictionary<int, bool>();
|
|
if (GameRoot.Instance._oprerationDict.TryGetValue(PassIndex, out dict))
|
|
{
|
|
dict.Add(QuestionIndex, answer);
|
|
|
|
GameRoot.Instance._oprerationDict[PassIndex] = dict;
|
|
|
|
Debug.Log("关卡字典已存在,更新" + QuestionIndex + "问题的答案为" + answer);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public void CheckChoiceAnswer()
|
|
{
|
|
int passCount = _choiceDict.Keys.Count;
|
|
Debug.Log("总关卡:"+passCount);
|
|
|
|
for (int i = 0; i < passCount+1; i++)
|
|
{
|
|
|
|
Dictionary<int, int> dict = new Dictionary<int, int>();
|
|
if(_choiceDict.TryGetValue(i, out dict))
|
|
{
|
|
int questionCount = dict.Keys.Count;
|
|
// Debug.Log("第" + i + "关有" + questionCount + "道题");
|
|
for (int j = 0; j < questionCount+1; j++)
|
|
{
|
|
if (dict.ContainsKey(j))
|
|
{
|
|
Debug.Log("第"+i+"关第" + j + "题用户作答为" + dict[j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
public static string ArrToString(int[] arr)
|
|
{
|
|
string str="";
|
|
for (int i = 0; i < arr.Length; i++)
|
|
{
|
|
if (arr[i].ToString() != "")
|
|
{
|
|
str += arr[i].ToString();
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
|
|
|
|
}
|