- 论坛徽章:
- 0
|
本帖最后由 dreamlearn 于 2012-10-24 12:02 编辑
代碼複製在這裡有有些醜陋sorry
猜linux命令
因為有其他程序在寫所以沒有時間完善他, 所以有一些功能不完整
有興趣的請完善他謝謝!!
我的設計上每通過10關上一級
words 寫入 shelve 是想方便用戶添加words
原本猜對了會有中文解釋命令但還沒有寫
- import os
- import random
- import shelve
- losed = 0
- if not os.path.exists('/home/jack/project/protector_lib'):
- db = shelve.open('/home/jack/project/protector_lib')
- db['round'] = 0
- db['level'] = 0
- db['words_0'] = ['ls', 'cd', 'cat', 'clear', 'cat',
- 'cal', 'cp', 'df', 'find', 'file']
- db['words_1'] = ['login', 'loginame', 'logout', 'adduser','useradd',
- 'userdel', 'uname', 'hostname', 'whoami', 'finger']
- else:
- db = shelve.open('/home/jack/project/protector_lib.py')
- interface = (
- '''
- Wellcome to play the [Protector game]
- 1 Play game.
- 2 Add new words.
- 3 Exit.
- ''')
- def Main( ):
- print(game_name)
- print(interface)
- opt = input('Please input option: ')
- opt = int(opt)
- if opt == 1:
- Game()
- if opt == 2:
- Add_Words()
- if opt == 3:
- exit( )
- def get_words( ):
- words = 'words_%s' % db['level']
- return db[words]
- def Game_OPT(opt):
- if opt == 'menu':
- opt = input('Your want quit game to Menu?[Y/N]').upper( )
- if opt != 'Y': print('Cancel!')
- else: return True
- elif opt == 'exit':
- opt = input('Your want exit the Game?[Y/N]').upper( )
- if opt != 'Y': print('Cancel')
- else: return True
-
- def Game( ):
- global losed
- MAX_WRONG = len(pattern_1) - 1
- words = random.choice(get_words( ))
- words.upper( )
- print(words)
- so_far= '-' * len(words)
- used = [ ]
- wrong = 0
- losed += 1
- if losed >= 4: print('Game Over!')
- if db['round'] >= 10:
- db['round'] = 0
- db['level'] += 1
- while True:
- print("You've used the following letters\n%s:" % used)
- print(pattern_1[wrong])
- print('So far, the word is:\n%s' % so_far)
- guess = input('Enter your guess: ')
- guess.upper( )
- while guess in used:
- print("You've already guess the letter %s" % guess)
- guess = input('Enter your guess: ')
- guess.upper( )
- used.append(guess)
- if guess == 'menu':
- if Game_OPT('menu'): Main( )
- elif guess == 'exit':
- if Game_OPT('exit'): exit( )
- if guess not in words:
- print('Sorry, %s is not in the word.' % guess)
- wrong += 1
- if MAX_WRONG < wrong:
- print('aaasas')
- Game( )
-
- elif guess in words:
- new = ''
- for i in range(len(words)):
- if guess == words[i]:
- new += guess
- else:
- new += so_far[i]
- so_far = new
- if so_far == words:
- db['round'] += 1
- Game( )
- if db['round'] == 10:
- Game( )
- game_name = (
- r'''
- _______ _______ ____ ________ ________ ______ ________ ____ _______
- | ___ \ | ___ \ / __ \ |__ __| | _____| / _____| |__ __| / __ \ | __ \
- | |___| | | |___| | / / \ \ | | | |_____ / / | | / / \ \ | |___| |
- | _____/ | ___ / | | | | | | | _____| | | | | | | | | | ___ /
- | | | | \ \ \ \__/ / | | | |_____ \ \____ | | \ \__/ / | | \ \
- |_| |_| \_\ \____/ |__| |________| \______| |__| \____/ |_| \_\
- ''')
- pattern_1 = (
- r'''
- _____________________________
- | | |
- | | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- | |
- |_____________________________|
- ''',
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ o / |
- | --- |
- | |
- | |
- | |
- | |
- | |
- | |
- |_____________________________|
- ''',
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ * / |
- | --- |
- | === |
- | |
- | |
- | |
- | |
- | |
- |_____________________________|
- ''',
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ ^ / |
- | --- |
- | === |
- | === |
- | === |
- | |
- | |
- | |
- |_____________________________|
- ''',
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ ~ / |
- | --- |
- | //=== |
- | //=== |
- | * === |
- | |
- | |
- | |
- |_____________________________|
- ''',
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ + / |
- | --- |
- | //===\\ |
- | // === \\ |
- | * === * |
- | |
- | |
- | |
- |_____________________________|
- ''',
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ ~ / |
- | --- |
- | //===\\ |
- | // === \\ |
- | * === * |
- | // |
- | // |
- | `` |
- |_____________________________|
- ''',
-
- r'''
- _____________________________
- | | |
- | | |
- | --- |
- | /* *\ |
- | \ ~ / |
- | --- |
- | // ===\\ |
- | // === \\ |
- | * === * |
- | // \\ |
- | // \\ |
- | `` `` |
- |_____________________________|
- ''')
- pattern_2 = (
- '''
-
- O .------.
- ||| / [] [] \
- | ---- \
- | | /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- O .------.
- ||| / [] [] \
- | ---- \
- | | /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- O .------.
- ||| / [] [] \
- | ---- \
- | | /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- O .------.
- /|\ / [] [] \
- | ---- \
- | | /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- O .------.
- \|/ / [] [] \
- | ---- \
- | | /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- O .------.
- \|/ / [] [] \
- | ---- \
- / \ /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- O .------.
- \|/ / [] [] \
- | ---- \
- / \ /__(O)_____(O)__.
- ___________________________________________________________________________
- ''',
- '''
-
- .------.
- \ / / [] [] \
- O----- --- \
- / \/__(O)_____(O)__.
- ___________________________________________________________________________
- ''')
- Main( )
复制代码 |
|