#!/usr/bin/env python #File: login.py #Date: 2016-01-10 import os,sys //导入模块函数 wide = 50 //设置宽度 title = 'Cross Fire' //游戏名 half = (wide - len(title) -2) // 2 //整除 print wide * '*' print half * '*' + ' ' + title + ' ' + half * '*' print wide * '*' //这三个print是做的游戏标题 while True: name = raw_input("Please input your name to login for game:") .strip() if len(name) == 0: //如果游戏名为空 print "You input enpty name, Please try again!" continue if name == 'strike': print "Welcome, %s!" %name for i in range(1,4): //密码输入三次机会 passwd = raw_input("Please input your password:") .strip() if passwd == '123456': print "Congratulation, the game is about to land!" sys.exit() //输入正确跳出循环 else: print "Your password is wrong, you have three times, try again!" i += 1 continue else: key = raw_input("Your account is not exist, Do you want to register? (Y/N) ") .strip() //注册信息 if key == 'Y': user = raw_input("Please input your name for user:") .strip() password = raw_input("Please input your new password:") .strip() if len(user) != 0 and len(password) != 0: //账户密码不为空 print "OK, register over, your account is %s, password is %s, and you can login game after five minute!" %(user,password) if len(user) == 0 or len(password) == 0: //账户或者密码有一个为空 print "Sorry, register account fail, program will exit!" break
附上游戏标题图片: