Skip to content

MumbaiHackathon/headshot

 
 

Repository files navigation

Headshot

github api logo

Table of Contents

1 INTRODUCTION

Headshot is a collection of 5 independent APIs with easy to integrate RESTful architecture . These APIs can be used as a open source platform to develope educational, fun and enganing games. A user will be able to register and login with Register and Login API. They will able to use the feature of question generator to generate the question and also hints. Using this we have implemented a poker based quizzing game in which multiple users can join a game room and start a game. Many such innovative ideas can be implemented using these API's.

2 INSTALLATION

  1. Download the repository Clone the base repository onto your desktop with git as follows:
$ git clone https://github.com/jitendra1998/headshot
  1. Install necessary dependencies The project has its base on Python tornado frame work. Make user you have python install in your computer. Refer this for more information click here. (It is recommended to start a virtual environment before installing all dependencies, Read further )

Install necessary Python dependencies as follows:

$ pip install -r req.txt
  1. how to initialize the game
*install tornado, mqsql-server, redis-server
  1. mysql setup
sudo apt-get update
sudo apt-get install mysql-server
  1. mysql secure installation
/usr/bin/mysql_secure_installation
  1. start mysql
/usr/bin/mysql -u root -p
  1. create a database quizycash
CREATE DATABASE quizycash;
USE quizycash;
  1. create a user development with pass 12345
CREATE USER 'development'@'localhost' IDENTIFIED BY '12345';
GRANT ALL PRIVILEGES ON * . * TO 'development'@'localhost';
  1. install mysq-db
$ sudo apt-get install python-pip python-dev libmysqlclient-dev
pip install MySQL-python
  1. initialize the database schema
/usr/bin/mysql -u development -p quizycash < database_schema.sql
  1. insert game data (game data for 3 game rooms)
INSERT INTO game_room (game_room_name, game_category, max_players, game_theme, min_buy_in, max_buy_in, game_status, created_at, big_blind, small_blind) VALUES ('game1', 'football', 10, 'sports', 20,80,1,'2017-08-03 15:36:45', 2, 1);

INSERT INTO game_room (game_room_name, game_category, max_players, game_theme, min_buy_in, max_buy_in, game_status, created_at, big_blind, small_blind) VALUES ('game2', 'football', 10, 'science', 250,1000,1,'2017-09-13 21:40:05', 40, 20);

INSERT INTO game_room (game_room_name, game_category, max_players, game_theme, min_buy_in, max_buy_in, game_status, created_at, big_blind, small_blind) VALUES ('game3', 'football', 10, 'economics', 100,500,1,'2017-09-20 08:19:32', 40, 20);
INSERT INTO game_room (game_room_name, game_category, max_players, game_theme, min_buy_in, max_buy_in, game_status, created_at, big_blind, small_blind) VALUES ('game4', 'football', 10, 'sports', 25,100,1,'2017-09-20 08:19:32', 4, 2);
  1. redis-server setup
sudo apt-get install redis-server
  1. check redis by running reddis-cli on terminal
redis-cli
  1. flush redis
redis-cli flushall
  1. insert active_games data in redis (for that on a new terminal run python)
import redis
import json
r = redis.StrictRedis(host='localhost', db=4)
r.set('active_games', json.dumps({'game1':'1'}))
  1. new redis active_games data
r.set('active_games', json.dumps({"game3": "3", "game2": "2", "game1": "1"}))
  1. initial check
r.get('active_players')
r.get('user_session')
r.get('active_games')

For deployment change host in statrting of file

admin_func.js - 1
game_room_api.py - 1

3 END POINT

1. UserLogin API

On successful login sets the username in cookie and fetches the user data and appends in user_session redis table and in case of incorrect email or password redirects it to the same webpage asking to provide information again.

Field Name Description Value Type Mandatory
user_email Email of user registered with String YES
password Password belonging to that email String Yes

2. USERSIGNUP API

On successful signup redirects to login page and adds the user data in the sql table ‘user’

Field Name Description Value Type Mandatory
avatar Email of user registered with. String Yes
user_name Username of the User to be displayed(Must be Unique) String Yes
user_email Email of user String Yes
password Password for the account. String Yes
first_name First name of the User String NO
last_name Last name of the User String NO
d_o_b Date of birth of the User. Date NO
gender Gender of the User String NO
country Country at which the user belong. String NO

3. QUESTION GENERATE API

On successful request return a question and its correct answer all four options and its hint according to difficulty level.

Field Name Description Value Type Mandatory
Game_room_id Id of current game room with users in it. Multiple INT Yes
theme Theme of the question to show. String Yes

Sample Json response:-

{
   "success": {
       "code": 200,
       "data": {
           "c_ans": [
               2
           ],
           "question": [
               "What continental football federation is Nigeria a member of?"
           ],
           "ans": [
               "CONMEBOL",
               "OFC",
               "CAF",
               "UEFA"
           ],
           "d2": [
               "Sports",
               "Football",
               "National Teams",
               "Nigeria"
           ],
           "d3": [
               null,
               null,
               null,
               null
           ],
           "d1": [
               "Sports",
               "Football",
               "Rules",
               "Governing Bodies"
           ]
       }
   }
}

4. Start_game

Start the game of all users connected in the game room.

Field Name Description Value Type Mandatory
Game_room_id Id of current game room with users in it. Int Yes

5. Bet

Increases the current bet according the amount.

Field Name Description Value Type Mandatory
User_id Id of current User loged in. Int Yes
Game_room_id Id of current game room with users in it. Int Yes
bet_amount Amount to bet Int Yes

6. Call

Match the current amount of the bet made by a previous player in the round .

Field Name Description Value Type Mandatory
User_id Id of current User loged in. Int Yes
Game_room_id Id of current game room with users in it. Int Yes

7. All_in

Commits player entire stack(all money).

Field Name Description Value Type Mandatory
User_id Id of current User loged in. Int Yes
Game_room_id Id of current game room with users in it. Int Yes

8. Fold

Ending participation in a hand. No more bets are required to go into the pot by someone once they fold.

Field Name Description Value Type Mandatory
User_id Id of current User loged in. Int Yes
Game_room_id Id of current game room with users in it. Int Yes

4 SCREENSHOTS

ss

ss

ss

ss

ss

ss

ss

ss

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 69.9%
  • Python 20.2%
  • CSS 7.3%
  • JavaScript 2.6%