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

reto terminado, tendre que aprender a dibujar en con css #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Binary file added github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Platzi Game 🎮</title>
<link rel="stylesheet" href="styles.css" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="modal" id="modal">
<div class="sub-modal">
<div class="gif" id="gif"></div>
<div class="winner">
<label for="">The winner is:</label>
<label id="winner"></label>
<button id="play-again">Play Again</button>
</div>
</div>
</div>
<div class="container">
<header class="header">
<h1 class="title">Platzi Game</h1>
<div class="circle-1"></div>
<div class="circle-2"></div>
<div class="circle-3"></div>
<div class="circle-4"></div>
</header>
<section class="main">
<div class="card-player1">
<h2>Player 1</h2>
<div class="life-play">
<div class="container-life">
<label class="labelpercent" id="percent1">50%</label>
<div class="life">
<div id="cant-life1"></div>
</div>
</div>
<div class="play" id="play1">
<label>Play</label>
</div>
</div>
<div class="draw">
<img src="player1.png" alt="no_se_dibujar_en_CSS">
</div>
</div>
<div class="card-player2">
<h2>Player 2</h2>
<div class="life-play">
<div class="container-life">
<label class="labelpercent" id="percent2">70%</label>
<div class="life">
<div id="cant-life2"></div>
</div>
</div>
<div class="play" id="play2">
<label>Play</label>
</div>
</div>
<div class="draw">
<img src="player2.png" alt="no_se_dibujar_en_CSS">
</div>
</div>
</section>
<footer class="footer">
<label for="">Made by @jesuslgarciah</label>
<a href="https://github.com/jesuslgarciah" target="_blank">
<img src="./github.png" alt="github">
</a>
<a href="https://twitter.com/jesuslgarciah" target="_blank">
<img src="./twitter.png" alt="twitter">
</a>
<a href="https://instagram.com/jesuslgarciah" target="_blank">
<img src="./instagram.png" alt="instagram">
</a>
</footer>
</div>
<script src="index.js"></script>
</body>
</html>
100 changes: 100 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const player1 = document.getElementById('play1')
const player2 = document.getElementById('play2')
const modal = document.getElementById('modal')
const play_again = document.getElementById('play-again')
const percent1 = document.getElementById('percent1')
const percent2 = document.getElementById('percent2')
const bar_life1 = document.getElementById('cant-life1')
const bar_life2 = document.getElementById('cant-life2')
const gif = document.getElementById('gif')

let playerLife2 = 0
let playerLife1 = 0

init()

player1.addEventListener('click', () => {
disablePlayer(1)
game(1)
})

player2.addEventListener('click', () => {
disablePlayer(2)
game(2)
})

play_again.addEventListener('click', () => {
console.log('play-again')
init()
})

function init(){
disablePlayer()
playerLife2 = 100
playerLife1 = 100
modal.classList.add("none")
gif.innerHTML = ""
percent1.innerHTML = `${playerLife1}%`
percent2.innerHTML = `${playerLife1}%`
bar_life1.style.width = "100%"
bar_life2.style.width = "100%"
}

function disablePlayer(player = 2){
if(player === 1){
player1.classList.add('hiden-play')
player2.classList.remove('hiden-play')
}
else{
player2.classList.add('hiden-play')
player1.classList.remove('hiden-play')
}
}

function randomAttack(){
let attack = Math.floor(Math.random() * 10) + 1
return attack
}

function game(player){
if(playerLife1 > 0 && playerLife2 > 0){
if (player === 1){
playerLife2 -= randomAttack()
percent2.innerHTML = `${playerLife2}%`
bar_life2.style.width = `${playerLife2}%`
if(playerLife2 <= 0){
winner(1)
}
} else if (player === 2){
playerLife1 -= randomAttack()
percent1.innerHTML = `${playerLife1}%`
bar_life1.style.width = `${playerLife1}%`
if(playerLife1 <= 0){
winner(2)
}
}
}
}

function winner(player){
modal.classList.remove("none")
giphy()
let win = `Player ${player}`
const playerLabel = document.getElementById('winner')
playerLabel.innerHTML = win
}

async function giphy(){
const giphyParams = {
baseURL: "https://api.giphy.com/v1/gifs/",
type: "random",
apiKey: "iUF8SB6tppRCuB5bviHb57mdpcO7JKhH",
tag: "fail",
rating: "pg-13"
}
const URL = `${giphyParams.baseURL}${giphyParams.type}?api_key=${giphyParams.apiKey}&tag=${giphyParams.tag}&rating=${giphyParams.rating}`
let api = await fetch(URL)
let response = await api.json()

gif.innerHTML = `<img src="${response.data.image_original_url}" alt="instagram"> `
}
Binary file added instagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added player1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added player2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading