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

[pygame] a little game help with text coding.



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()