|
@@ -1,20 +1,20 @@
|
|
-# save.php
|
|
|
|
|
|
+# Configuring `save.php`
|
|
|
|
|
|
-iFractions is developed to run mainly on the client side. However, it communicates with a MySQL database to save info about the player's progress after each level. There's a PHP file called **save.php** that manages the connection between the game and the database. Also, the asynchronous communication is stablished using **XMLHTTPRequest**.
|
|
|
|
|
|
+iFractions is developed to run mainly on the client side. However, it communicates with a **MySQL** database to save information about the player's progress after each level. There's a **PHP** file called `save.php` that manages the connection between the game and the database. Also, the asynchronous communication is stablished using **XMLHTTPRequest**.
|
|
|
|
|
|
# How to set up the database connection correctly
|
|
# How to set up the database connection correctly
|
|
|
|
|
|
-First you'll need a MySQL database installed on the server (more info in https://www.mysql.com).
|
|
|
|
|
|
+First you'll need a **MySQL** database installed on the server (more info in https://www.mysql.com).
|
|
|
|
|
|
Now, in order for iFractions to successfully establish a connection to the database you must:
|
|
Now, in order for iFractions to successfully establish a connection to the database you must:
|
|
|
|
|
|
1. create and set up the database for the game.
|
|
1. create and set up the database for the game.
|
|
-2. update /php/save.php
|
|
|
|
-3. update /js/globals.js
|
|
|
|
|
|
+2. update `/php/save.php`
|
|
|
|
+3. update `/js/globals/globals_functions.js`
|
|
|
|
|
|
## 1) Creating the database for iFractions
|
|
## 1) Creating the database for iFractions
|
|
|
|
|
|
-Considering the database name to be **db_ifractins** and the table to be **ifractions**, you can setup the MySQL database as follows:
|
|
|
|
|
|
+Considering the **database name** to be `db_ifractins` and the **table name** to be `ifractions`, you can setup the MySQL database as follows:
|
|
|
|
|
|
CREATE DATABASE db_ifractions;
|
|
CREATE DATABASE db_ifractions;
|
|
|
|
|
|
@@ -37,21 +37,21 @@ Considering the database name to be **db_ifractins** and the table to be **ifrac
|
|
PRIMARY KEY (line_id)
|
|
PRIMARY KEY (line_id)
|
|
) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = latin1;
|
|
) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = latin1;
|
|
|
|
|
|
-Note that each column has the prefix **line_**.
|
|
|
|
|
|
+Note that each column has the prefix `line_`.
|
|
|
|
|
|
-## 2) /php/save.php
|
|
|
|
|
|
+## 2) `save.php`
|
|
|
|
|
|
-You have to set values for the following variables in **/php/save.php** to match the database's:
|
|
|
|
|
|
+You have to set values for the following variables in `/php/save.php` to match the database's:
|
|
|
|
|
|
$servername = "localhost"; // INSERT MySQL server
|
|
$servername = "localhost"; // INSERT MySQL server
|
|
- $username = "put_username"; // INSERT MySQL user name
|
|
|
|
- $password = "put_password"; // INSERT MySQL password
|
|
|
|
|
|
+ $username = "your_db_username"; // INSERT MySQL user name
|
|
|
|
+ $password = "your_db_password"; // INSERT MySQL password
|
|
$dbname = "db_ifractions"; // INSERT database name (default=db_ifractions)
|
|
$dbname = "db_ifractions"; // INSERT database name (default=db_ifractions)
|
|
$tablename = "ifractions"; // INSERT table name (default=ifractions)
|
|
$tablename = "ifractions"; // INSERT table name (default=ifractions)
|
|
|
|
|
|
-## 3) /js/globals.js
|
|
|
|
|
|
+## 3) `globals_functions.js`
|
|
|
|
|
|
-Inside **/js/globals.js** there's a global function called **sendToDatabase()**. When the player's information is collected after each game, the game file sends it as a parameter to **sendToDatabase()**. It makes an asynchronous call to **/php/save.php**, that executes the connection to the database.
|
|
|
|
|
|
+Inside `/js/globals/globals_functions.js` there's a global function called `sendToDatabase()`. When the player's information is collected after each game, the game file sends it as a parameter to `sendToDatabase()`. It makes an asynchronous call to `/php/save.php`, that executes the connection to the database.
|
|
|
|
|
|
const data = 'line_ip='// INSERT the IP of the machine where the MySQL was set up
|
|
const data = 'line_ip='// INSERT the IP of the machine where the MySQL was set up
|
|
+ '&line_name=' + // player's name
|
|
+ '&line_name=' + // player's name
|
|
@@ -61,12 +61,12 @@ Inside **/js/globals.js** there's a global function called **sendToDatabase()**.
|
|
|
|
|
|
# Where do we use the database in the code?
|
|
# Where do we use the database in the code?
|
|
|
|
|
|
-There is a function **postScore()** in every game file:
|
|
|
|
-* /js/squareOne.js
|
|
|
|
-* /js/squareTwo.js
|
|
|
|
-* /js/circleOne.js
|
|
|
|
|
|
+There is a function `postScore()` in every game file:
|
|
|
|
+* `/js/games/squareOne.js`
|
|
|
|
+* `/js/games/squareTwo.js`
|
|
|
|
+* `/js/games/circleOne.js`
|
|
|
|
|
|
-After each level is completed (with the player's answer being correct or not), before going back to the level map, the function **postScore()**, is called. It joins all the player's progress information into a string (as can be seen below), that is sent as a parameter to **sendToDatabase()**, from **/js/globals.js**, that sends it to the database.
|
|
|
|
|
|
+After each level is completed (with the player's answer being correct or not), before going back to the level map, the function `postScore()`, is called. It joins all the player's progress information into a string (as can be seen below), that is sent as a parameter to `sendToDatabase()`, from `/js/globals/globals_functions.js`, that sends it to the database.
|
|
|
|
|
|
const data = '&line_game=' + // collect game shape
|
|
const data = '&line_game=' + // collect game shape
|
|
+ '&line_mode=' + // collect game mode type
|
|
+ '&line_mode=' + // collect game mode type
|