-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add example of function memory game #2313
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [package] | ||
| name = "function_memory_game" | ||
| version = "0.1.0" | ||
| authors = ["Howard.Zuo <leftstick@qq.com>"] | ||
| edition = "2018" | ||
| license = "MIT OR Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| strum = "0.23" | ||
| strum_macros = "0.23" | ||
| gloo = "0.4" | ||
| nanoid = "0.4" | ||
| rand = "0.8" | ||
| getrandom = { version = "0.2", features = ["js"] } | ||
| yew = { path = "../../packages/yew" } | ||
|
|
||
| [dependencies.web-sys] | ||
| version = "0.3" | ||
| features = [ | ||
| "HtmlInputElement", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # rust-memory-game | ||
|
|
||
|
|
||
| A port version of [react-memory-game](https://github.com/leftstick/react-memory-game). You are able to try it at [here](https://img.shields.io/website?label=demo&url=https%3A%2F%2Fexamples.yew.rs%2Ffunction_memory_game)](https://examples.yew.rs/function_memory_game) | ||
|
Comment on lines
+1
to
+4
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we adjust this to be more in line with the other examples? I.e. title, example badge. Also that [here] markdown is all over the place.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WIll update it |
||
|
|
||
| ## Concepts | ||
|
|
||
| - Uses [`function_components`](https://yew.rs/docs/next/concepts/function-components) | ||
| - Uses [`gloo_storage`](https://gloo-rs.web.app/docs/storage) to persist the state | ||
|
|
||
|
|
||
|
|
||
| ## LICENSE | ||
|
|
||
| [MIT License](https://raw.githubusercontent.com/yewstack/yew/examples/function_memory_game/master/LICENSE) | ||
|
Comment on lines
+13
to
+15
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird link and probably not really needed since the license isn't particular to this example, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, it should be removed. Thanks for reminding |
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||
| <!DOCTYPE html> | ||||||||||
| <html lang="en"> | ||||||||||
| <head> | ||||||||||
| <meta charset="utf-8" /> | ||||||||||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||||||||||
| <link rel="icon" href="public/favicon.ico" /> | ||||||||||
| <title>Yew • Function MemoryGame</title> | ||||||||||
| <base data-trunk-public-url/> | ||||||||||
|
Comment on lines
+7
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless it's actually supposed to be stylised as MemoryGame...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will update |
||||||||||
|
|
||||||||||
| <link data-trunk rel="sass" href="scss/index.scss" /> | ||||||||||
| <link data-trunk rel="copy-dir" href="public/" /> | ||||||||||
|
|
||||||||||
| </head> | ||||||||||
| <body></body> | ||||||||||
| </html> | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| .chess-board { | ||
| margin-top: 20px; | ||
| width: 100%; | ||
| background-color: #fff; | ||
| height: 530px; | ||
| border-radius: 4px; | ||
| padding: 10px 5px; | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| justify-content: center; | ||
| align-items: center; | ||
| align-content: space-around; | ||
| .chess-board-card-container:nth-child(4n) { | ||
| margin-right: 0px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 450px) { | ||
| .chess-board { | ||
| height: 480px; | ||
| padding: 10px 0px; | ||
| } | ||
| } | ||
| @media screen and (max-width: 370px) { | ||
| .chess-board { | ||
| height: 450px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| .chess-board-card-container { | ||
| width: 100px; | ||
| height: 121px; | ||
| margin-right: 3px; | ||
| cursor: pointer; | ||
| position: relative; | ||
| perspective: 800px; | ||
|
|
||
| .card { | ||
| width: 100%; | ||
| height: 100%; | ||
| transition: transform 1s; | ||
| transform-style: preserve-3d; | ||
| } | ||
|
|
||
| .card.flipped { | ||
| transform: rotateY(180deg); | ||
| } | ||
|
|
||
| .card img { | ||
| display: block; | ||
| height: 100%; | ||
| width: 100%; | ||
| position: absolute; | ||
| backface-visibility: hidden; | ||
| } | ||
|
|
||
| .card .back { | ||
| background: blue; | ||
| transform: rotateY(0deg); | ||
| } | ||
|
|
||
| .card .front { | ||
| background: blue; | ||
| transform: rotateY(180deg); | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 450px) { | ||
| .chess-board-card-container { | ||
| width: 92px; | ||
| height: 111px; | ||
| margin-right: 1px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 395px) { | ||
| .chess-board-card-container { | ||
| width: 85px; | ||
| height: 102px; | ||
| margin-right: 1px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 360px) { | ||
| .chess-board-card-container { | ||
| width: 70px; | ||
| height: 84px; | ||
| margin-right: 1px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| .game-progress { | ||
| width: 120px; | ||
| height: 100px; | ||
| padding: 10px; | ||
| background-color: #bbada0; | ||
| border-radius: 5px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| color: #eae0d1; | ||
|
|
||
| span { | ||
| font-size: 19px; | ||
| font-weight: bold; | ||
| display: block; | ||
| width: 100%; | ||
| text-align: center; | ||
| } | ||
|
|
||
| h2 { | ||
| color: #fff; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 450px) { | ||
| .game-progress { | ||
| width: 105px; | ||
| span { | ||
| font-size: 17px; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 380px) { | ||
| .game-progress { | ||
| width: 95px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 360px) { | ||
| .game-progress { | ||
| width: 90px; | ||
| span { | ||
| font-size: 15px; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| .game-status-container { | ||
| position: relative; | ||
| margin-top: 10px; | ||
| width: 100%; | ||
| height: 20px; | ||
| line-height: 20px; | ||
| text-align: center; | ||
| font-size: 18px; | ||
| font-weight: bold; | ||
| a { | ||
| text-decoration: none; | ||
| cursor: pointer; | ||
| color: #5979ab; | ||
| } | ||
| .sec-past { | ||
| position: absolute; | ||
| right: 10px; | ||
| font-size: 15px; | ||
| font-weight: normal; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| * { | ||
| box-sizing: border-box; | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| html, | ||
| body { | ||
| height: 100vh; | ||
| width: 100vw; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| body { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .game-panel { | ||
| width: 450px; | ||
| height: 670px; | ||
| border: 4px solid #bdbdbd; | ||
| border-radius: 2px; | ||
| background-color: #faf8ef; | ||
| padding: 10px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| @media screen and (max-width: 450px) { | ||
| .game-panel { | ||
| width: 100%; | ||
| height: 100%; | ||
| justify-content: space-around; | ||
| } | ||
| } | ||
|
|
||
| @import './score_board.scss'; | ||
| @import './score_board_best_score.scss'; | ||
| @import './game_progress'; | ||
| @import './chess_board.scss'; | ||
| @import './chess_board_card.scss'; | ||
| @import './game_status_board.scss'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| .score-board { | ||
| width: 100%; | ||
| height: 100px; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| .logo { | ||
| width: 160px; | ||
| height: 100px; | ||
| line-height: 90px; | ||
| padding: 5px; | ||
| border-radius: 5px; | ||
| background-color: #5979ac; | ||
| color: #fff; | ||
| text-align: center; | ||
| } | ||
| a { | ||
| text-decoration: none; | ||
| color: #fff; | ||
| } | ||
| } | ||
|
|
||
| // score board -> logo | ||
|
|
||
| @media screen and (max-width: 450px) { | ||
| .score-board .logo { | ||
| width: 150px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 380px) { | ||
| .score-board .logo { | ||
| width: 140px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 360px) { | ||
| .score-board { | ||
| .logo { | ||
| width: 110px; | ||
| } | ||
| a { | ||
| font-size: 18px; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| .best-score { | ||
| width: 120px; | ||
| height: 100px; | ||
| padding: 10px; | ||
| background-color: #bbada0; | ||
| border-radius: 5px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| color: #eae0d1; | ||
| span { | ||
| font-size: 19px; | ||
| font-weight: bold; | ||
| display: block; | ||
| width: 100%; | ||
| text-align: center; | ||
| } | ||
|
|
||
| h2 { | ||
| color: #fff; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 450px) { | ||
| .best-score { | ||
| width: 105px; | ||
| span { | ||
| font-size: 17px; | ||
| } | ||
| } | ||
| } | ||
| @media screen and (max-width: 380px) { | ||
| .best-score { | ||
| width: 95px; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 360px) { | ||
| .best-score { | ||
| width: 90px; | ||
| span { | ||
| font-size: 15px; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| pub mod chessboard; | ||
| pub mod chessboard_card; | ||
| pub mod game_status_board; | ||
| pub mod score_board; | ||
| pub mod score_board_best_score; | ||
| pub mod score_board_logo; | ||
| pub mod score_board_progress; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| use yew::prelude::*; | ||
|
|
||
| use crate::components::chessboard_card::ChessboardCard; | ||
| use crate::state::{Card, RawCard}; | ||
|
|
||
| #[derive(Properties, Clone, PartialEq)] | ||
| pub struct Props { | ||
| pub cards: Vec<Card>, | ||
| pub on_flip: Callback<RawCard>, | ||
| } | ||
|
|
||
| #[function_component] | ||
| pub fn Chessboard(props: &Props) -> Html { | ||
| html! { | ||
| <div class="chess-board"> | ||
| { for props.cards.iter().map(|card| | ||
| html! { | ||
| <ChessboardCard card={card.clone()} on_flip={&props.on_flip} /> | ||
| } | ||
| ) } | ||
| </div> | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted alphabetically:
Hope I didn't mess up the indentation on my phone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will update