From 137616c895d92a964c384b0a4345fe1f1c950489 Mon Sep 17 00:00:00 2001 From: JhonAngulo Date: Sat, 15 Aug 2020 22:55:18 -0500 Subject: [PATCH 1/2] first template --- css/normalize.css | 349 ++++++++++++++++++++++++++++++++++++++++++++++ css/style.css | 130 +++++++++++++++++ index.html | 42 ++++++ 3 files changed, 521 insertions(+) create mode 100644 css/normalize.css create mode 100644 css/style.css create mode 100644 index.html diff --git a/css/normalize.css b/css/normalize.css new file mode 100644 index 0000000..192eb9c --- /dev/null +++ b/css/normalize.css @@ -0,0 +1,349 @@ +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ + +/** + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. + */ + +html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/* Sections + ========================================================================== */ + +/** + * Remove the margin in all browsers. + */ + +body { + margin: 0; +} + +/** + * Render the `main` element consistently in IE. + */ + +main { + display: block; +} + +/** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/* Grouping content + ========================================================================== */ + +/** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + +hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Remove the gray background on active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + +abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ +} + +/** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + +b, +strong { + font-weight: bolder; +} + +/** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + +code, +kbd, +samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** + * Add the correct font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove the border on images inside links in IE 10. + */ + +img { + border-style: none; +} + +/* Forms + ========================================================================== */ + +/** + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. + */ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + +button, +input { /* 1 */ + overflow: visible; +} + +/** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + +button, +select { /* 1 */ + text-transform: none; +} + +/** + * Correct the inability to style clickable types in iOS and Safari. + */ + +button, +[type="button"], +[type="reset"], +[type="submit"] { + -webkit-appearance: button; +} + +/** + * Remove the inner border and padding in Firefox. + */ + +button::-moz-focus-inner, +[type="button"]::-moz-focus-inner, +[type="reset"]::-moz-focus-inner, +[type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** + * Restore the focus styles unset by the previous rule. + */ + +button:-moz-focusring, +[type="button"]:-moz-focusring, +[type="reset"]:-moz-focusring, +[type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** + * Correct the padding in Firefox. + */ + +fieldset { + padding: 0.35em 0.75em 0.625em; +} + +/** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + +legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ +} + +/** + * Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + +progress { + vertical-align: baseline; +} + +/** + * Remove the default vertical scrollbar in IE 10+. + */ + +textarea { + overflow: auto; +} + +/** + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. + */ + +[type="checkbox"], +[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + +[type="number"]::-webkit-inner-spin-button, +[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + +[type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** + * Remove the inner padding in Chrome and Safari on macOS. + */ + +[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* Interactive + ========================================================================== */ + +/* + * Add the correct display in Edge, IE 10+, and Firefox. + */ + +details { + display: block; +} + +/* + * Add the correct display in all browsers. + */ + +summary { + display: list-item; +} + +/* Misc + ========================================================================== */ + +/** + * Add the correct display in IE 10+. + */ + +template { + display: none; +} + +/** + * Add the correct display in IE 10. + */ + +[hidden] { + display: none; +} diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..268cc7f --- /dev/null +++ b/css/style.css @@ -0,0 +1,130 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap'); + +/* Colores: #1A46E5 (azul), #43D8C9 (verde), #FFBD11 (amarillo), #FF89BB (rosado), #FFFFFF (blanco) y #000000 (negro). */ + +:root { + --blue-color: #1A46E5; + --green-color: #43D8C9; + --yellow-color: #FFBD11; + --pink-color: #FF89BB; + --white-color: #FFFFFF; + --black-color: #000000; +} + +body { + font-family: 'Poppins', sans-serif; + max-width: 1440px; + margin: 0 auto; +} + +header { + text-align: center; + height: 90px; + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 40px; + line-height: 50px; + color: #100303; +} + +.circle { + position: absolute; + background-color: var(--blue-color); + border-radius: 50%; +} + +.t1 { + top: 26px; + left: -38px; + width: 120px; + height: 120px; +} + +.t2 { + top: 16px; + left: 100px; + width: 60px; + height: 60px; +} + +.t3 { + top: -160px; + right: 80px; + width: 220px; + height: 220px; +} + +.t4 { + top: 60px; + right: 60px; + width: 40px; + height: 40px; +} +.container { + margin: 0 auto; + display: flex; + justify-content: space-evenly; +} + +.card { + width: 320px; + height: 400px; + background-color: var(--green-color); + border: 3px solid var(--black-color); + box-sizing: border-box; + border-radius: 20px; +} + +.player_2 { + background-color: var(--yellow-color); +} + +.card_title { + margin-top: 20px; + text-align: center; + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 30px; + line-height: 50px; + color: var(--white-color); +} + +.card_actions { + margin: 30px; + height: 80px; +} + +.card_actions--button { + width: 80px; + height: 80px; + border-radius: 50%; + background-color: var(--blue-color); + color: var(--white-color); + border: 3px solid #000000; + box-sizing: border-box; + + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 26px; + line-height: 30px; +} + +.card_body { + margin: 0 auto; + width: 85%; + height: 150px; + background-color: var(--white-color); + border-radius: 20px; + border: 3px solid var(--black-color); + box-sizing: border-box; + border-radius: 20px; +} + +footer { + margin-top: 30px; + text-align: right; + margin-right: 50px; +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..5adc673 --- /dev/null +++ b/index.html @@ -0,0 +1,42 @@ + + + + + + + + Platzi Game + + +
+
+
+

Platzi Game

+
+
+
+
+
+
Player 1
+
+
+ +
+
+
+ +
+
Player 2
+
+
+ +
+
+
+
+ + + + \ No newline at end of file From a6bf2fbf160ab2938fa9e526cd41c6ca330cafb0 Mon Sep 17 00:00:00 2001 From: JhonAngulo Date: Mon, 17 Aug 2020 00:50:44 -0500 Subject: [PATCH 2/2] resolve challenge-prework-frontend --- css/character_1.css | 190 +++++++++++++++++++++++++++++++++++++++ css/character_2.css | 214 ++++++++++++++++++++++++++++++++++++++++++++ css/style.css | 165 ++++++++++++++++++++++++++++++++-- index.html | 193 +++++++++++++++++++++++++++++++-------- js/script.js | 165 ++++++++++++++++++++++++++++++++++ 5 files changed, 886 insertions(+), 41 deletions(-) create mode 100644 css/character_1.css create mode 100644 css/character_2.css create mode 100644 js/script.js diff --git a/css/character_1.css b/css/character_1.css new file mode 100644 index 0000000..24af6e7 --- /dev/null +++ b/css/character_1.css @@ -0,0 +1,190 @@ +.character__container { + margin: 0 auto; + margin-top: 1rem; + position: relative; + z-index: 1; +} + +.character__body { + position: relative; + width: 10rem; + height: 11rem; + background-color: #0e3441; + border-radius: 2rem; +} + +.character__body::before { + position: absolute; + content: ''; + right: -1rem; + bottom: 1rem; + width: 2rem; + height: 6rem; + background-color: #00b0ad; + border-radius: 50px; +} + +.character__body::after { + position: absolute; + content: ''; + left: -0.75rem; + bottom: 1rem; + width: 2rem; + height: 6rem; + background-color: #008790; + border-radius: 50px; + z-index: -1; +} + +.character__antenna--left { + position: absolute; + top: 0rem; + right: 1rem; + width: 1.5rem; + height: 4rem; + border-radius: 50px; + background-color: #a8d2e8; +} + +.character__antenna--right { + width: 1.5rem; + height: 4rem; + margin-bottom: -1.5rem; + margin-left: 0.5rem; + border-radius: 50px; + background-color: #5cbee3; +} + +.character__eyes { + position: absolute; + top: 4rem; + left: 1rem; + width: 1.5rem; + height: 0.5rem; + background-color: #cad422; + border-radius: 50px; +} + +.character__eyes::before { + position: absolute; + content: ''; + left: 4rem; + width: 1.5rem; + height: 0.5rem; + background-color: #cad422; + border-radius: 50px; +} + +.character__mouth { + position: absolute; + top: 5.5rem; + left: 0.5rem; + width: 8rem; + height: 4rem; + border-radius: 1rem; + background-color: #00b0ad; +} + +.points__mouth { + width: 1rem; + height: 1rem; + background-color: white; + border-radius: 50px; + margin-top: 0.5rem; + margin-left: 0.5rem; +} + +.points__mouth::before { + position: absolute; + content: ''; + left: 5rem; + width: 1rem; + height: 1rem; + background-color: white; + border-radius: 50px; +} + +.teeth__container { + display: flex; + width: 80%; + margin: 0 auto; + justify-content: space-evenly; +} + +.teeth__container--down { + position: absolute; + bottom: 0rem; + left: 0.75rem; + display: flex; + width: 80%; + margin: 0 auto; + justify-content: space-evenly; + transform: rotate(180deg); +} + +.teeth__1 { + width: 1rem; + height: 1rem; + border-radius: 0 0 50% 50%; + background-color: #55c7d9; +} + +.teeth__2 { + width: 1rem; + height: 1rem; + border-radius: 0 0 50% 50%; + background-color: #55c7d9; +} + +.teeth__3 { + width: 1rem; + height: 1rem; + border-radius: 0 0 50% 50%; + background-color: #55c7d9; +} + +.teeth__4 { + width: 1rem; + height: 1rem; + border-radius: 0 0 50% 50%; + background-color: #55c7d9; +} + +.teeth__5 { + width: 1rem; + height: 1rem; + border-radius: 0 0 50% 50%; + background-color: #55c7d9; +} + +.character__feets { + position: absolute; + width: 2rem; + height: 2.5rem; + bottom: -2.5rem; + left: 2.5rem; + border-radius: 0 0 50px 50px; + background-color: #001623; +} + +.character__feets::before { + position: absolute; + content: ''; + width: 2rem; + height: 2.5rem; + left: 3rem; + border-radius: 0 0 50px 50px; + background-color: #0e3441; +} + +.character__feets::after { + position: absolute; + content: ''; + width: 7.5rem; + height: 1rem; + left: -0.75rem; + bottom: -0.25rem; + border-radius: 50px; + background-color: #a8d2e7; + z-index: -1; +} \ No newline at end of file diff --git a/css/character_2.css b/css/character_2.css new file mode 100644 index 0000000..e45a1d5 --- /dev/null +++ b/css/character_2.css @@ -0,0 +1,214 @@ +/* *{ + border: 2px solid red !important; +} */ + + +.character_2__container { + margin: 0 auto; + margin-top: 1.5rem; + position: relative; + z-index: 1; +} + +.character_2_eyes { + display: flex; + margin-left: -1rem; +} + +.container__eye { + position: relative; + width: 3rem; + height: 3rem; + background-color: #00b0ad; + border-radius: 50%; +} + +.eye__left { + background-color: #008891; +} + +.container__eye::before { + content: ''; + position: absolute; + top: 0.5rem; + left: 0.5rem; + width: 2rem; + height: 2rem; + background-color: white; + border-radius: 50%; +} + +.container__eye::after { + content: ''; + position: absolute; + top: 1rem; + left: 0.8rem; + width: 0.8rem; + height: 0.8rem; + background-color: #103142; + border-radius: 50%; +} + +.eyes_lines { + display: flex; + margin-left: -1rem; +} + +.eye__line{ + width: 0.7rem; + height: 4rem; + background-color: #008891; + margin-top: -1rem; + margin-left: 2rem; + z-index: -1; +} + +.eye__line--right{ + width: 0.7rem; + height: 4rem; + background-color: #00b0ad; + margin-top: -1rem; + margin-left: 2rem; +} + +.character_2__body { + margin-top: -1rem;; + width: 6rem; + height: 6rem; + background-color: #00b0ad; + border-radius: 50%; +} + +.character_2__hand { + position: absolute; + bottom: 7.2rem; + right: -1rem; + width: 2rem; + height: 3.4rem; + border-radius: 50px; + transform: rotate(-45deg); + background-color: #46c2c2; +} + +.character_2__hand--left { + position: absolute; + bottom: 7.5rem; + left: -2.5rem; + width: 2rem; + height: 2rem; + border-radius: 50px; + background-color: #01b1ae; + box-shadow: 0px 14px 0px -4px #0e3441; +} + +.character_2__hand--left::before { + content: ''; + position: absolute; + bottom: 0rem; + left: 1rem; + width: 2rem; + height: 2rem; + z-index: -1; + background-color: #008385; +} + +.character_2__hand--left::after { + content: ''; + position: absolute; + bottom: 1rem; + left: 1.3rem; + width: 0.7rem; + height: 1.2rem; + border-radius: 20px; + background-color: #46c2c2; +} + +.character_2__arm { + z-index: -1; + position: absolute; + bottom: 1rem; + left: -1.5rem; + width: 4rem; + height: 4rem; + border-radius: 100px; + background-color: #0e3441; +} + +.character_2__arm--circle { + position: absolute; + bottom: 2.5rem; + right: 6rem; + width: 1rem; + height: 1rem; + border-radius: 100px; + background-color: #0e3441; +} + +.character_2__arm--circle::before { + position: absolute; + content: ''; + left: 0.5rem; + top: 0.35rem; + width: 4rem; + height: 0.2rem; + background-color: #0e3441; +} + +.character_2__arm--line{ + position: absolute; + top: -3rem; + right: 4rem; + width: 0.6rem; + height: 4rem; + border-radius: 20px; + background-color: #f15a45; +} + +.character_2__arm--line::before { + content: ''; + position: absolute; + top: 1rem; + right: 1rem; + width: 0.6rem; + height: 2rem; + border-radius: 20px; + background-color: #f15a45; +} + +.character_2_feets { + display: flex; + position: relative; +} + +.character_2_feet--left { + position: absolute; + top: -2rem; + left: 1rem; + width: 2rem; + height: 5rem; + border-radius: 50px; + background-color: #00b0ad; + transform: rotate(45deg); +} + +.character_2_feet--right { + position: absolute; + top: -2.1rem; + right: -1.5rem; + width: 4.5rem; + height: 2rem; + border-radius: 50px; + background-color: #008891; + z-index: -1; +} + +.character_2_footer { + position: absolute; + z-index: -1; + left: -1rem; + bottom: 2.3rem; + width: 12rem; + height: 1.3rem; + border-radius: 50px; + background-color: #a8e0fb; +} \ No newline at end of file diff --git a/css/style.css b/css/style.css index 268cc7f..e879c17 100644 --- a/css/style.css +++ b/css/style.css @@ -11,6 +11,10 @@ --black-color: #000000; } +html { + font-size: 8px; +} + body { font-family: 'Poppins', sans-serif; max-width: 1440px; @@ -23,7 +27,7 @@ header { font-family: Poppins; font-style: normal; font-weight: bold; - font-size: 40px; + font-size: 5rem; line-height: 50px; color: #100303; } @@ -94,6 +98,74 @@ header { .card_actions { margin: 30px; height: 80px; + display: flex; + justify-content: space-between; +} + +.card_actions__live { + width: 18rem; + height: 10rem; + text-align: center; +} + +.card_actions__percentage { + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 3rem; + line-height: 5rem; + color: var(--white-color); +} + +.card_actions__percentage--graphic { + width: 100%; + height: 3.5rem; + border-radius: 50px; + border: 3px solid var(--black-color); +} + +.card_actions__percentage--graphic.life_100 { + background: var(--pink-color); +} + +.card_actions__percentage--graphic.life_90 { + background: linear-gradient(to right, var(--pink-color) 90%, var(--blue-color) 10%); +} + +.card_actions__percentage--graphic.life_80 { + background: linear-gradient(to right, var(--pink-color) 80%, var(--blue-color) 20%); +} + +.card_actions__percentage--graphic.life_70 { + background: linear-gradient(to right, var(--pink-color) 70%, var(--blue-color) 30%); +} + +.card_actions__percentage--graphic.life_60 { + background: linear-gradient(to right, var(--pink-color) 60%, var(--blue-color) 40%); +} + +.card_actions__percentage--graphic.life_50 { + background: linear-gradient(to right, var(--pink-color) 50%, var(--blue-color) 50%); +} + +.card_actions__percentage--graphic.life_40 { + background: linear-gradient(to left, var(--blue-color) 60%, var(--pink-color) 40%); +} + +.card_actions__percentage--graphic.life_30 { + background: linear-gradient(to left, var(--blue-color) 70%, var(--pink-color) 30%); +} + +.card_actions__percentage--graphic.life_20 { + background: linear-gradient(to left, var(--blue-color) 80%, var(--pink-color) 20%); +} + +.card_actions__percentage--graphic.life_10 { + background: linear-gradient(to left, var(--blue-color) 90%, var(--pink-color) 10%); +} + +.card_actions__percentage--graphic.life_0 { + background: var(--blue-color); } .card_actions--button { @@ -104,12 +176,17 @@ header { color: var(--white-color); border: 3px solid #000000; box-sizing: border-box; - + outline: none; font-family: Poppins; font-style: normal; font-weight: bold; font-size: 26px; line-height: 30px; + box-shadow: 1px 3px 0px 0px rgba(0,0,0); +} + +.card_actions--button.disabled { + background-color: grey; } .card_body { @@ -121,10 +198,86 @@ header { border: 3px solid var(--black-color); box-sizing: border-box; border-radius: 20px; + display: flex; } -footer { - margin-top: 30px; - text-align: right; +.footer { + + margin-top: 20px; margin-right: 50px; -} \ No newline at end of file + font-size: 2rem; + display: flex; + justify-content: flex-end; + align-items: center; +} + +.footer_icon { + margin: 0 5px; +} + +.modal { + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100vw; + height: 100vh; + overflow: none; + background-color: rgba(0,0,0,0.4); +} + +.modal__container { + background-color: #fefefe; + margin: 6% auto; + padding: 20px; + border: 3px solid var(--black-color); + width: 70%; + height: 65%; + border-radius: 20px; + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 3rem; + line-height: 3rem; +} + +.card-winner { + display: flex; + padding: 5% 10%; + justify-content: space-around; +} + +.card__gif { + width: 40rem; + height: 40rem; + border-radius: 20px; + border: 2px solid var(--black-color); + background-repeat: no-repeat; + background-size: cover; + background-position: center; +} + +.card__info { + margin: auto 0; + text-align: center; + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 3rem; +} + +.btn__play--again { + background-color: var(--blue-color); + color: white; + padding: 14px 40px; + font-family: Poppins; + font-style: normal; + font-weight: bold; + font-size: 3rem; + line-height: 3rem; + border-radius: 50px; + border: 3px solid var(--black-color); + outline: none; +} + diff --git a/index.html b/index.html index 5adc673..5047b10 100644 --- a/index.html +++ b/index.html @@ -1,42 +1,165 @@ - - - - - - Platzi Game - - -
-
-
-

Platzi Game

-
-
-
-
-
-
Player 1
-
-
- + + + + + + + + Platzi Game + + +
+
+
+

Platzi Game

+
+
+
+
+
+
Player 1
+
+
+ 100% +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
Player 2
-
-
- +
+
Player 2
+
+
+ 100% +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + + + - -
-

Made by JhonAngulo G T

-
- - \ No newline at end of file + + + + diff --git a/js/script.js b/js/script.js new file mode 100644 index 0000000..043a1dd --- /dev/null +++ b/js/script.js @@ -0,0 +1,165 @@ +'use strict' + +const winner = document.getElementById('winner') +const btn_player_1 = document.getElementById('btn_player_1') +const btn_player_2 = document.getElementById('btn_player_2') +const player_1_life = document.getElementById('player_1_life') +const player_2_life = document.getElementById('player_2_life') +const player_1_life_g = document.getElementById('player_1_life_g') +const player_2_life_g = document.getElementById('player_2_life_g') +const card__gif = document.getElementsByClassName('card__gif')[0] +const modal = document.getElementById('modal') +const span = document.getElementsByClassName('btn__play--again')[0] + +const players = { + player_1: { + life: 100, + }, + player_2: { + life: 100, + }, +} + +var turn = 'btn_player_1' + +class Gif { + constructor() { + this.api_key = '6kYAkQBA8YPQLiGdydHT8mxx17PFFQzF' + } + + async getGif() { + let gif = await fetch( + `https://api.giphy.com/v1/gifs/random?api_key=${this.api_key}&tag=winner&rating=g`, + { + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + }, + } + ) + const { data } = await gif.json() + console.log(data.images.downsized_medium.url) + card__gif.style.backgroundImage = `url('${data.images.downsized_medium.url}')` + } +} + +// modal.style.display = "block"; + +const gif = new Gif() + +const lifeLevel = (life) => { + switch (true) { + case life > 90: + return 'life_90' + + case life > 80: + return 'life_80' + + case life > 70: + return 'life_70' + + case life > 60: + return 'life_60' + + case life > 50: + return 'life_50' + + case life > 40: + return 'life_40' + + case life > 30: + return 'life_30' + + case life > 20: + return 'life_20' + + case life > 1: + return 'life_10' + + default: + return 'life_0' + } +} + +const resetGamme = () => { + players.player_1.life = 100 + players.player_2.life = 100 + player_1_life.textContent = `100%` + player_2_life.textContent = `100%` + player_1_life_g.className = `card_actions__percentage--graphic life_100` + player_2_life_g.className = `card_actions__percentage--graphic life_100` + btn_player_1.className = 'card_actions--button' + btn_player_2.className = 'card_actions--button disabled' + return +} + +const checkWinner = () => { + if (players.player_1.life == 0) { + console.log('Player 2 Winner') + resetGamme() + gif.getGif() + winner.textContent = 'Player 2' + modal.style.display = 'block' + } else if (players.player_2.life == 0) { + console.log('Player 1 Winner') + resetGamme() + gif.getGif() + winner.textContent = 'Player 1' + modal.style.display = 'block' + } +} + +const attack = (player) => { + let value = Math.floor(Math.random() * (30 - 0) + 0) + + if (player == 'btn_player_1') { + let life = players.player_2.life + life - value >= 0 ? (life -= value) : (life = 0) + players.player_2.life = life + player_2_life.textContent = `${players.player_2.life}%` + player_2_life_g.className = `card_actions__percentage--graphic ${lifeLevel( + life + )}` + } else { + let life = players.player_1.life + life - value >= 0 ? (life -= value) : (life = 0) + players.player_1.life = life + player_1_life.textContent = `${players.player_1.life}%` + player_1_life_g.className = `card_actions__percentage--graphic ${lifeLevel( + life + )}` + } + + checkWinner() +} + +const play = (event) => { + if (event.target.id == turn) { + if (turn == 'btn_player_1' ) { + btn_player_2.className = 'card_actions--button' + btn_player_1.className = 'card_actions--button disabled' + } else { + btn_player_1.className = 'card_actions--button' + btn_player_2.className = 'card_actions--button disabled' + } + attack(event.target.id) + turn = turn == 'btn_player_1' ? 'btn_player_2' : 'btn_player_1' + + } else { + swal("it's not your turn"); + } +} + +btn_player_1.addEventListener('click', (event) => { + play(event) +}) + +btn_player_2.addEventListener('click', (event) => { + play(event) +}) + + + +span.onclick = function () { + modal.style.display = 'none' +}