Skip to content

Commit

Permalink
Merge pull request #4 from bhamidou/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bhamidou authored Oct 11, 2023
2 parents c09c494 + 4382b88 commit 69c4750
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
"mesg",
"otro",
"soporte"
],
"cSpell.ignoreWords": [
"buscaminas",
"lado",
"nada"
]
}
5 changes: 2 additions & 3 deletions Controller/Constantes.php → Constantes.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

class Constantes{
class Constantes {
static $host = "localhost";
static $user = "root";
static $pass = "1234";
static $database = "buscaminas";
static $port = "3333";

}
}
4 changes: 2 additions & 2 deletions Controller/Conexion/Conexion.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require_once 'Constantes.php';
require __DIR__.'../../../Constantes.php';


class Conexion
{
Expand All @@ -21,4 +22,3 @@ public function desconectar()
mysqli_close(self::$conexion);
}
}

26 changes: 24 additions & 2 deletions Controller/Conexion/ConexionPartida.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php


require __DIR__.'/Controller/Conexion.php';
class ConexionPartida{
public function getPartida(){
public function getPartidas(){
$con = new Conexion();
$con->conectar();

Expand All @@ -23,6 +23,28 @@ public function getPartida(){
echo json_encode($rtn);
}

public function getPartida($id){
$con = new Conexion();
$con->conectar();

$consulta = "SELECT * FROM PARTIDA WHERE id = ?";

$stmt = mysqli_prepare(Conexion::$conexion, $consulta);
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);

$resultados = mysqli_stmt_get_result($stmt);
$con->desconectar();

$rtn= [];

while ($fila = mysqli_fetch_row($resultados)) {
$rtn[] = $fila[0].",". $fila[1].",".$fila[2].",".$fila[3];
}

echo json_encode($rtn);
}

public function updatePartida($posicion){
$con = new Conexion();
$con->conectar();
Expand Down
33 changes: 0 additions & 33 deletions Controller/Conexion/ConexionPersona.php

This file was deleted.

74 changes: 74 additions & 0 deletions Controller/Conexion/ConexionUsuario.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

require __DIR__.'../Conexion.php';

class ConexionUsuario{
public function checkLogin($email,$pass){
$con = new Conexion();
$con->conectar();

$consulta = "SELECT * FROM USUARIO WHERE email = ? AND pass = ? ";

$stmt = mysqli_prepare(Conexion::$conexion, $consulta);

$parsePw = md5($pass);

mysqli_stmt_bind_param($stmt, "ss", $email, $parsePw);

mysqli_stmt_execute($stmt);
$resultados = mysqli_stmt_get_result($stmt);

$rtn = [];

while ($fila = mysqli_fetch_row($resultados)) {
$rtn[] = [$fila[1],$fila[2]];
}

$check = false;
if($email == !empty($rtn[0][0]) && $pass == !empty($rtn[0][1])){
$check = true;
}

$con->desconectar();

return $check;
}

public function updatePassword($id, $newPw){
$con = new Conexion();
$con->conectar();

$consulta = "UPDATE USUARIO SET pass = ? WHERE id = ? ";

$stmt = mysqli_prepare(Conexion::$conexion, $consulta);

$hashPw = md5($newPw);

mysqli_stmt_bind_param($stmt, "si", $hashPw, $id);

mysqli_stmt_execute($stmt);

$con->desconectar();

}

function createUser($email, $pass, $nombre){
$con = new Conexion();
$con->conectar();

$consulta = "INSERT INTO USUARIO (email, pass, nombre) VALUES (?, ?, ?)";

$stmt = mysqli_prepare(Conexion::$conexion, $consulta);

$hashPw = md5($pass);

mysqli_stmt_bind_param($stmt, "sss", $email, $hashPw, $nombre);

mysqli_stmt_execute($stmt);

$con->desconectar();
}



}
36 changes: 2 additions & 34 deletions Controller/Partida.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
<?php

require_once 'Constantes.php';
require_once 'Conexion.php';
class Partida {

class Partida{

private $tablero;

public function darManotazo($pos){
/**
* 0-> nada
* 1 -> al lado
* 2 -> le has
*/
$code = 0;
if( $this->tablero[$pos] == '*'){
$code = 2;
}else if($this->tablero[$pos-1] == '*' || $this->tablero[$pos+1] == '*'){
$code = 1;
}

return $code;
}

public function crearTablero($size, $numMinas){

$rtnVec = array_fill(0,$size,'-');

while($numMinas>=0){
$randPos = rand(0,($size-1)) ;
$rtnVec[$randPos] = '*';
$numMinas--;
}

$this->tablero =$rtnVec;
}

}
}
7 changes: 0 additions & 7 deletions Controller/Persona.php

This file was deleted.

59 changes: 59 additions & 0 deletions Controller/Usuario.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

// require_once __DIR__.'/Conexion/Conexion.php';
require_once __DIR__.'/Conexion/ConexionUsuario.php';

class Usuario{


private $id;
private $email;
private $pass;
private $nombre;
private $tablero;
private $estadoPartida;

public function __construct($id,$email, $pass) {
$this->id = $id;
$this->email= $email;
$this->pass = $pass;
}

public function darManotazo($pos){
/**
* 0-> nada
* 1 -> al lado
* 2 -> le has dado
*/
$code = 0;
if( $this->tablero[$pos] == '*'){
$code = 2;
}elseif($this->tablero[$pos-1] == '*' || $this->tablero[$pos+1] == '*'){
$code = 1;
}

return $code;
}

public function crearTablero($size, $numMinas){

$rtnVec = array_fill(0,$size,'-');

while($numMinas>=0){
$randPos = rand(0,($size-1)) ;
$rtnVec[$randPos] = '*';
$numMinas--;
}

$this->tablero =$rtnVec;
}

public function changePassword($newPw){
$conexionUsuario = new ConexionUsuario();

$conexionUsuario->updatePassword(1, $newPw);
}

}


13 changes: 6 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


require_once './Controller/Partida.php';
require_once './Controller/Persona.php';
require_once './Controller/Usuario.php';

header("Content-Type:application/json");

Expand All @@ -22,14 +22,13 @@

switch ($requestMethod) {
case 'GET': {
$persona = new Persona();

$checkPersona = $persona->checkLogin($decode['email'], $decode['pass']);
$conexionUsuario = new ConexionUsuario();
$checkPersona = $conexionUsuario->checkLogin($decode['email'], $decode['pass']);

if ($checkPersona) {
$partida = new Partida();

if (!empty($v[1] && !empty($v[2]))) {
$user = new Usuario(1,$decode['email'], $decode['pass']);

$partida->crearTablero($v[1], $v[2]);

Expand All @@ -44,14 +43,14 @@
switch ($cod) {
case 0:
case 1:
$partida->getTableroInvisible($idUser);
// $partida->getTableroInvisible($idUser);
break;

case 2:

break;
default: {
$partida->getTableroInvisible($idUser);
// $partida->getTableroInvisible($idUser);
}
break;
}
Expand Down

0 comments on commit 69c4750

Please sign in to comment.