Python a small game development _ their development

Have a look first game performance:

After the operation of the game, you may have some understanding of the game:

#Run the game, game player must first carry voice selection, 1 English, 2 Chinese, the other is selected by default.
#According to the voice game player choice, into different phonetic environments
#The rules of the game: the game player to enter a 0-9 digital system according to the game player, digital input, digital print out information
#        If the digital range of game player input is not in the 0-9, it will print out"Error!"
#Out of the game: the game with complete print messages to quit the game.

Part of the code:

 1 #Run the game, game player must first carry voice selection, 1 English, 2 Chinese, the other is selected by default.
 2 #According to the voice game player choice, into different phonetic environments
 3 #The rules of the game: the game player to enter a 0-9 digital system according to the game player, digital input, digital print out information
 4 #        If the digital range of game player input is not in the 0-9, it will print out"Error!"
 5 #Out of the game: the game with complete print messages to quit the game.
 6 language_option = """\
 7     Language: Choose the language for System[OPTION]
 8             -1                    Choose English Language
 9             -2                    Choose Chinese Language
10             """
11 enter_str = 'please enter an integer:'
12 #Before the game began to explain
13 en_game_start_str = 'You choose English language!,Now, Game Start!'
14 cn_game_start_str = 'Your choice of Chinese mode! Now, start the game!'
15 #The rules of the game
16 en_game_rule_str = 'you should enter a number that from 0 to 9,then the \nSystem will print the information of the number'
17 cn_game_rule_str = 'You enter a 0-9 number, the system will print out the digital information'
18 #The end of the game
19 en_game_over_str = 'Game Over!'
20 cn_game_over_str = 'The end of the game!'
21 print(language_option)
22 number = int(input(enter_str))
23 
24 def print_info(num):
25     if num == 0:
26         print('0 zero zero')
27     elif num == 1:
28         print('1 one.')
29     elif num == 2:
30         print('2 two.')
31     elif num == 3:
32         print('3 three 3')
33     elif num == 4:
34         print('4 four.')
35     elif num == 5:
36         print('5 five Wu')
37     elif num == 6:
38         print('6 six land')
39     elif num == 7:
40         print('7 seven.')
41     elif num == 8:
42         print('8 eight Ba')
43     elif num == 9:
44         print('9 nine nine')
45     else:
46         print('Error!')
47 
48 def start_game(num):
49     if num == 1:
50         print(en_game_rule_str)
51     elif num == 2:
52         print(cn_game_rule_str)
53     else:
54         print(en_game_rule_str)
55     n = int(input(enter_str))
56     print_info(n)
57           
58 
59 if number == 1:
60     print(en_game_start_str)
61     start_game(1)
62     print(en_game_over_str)
63     exit()
64 elif number == 2:
65     print(cn_game_start_str)
66     start_game(2)
67     print(cn_game_over_str)
68     exit()
69 else:
70     print(en_game_start_str)
71     start_game(number)
72     print(en_game_over_str)
73     exit()

Just begin to contact python, hope that like-minded friends to learn Python... Together.

=================================================

Edit by Hongten 2013-07-21

=================================================

The following is the improvement of the above processes:

Optimization of the print_info () method, increased the game player is to continue to play the function of query. Please refer to the detailed code

  1 #Run the game, game player must first carry voice selection, 1 English, 2 Chinese, the other is selected by default.
  2 #According to the voice game player choice, into different phonetic environments
  3 #The rules of the game: the game player to enter a 0-9 digital system according to the game player, digital input, digital print out information
  4 #        If the digital range of game player input is not in the 0-9, it will print out"Error!"
  5 #Out of the game: the game with complete print messages to quit the game.
  6 language_option = """\
  7     Language: Choose the language for System[OPTION]
  8             -1                    Choose English Language
  9             -2                    Choose Chinese Language
 10             """
 11 enter_str = 'please enter an integer:'
 12 
 13 #Before the game began to explain
 14 en_game_start_str = 'You choose English language!,Now, Game Start!'
 15 cn_game_start_str = 'Your choice of Chinese mode! Now, start the game!'
 16 
 17 #The rules of the game
 18 en_game_rule_str = 'you should enter a number that from 0 to 9,then the \nSystem will print the information of the number'
 19 cn_game_rule_str = 'You enter a 0-9 number, the system will print out the digital information'
 20 
 21 #The end of the game
 22 en_game_over_str = 'Game Over!'
 23 cn_game_over_str = 'The end of the game!'
 24 print(language_option)
 25 
 26 #A definition list
 27 en_list = ['zero','one','two','three','four','five','six','seven','eight','nine']
 28 cn_list = ['Fatal Frame','One','II.','Three','Shop','Wu','Land','Seven','BA','Nine']
 29 
 30 #Circulating markers
 31 FLAG = True
 32 
 33 #Also need to play it?
 34 en_play_again_str = """\
 35     #############################################
 36     Do you want play again?
 37     -1              Play Again
 38     -2              Exit Game
 39              """
 40 cn_play_again_str = """\
 41     #############################################
 42     You still want to play with me? 
 43     -1 continues to play
 44     -2 quit the game
 45              """
 46 
 47 number = int(input(enter_str))
 48 
 49 #The game printed information
 50 def print_info(num):
 51     if num in range(0,9):
 52         print(num,en_list[num],cn_list[num])
 53     else:
 54         print('Error!')
 55 
 56 #To start the game
 57 def start_game(num):
 58     if num == 1:
 59         print(en_game_rule_str)
 60     elif num == 2:
 61         print(cn_game_rule_str)
 62     else:
 63         print(en_game_rule_str)
 64     n = int(input(enter_str))
 65     print_info(n)
 66 
 67 #Circulation play games
 68 def play_again(n):
 69     if n == 1:
 70         print(en_play_again_str)
 71     elif n == 2:
 72         print(cn_play_again_str)
 73     else:
 74         print(en_play_again_str)
 75     again = int(input(enter_str))
 76     if again == 1:
 77         pass
 78     elif again == 2:
 79         #Here is the use of global variables, note here don't write: global FLAG = False
 80         global FLAG
 81         FLAG = False
 82         
 83 #The body of the loop of the game   
 84 while True:
 85     if FLAG:
 86         if number == 1:
 87             print(en_game_start_str)
 88             start_game(1)
 89             play_again(1)
 90         elif number == 2:
 91             print(cn_game_start_str)
 92             start_game(2)
 93             play_again(2)
 94         else:
 95            print(en_game_start_str)
 96            start_game(number)
 97            play_again(number)
 98     else:
 99         print(en_game_over_str)
100         break
101         #exit()

Effect of operation

Posted by Carol at November 23, 2013 - 12:25 PM