Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatziGame Terminado #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions PlatziGame/controler/Game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@


const modal = document.getElementById('modalView');
const modalGif = document.getElementById('modalGif');
const whinerLabel = document.getElementById('whinerLabel');
const healtPlayer1 = [
document.getElementById('pHealtPlayer1'),
document.getElementById('nHealtPlayer1'),
];
const healtPlayer2 = [
document.getElementById('pHealtPlayer2'),
document.getElementById('nHealtPlayer2'),
];
const healtPlayers =[ healtPlayer1,healtPlayer2];

let jugadores = [new Jugador(1),new Jugador(2)];

function hacerDañoAJugador(quienLanzoAtaque){
const daño = jugadores[quienLanzoAtaque].hacerDaño() ;
const quienReciveDano = (quienLanzoAtaque+1)%2;
if(!jugadores[quienReciveDano].recibirDaño(daño)){
MostrarModal(jugadores[quienLanzoAtaque].getId());
return 0;
}
actualizarBarraDeVida(quienReciveDano);

}
function actualizarBarraDeVida(jugador){
healtPlayers[jugador][0].style.flexGrow = jugadores[jugador].getHealt()
healtPlayers[jugador][1].style.flexGrow = jugadores[jugador].getDamage()
}
function MostrarModal(jugador){
whinerLabel.innerHTML = `Player ${jugador}`;
obtenerGift()
.then((gifts)=>{
const {data} = gifts;
const urslImages = data.map(gif => gif.images.downsized_large.url);
let urlElegida = urslImages[Math.floor(Math.random() * urslImages.length)];
modalGif.setAttribute('src',urlElegida);
})
.catch(()=>{
console.log('error')
})
modal.classList.remove('hide')
}
function obtenerGift(){
const url = "http://api.giphy.com/v1/gifs/search?q=winner&api_key=4quN3Z1vE3QA3o0qXRor70NioXGu33cN&limit=5";
const opts = {crossDomain: true};
return new Promise((resolve,reject)=>{
$
.get(url,opts,data=>{
resolve(data)
})
.fail(() => reject(id));
});
}
function reStartJuego(){
modal.classList.add('hide');
jugadores = [new Jugador(1),new Jugador(2)];
for(let i=0; i<2;i++){
healtPlayers[i][0].style.flexGrow = 100;
healtPlayers[i][1].style.flexGrow = 0;
}
}
18 changes: 18 additions & 0 deletions PlatziGame/model/Jugador.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Jugador{
constructor(id){
this.healt = 100;
this.damageRecived = 0;
this.id = id;
}
hacerDaño = () =>Math.round(Math.random()*30)
recibirDaño (damage) {
this.healt -= damage;
this.healt = this.healt<0 ? 0:this.healt;
this.damageRecived += damage;
return this.healt;
}
getHealt = ()=> this.healt
getDamage = ()=> this.damageRecived
getId = ()=>this.id

}
189 changes: 189 additions & 0 deletions PlatziGame/view/Caracter2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
.piel{
background-color: var(--pielclara);
}
.cabello{
background-color: var(--pantalon);
}
.rojo{
background-color: var(--rojo);
}
.rojo_claro{
background-color: var(--rojoClaro);
}
.rojo_obscuro{
background-color: var(--rojoObscuro);
}
.eboy{
height: 150px;
width: 250px;
position: relative;
}
.eboy__head{
z-index: 3;
height: 45px;
width: 45px;
border-radius: 6px;
position: absolute;
top: 40px;
left: 100px;
}
.eboy__head--lente{
position: absolute;
width: 45px;
height: 21px;
top: 10px;
left: -5px;
border-radius: 10px;
}
.eboy__head--lente::after{
z-index: 3;
position: absolute;
width: 40px;
height: 15px;
top: 3px;
left: 2px;
border-radius: 10px;
background-color: var(--azul);
content: '';
}
.eboy__head--lente::before{
z-index: 1;
position: absolute;
width: 11px;
height: 12px;
top: 4px;
left: 39px;
background-color: var(--pantalon);
content: '';
}
.eboy__head--oreja{
height: 11px;
width: 11px;
border-radius: 20px;
position: absolute;
left: 41px;
top: 20px;
z-index: 2;
}
.eboy__head--oreja::before{
background-color: var(--pielrosada);
height: 7px;
width: 7px;
border-radius: 20px;
content: '';
position: absolute;
top: 2px;
left: 2px;
}
.eboy__head--details{
position: absolute;
height: 17px;
width: 45px;
border-radius: 20px;
top: -9px;
left: -7px;
}
.eboy__head--details::after{
background-color: var(--pantalon);
position: absolute;
height: 15px;
width: 18px;
border-radius: 20px;
top: 6px;
left: 40px;
content: '';
}
.eboy__head--details::before{
background-color: var(--pantalon);
position: absolute;
height: 5px;
width: 12px;
border-radius: 20px;
top: 45px;
left: 33px;
content: '';
}
.eboy__body{
z-index: 2;
position: absolute;
height: 47px;
width: 47px;
border-radius: 30px;
top: 63px;
left: 116px;
}
.eboy__body--brazoIzquierdo{
position: absolute;
height: 14px;
width: 24px;
top: 9px;
left: 31px;
border-radius: 10px;
}
.eboy__body--brazoIzquierdo::after{
background-color: inherit;
position: absolute;
height: 14px;
width: 24px;
content: '';
top: 4px;
left: 11px;
border-radius: 10px;
transform: rotateZ(45deg);
}
.eboy__boy--piernaIzquierda{
position: absolute;
height: 12px;
width: 24px;
top: 29px;
left: 16px;
border-radius: 10px;
}
.eboy__boy--piernaIzquierda::after{
background-color: inherit;
position: absolute;
height: 13px;
width: 33px;
content: '';
top: 7px;
left: -6px;
border-radius: 10px;
transform: rotateZ(45deg);
}
.eboy__derecho{
position: absolute;
height: 13px;
width: 33px;
top: 105px;
left: 125px;
border-radius: 10px;
transform: rotateZ(45deg);
}
.eboy__derecho::after{

background-color: inherit;
position: absolute;
height: 13px;
width: 33px;
content: '';
top: -1px;
left: -32px;
border-radius: 10px;
transform: rotateZ(135deg);

}
/*<div class="eboy">
<div class="eboy__head piel">
<div class="eboy__head--lente"></div>
<div class="eboy__head--oreja piel"></div>
<div class="eboy__head--details cabello"></div>
</div>
<div class="eboy__body rojo">
<div class="eboy__body--brazoIzquierdo rojo_claro"></div>
<div class="eboy__boy--piernaIzquierda rojo_claro"></div>
</div>
<div class="eboy__derecho">
<div class="eboy__body--brazoDerecho rojo_obscuro"></div>
<div class="eboy__boy--piernaDerecha rojo_obscuro"></div>
</div>
</div>*/
Loading