Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/elephant.py
diff options
context:
space:
mode:
Diffstat (limited to 'elephant.py')
-rwxr-xr-xelephant.py85
1 files changed, 71 insertions, 14 deletions
diff --git a/elephant.py b/elephant.py
index 5f680e7..fc22814 100755
--- a/elephant.py
+++ b/elephant.py
@@ -1,16 +1,13 @@
-#!/usr/bin/python
-
import ConfigParser
-
-from random import choice
+import random
# Global definition
CONF_FILE='elephant.conf'
CAT_SECTION='Categories'
WORDS_SECTION='Words'
+MAIN_SECTION='Main'
-# Class
-# Return the word list from config file and numbers of word
+# Class word_list
class word_list:
def __init__(self):
@@ -55,20 +52,80 @@ class word_list:
return image_path
+# Class letters
class letters:
- def __init__(self):
- pass
+ def __init__(self, word):
+ self.letter_index, self.letter = self._get_letter_index(word)
- def get_letter(self, word):
- letter = choice (word)
+ # Return a random letter for a given word and index
+ def _get_letter_index(self, word):
- return letter
+ word_len = len(word)
+ # Generate a random index of a letter in the word
+ letter_index = random.randint(0, word_len - 1)
+
+ # Get the letter at position letter_index
+ letter = word[letter_index]
-
+ return letter_index+1, letter
-
+ # Return list of indexes for every ocurrence ot the letter in the word.
+ def get_all_indexes(self, word, letter):
+
+ # Init vars
+ word_len = len(word)
+ indexes = []
+ i = 0
+
+ # Generates a list with indexes of ocurrences of the letter
+ for i in range(word_len):
+ if word[i] == letter:
+ indexes.append(i+1)
+ i+=1
+
+ return indexes
+
+ # Return false options non-overlaping with true options
+ def get_false_options(self, word, true_indexes):
+ word_len = len(word)
+
+ #parser = ConfigParser.SafeConfigParser()
+ #parser.read(CONF_FILE)
+
+ #false_options = parser.get(MAIN_SECTION, 'Falseoptions')
+
+ false_choices = []
+ for i in [1, 2]:
+ false_choice = random.randrange(word_len)
+ if (false_choice in true_indexes) == True:
+ pass
+ else:
+ false_choices.append(false_choice)
+ i += 1
+
+ return false_choices
+
+ # Return the relative place of a letter in case there are multiples
+ # ocurrences of the letter. False in case there are only one.
+ def get_relative_place(self, letter_index, true_indexes):
+
+ if len(true_indexes) == 1:
+ return False
+
+ relative_place = true_indexes.index(letter_index)
+
+ return relative_place+1
+
+
+ # Translate relative place to words
+ def translate_relative_place(self, relative_place):
+
+ if relative_place == False:
+ return False
+ relative_place -= 1
+ places = ['Primera', 'Segunda', 'Tercera', 'Cuarta', 'Quinta', 'Sexta']
- \ No newline at end of file
+ return places[relative_place] \ No newline at end of file