[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] a little game help with text coding.



Hi Martin,

If I understand correctly, you want the game to muddle up the words for
the player. The higher the player's lang skill the less muddled up it
will be.

I think this is a cool idea, the only other place I have seen something
like this is the Al Bhed language in Final Fantasy X, which was much
simpler. It simply substituted letters, like A=E, B=F or something, then
you would find objects that translate a letter. Your idea is much more
intriguing.

As for the code, I can make it a little more elegant by replacing the
block of "if lang_level == x" with:

if len(word) < lang_level*2:
    new_words.append(word)
else:
    start = word[0]
    if lang_level > 1:
        end = word[-1]
        middle = list(word[1:-1])
    else:
        end = ""
        middle = list(word[1:])
    random.shuffle(middle)
    middle = "".join(middle)
    new_words.append(start + middle + end)

That does the same thing dynamically based on level. As for making it
more sophisticated, you could consider messing with the order of the
words in a sentence or something. Maybe at level 4 you can understand
all the words but they are in a random order requiring you to reread the
sentence to make sense of it, and levels above 4 will sort out the order
of the words so it takes less mental effort to work out what people are
saying.


On Mon, 08 Aug 2011 11:43 +0200, "Martin B."
<spooky.ln@xxxxxxxxxxxxxxxx> wrote:
> hi all,
> at first sorry for my english.
> In my free time i coding some small adventure game in pygame.
> Now i write some 'strange' stuff for it. Coz i dont registered in
> another mailinglist for gamedev i write my question here.
> 
> My hero has a 'language' option. When he arrive into unknown island
> his lang is on level0. this level is increased after time. now i write
> some lang stuff for it but how to write [ehm] "more sophisticated" ?
> is this right word for it ?
> 
> heres the ugly code for it.
> I know it need more work but this is my first idea how to do it.
> Im testing in shell for now.
> developing in Py2.7 on Arch. 
> every comment is welcome. thanks
> 
> #encoding: utf-8
> import random
> 
> def MultiInput():
>     ''' Pseudo multiline zadavani '''
>     
>     text = ''
>     while True:
>         line = raw_input('? ')
>         if line == 'konec':
>             break
>         text = text + line + '\n'
>     return text
> 
> def Alcoholer(text, lang_level=0):
>     new_lines = []
>     for line in text:
>         new_words = []
>         words = line.split()
>         for word in words:
>             if lang_level == 0:
>                 txt = list(word)
>                 random.shuffle(txt, random.random)
>                 x = ''.join(txt)
>                 new_words.append(x)
>             elif lang_level == 1:
>                 if len(word) > 1:
>                     start = word[0]
>                     rest  = list(word[1:])
>                     random.shuffle(rest, random.random)
>                     x = ''.join(rest)
>                     new_words.append(start + x)
>                 else:
>                     new_words.append(word)
>                     
>             elif lang_level == 2:
>                 if len(word) > 3:
>                     start, end = word[0], word[-1]
>                     middle     = list(word[1:-1])
>                     random.shuffle(middle, random.random)
>                     x = ''.join(middle)
>                     new_words.append(start+x+end)
>                 else:
>                     new_words.append(word)
>                     
>             elif lang_level == 3:
>                 if len(word) > 5:
>                     start, end = word[0], word[-1]
>                     middle     = list(word[1:-1])
>                     random.shuffle(middle, random.random)
>                     x = ''.join(middle)
>                     new_words.append(start+x+end)
>                 else:
>                     new_words.append(word)
>                     
>             elif lang_level == 4:
>                 if len(word) > 7:
>                     start, end = word[0], word[-1]
>                     middle     = list(word[1:-1])
>                     random.shuffle(middle, random.random)
>                     x = ''.join(middle)
>                     new_words.append(start+x+end)
>                 else:
>                     new_words.append(word)
>                     
>         new_line  = ' '.join(new_words)
>         new_lines.append(new_line)
>     return '\n'.join(new_lines)
> 
> if __name__ == '__main__':
>     #print("""Pro skonÄenà zadÃvÃnà textu napiÅ slovo 'konec'.""")
>     #text = MultiInput().split('\n')
>     #print text
>     
>     text = ["Pokus o napsani neceho uplne blbyho co vypada jako",
>             "rec totalne ozralych pobudu ale je to ve skutecnosti",
>             "jazyk davno zapomenute vysoce rozvinute spolecnosti",
>             "ktera kdysi zila pod upatim hor Ankhmorporku"]
> 
>     print('Original')
>     print '\n'.join(text), '\n'
> 
>     print('level 0')
>     print Alcoholer(text), '\n'
> 
>     print('level 1')
>     print Alcoholer(text, lang_level=1), '\n'
> 
>     print('level 2')
>     print Alcoholer(text, lang_level=2), '\n'
> 
>     print('level 3')
>     print Alcoholer(text, lang_level=3), '\n'
> 
>     print('level 4')
>     print Alcoholer(text, lang_level=4), '\n'
>     s = raw_input()
>