Well, I have an Android app in which I have the following so far: The login screen and a "Welcome" screen, the point is that when the user manages to enter with the correct email and password I take him with an Intent to the screen of "Welcome", but by clicking on the "back" button he can return to the login screen, which I do not want to happen.
Cristian Alvarez Hernandez's questions
<?php
$usu = $_REQUEST['usu'];
$pas = $_REQUEST['pas'];
try{
// establecemos la conexion con PDO
$conexion = new PDO("mysql:host=pagina.000webhostapp.com;port=3306;dbname=id554244_basededatos", "id453244_usuario", "contraseña");
$conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// establecemos el juego de caracteres utf8
$conexion->exec("SET CHARACTER SET utf8");
// consulta para obtener el alumno con dicho usuario y contraseña
$consulta_sql = "SELECT * FROM alumnos WHERE codAlu=? AND pasUsu=?";
// preparamos la consulta
$resultado = $conexion->prepare($consulta_sql);
// ejecutamos la consulta con los aparametros del array, entrecomillado porque son varchar
$resultado->execute(array("$usu", "$pas"));// guardamos en resultado la tabla virtual que devele la consulta
$datos = array();
foreach($resultado as $row){
$datos[] = $row;
}
echo json_encode($datos);
}catch(Exception $e){
die("Error: " . $e->GetMessage());
}finally{// esto se ejecuta haya o no error
$conexion = null;
}
?>
I don't understand why this error comes out, since the PDO parameters are correct (I'm not sure about the port, but I've already tried several and it still doesn't work).
#include <iostream>
#include <windows.h>
#include <conio.h>
#define ARRIBA 72
#define IZQUIERDA 75
#define DERECHA 77
#define ABAJO 80
using namespace std;
int i=4;
void SetColor(int ForgC)
{
WORD wColor;
//This handle is needed to get the current background attribute
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
//csbi is used for wAttributes word
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
{
//To mask out all but the background attribute, and to add the color
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0xF0);
SetConsoleTextAttribute(hStdOut, wColor);
}
return;
}
void gotoxy(int x, int y) // funcion que posiciona el cursos en la coordenada (x,y)
{
HANDLE hCon;
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hCon,dwPos);
}
void seleccionarOpcion(char tecla){
gotoxy(4, i); cout<<" ";
if( tecla == ABAJO && i < 7 ){
gotoxy(8, 9);
cout<<" ";
i++;
}
if( tecla == ARRIBA && i > 4){
gotoxy(8, 9);
cout<<" ";
i--;
}
if( tecla == 13 ){
gotoxy(8, 9);
if( i == 4 ) cout<<"Eligio la primera opcion";
if( i == 5 ) cout<<"Eligio la segunda opcion";
if( i == 6 ) cout<<"Eligio la tercera opcion";
if( i == 7 ) cout<<"Eligio la cuarta opcion";
}
gotoxy(4, i); cout<<">";
}
void menu(char tecla){
seleccionarOpcion(tecla);
gotoxy(5, 4); cout<<" primera";
gotoxy(5, 5); cout<<" segunda";
gotoxy(5, 6); cout<<" tercera";
gotoxy(5, 7); cout<<" cuarta";
}
int main()
{
char tecla;
while(true){
if( kbhit() )
tecla = getch();
else
tecla = ' ';
menu(tecla);
Sleep(40);
}
system("pause>null");
return 0;
}
What I want to do is something more or less like this
This is my code with the class for a Gun and a Bullet, where there are functions defined to move, draw and erase each of them.
The problem is in the use of the function kbhit()
, which I call from 2 different parts of the code:
- To make the gun move
- To shoot
Just as I have the code, it doesn't work for me when I try to use it for the shots (commented at the end of the code).
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <list>
#include <stdio.h>
using namespace std;
void gotoxy(int x, int y){
HANDLE hCon;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pw;
pw.X = x;
pw.Y = y;
SetConsoleCursorPosition(hCon, pw);
}
class Pistola{
private:
int x, y;
public:
Pistola(int _x, int _y): x(_x), y(_y){}
void pintar();
void borrar();
void mover();
int getX(){return x;}
int getY(){return y;}
};
void Pistola::pintar(){
gotoxy(x,y); printf("( )==:");
gotoxy(x,y+1); printf("||");
}
void Pistola::borrar(){
gotoxy(x,y); printf(" ");
gotoxy(x,y+1); printf(" ");
}
void Pistola::mover(){
if(kbhit()){ // <--- Aca estoy usando para mover
borrar();
char tecla = getch();
if(tecla == 'i') y--;
if(tecla == 'k') y++;
if(tecla == 'j') x--;
if(tecla == 'l') x++;
pintar();
}
}
class Bala{
private:
int x, y;
public:
Bala(int _x, int _y): x(_x), y(_y){}
void pintar();
void mover();
void borrar();
int getX(){return x;}
int getY(){return y;}
};
void Bala::pintar(){
gotoxy(x,y); printf("*");
}
void Bala::mover(){
gotoxy(x,y); printf(" ");
if( x < 70 ) x++;
gotoxy(x,y); printf("*");
}
void Bala::borrar(){
gotoxy(x,y); printf(" ");
}
int main()
{
Pistola arma(10,10);
bool game_over = false;
list<Bala*> B;
list<Bala*>::iterator it;
arma.pintar();
while( !game_over ){
/// El problema esta en que si uso la funcion khbit() para hacer mover el armar, no me funcion cuando
/// la intento usar para los disparos, si corta arma.mover() y lo pega justo antes de Sleep(30) notara
/// que lo que funiona bien son los disparos y lo que falla es la funcion mover del arma.
arma.mover();
if( kbhit() ){ // <--- Aca estoy usando para disparar
char tecla = getch();
if( tecla == 'a'){
B.push_back(new Bala(arma.getX()+7, arma.getY()));
}
}
for( it = B.begin(); it != B.end(); it++){
(*it)->mover();
if( (*it)->getX() >= 70 ){
(*it)->borrar();
delete (*it);
it = B.erase(it);
}
}
Sleep(30);
}
return 0;
}
For example, debugging, if you cut the call to kbhit()
from arma.mover()
and paste it just before Sleep(30)
, changing the order of the loop so that it first reads the trigger and then the move, you'll notice that what works fine is the triggers and what fails is the move function of the weapon.
What can I do to fix it? How can I use the function kbhit()
repeatedly?