-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThinksyProblemPart.cs
More file actions
executable file
·173 lines (149 loc) · 4.25 KB
/
ThinksyProblemPart.cs
File metadata and controls
executable file
·173 lines (149 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
//A problem part represents a small piece of data
//used to construct questions and answers.
public abstract class ProblemPart
{
Senseix.Message.Atom.Atom atom;
public static ProblemPart CreateProblemPart(Senseix.Message.Atom.Atom newAtom)
{
ProblemPart newProblemPart = new TextProblemPart(newAtom);
bool actuallyConstructed = false;
if (newAtom.type == Senseix.Message.Atom.Atom.Type.IMAGE)
{
newProblemPart = new ImageProblemPart(newAtom);
actuallyConstructed = true;
}
if (newAtom.type == Senseix.Message.Atom.Atom.Type.TEXT)
{
newProblemPart = new TextProblemPart(newAtom);
actuallyConstructed = true;
}
if (newAtom.type == Senseix.Message.Atom.Atom.Type.NUMBER)
{
newProblemPart = new NumberProblemPart(newAtom);
actuallyConstructed = true;
}
if (!actuallyConstructed)
{
throw new Exception("I encountered an atom of an unimplemented type.");
}
return newProblemPart;
}
public static ProblemPart CreateProblemPart(int number)
{
Senseix.Message.Atom.Atom atom = new Senseix.Message.Atom.Atom ();
atom.data = BitConverter.GetBytes (404);
atom.type = Senseix.Message.Atom.Atom.Type.NUMBER;
atom.numberValue = number;
atom.description = "unity-side generated number";
atom.uuid = "unity-side generated number";
atom.required = false;
return CreateProblemPart (atom);
}
public static ProblemPart CreateProblemPart(string text)
{
Senseix.Message.Atom.Atom atom = new Senseix.Message.Atom.Atom ();
atom.data = BitConverter.GetBytes (404);
atom.type = Senseix.Message.Atom.Atom.Type.TEXT;
atom.text = text;
atom.description = "unity-side generated text";
atom.uuid = "unity-side generated text";
atom.required = false;
return CreateProblemPart (atom);
}
public ProblemPart(Senseix.Message.Atom.Atom newAtom)
{
atom = newAtom;
}
/// <summary>
/// This will build a text ProblemPart. Hot tip: numbers are actually text
/// ProblemParts. If the text happens to be numbers, it will be treated
/// as such.
/// </summary>
public ProblemPart (string textContent)
{
Senseix.Message.Atom.Atom newAtom = new Senseix.Message.Atom.Atom ();
//forced my hand
newAtom.uuid = "Developer-side generated problem part";
newAtom.required = false;
//text
newAtom.type = Senseix.Message.Atom.Atom.Type.TEXT;
newAtom.data = Encoding.ASCII.GetBytes (textContent);
}
/// <summary>
/// This will build an image ProblemPart. The filename references only
/// Sprites from resources.
/// </summary>
public ProblemPart (string filename, bool isPretty)
{
Senseix.Message.Atom.Atom newAtom = new Senseix.Message.Atom.Atom ();
//forced my hand
newAtom.uuid = "Developer-side generated problem part";
newAtom.required = false;
newAtom.data = new byte[0];
//text
newAtom.type = Senseix.Message.Atom.Atom.Type.IMAGE;
newAtom.filename = filename;
}
/// <summary>
/// This is a uuid for this problem part. But, most likely, from your perspective,
/// it's just a meaningless string.
/// </summary>
public string GetUniqueID()
{
return atom.uuid;
}
public virtual bool HasString()
{
return false;
}
public virtual bool HasInteger()
{
return false;
}
public virtual bool HasSprite()
{
return false;
}
/// <summary>
/// Determines whether this instance is multiple choice letter.
/// </summary>
/// <returns><c>true</c> if this instance is multiple choice letter; otherwise, <c>false</c>.</returns>
public bool IsMultipleChoiceLetter()
{
if (!HasString ())
{
return false;
}
return (GetString() == "A: " ||
GetString() == "B: " ||
GetString() == "C: " ||
GetString() == "D: " );
}
public virtual int GetInteger()
{
throw new Exception ("There is no way to represent this problem part as an integer.");
}
public virtual string GetString()
{
throw new Exception ("There is no way to represent this problem part as a string");
}
public virtual Sprite GetSprite()
{
throw new Exception ("There is no way to represent this problem part with a sprite");
}
public int TimesRepeated()
{
if (atom.repeated == 0)
return 1;
return atom.repeated;
}
public Senseix.Message.Atom.Atom GetAtom()
{
return atom;
}
}