Compare commits
5 Commits
32bdc6dcb6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 939513adfd | |||
| f6fa541f7f | |||
| 31bdff87e3 | |||
| 4666615535 | |||
| a31b069cb0 |
14
jscore.cpp
14
jscore.cpp
@@ -3,7 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -26,8 +26,9 @@ namespace jscore {
|
|||||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in client;
|
struct sockaddr_in client;
|
||||||
|
|
||||||
int PORT = 9911;
|
int PORT = 9911;
|
||||||
const char *HOST = "jaildoctor.duckdns.org";
|
string HOST = "jaildoctor.duckdns.org";
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
WSADATA WsaData;
|
WSADATA WsaData;
|
||||||
@@ -36,6 +37,11 @@ namespace jscore {
|
|||||||
bool jscore_error = false;
|
bool jscore_error = false;
|
||||||
string error_message;
|
string error_message;
|
||||||
|
|
||||||
|
void init(std::string host, const int port) {
|
||||||
|
PORT = port;
|
||||||
|
HOST = host;
|
||||||
|
}
|
||||||
|
|
||||||
void setErrorMessage(string message) {
|
void setErrorMessage(string message) {
|
||||||
jscore_error = true;
|
jscore_error = true;
|
||||||
error_message = message;
|
error_message = message;
|
||||||
@@ -46,7 +52,7 @@ namespace jscore {
|
|||||||
int ret = WSAStartup(0x101,&WsaData);
|
int ret = WSAStartup(0x101,&WsaData);
|
||||||
if (ret != 0) return 0;
|
if (ret != 0) return 0;
|
||||||
#endif
|
#endif
|
||||||
struct hostent * host = gethostbyname(HOST);
|
struct hostent * host = gethostbyname(HOST.c_str());
|
||||||
|
|
||||||
if ( (host == NULL) || (host->h_addr == NULL) ) {
|
if ( (host == NULL) || (host->h_addr == NULL) ) {
|
||||||
setErrorMessage("Error retrieving DNS information.\n");
|
setErrorMessage("Error retrieving DNS information.\n");
|
||||||
@@ -120,9 +126,11 @@ namespace jscore {
|
|||||||
return score.size();
|
return score.size();
|
||||||
}
|
}
|
||||||
string getUserName(const int index) {
|
string getUserName(const int index) {
|
||||||
|
if (score.size()==0 || index >= score.size()) return "";
|
||||||
return score[index].name;
|
return score[index].name;
|
||||||
}
|
}
|
||||||
const int getPoints(const int index) {
|
const int getPoints(const int index) {
|
||||||
|
if (score.size()==0 || index >= score.size()) return 0;
|
||||||
return score[index].points;
|
return score[index].points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
jscore.h
1
jscore.h
@@ -2,6 +2,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace jscore {
|
namespace jscore {
|
||||||
|
void init(std::string host, const int port);
|
||||||
const bool initOnlineScore(std::string game);
|
const bool initOnlineScore(std::string game);
|
||||||
const int getNumUsers();
|
const int getNumUsers();
|
||||||
std::string getUserName(const int index);
|
std::string getUserName(const int index);
|
||||||
|
|||||||
24
server/deleteuserdata.php
Normal file
24
server/deleteuserdata.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
class MiBD extends SQLite3
|
||||||
|
{
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->open('../bd/jailgames.db');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$bd = new MiBD();
|
||||||
|
|
||||||
|
$game = "";
|
||||||
|
if (isset($_GET['game'])) $game = $_GET['game'];
|
||||||
|
$user = "";
|
||||||
|
if (isset($_GET['user'])) $user = $_GET['user'];
|
||||||
|
|
||||||
|
$query = "DELETE FROM userdata WHERE game LIKE '".$game."' AND user LIKE '".$user."'";
|
||||||
|
$bd->exec($query);
|
||||||
|
echo("OK");
|
||||||
|
?>
|
||||||
44
server/getalluserdata.php
Normal file
44
server/getalluserdata.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
class MiBD extends SQLite3
|
||||||
|
{
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->open('../bd/jailgames.db');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$bd = new MiBD();
|
||||||
|
|
||||||
|
$query = "SELECT * FROM userdata";
|
||||||
|
$resultado = $bd->query($query);
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>ÍCARO</title>
|
||||||
|
<meta http-equiv="Cache-Control" content="no-cache ,must-revalidate" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<table>
|
||||||
|
<tr><th>game</th><th>user</th><th>data</th></tr>
|
||||||
|
<?php
|
||||||
|
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
|
||||||
|
while ($fila) {
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?=$fila['game']?></td>
|
||||||
|
<td><?=$fila['user']?></td>
|
||||||
|
<td><?=$fila['data']?></td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
30
server/getusers.php
Normal file
30
server/getusers.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
class MiBD extends SQLite3
|
||||||
|
{
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->open('../bd/jailgames.db');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$bd = new MiBD();
|
||||||
|
|
||||||
|
$game = "";
|
||||||
|
if (isset($_GET['game'])) $game = $_GET['game'];
|
||||||
|
|
||||||
|
$query = "SELECT user FROM userdata WHERE game LIKE '".$game."'";
|
||||||
|
$resultado = $bd->query($query);
|
||||||
|
|
||||||
|
$res = "";
|
||||||
|
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
|
||||||
|
while ($fila) {
|
||||||
|
$res = $res.$fila['user'];
|
||||||
|
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
|
||||||
|
if ($fila) $res = $res.",";
|
||||||
|
}
|
||||||
|
echo($res);
|
||||||
|
?>
|
||||||
@@ -16,7 +16,7 @@ $bd = new MiBD();
|
|||||||
$game = "";
|
$game = "";
|
||||||
if (isset($_GET['game'])) $game = $_GET['game'];
|
if (isset($_GET['game'])) $game = $_GET['game'];
|
||||||
|
|
||||||
$query = "SELECT user, points FROM scores WHERE game LIKE '".$game."' ORDER BY points DESC LIMIT 10";
|
$query = "SELECT user, points FROM scores WHERE game LIKE '".$game."' ORDER BY points DESC";
|
||||||
$resultado = $bd->query($query);
|
$resultado = $bd->query($query);
|
||||||
|
|
||||||
$res = "";
|
$res = "";
|
||||||
|
|||||||
39
tetris.cpp
39
tetris.cpp
@@ -37,7 +37,7 @@ bool is_valid_move() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stack_piece() {
|
void stack_piece() {
|
||||||
if (piece_pos.y==0) exit(0);
|
if (piece_pos.y==0) { state=STATE_ENNERYORNEIM; return; };
|
||||||
int x = piece_pos.x+3, y = piece_pos.y+3;
|
int x = piece_pos.x+3, y = piece_pos.y+3;
|
||||||
Uint16 piece = tetromino[current_piece].figure;
|
Uint16 piece = tetromino[current_piece].figure;
|
||||||
for (int i=0; i<16; i++) {
|
for (int i=0; i<16; i++) {
|
||||||
@@ -128,7 +128,7 @@ void doGame() {
|
|||||||
void doMenu() {
|
void doMenu() {
|
||||||
while(SDL_PollEvent(&sdlEvent)) {
|
while(SDL_PollEvent(&sdlEvent)) {
|
||||||
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
|
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
|
||||||
if (sdlEvent.type == SDL_KEYDOWN) {
|
if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) {
|
||||||
level=score=lines=0;
|
level=score=lines=0;
|
||||||
current_piece = starting[rand()%7];
|
current_piece = starting[rand()%7];
|
||||||
next_piece = starting[rand()%7];
|
next_piece = starting[rand()%7];
|
||||||
@@ -162,6 +162,40 @@ void doMenu() {
|
|||||||
SDL_RenderPresent(sdlRenderer);
|
SDL_RenderPresent(sdlRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char initials[4]={"AAA"};
|
||||||
|
int pos =0;
|
||||||
|
void doEnd() {
|
||||||
|
while(SDL_PollEvent(&sdlEvent)) {
|
||||||
|
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
|
||||||
|
if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) {
|
||||||
|
if (sdlEvent.key.keysym.scancode>=SDL_SCANCODE_A && sdlEvent.key.keysym.scancode<=SDL_SCANCODE_0) {
|
||||||
|
if (sdlEvent.key.keysym.scancode<=SDL_SCANCODE_Z) {
|
||||||
|
initials[pos] = sdlEvent.key.keysym.scancode+61;
|
||||||
|
} else if (sdlEvent.key.keysym.scancode<SDL_SCANCODE_0) {
|
||||||
|
initials[pos] = sdlEvent.key.keysym.scancode+19;
|
||||||
|
} else {
|
||||||
|
initials[pos] = '0';
|
||||||
|
}
|
||||||
|
pos++; if (pos==3) pos=0;
|
||||||
|
} else if (sdlEvent.key.keysym.scancode==SDL_SCANCODE_RETURN) {
|
||||||
|
state=STATE_MENU;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
|
||||||
|
//SDL_RenderClear(sdlRenderer);
|
||||||
|
|
||||||
|
print(90, 100, "GAME OVER", 7);
|
||||||
|
if (score>0 && (jscore::getNumUsers()<10 || score>jscore::getPoints(jscore::getNumUsers()-1))) {
|
||||||
|
print(40, 150, "CONGRATULATIONS", 1);
|
||||||
|
print(40, 180, "ENTER YOU NAME", 2);
|
||||||
|
print(40, 250, initials, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderPresent(sdlRenderer);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
current_piece = starting[rand()%7];
|
current_piece = starting[rand()%7];
|
||||||
@@ -181,6 +215,7 @@ int main(int argc, char* argv[]) {
|
|||||||
doGame();
|
doGame();
|
||||||
break;
|
break;
|
||||||
case STATE_ENNERYORNEIM:
|
case STATE_ENNERYORNEIM:
|
||||||
|
doEnd();
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user