Ejemplo n.º 1
0
 def _create_game(self, game_key=100000, team_count=4):
     test_game = GameModel(game_key=game_key,
                           start_time=datetime.now(),
                           end_time=datetime.now() + timedelta(days=1),
                           team_count=team_count)
     test_game.save()
     return test_game
Ejemplo n.º 2
0
def get_scene():
    scene = cocos.scene.Scene()

    model = GameModel()
    view = GameView(model)
    controller = GameController(model)

    model.next_level()

    scene.add(view)
    scene.add(controller)

    return scene
Ejemplo n.º 3
0
    def post(self, gameKey: int) -> Response:
        payload: dict = request.json
        game: GameModel = GameModel.objects(game_key=gameKey).first()
        if not game:
            return Response('', 204)

        user: UserModel = UserModel.objects(user_id=payload['id'],
                                            game=game).first()
        if user:
            if check_password_hash(user.password, payload['password']):
                return jsonify({
                    'accessToken':
                    create_access_token(payload['id'],
                                        expires_delta=timedelta(days=10))
                })

            else:
                return Response('', 205)

        default_team: TeamModel = TeamModel.objects(game=game,
                                                    team_id=0).first()
        UserModel(game, payload['id'], payload['email'],
                  generate_password_hash(payload['password']),
                  default_team).save()
        return jsonify({
            'accessToken':
            create_access_token(payload['id'],
                                expires_delta=timedelta(days=10))
        })
Ejemplo n.º 4
0
    def wrapper(*arg, **kwargs):
        jwt = get_jwt_claims()

        g.game: GameModel = GameModel.objects(game_key=jwt['game_key']).first()
        if not g.game:
            abort(403)

        g.user: UserModel = UserModel.objects(user_id=jwt['user_id'],
                                              game=g.game).first()
        if not g.user:
            abort(403)
        return fn(*arg, **kwargs)
Ejemplo n.º 5
0
    def put(self):
        payload = request.json
        start_ = datetime.strptime(payload['start'], '%Y-%m-%d %H:%M:%S')
        end_ = datetime.strptime(payload['end'], '%Y-%m-%d %H:%M:%S')

        if start_ < datetime.now() or end_ < datetime.now():
            return Response('현재보다 오래된 시간을 감지했습니다. 다시 요청하세요.', 406)

        user = AdminUserModel.objects(userId=get_jwt_identity()).first()

        GameModel(gameKey=user['game'].id,
                  start_time=start_,
                  end_time=end_,
                  teamCount=4).save()

        return {"status": "success"}, 201
Ejemplo n.º 6
0
    def post(self):
        payload = request.json
        ID_ = payload['userId']
        PW_ = payload['password']
        start_ = '2018-10-10 10:10:10'   # '%Y-%m-%d %H:%M:%S' 형식
        end_ = '2018-12-25 10:10:10'       # '%Y-%m-%d %H:%M:%S' 형식

        if AdminUserModel.objects(userId=ID_).first():
            return {"status": "The ID already exists."}, 409

        game = GameModel(
            gameKey=create_game_key(),
            start_time=datetime.strptime(start_, '%Y-%m-%d %H:%M:%S'),
            end_time=datetime.strptime(end_, '%Y-%m-%d %H:%M:%S'),
            teamCount=4
        ).save()
        AdminUserModel(game=game.id, userId=ID_, password=PW_).save()
        for i in range(0, 5):
            create_team(game.id, teamId=i)

        return Response('회원가입 성공', 201)
Ejemplo n.º 7
0
 def editgame_action(self, *args, **kwargs):  #修改一个已经存在的游戏
     id = self.get_body_argument("id")
     game = dict(
         path=self.get_body_argument("path"),
         type=intval(self.get_body_argument("type")),
         play_type=intval(self.get_body_argument("play_type")),
         resource_type=intval(self.get_body_argument("resource_type")),
         question=self.get_body_argument("question"),
         answer1=self.get_body_argument("answer1"),
         answer2=self.get_body_argument("answer2"),
         answer3=self.get_body_argument("answer3"),
         answer4=self.get_body_argument("answer4"),
         right_answer=self.get_body_argument("right_answer"),
         switch=intval(self.get_body_argument("switch")),
     )
     model = GameModel()
     if not model(game):
         self.custom_error(model.error_msg)
     game = yield self.db.games.find_and_modify({"_id": ObjectId(id)},
                                                {"$set": game})
     self.redirect("/manage/gamedetail/%s" % game['_id'])
Ejemplo n.º 8
0
 def newgame_action(self, *args, **kwargs):  #创建一个新的游戏
     game = dict(name=self.get_body_argument("name"),
                 type=intval(self.get_body_argument("type")),
                 play_type=intval(self.get_body_argument("play_type")),
                 resource_type=intval(
                     self.get_body_argument("resource_type")),
                 path=self.get_body_argument("path"),
                 question=self.get_body_argument("question"),
                 answer1=self.get_body_argument("answer1"),
                 answer2=self.get_body_argument("answer2"),
                 answer3=self.get_body_argument("answer3"),
                 answer4=self.get_body_argument("answer4"),
                 right_answer=self.get_body_argument("right_answer"),
                 switch=intval(self.get_body_argument("switch")),
                 plays=0,
                 right_plays=0,
                 wrong_plays=0)
     model = GameModel()
     if not model(game):
         self.custom_error(model.error_msg)
     sort = yield self.db.games.insert(game)
     self.redirect("/manage/games")
Ejemplo n.º 9
0
 def get(self, gameKey: int) -> Response:
     if not GameModel.objects(game_key=gameKey).first():
         return Response('', 204)
     return jsonify({'gameKey': gameKey})
Ejemplo n.º 10
0
#import python internal lib
from random import randint

#import own lib
from util.database_connection import DatabaseConnector
from util.tournament_matchup import InitializeCupTournament
from util.rating_calculator import EloCalculator
from model.game import GameModel
from model.song_tournament import SongTournamentModel

#init
db_conn = DatabaseConnector()
connector = db_conn.get_connection()
elo_calc = EloCalculator()
cup_tournament_id = 2
game_model = GameModel(connector)
song_tournament_model = SongTournamentModel(connector)

init_cup_tour = InitializeCupTournament(connector,cup_tournament_id)
(tournament_tuple,games_list,songs_list) = init_cup_tour.initialize()

# print(">>>")
# print(tournament_tuple)
# for(id, title, url, rating, matches, wins, draws, losses, full_name, alias) in songs_list:
#     print(id, url, rating, matches, wins, draws, losses)

for (id, tournament_id, user_id, ucalias, state, round, song_left_id, s1title, s1url, u1alias, song_left_before_rating, song_left_after_rating, song_left_score, song_right_score, song_right_after_rating, song_right_before_rating, song_right_id, s2title, s2url, u2alias, creation_time, modification_time) in games_list:
    # print(id, state, round, song_left_id, song_left_before_rating, "-vs-" , song_left_before_rating, song_right_id)
    left_score = randint(0, 10)
    right_score = 10 - left_score