gbrainy r334 - trunk/src
- From: jmas svn gnome org
- To: svn-commits-list gnome org
- Subject: gbrainy r334 - trunk/src
- Date: Sat, 10 May 2008 18:36:28 +0100 (BST)
Author: jmas
Date: Sat May 10 17:36:28 2008
New Revision: 334
URL: http://svn.gnome.org/viewvc/gbrainy?rev=334&view=rev
Log:
Use generics
Modified:
trunk/src/ArrayListIndicesRandom.cs
trunk/src/CalculationWhichNumber.cs
trunk/src/ChangeLog
trunk/src/MemoryColouredFigures.cs
trunk/src/MemoryCountDots.cs
trunk/src/MemoryFigures.cs
trunk/src/MemoryIndications.cs
trunk/src/MemoryWords.cs
trunk/src/PuzzleExtraCircle.cs
trunk/src/PuzzleFigures.cs
trunk/src/PuzzleMissingPiece.cs
trunk/src/PuzzleMissingSlice.cs
trunk/src/PuzzleMostInCommon.cs
trunk/src/PuzzleOstracism.cs
trunk/src/PuzzlePencil.cs
trunk/src/PuzzleSquareDots.cs
trunk/src/PuzzleSquaresAndLetters.cs
trunk/src/PuzzleTetris.cs
Modified: trunk/src/ArrayListIndicesRandom.cs
==============================================================================
--- trunk/src/ArrayListIndicesRandom.cs (original)
+++ trunk/src/ArrayListIndicesRandom.cs Sat May 10 17:36:28 2008
@@ -18,12 +18,12 @@
*/
using System;
-using System.Collections;
+using System.Collections.Generic;
//
// Returns a list of indexes in random order
//
-public class ArrayListIndicesRandom : ArrayList
+public class ArrayListIndicesRandom : List <int>
{
protected Random random;
@@ -34,18 +34,18 @@
public void Initialize ()
{
- ArrayList random_list = new ArrayList (Capacity);
+ List <int> random_list = new List <int> (Capacity);
for (int i = 0; i < Capacity; i++) {
random_list.Add (i);
}
RandomizeFromArray (random_list);
}
- public void RandomizeFromArray (ArrayList ar)
+ public void RandomizeFromArray (List <int> ar)
{
int left = Capacity;
int index;
- object []array = (object []) ar.ToArray (typeof (object));
+ int []array = ar.ToArray ();
Clear ();
// Generate a random number that can be as big as the maximum -1
Modified: trunk/src/CalculationWhichNumber.cs
==============================================================================
--- trunk/src/CalculationWhichNumber.cs (original)
+++ trunk/src/CalculationWhichNumber.cs Sat May 10 17:36:28 2008
@@ -45,7 +45,7 @@
public override string Answer {
get {
string answer = base.Answer + " ";
- int ans_idx = (int) random_indices[which];
+ int ans_idx = random_indices[which];
answer += String.Format (Catalog.GetString ("The result of the operation {0} / {1} is {2:###.###}"),
options[ans_idx * 2], options[(ans_idx * 2) + 1], question_num);
@@ -131,7 +131,7 @@
random_indices.Initialize ();
which = random.Next (options_cnt);
- ans_idx = (int) random_indices[which];
+ ans_idx = random_indices[which];
question_num = options[ans_idx * 2] / options[(ans_idx * 2) + 1];
right_answer += (char) (65 + which);
}
@@ -151,7 +151,7 @@
{
gr.MoveTo (x, y);
option = (char) (65 + i);
- indx = (int) random_indices[i];
+ indx = random_indices[i];
gr.ShowText (option + ") " + options [indx * 2] + " / " + options [(indx * 2) +1]);
y = y + 0.15;
Modified: trunk/src/MemoryColouredFigures.cs
==============================================================================
--- trunk/src/MemoryColouredFigures.cs (original)
+++ trunk/src/MemoryColouredFigures.cs Sat May 10 17:36:28 2008
@@ -87,7 +87,7 @@
right_answer = string.Empty;
for (int i = 0; i < answers_order.Count; i++) {
- if ((int) answers_order[i] == 0) {
+ if (answers_order[i] == 0) {
right_answer += (char) (65 + (int) i);
break;
}
@@ -144,7 +144,7 @@
y += 0.45;
x = DrawAreaX;
}
- DrawSquare (gr, x, y, squares_colours, squares * (int) answers_order[i]);
+ DrawSquare (gr, x, y, squares_colours, squares * answers_order[i]);
gr.MoveTo (x, y + block_space + 0.02);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
gr.Stroke ();
Modified: trunk/src/MemoryCountDots.cs
==============================================================================
--- trunk/src/MemoryCountDots.cs (original)
+++ trunk/src/MemoryCountDots.cs Sat May 10 17:36:28 2008
@@ -123,8 +123,8 @@
{
int dx,dy;
Color color = palette.Cairo(itcolor);
- dx = ((int)location_order[i]) % NUMCOLUMNS;
- dy = ((int)location_order[i]) / NUMCOLUMNS;
+ dx = (location_order[i]) % NUMCOLUMNS;
+ dy = (location_order[i]) / NUMCOLUMNS;
gr.Arc (pos_x+square_size*dx, pos_y+square_size*dy,radius_square,0,2*Math.PI);
gr.FillGradient (pos_x+square_size*dx, pos_y+square_size*dy, radius_square, radius_square, color);
Modified: trunk/src/MemoryFigures.cs
==============================================================================
--- trunk/src/MemoryFigures.cs (original)
+++ trunk/src/MemoryFigures.cs Sat May 10 17:36:28 2008
@@ -79,20 +79,20 @@
rect_w = 0.6 / columns;
rect_h = 0.8 / rows;
- figures = new ArrayListIndicesRandom ((int) figures_active * 2);
+ figures = new ArrayListIndicesRandom (figures_active * 2);
figures.Initialize ();
- question_pos = (int) random.Next ((int) figures_active * 2);
+ question_pos = random.Next (figures_active * 2);
- for (int figure = 0; figure < (int) figures_active * 2; figure++)
+ for (int figure = 0; figure < figures_active * 2; figure++)
{
if (figure == question_pos)
continue;
- fig1 = (int) figures[figure];
- fig2 = (int) figures[question_pos];
+ fig1 = figures[figure];
+ fig2 = figures[question_pos];
- if (fig1 >= (int) figures_active) fig1 -= (int) figures_active;
- if (fig2 >= (int) figures_active) fig2 -= (int) figures_active;
+ if (fig1 >= figures_active) fig1 -= figures_active;
+ if (fig2 >= figures_active) fig2 -= figures_active;
if (fig1 == fig2) {
question_answer = figure + 1;
Modified: trunk/src/MemoryIndications.cs
==============================================================================
--- trunk/src/MemoryIndications.cs (original)
+++ trunk/src/MemoryIndications.cs Sat May 10 17:36:28 2008
@@ -222,7 +222,7 @@
answers.Initialize ();
for (int i = 0; i < answers.Count; i++) {
- if ((int) answers [i] == 0) {
+ if (answers [i] == 0) {
right_answer += (char) (65 + i);
break;
}
Modified: trunk/src/MemoryWords.cs
==============================================================================
--- trunk/src/MemoryWords.cs (original)
+++ trunk/src/MemoryWords.cs Sat May 10 17:36:28 2008
@@ -22,12 +22,12 @@
using Mono.Unix;
using System.Timers;
using Gtk;
-using System.Collections;
+using System.Collections.Generic;
public class MemoryWords : Memory
{
private ArrayListIndicesRandom words_order;
- private ArrayList words;
+ private List <string> words;
private const int total_words = 35;
private int showed;
private int answer;
@@ -44,7 +44,7 @@
public override void Initialize ()
{
int tmp;
- words = new ArrayListIndicesRandom (total_words);
+ words = new List <string> (total_words);
// Body parts
words.Add (Catalog.GetString ("wrist"));
@@ -110,8 +110,8 @@
words_order = new ArrayListIndicesRandom (total_words);
words_order.Initialize ();
answer = random.Next (showed);
- tmp = (int) words_order [answer];
- right_answer = (string) words [tmp];
+ tmp = words_order [answer];
+ right_answer = words [tmp];
base.Initialize ();
}
@@ -126,7 +126,7 @@
continue;
gr.MoveTo (x, y);
- gr.ShowText ((string) words[(int)words_order[i]]);
+ gr.ShowText (words[words_order[i]]);
gr.Stroke ();
if ((cnt + 1) % 3 == 0) {
@@ -151,7 +151,7 @@
for (int i = 0; i < showed; i++)
{
gr.MoveTo (x, y);
- gr.ShowText ((string) words[(int)words_order[i]]);
+ gr.ShowText (words[words_order[i]]);
gr.Stroke ();
if ((i + 1) % 3 == 0) {
Modified: trunk/src/PuzzleExtraCircle.cs
==============================================================================
--- trunk/src/PuzzleExtraCircle.cs (original)
+++ trunk/src/PuzzleExtraCircle.cs Sat May 10 17:36:28 2008
@@ -71,14 +71,14 @@
// Correct answer
random_indices.Initialize ();
- clr = badcercle_colors [(int) random_indices[0]];
- badcercle_colors [(int) random_indices[0]] = badcercle_colors [(int) random_indices[1]];
- badcercle_colors [(int) random_indices[1]] = clr;
+ clr = badcercle_colors [random_indices[0]];
+ badcercle_colors [random_indices[0]] = badcercle_colors [random_indices[1]];
+ badcercle_colors [random_indices[1]] = clr;
// Indices
start_indices = new int [circles];
for (int i = 0; i < circles; i++)
- start_indices[i] = (int) random_indices[i];
+ start_indices[i] = (random_indices[i]);
ans_pos = random.Next (circles);
right_answer += (char) (65 + ans_pos);
Modified: trunk/src/PuzzleFigures.cs
==============================================================================
--- trunk/src/PuzzleFigures.cs (original)
+++ trunk/src/PuzzleFigures.cs Sat May 10 17:36:28 2008
@@ -60,9 +60,9 @@
StringBuilder sb = new StringBuilder (3);
- sb.Append ((char) (65 + figures[(int) random_indices [5]]));
- sb.Append ((char) (65 + figures[6 + (int) random_indices [5]]));
- sb.Append ((char) (65 + figures[(2 * 6) + (int) random_indices [5]]));
+ sb.Append ((char) (65 + figures[random_indices [5]]));
+ sb.Append ((char) (65 + figures[6 + random_indices [5]]));
+ sb.Append ((char) (65 + figures[(2 * 6) + random_indices [5]]));
right_answer = sb.ToString ();
}
@@ -114,7 +114,7 @@
for (int i = 0; i < (DrawAnswer ? 6 : 5) ; i++)
{
- element = (int) random_indices [i];
+ element = random_indices [i];
y = DrawAreaY;
for (int n = 0; n < 3; n++)
{
Modified: trunk/src/PuzzleMissingPiece.cs
==============================================================================
--- trunk/src/PuzzleMissingPiece.cs (original)
+++ trunk/src/PuzzleMissingPiece.cs Sat May 10 17:36:28 2008
@@ -54,7 +54,7 @@
random_indices.Initialize ();
for (int i = 0; i < random_indices.Count; i++) {
- if ((int) random_indices [i] == 0) {
+ if (random_indices [i] == 0) {
right_answer += (char) (65 + i);
break;
}
@@ -150,7 +150,7 @@
x = DrawAreaX + 0.1;
for (int i = 0; i < random_indices.Count; i++) {
- figure = (int) random_indices [i];
+ figure = random_indices [i];
DrawAnswerFigures (gr, x + (0.08 + sub_figure) * i, 0.70, figure);
gr.MoveTo (x + (0.08 + sub_figure) * i, 0.9);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
Modified: trunk/src/PuzzleMissingSlice.cs
==============================================================================
--- trunk/src/PuzzleMissingSlice.cs (original)
+++ trunk/src/PuzzleMissingSlice.cs Sat May 10 17:36:28 2008
@@ -163,12 +163,12 @@
}
if (slice < half_slices) {
- pos = (int) random_indices [slice];
+ pos = random_indices [slice];
DrawSliceText (gr, x + arc_centerx, y + arc_centery, slice, (sum_offset + slices [pos * items_per_slice]).ToString (),
(sum_offset + slices [1 + (pos * items_per_slice)]).ToString (), (sum_offset + slices [2 + (pos * items_per_slice)]).ToString ());
}
else {
- pos = (int) random_indices [slice - half_slices];
+ pos = random_indices [slice - half_slices];
DrawSliceText (gr, x + arc_centerx, y + arc_centery, slice, slices_opposite [pos * items_per_slice].ToString (),
slices_opposite [2 + (pos * items_per_slice)].ToString (), slices_opposite [1 + (pos * items_per_slice)].ToString ());
}
@@ -182,7 +182,7 @@
{
DrawSlice (gr, 0.10 + i * 0.28, y);
if (i == ans_pos) {
- pos = (int) random_indices [0];
+ pos = random_indices [0];
DrawSliceText (gr, 0.10 + i * 0.28, y, 0, (sum_offset + slices [pos * items_per_slice]).ToString (),
(sum_offset + slices [1 + (pos * items_per_slice)]).ToString (), (sum_offset + slices [2 + (pos * items_per_slice)]).ToString ());
} else {
Modified: trunk/src/PuzzleMostInCommon.cs
==============================================================================
--- trunk/src/PuzzleMostInCommon.cs (original)
+++ trunk/src/PuzzleMostInCommon.cs Sat May 10 17:36:28 2008
@@ -169,6 +169,25 @@
answers.Add (BuildFigure (array, answers));
}
+ private ArrayListIndicesRandom RandomizeFromArray (ArrayList ar)
+ {
+ int index;
+ object []array = (object []) ar.ToArray (typeof (object));
+ ArrayListIndicesRandom elements = new ArrayListIndicesRandom (ar.Count);
+ int left = ar.Count;
+ elements.Clear ();
+
+ // Generate a random number that can be as big as the maximum -1
+ // Add the random element picked up element in the list
+ // The element just randomized gets out of pending list and replaced by the maximum -1 element
+ for (int i = 0; i < ar.Count; i++, left--) {
+ index = random.Next (left);
+ elements.Add ((int) array[index]);
+ array[index] = array[left - 1];
+ }
+ return elements;
+ }
+
// Generates a new figure that was not generated before
private FigureElement [] BuildFigure (ArrayList array, ArrayList figures)
{
@@ -179,7 +198,7 @@
while (done == false) {
- elements.RandomizeFromArray (array);
+ elements = RandomizeFromArray (array);
element = new FigureElement []
{
new FigureElement (pos1_x, pos1_y, (Element) elements[0]),
Modified: trunk/src/PuzzleOstracism.cs
==============================================================================
--- trunk/src/PuzzleOstracism.cs (original)
+++ trunk/src/PuzzleOstracism.cs Sat May 10 17:36:28 2008
@@ -63,7 +63,7 @@
for (int i = 0; i < random_indices.Count; i++)
{
- if ((int) random_indices[i] == wrong_answer) {
+ if (random_indices[i] == wrong_answer) {
right_answer += ((char) (65 + i));
break;
}
@@ -82,7 +82,7 @@
for (int i = 0; i < random_indices.Count; i++)
{
gr.MoveTo (x, y);
- gr.ShowText (((char)( 65 + i)) + ") " + equations [(int)random_indices[i]]);
+ gr.ShowText (((char)( 65 + i)) + ") " + equations [random_indices[i]]);
y += 0.1;
}
}
Modified: trunk/src/PuzzlePencil.cs
==============================================================================
--- trunk/src/PuzzlePencil.cs (original)
+++ trunk/src/PuzzlePencil.cs Sat May 10 17:36:28 2008
@@ -44,7 +44,7 @@
right_answer = string.Empty;
for (int i = 0; i < random_indices.Count; i++) {
- if ((int) random_indices[i] != answer_index)
+ if (random_indices[i] != answer_index)
continue;
right_answer += (char) (65 + (int) i);
@@ -142,7 +142,7 @@
for (int figure = 0; figure < figures; figure++)
{
- switch ((int) random_indices[figure]) {
+ switch (random_indices[figure]) {
case 0:
DrawTriangle (gr, x, y);
break;
Modified: trunk/src/PuzzleSquareDots.cs
==============================================================================
--- trunk/src/PuzzleSquareDots.cs (original)
+++ trunk/src/PuzzleSquareDots.cs Sat May 10 17:36:28 2008
@@ -97,7 +97,7 @@
possible_answers.Initialize ();
for (int i = 0; i < possible_answers.Count; i++) {
- if ((int) possible_answers[i] == 0) {
+ if (possible_answers[i] == 0) {
right_answer += (char) (65 + (int) i);
break;
}
@@ -182,7 +182,7 @@
y += 0.05;
for (int i = 0; i < possible_answers.Count; i++) {
- DrawPossibleAnswer (gr, x, y, (int) possible_answers[i]);
+ DrawPossibleAnswer (gr, x, y, possible_answers[i]);
gr.MoveTo (x, y + figure_size + 0.05);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
gr.Stroke ();
Modified: trunk/src/PuzzleSquaresAndLetters.cs
==============================================================================
--- trunk/src/PuzzleSquaresAndLetters.cs (original)
+++ trunk/src/PuzzleSquaresAndLetters.cs Sat May 10 17:36:28 2008
@@ -56,7 +56,7 @@
characters = new char [(1 + figures) * 4];
for (int figure = 0; figure < figures; figure++) {
- first_letter = (int) first_letters [figure];
+ first_letter = first_letters [figure];
for (int letter = 0; letter < 4; letter++) {
characters[(figure * 4) + letter] = (char) (65 + first_letter + (step * letter));
}
Modified: trunk/src/PuzzleTetris.cs
==============================================================================
--- trunk/src/PuzzleTetris.cs (original)
+++ trunk/src/PuzzleTetris.cs Sat May 10 17:36:28 2008
@@ -141,7 +141,7 @@
PrepareGC (gr);
for (int i = 0; i < 4; i++) {
- DrawQuestionFigures (gr, x, y, (int) random_indices_questions [i]);
+ DrawQuestionFigures (gr, x, y, random_indices_questions [i]);
x += space_figures;
}
@@ -151,7 +151,7 @@
x = 0.2;
y = 0.6;
for (int i = 0; i < 3; i++) {
- DrawAnswerFigures (gr, x, y, (int) random_indices_answers [i]);
+ DrawAnswerFigures (gr, x, y, random_indices_answers [i]);
gr.MoveTo (x, y + 0.15);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), (char) (65 + i)));
x += space_figures;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]