-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,100 @@ | ||
# Battle | ||
# Battle API手册 | ||
|
||
## 介绍 | ||
|
||
|
||
访问入口:(http://127.0.0.1:12356/) | ||
|
||
示例系统python3.6及其以上运行的,安装好python后,需要安装如下安装包 | ||
|
||
pip install bottle | ||
pip install beaker | ||
|
||
系统按照一种类似对战游戏的模式设计。 | ||
|
||
## 1.1 首页 | ||
|
||
接口描述:访问主页 | ||
|
||
调用方式:get | ||
|
||
访问路由:/ 或者/index | ||
|
||
响应内容:说明性文本 | ||
|
||
## 1.2 登录 | ||
|
||
|
||
接口描述:登录 | ||
|
||
调用方式: post | ||
|
||
访问路由:/login | ||
|
||
入参格式:param1=1¶m2=2 | ||
|
||
入参内容:body | ||
|
||
|
||
|名称|类型|长度限制|可空|备注| | ||
|---|---|---|---|---| | ||
|username|String|30|no|英文名称| | ||
|password|String|30|no|英文名称| | ||
|
||
|
||
|
||
响应格式:文本 | ||
|
||
响应内容:说明性文字 | ||
|
||
|
||
## 1.3 选择装备 | ||
|
||
接口描述:选择装备 | ||
|
||
调用方式: post | ||
|
||
访问路由:/selectEq | ||
|
||
入参格式:param1=1¶m2=2 | ||
|
||
入参内容:body | ||
|
||
|名称|类型|长度限制|可空|备注| | ||
|---|---|---|---|---| | ||
|equipmentid|int|4|no|装备编号| | ||
|
||
|
||
响应格式:json | ||
|
||
响应内容: | ||
|
||
|
||
|名称|类型|长度|可空|备注| | ||
|---|---|---|---|---| | ||
|equipmentid|int| | no|选择的装备id| | ||
|message|String ||yes|交互结果描述 | | ||
|
||
|
||
## 1.4 杀敌 | ||
|
||
接口描述:选择装备 | ||
|
||
调用方式: post | ||
|
||
访问路由:/kill | ||
|
||
入参格式:param1=1¶m2=2 | ||
|
||
入参内容:body | ||
|
||
|
||
|
||
|名称|类型|长度限制|可空|备注| | ||
|equipmentid|int|4|no|装备编号| | ||
|enemyid|int|4|no|打怪兽编号| | ||
|
||
响应格式:文本 | ||
|
||
响应内容:说明性文本,说明战斗结果 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
#__from__ = 'Battle' | ||
#__title__='PyCharm' | ||
#__author__ = 'chancriss' | ||
#__mtime__ = '2018/01/01' | ||
#__instruction__='' | ||
|
||
from bottle import Bottle, run,get,post,request,static_file,redirect | ||
from beaker.middleware import SessionMiddleware | ||
import json | ||
app = Bottle() | ||
msUsername = '' | ||
msEquipmentid='' | ||
session_opts = { | ||
'session.type':'file', #以文件的方式保存session | ||
'session.cookei_expires':300, #session过期时间为300秒 | ||
'session.data_dir':'/tmp/sessions_dir', #session保存目录 | ||
'session.auto':True #自动保存session | ||
} | ||
|
||
@app.get('/') | ||
@app.get('/index') | ||
def index(): | ||
return 'please input your username(your english name) and password(your english name)' | ||
|
||
@app.post('/login') | ||
def login(): | ||
msUsername = request.POST.get('username') | ||
|
||
sPassword = request.POST.get('password') | ||
if msUsername==sPassword: | ||
ssSession = request.environ.get('beaker.session') | ||
|
||
ssSession['user'] = msUsername | ||
ssSession.save | ||
|
||
|
||
return 'please select One Equipment:\n10001:Knife\n10002:Big Sword\n10003:KuiHuaBaoDian' | ||
else: | ||
return 'Error 9901: Username or PassWord!!' | ||
@app.post('/selectEq') | ||
def selectEq(): | ||
|
||
msEquipmentid = request.POST.get('equipmentid') | ||
ssSession = request.environ.get('beaker.session') | ||
#print 'msEquipmentid:'+msEquipmentid | ||
#print 'ssSession:'+ssSession | ||
if msEquipmentid is not None: | ||
if str(msEquipmentid).isdigit(): | ||
ssSession['equipmentid']=msEquipmentid | ||
ssSession.save | ||
return {'equipmentid':msEquipmentid,'Message':'your pick up equipmentid:'+msEquipmentid+' please select your enemyid:\n20001:Terran\n20002:ORC\n20003:Undead'} | ||
else: | ||
return {'equipmentid':'-1','Message':'Error 9902: Your kill yourself!!'} | ||
|
||
|
||
@app.post('/kill') | ||
def kill(): | ||
sEnemyid = request.POST.get('enemyid') | ||
#print 'sEnemyid'+sEnemyid | ||
msEquipmentid = request.POST.get('equipmentid') | ||
coockies = request.get_cookie("account", secret='some-secret-key') | ||
#print sEnemyid | ||
#print msEquipmentid | ||
if sEnemyid is None: | ||
return 'Error 9904: Your kill yourself!!' | ||
if msEquipmentid is None: | ||
return 'Error 9905: Your fight your enemy by nothing!And you are died!' | ||
if msEquipmentid in ['10001','10002','10003']: | ||
if sEnemyid in ['20001','20002','20003']: | ||
|
||
if (int(msEquipmentid)-int(sEnemyid)+10000)>0: | ||
return 'You are win Level 1!' | ||
elif (int(msEquipmentid)-int(sEnemyid)+10000)==0: | ||
return 'Your and your enemy all dead!!!' | ||
else: | ||
return 'Your dead!' | ||
else: | ||
return 'Error 9902: Your kill yourself!!' | ||
else: | ||
return 'Error 9903: You Broken The Rule!And Kill yourself' | ||
|
||
|
||
app = SessionMiddleware(app, session_opts) | ||
|
||
if __name__ == '__main__': | ||
run(app=app, port=12356) |