码迷,mamicode.com
首页 > 编程语言 > 详细

python---游戏登录

时间:2016-01-11 01:35:59      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:每天一段python

#!/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

附上游戏标题图片:

技术分享

本文出自 “经验来自痛苦” 博客,谢绝转载!

python---游戏登录

标签:每天一段python

原文地址:http://strike.blog.51cto.com/10311680/1733595

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!