int GameUpdate(TGAME* Juego){ Juego->GanadorEncontrado = CheckFull(); Keyboard_Update(&(Juego->Teclado)); if(Keyboard_Check(&(Juego->Teclado), eKey_Esc)){ Juego->EstadoActual = Terminado; return 0; } if(Juego->GanadorEncontrado){ Juego->EstadoActual = Lleno; if(Keyboard_Check(&(Juego->Teclado), eKey_Enter)){ GameInit(Juego); } return 0; } if(!(Juego->pos_o_linea)){ CheckForWin(Juego); } if(Keyboard_Check(&(Juego->Teclado), eKey_Enter) && Juego->pos_o_linea==false){ Sleep(200); Juego->pos_o_linea = !(Juego->pos_o_linea); //GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0], pos_cursor[1], ' '); if(pos_cursor[0]<48) Juego->eLinea = Right; else Juego->eLinea = Left; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Enter) && Juego->pos_o_linea==true){ Juego->pos_o_linea = !(Juego->pos_o_linea); // GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0], pos_cursor[1], ' '); } return 0; }
void ChoosePos(TGAME* Juego){ if(Keyboard_Check(&(Juego->Teclado), eKey_Right)){ pos_cursor[0]+=3; if(pos_cursor[0]>48) pos_cursor[0]=30; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Left)){ pos_cursor[0]-=3; if(pos_cursor[0]<30) pos_cursor[0]=48; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Down)){ pos_cursor[1]+=2; if(pos_cursor[1]>18) pos_cursor[1]=6; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Up)){ pos_cursor[1]-=2; if(pos_cursor[1]<6) pos_cursor[1]=18; } }
/** * Actualiza los elementos que componen el juego y las variables auxiliares **/ void Game_Update(TGAME * lsGame, float lfTimeStep) { //controlando la velocidad lsGame->mfAcumulatedTime += lfTimeStep; if ( lsGame->mfAcumulatedTime < kfTimeLimit ) { return; } lsGame->mfAcumulatedTime = 0.0f; //Validar si el usuario quiere salir del juego ESC lsGame->mbFinish= Keyboard_Check(&(lsGame->mKeyboard),eKey_Esc); Scene_Update(&(lsGame->mScene), &(lsGame->mKeyboard),lfTimeStep); }
void ChooseLine(TGAME* Juego){ if(Juego->turno == false){ GraphicManager_SetColor(&(Juego->Pantalla), eRed, eLightAqua); } else{ GraphicManager_SetColor(&(Juego->Pantalla), eYellow, eLightAqua); } if(Keyboard_Check(&(Juego->Teclado), eKey_Right) && pos_cursor[0] != 48){ Juego->eLinea = Right; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Left) && pos_cursor[0] != 30){ Juego->eLinea = Left; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Down) && pos_cursor[1] != 18){ Juego->eLinea = Down; } else if(Keyboard_Check(&(Juego->Teclado), eKey_Up) && pos_cursor[1] != 6){ Juego->eLinea = Up; } //Switch que dibuja la linea switch ( Juego->eLinea ) { case Right: CleanDot(Juego); GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0]+1, pos_cursor[1], char(196)); GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0]+2, pos_cursor[1], char(196)); break; case Left: CleanDot(Juego); GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0]-2, pos_cursor[1], char(196)); GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0]-1, pos_cursor[1], char(196)); break; case Down: CleanDot(Juego); GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0], pos_cursor[1]+1, char(179)); break; case Up: CleanDot(Juego); GraphicManager_WriteChar(&(Juego->Pantalla), pos_cursor[0], pos_cursor[1]-1, char(179)); break; default: CleanDot(Juego); } //Switch para elejir permanentemente una posicion if(Keyboard_Check(&(Juego->Teclado), eKey_Space)){ Juego->pos_o_linea = false; Juego->turno = !(Juego->turno); switch ( Juego->eLinea ) { case Right: if(puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-27)/3].left==false){ puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-30)/3].right=true; puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-27)/3].left=true; } else Juego->turno = !(Juego->turno); break; case Left: if(puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-33)/3].right==false){ puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-30)/3].left=true; puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-33)/3].right=true; } else Juego->turno = !(Juego->turno); break; case Down: if(puntos[(pos_cursor[1]-4)/2][(pos_cursor[0]-30)/3].up==false){ puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-30)/3].down=true; puntos[(pos_cursor[1]-4)/2][(pos_cursor[0]-30)/3].up=true; } else Juego->turno = !(Juego->turno); break; case Up: if(puntos[(pos_cursor[1]-8)/2][(pos_cursor[0]-30)/3].down==false){ puntos[(pos_cursor[1]-6)/2][(pos_cursor[0]-30)/3].up=true; puntos[(pos_cursor[1]-8)/2][(pos_cursor[0]-30)/3].down=true; } else Juego->turno = !(Juego->turno); break; } } }