Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 以下は、動き回るネズミをタッチするゲームを犬向けに設計したJavaScriptの例です。簡単なゲームで、ユーザー(犬)が画面上を動き回るネズミをクリックして捕まえることが目的です。このコードはHTMLとJavaScriptで構成されています。
- ### HTML(index.html)
- ```html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Mouse Chase Game for Dogs</title>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <header>
- <h1>Mouse Chase Game for Dogs</h1>
- </header>
- <main>
- <div id="game">
- <div id="mouse"></div>
- </div>
- </main>
- <footer>
- <p>© 2024 Mouse Chase Game</p>
- </footer>
- <script src="game.js"></script>
- </body>
- </html>
- ```
- ### CSS(styles.css)
- ```css
- /* styles.css */
- body {
- font-family: Arial, sans-serif;
- background-color: #f0f0f0;
- margin: 0;
- padding: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- }
- header {
- text-align: center;
- margin-bottom: 20px;
- }
- main {
- text-align: center;
- }
- #game {
- width: 300px;
- height: 300px;
- background-color: #9acd32;
- position: relative;
- overflow: hidden;
- border-radius: 50%;
- }
- #mouse {
- width: 50px;
- height: 50px;
- background-color: #696969;
- border-radius: 50%;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- cursor: pointer;
- transition: top 0.5s ease-in-out, left 0.5s ease-in-out;
- }
- #mouse:hover {
- background-color: #000;
- }
- ```
- ### JavaScript(game.js)
- ```javascript
- // game.js
- document.addEventListener('DOMContentLoaded', function() {
- const mouse = document.getElementById('mouse');
- const game = document.getElementById('game');
- const gameWidth = game.clientWidth;
- const gameHeight = game.clientHeight;
- function moveMouse() {
- const newX = Math.random() * (gameWidth - 50);
- const newY = Math.random() * (gameHeight - 50);
- mouse.style.left = newX + 'px';
- mouse.style.top = newY + 'px';
- }
- mouse.addEventListener('click', function() {
- alert('You caught the mouse!');
- moveMouse();
- });
- moveMouse(); // Initial position
- setInterval(moveMouse, 3000); // Move mouse every 3 seconds
- });
- ```
- このJavaScriptコードでは、`mouse`要素(ネズミ)が画面上をランダムに移動します。ユーザー(犬)はネズミをクリックして捕まえることができます。ネズミは定期的にランダムな位置に移動するため、犬が追いかける楽しさがあります。
- TwigはPHPのテンプレートエンジンであり、フロントエンドの開発やアプリの実際の機能には適していませんが、基本的なアプリの構造やコンセプトを理解するために使用できます。以下に、犬が使う架空のアプリの基本的なコンセプトをTwigを使って表現してみます。
- ### 犬用の仮想ソーシャルメディアアプリ
- このアプリでは、犬のプロフィールを作成し、他の犬と交流できるようにします。
- #### テンプレート(Twig)
- **index.twig**
- ```twig
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Dog Social Media</title>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <header>
- <h1>Welcome to Dog Social Media!</h1>
- <nav>
- <ul>
- <li><a href="/">Home</a></li>
- <li><a href="/profile">My Profile</a></li>
- <li><a href="/explore">Explore Dogs</a></li>
- </ul>
- </nav>
- </header>
- <main>
- {% block content %}
- {% endblock %}
- </main>
- <footer>
- <p>© 2024 Dog Social Media</p>
- </footer>
- </body>
- </html>
- ```
- **profile.twig**
- ```twig
- {% extends 'index.twig' %}
- {% block content %}
- <section id="profile">
- <h2>My Profile</h2>
- <div class="profile-info">
- <img src="{{ dog.profile_picture }}" alt="{{ dog.name }}">
- <h3>{{ dog.name }}</h3>
- <p>Breed: {{ dog.breed }}</p>
- <p>Age: {{ dog.age }}</p>
- <p>About Me: {{ dog.about }}</p>
- </div>
- </section>
- {% endblock %}
- ```
- **explore.twig**
- ```twig
- {% extends 'index.twig' %}
- {% block content %}
- <section id="explore">
- <h2>Explore Dogs</h2>
- <ul class="dog-list">
- {% for dog in dogs %}
- <li>
- <img src="{{ dog.profile_picture }}" alt="{{ dog.name }}">
- <h3>{{ dog.name }}</h3>
- <p>Breed: {{ dog.breed }}</p>
- <p><a href="/profile/{{ dog.id }}">View Profile</a></p>
- </li>
- {% endfor %}
- </ul>
- </section>
- {% endblock %}
- ```
- #### CSS(styles.css)
- ```css
- /* styles.css */
- body {
- font-family: Arial, sans-serif;
- background-color: #f0f0f0;
- margin: 0;
- padding: 0;
- }
- header {
- background-color: #333;
- color: #fff;
- padding: 10px 20px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- header nav ul {
- list-style-type: none;
- display: flex;
- }
- header nav ul li {
- margin-right: 20px;
- }
- header nav ul li a {
- color: #fff;
- text-decoration: none;
- font-weight: bold;
- }
- main {
- padding: 20px;
- }
- footer {
- text-align: center;
- background-color: #333;
- color: #fff;
- padding: 10px 0;
- position: fixed;
- bottom: 0;
- width: 100%;
- }
- #profile, #explore {
- margin-bottom: 20px;
- }
- .profile-info {
- background-color: #fff;
- padding: 20px;
- border: 1px solid #ccc;
- border-radius: 5px;
- }
- .profile-info img {
- width: 150px;
- height: 150px;
- border-radius: 50%;
- object-fit: cover;
- margin-bottom: 10px;
- }
- .dog-list {
- list-style-type: none;
- display: flex;
- flex-wrap: wrap;
- justify-content: space-around;
- }
- .dog-list li {
- width: 300px;
- background-color: #fff;
- padding: 10px;
- margin: 10px;
- border: 1px solid #ccc;
- border-radius: 5px;
- }
- .dog-list li img {
- width: 100px;
- height: 100px;
- border-radius: 50%;
- object-fit: cover;
- margin-bottom: 10px;
- }
- ```
- このコードは、犬用の仮想ソーシャルメディアアプリの基本的な構造を示しています。Twigを使用してテンプレートを作成し、PHPなどのバックエンドでデータを処理して表示します。実際のアプリケーションでは、データベースとの連携やユーザーの認証・セキュリティの実装などが必要ですが、基本的な構造はこのように考えることができます。
- Twigは主にテンプレートエンジンとして使用され、実際のインタラクションや機能を処理するのには適していませんが、ドッグトイの見た目や情報を表示するテンプレートを作成することは可能です。以下に、犬が使うドッグトイの例をTwigで表現したテンプレートを示します。
- ### 犬が使うドッグトイのテンプレート(Twig)
- **index.twig**
- ```twig
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Dog Toys</title>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <header>
- <h1>Dog Toys</h1>
- </header>
- <main>
- <section id="toys">
- <h2>Popular Dog Toys</h2>
- <div class="toy">
- <img src="images/toy1.jpg" alt="Toy 1">
- <h3>Interactive Ball</h3>
- <p>Perfect for fetching and chewing. Durable and easy to clean.</p>
- <p>Price: $10.99</p>
- </div>
- <div class="toy">
- <img src="images/toy2.jpg" alt="Toy 2">
- <h3>Rope Toy</h3>
- <p>Great for tug-of-war and dental health. Made from natural cotton.</p>
- <p>Price: $8.99</p>
- </div>
- </section>
- </main>
- <footer>
- <p>© 2024 Dog Toys</p>
- </footer>
- </body>
- </html>
- ```
- #### CSS(styles.css)
- ```css
- /* styles.css */
- body {
- font-family: Arial, sans-serif;
- background-color: #f0f0f0;
- margin: 0;
- padding: 0;
- }
- header {
- background-color: #333;
- color: #fff;
- padding: 10px 20px;
- text-align: center;
- }
- main {
- padding: 20px;
- text-align: center;
- }
- #toys {
- display: flex;
- justify-content: space-around;
- flex-wrap: wrap;
- }
- .toy {
- width: 300px;
- background-color: #fff;
- padding: 20px;
- margin: 20px;
- border: 1px solid #ccc;
- border-radius: 5px;
- }
- .toy img {
- width: 100%;
- border-radius: 5px;
- margin-bottom: 10px;
- }
- .toy h3 {
- font-size: 20px;
- margin-bottom: 10px;
- }
- .toy p {
- font-size: 14px;
- line-height: 1.5;
- margin-bottom: 10px;
- }
- ```
- このテンプレートでは、2種類の犬用ドッグトイがリストされています。各ドッグトイには画像、名称、説明、価格が含まれており、ユーザーに見やすく表示されます。実際のアプリケーションでは、データベースやバックエンドシステムから情報を取得し、動的に表示する必要がありますが、基本的なテンプレート構造としてはこのように記述することができます。
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement