Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mailgyc-163 committed Feb 12, 2019
1 parent ce7f7e3 commit a52bcb8
Show file tree
Hide file tree
Showing 96 changed files with 677 additions and 368 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
## 斗地主   [![Build Status](https://travis-ci.org/mailgyc/doudizhu.svg?branch=master)](https://travis-ci.org/mailgyc)   [![Coverage Status](https://coveralls.io/repos/github/mailgyc/doudizhu/badge.svg?branch=master)](https://coveralls.io/github/mailgyc/doudizhu?branch=master)   [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)
## 斗地主   
[![Build Status](https://travis-ci.org/mailgyc/doudizhu.svg?branch=master)](https://travis-ci.org/mailgyc)   
[![Coverage Status](https://coveralls.io/repos/github/mailgyc/doudizhu/badge.svg?branch=master)](https://coveralls.io/github/mailgyc/doudizhu?branch=master)   
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)


斗地主游戏,后端基于Python+Tornado+MySQL开发,前端 Phaser 引擎
斗地主游戏,后端基于Python+Tornado+MySQL开发,前端 Phaser 引擎

**Dependencies**

运行步骤:
* Python3.6+
* Mysql5.7+

1.安装MySQL数据库, 执行:

mysql --user=root -p < schema.sql

2.安装Python3.6, 执行:
Quick Start

```
git clone https://github.com/mailgyc/doudizhu
cd doudizhu
mysql --user=root -p < schema.sql
pip3 install -r requirements.txt

python3 app.py --password=your_database_password
```
Now visit http://127.0.0.1:8080

浏览器访问 http://127.0.0.1:8080

3.在线体验 <http://m.ihouser.com/>
Online Demo
<http://m.ihouser.com/>

---

运行截图

Expand Down
31 changes: 0 additions & 31 deletions app.py

This file was deleted.

15 changes: 15 additions & 0 deletions compose/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.7.2-alpine

ENV PYTHONUNBUFFERED 1

COPY ../.../requirements.txt requirements.txt
COPY ../../doudizhu /app

RUN apk add --no-cache --update gcc musl-dev openssl-dev libffi-dev libjpeg-turbo-dev
RUN pip install -r requirements.txt -i https://pypi.douban.com/simple

ENTRYPOINT ["entrypoint.sh"]

WORKDIR /app
EXPOSE 8080
CMD ["python3", "app.py"]
File renamed without changes.
2 changes: 2 additions & 0 deletions compose/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx:latest
ADD nginx.conf /etc/nginx/conf.d/doudizhu
Empty file added compose/nginx/entrypoint.sh
Empty file.
Binary file removed core/res/encoding.npy
Binary file not shown.
151 changes: 0 additions & 151 deletions core/rule.py

This file was deleted.

23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3"

services:
nginx:
build: ./compose/nginx

doudizhu:
image: mailyc/doudizhu:latest
build: ./compose/app/
command: python3 app.py --host=172.20.0.1
networks:
- default
ports:
- "8080:8080"
volumes:
- /var/log:/var/log
- ./doudizhu:/app
restart: always

networks:
default:
driver: bridge

5 changes: 5 additions & 0 deletions douduzhu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
import sys


sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
52 changes: 52 additions & 0 deletions douduzhu/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import logging.config
from concurrent.futures import ThreadPoolExecutor

import tornado.web
import tornado.websocket
from tornado.ioloop import IOLoop
from tornado.options import options

from apps.urls import url_patterns
from contrib.db import AsyncConnection
from settings import settings

logging.config.dictConfig(settings.LOGGING)

# APPLICATION = {
# 'login_url': '/',
# 'xheaders': True,
# }


class Application(tornado.web.Application):
settings = {
'debug': settings.DEBUG,
'gzip': getattr(settings, 'GZIP', False),
'cookie_secret': settings.SECRET_KEY,
'xsrf_cookies': getattr(settings, 'XSRF_COOKIES', True),
'autoescape': "xhtml_escape",
'template_path': settings.TEMPLATE_ROOT,
'static_path': settings.STATIC_ROOT,
'static_url_prefix': settings.STATIC_URL,
}

def __init__(self):
super().__init__(url_patterns, **self.settings)
self.db = AsyncConnection(**settings.DATABASE)
self.executor = ThreadPoolExecutor()


def make_app(port):
app = Application()
app.listen(port)
return app


def main():
make_app(settings.PORT)
logging.info(f'server on http://127.0.0.1:{settings.PORT}')
IOLoop.current().start()


if __name__ == '__main__':
main()
Empty file added douduzhu/apps/__init__.py
Empty file.
Empty file.
8 changes: 4 additions & 4 deletions handlers/web.py → douduzhu/apps/account/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import asyncio
import json

import bcrypt

from handlers.base import BaseHandler
from contrib.handlers import BaseHandler


class WebHandler(BaseHandler):
class HomeHandler(BaseHandler):

def get(self):
if not self.get_cookie("_csrf"):
self.set_cookie("_csrf", self.xsrf_token)
Expand All @@ -15,7 +15,7 @@ def get(self):
self.render('poker.html', user=user)


class RegHandler(BaseHandler):
class SignupHandler(BaseHandler):

async def post(self):
email = self.get_query_params('email', self.get_query_params('username'))
Expand Down
1 change: 1 addition & 0 deletions douduzhu/apps/game/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 4 additions & 4 deletions core/robot.py → douduzhu/apps/game/components/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from tornado.ioloop import IOLoop

from core import rule
from core.player import Player
from handlers.protocol import Protocol as Pt
from ..player import Player
from ..protocol import Protocol as Pt
from ..rule import rule


class AiPlayer(Player):

def __init__(self, uid: int, username: str, player: Player):
from handlers.loopback import LoopBackSocketHandler
from ..views import LoopBackSocketHandler
super().__init__(uid, username, LoopBackSocketHandler(self))
self.room = player.room

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a52bcb8

Please sign in to comment.