Advertisement
Guest User

Dog Toy

a guest
Jul 10th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1. 以下は、動き回るネズミをタッチするゲームを犬向けに設計したJavaScriptの例です。簡単なゲームで、ユーザー(犬)が画面上を動き回るネズミをクリックして捕まえることが目的です。このコードはHTMLとJavaScriptで構成されています。
  2.  
  3. ### HTML(index.html)
  4.  
  5. ```html
  6. <!DOCTYPE html>
  7. <html lang="en">
  8. <head>
  9. <meta charset="UTF-8">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <title>Mouse Chase Game for Dogs</title>
  12. <link rel="stylesheet" href="styles.css">
  13. </head>
  14. <body>
  15. <header>
  16. <h1>Mouse Chase Game for Dogs</h1>
  17. </header>
  18.  
  19. <main>
  20. <div id="game">
  21. <div id="mouse"></div>
  22. </div>
  23. </main>
  24.  
  25. <footer>
  26. <p>&copy; 2024 Mouse Chase Game</p>
  27. </footer>
  28.  
  29. <script src="game.js"></script>
  30. </body>
  31. </html>
  32. ```
  33.  
  34. ### CSS(styles.css)
  35.  
  36. ```css
  37. /* styles.css */
  38.  
  39. body {
  40. font-family: Arial, sans-serif;
  41. background-color: #f0f0f0;
  42. margin: 0;
  43. padding: 0;
  44. display: flex;
  45. justify-content: center;
  46. align-items: center;
  47. height: 100vh;
  48. }
  49.  
  50. header {
  51. text-align: center;
  52. margin-bottom: 20px;
  53. }
  54.  
  55. main {
  56. text-align: center;
  57. }
  58.  
  59. #game {
  60. width: 300px;
  61. height: 300px;
  62. background-color: #9acd32;
  63. position: relative;
  64. overflow: hidden;
  65. border-radius: 50%;
  66. }
  67.  
  68. #mouse {
  69. width: 50px;
  70. height: 50px;
  71. background-color: #696969;
  72. border-radius: 50%;
  73. position: absolute;
  74. top: 50%;
  75. left: 50%;
  76. transform: translate(-50%, -50%);
  77. cursor: pointer;
  78. transition: top 0.5s ease-in-out, left 0.5s ease-in-out;
  79. }
  80.  
  81. #mouse:hover {
  82. background-color: #000;
  83. }
  84. ```
  85.  
  86. ### JavaScript(game.js)
  87.  
  88. ```javascript
  89. // game.js
  90.  
  91. document.addEventListener('DOMContentLoaded', function() {
  92. const mouse = document.getElementById('mouse');
  93. const game = document.getElementById('game');
  94. const gameWidth = game.clientWidth;
  95. const gameHeight = game.clientHeight;
  96.  
  97. function moveMouse() {
  98. const newX = Math.random() * (gameWidth - 50);
  99. const newY = Math.random() * (gameHeight - 50);
  100. mouse.style.left = newX + 'px';
  101. mouse.style.top = newY + 'px';
  102. }
  103.  
  104. mouse.addEventListener('click', function() {
  105. alert('You caught the mouse!');
  106. moveMouse();
  107. });
  108.  
  109. moveMouse(); // Initial position
  110.  
  111. setInterval(moveMouse, 3000); // Move mouse every 3 seconds
  112. });
  113. ```
  114.  
  115. このJavaScriptコードでは、`mouse`要素(ネズミ)が画面上をランダムに移動します。ユーザー(犬)はネズミをクリックして捕まえることができます。ネズミは定期的にランダムな位置に移動するため、犬が追いかける楽しさがあります。
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. TwigはPHPのテンプレートエンジンであり、フロントエンドの開発やアプリの実際の機能には適していませんが、基本的なアプリの構造やコンセプトを理解するために使用できます。以下に、犬が使う架空のアプリの基本的なコンセプトをTwigを使って表現してみます。
  124.  
  125. ### 犬用の仮想ソーシャルメディアアプリ
  126.  
  127. このアプリでは、犬のプロフィールを作成し、他の犬と交流できるようにします。
  128.  
  129. #### テンプレート(Twig)
  130.  
  131. **index.twig**
  132.  
  133. ```twig
  134. <!DOCTYPE html>
  135. <html lang="en">
  136. <head>
  137. <meta charset="UTF-8">
  138. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  139. <title>Dog Social Media</title>
  140. <link rel="stylesheet" href="styles.css">
  141. </head>
  142. <body>
  143. <header>
  144. <h1>Welcome to Dog Social Media!</h1>
  145. <nav>
  146. <ul>
  147. <li><a href="/">Home</a></li>
  148. <li><a href="/profile">My Profile</a></li>
  149. <li><a href="/explore">Explore Dogs</a></li>
  150. </ul>
  151. </nav>
  152. </header>
  153.  
  154. <main>
  155. {% block content %}
  156. {% endblock %}
  157. </main>
  158.  
  159. <footer>
  160. <p>&copy; 2024 Dog Social Media</p>
  161. </footer>
  162. </body>
  163. </html>
  164. ```
  165.  
  166. **profile.twig**
  167.  
  168. ```twig
  169. {% extends 'index.twig' %}
  170.  
  171. {% block content %}
  172. <section id="profile">
  173. <h2>My Profile</h2>
  174. <div class="profile-info">
  175. <img src="{{ dog.profile_picture }}" alt="{{ dog.name }}">
  176. <h3>{{ dog.name }}</h3>
  177. <p>Breed: {{ dog.breed }}</p>
  178. <p>Age: {{ dog.age }}</p>
  179. <p>About Me: {{ dog.about }}</p>
  180. </div>
  181. </section>
  182. {% endblock %}
  183. ```
  184.  
  185. **explore.twig**
  186.  
  187. ```twig
  188. {% extends 'index.twig' %}
  189.  
  190. {% block content %}
  191. <section id="explore">
  192. <h2>Explore Dogs</h2>
  193. <ul class="dog-list">
  194. {% for dog in dogs %}
  195. <li>
  196. <img src="{{ dog.profile_picture }}" alt="{{ dog.name }}">
  197. <h3>{{ dog.name }}</h3>
  198. <p>Breed: {{ dog.breed }}</p>
  199. <p><a href="/profile/{{ dog.id }}">View Profile</a></p>
  200. </li>
  201. {% endfor %}
  202. </ul>
  203. </section>
  204. {% endblock %}
  205. ```
  206.  
  207. #### CSS(styles.css)
  208.  
  209. ```css
  210. /* styles.css */
  211.  
  212. body {
  213. font-family: Arial, sans-serif;
  214. background-color: #f0f0f0;
  215. margin: 0;
  216. padding: 0;
  217. }
  218.  
  219. header {
  220. background-color: #333;
  221. color: #fff;
  222. padding: 10px 20px;
  223. display: flex;
  224. justify-content: space-between;
  225. align-items: center;
  226. }
  227.  
  228. header nav ul {
  229. list-style-type: none;
  230. display: flex;
  231. }
  232.  
  233. header nav ul li {
  234. margin-right: 20px;
  235. }
  236.  
  237. header nav ul li a {
  238. color: #fff;
  239. text-decoration: none;
  240. font-weight: bold;
  241. }
  242.  
  243. main {
  244. padding: 20px;
  245. }
  246.  
  247. footer {
  248. text-align: center;
  249. background-color: #333;
  250. color: #fff;
  251. padding: 10px 0;
  252. position: fixed;
  253. bottom: 0;
  254. width: 100%;
  255. }
  256.  
  257. #profile, #explore {
  258. margin-bottom: 20px;
  259. }
  260.  
  261. .profile-info {
  262. background-color: #fff;
  263. padding: 20px;
  264. border: 1px solid #ccc;
  265. border-radius: 5px;
  266. }
  267.  
  268. .profile-info img {
  269. width: 150px;
  270. height: 150px;
  271. border-radius: 50%;
  272. object-fit: cover;
  273. margin-bottom: 10px;
  274. }
  275.  
  276. .dog-list {
  277. list-style-type: none;
  278. display: flex;
  279. flex-wrap: wrap;
  280. justify-content: space-around;
  281. }
  282.  
  283. .dog-list li {
  284. width: 300px;
  285. background-color: #fff;
  286. padding: 10px;
  287. margin: 10px;
  288. border: 1px solid #ccc;
  289. border-radius: 5px;
  290. }
  291.  
  292. .dog-list li img {
  293. width: 100px;
  294. height: 100px;
  295. border-radius: 50%;
  296. object-fit: cover;
  297. margin-bottom: 10px;
  298. }
  299. ```
  300.  
  301. このコードは、犬用の仮想ソーシャルメディアアプリの基本的な構造を示しています。Twigを使用してテンプレートを作成し、PHPなどのバックエンドでデータを処理して表示します。実際のアプリケーションでは、データベースとの連携やユーザーの認証・セキュリティの実装などが必要ですが、基本的な構造はこのように考えることができます。
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308. Twigは主にテンプレートエンジンとして使用され、実際のインタラクションや機能を処理するのには適していませんが、ドッグトイの見た目や情報を表示するテンプレートを作成することは可能です。以下に、犬が使うドッグトイの例をTwigで表現したテンプレートを示します。
  309.  
  310. ### 犬が使うドッグトイのテンプレート(Twig)
  311.  
  312. **index.twig**
  313.  
  314. ```twig
  315. <!DOCTYPE html>
  316. <html lang="en">
  317. <head>
  318. <meta charset="UTF-8">
  319. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  320. <title>Dog Toys</title>
  321. <link rel="stylesheet" href="styles.css">
  322. </head>
  323. <body>
  324. <header>
  325. <h1>Dog Toys</h1>
  326. </header>
  327.  
  328. <main>
  329. <section id="toys">
  330. <h2>Popular Dog Toys</h2>
  331. <div class="toy">
  332. <img src="images/toy1.jpg" alt="Toy 1">
  333. <h3>Interactive Ball</h3>
  334. <p>Perfect for fetching and chewing. Durable and easy to clean.</p>
  335. <p>Price: $10.99</p>
  336. </div>
  337. <div class="toy">
  338. <img src="images/toy2.jpg" alt="Toy 2">
  339. <h3>Rope Toy</h3>
  340. <p>Great for tug-of-war and dental health. Made from natural cotton.</p>
  341. <p>Price: $8.99</p>
  342. </div>
  343. </section>
  344. </main>
  345.  
  346. <footer>
  347. <p>&copy; 2024 Dog Toys</p>
  348. </footer>
  349. </body>
  350. </html>
  351. ```
  352.  
  353. #### CSS(styles.css)
  354.  
  355. ```css
  356. /* styles.css */
  357.  
  358. body {
  359. font-family: Arial, sans-serif;
  360. background-color: #f0f0f0;
  361. margin: 0;
  362. padding: 0;
  363. }
  364.  
  365. header {
  366. background-color: #333;
  367. color: #fff;
  368. padding: 10px 20px;
  369. text-align: center;
  370. }
  371.  
  372. main {
  373. padding: 20px;
  374. text-align: center;
  375. }
  376.  
  377. #toys {
  378. display: flex;
  379. justify-content: space-around;
  380. flex-wrap: wrap;
  381. }
  382.  
  383. .toy {
  384. width: 300px;
  385. background-color: #fff;
  386. padding: 20px;
  387. margin: 20px;
  388. border: 1px solid #ccc;
  389. border-radius: 5px;
  390. }
  391.  
  392. .toy img {
  393. width: 100%;
  394. border-radius: 5px;
  395. margin-bottom: 10px;
  396. }
  397.  
  398. .toy h3 {
  399. font-size: 20px;
  400. margin-bottom: 10px;
  401. }
  402.  
  403. .toy p {
  404. font-size: 14px;
  405. line-height: 1.5;
  406. margin-bottom: 10px;
  407. }
  408. ```
  409.  
  410. このテンプレートでは、2種類の犬用ドッグトイがリストされています。各ドッグトイには画像、名称、説明、価格が含まれており、ユーザーに見やすく表示されます。実際のアプリケーションでは、データベースやバックエンドシステムから情報を取得し、動的に表示する必要がありますが、基本的なテンプレート構造としてはこのように記述することができます。
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement