• 养了个羊(简易版)


    不出意外 大家是我的粉丝吧

    圈粉操作一波~

    话不多说直接给大家上源码

     注:本案例是根据网上代码进行了优化改动 禁止网上传阅!!!

     注:本案例是根据网上代码进行了优化改动 禁止网上传阅!!!

     注:本案例是根据网上代码进行了优化改动 禁止网上传阅!!!

    目录

    目录就是最简单的目录 只需要建立audio文件夹 css文件夹 imgs文件夹 king文件夹 和一个index.html文件就行啦!~

    代码块

    接着这一步 复制粘贴 ctrl+c ctrl+v大家都会吧

    把下面这段代码直接进行复制粘贴到index.html文件中 就完事了!

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <link rel="stylesheet" href="css/PC.css" class="equipment">
    8. <link rel="shortcut icon" href="imgs/icon.jpg">
    9. <title>养了个羊</title>
    10. <style>
    11. :root {
    12. --top-text-color: #ffffff;
    13. }
    14. * {
    15. margin: 0;
    16. padding: 0;
    17. }
    18. body {
    19. width: 100vw;
    20. height: 100vh;
    21. overflow: hidden;
    22. background-image: url(king/BG1.jpg);
    23. background-size: cover;
    24. background-position: left;
    25. background-color: #b6b6b6;
    26. user-select: none;
    27. }
    28. .reset {
    29. width: 75px;
    30. }
    31. .controlBGM {
    32. position: fixed;
    33. top: 20px;
    34. left: 20px;
    35. background-color: transparent;
    36. border: none;
    37. }
    38. .surplus {
    39. position: fixed;
    40. top: 15px;
    41. right: 20px;
    42. color: var(--top-text-color);
    43. font-size: 22px;
    44. font-weight: 800;
    45. text-shadow: 0 0 5px black;
    46. }
    47. .surplus::before {
    48. content: '剩余 ';
    49. font-size: 16px;
    50. }
    51. .operate {
    52. width: 100vw;
    53. position: fixed;
    54. bottom: 100px;
    55. left: 0;
    56. display: flex;
    57. justify-content: center;
    58. }
    59. .operate button {
    60. width: 55px;
    61. height: 40px;
    62. background-color: #ffffff;
    63. border-radius: 3px;
    64. font-size: 14px;
    65. color: rgb(66, 144, 255);
    66. font-weight: 800;
    67. border: none;
    68. margin: 0 8px;
    69. }
    70. @keyframes fade {
    71. 100% {
    72. opacity: 0.2;
    73. transform: scale(0.5);
    74. }
    75. }
    76. @keyframes enter {
    77. 0% {
    78. transform: scale(0);
    79. }
    80. }
    81. .levelBox {
    82. display: none;
    83. }
    84. .levelBox>div {
    85. width: 100vw;
    86. height: 100vh;
    87. position: fixed;
    88. z-index: 999;
    89. top: 0;
    90. left: 0;
    91. background-color: rgba(0, 0, 0, 0.5);
    92. display: flex;
    93. justify-content: center;
    94. align-items: center;
    95. flex-direction: column;
    96. }
    97. .levelBox>div button {
    98. width: 200px;
    99. height: 45px;
    100. margin-top: 20px;
    101. font-size: 16px;
    102. color: #060200;
    103. background-color: rgb(250, 250, 250);
    104. border: 1px solid transparent;
    105. animation: enter .3s;
    106. }
    107. .levelBox>div button.win {
    108. color: rgb(255, 102, 0);
    109. font-weight: 800;
    110. }
    111. .chronoscope {
    112. position: fixed;
    113. top: 60px;
    114. right: 20px;
    115. color: var(--top-text-color);
    116. font-weight: 700;
    117. text-shadow: 0 0 5px black;
    118. }
    119. .chronoscope::after {
    120. content: ' S';
    121. }
    122. .updataPage {
    123. width: 26px;
    124. color: var(--top-text-color);
    125. font-size: 14px;
    126. position: fixed;
    127. top: 70px;
    128. left: 23px;
    129. border: 2px solid var(--top-text-color);
    130. background-color: transparent;
    131. font-weight: 800;
    132. }
    133. button:focus {
    134. outline: none;
    135. }
    136. .box {
    137. border-color: rgb(99, 164, 255);
    138. bottom: 25px;
    139. }
    140. .goods {
    141. padding: 23px;
    142. filter: grayscale(6%);
    143. }
    144. .goods.grey {
    145. filter: grayscale(100%);
    146. }
    147. .hrefSheep {
    148. position: fixed;
    149. top: 100px;
    150. right: 20px;
    151. color: white;
    152. }
    153. </style>
    154. </head>
    155. <body>
    156. <button class="controlBGM"></button>
    157. <div class="surplus"></div>
    158. <div class="chronoscope">0</div>
    159. <button class="updataPage" onclick="javascript:location.reload();">更新</button>
    160. <a href="king.html" class="hrefSheep">养了个羊</a>
    161. <div class="operate">
    162. <button class="disorganize">洗牌</button>
    163. <button class="recall">撤回</button>
    164. <button class="lightUp">点亮</button>
    165. <button class="selectLevel" level="5" index="0">第一关</button>
    166. <button class="reset">重置</button>
    167. </div>
    168. <div class="levelBox">
    169. <div>
    170. <button level="5" index="0">第一关</button>
    171. <button level="8" index="1">第二关</button>
    172. <button level="11" index="2">第三关</button>
    173. <button level="14" index="3">第四关</button>
    174. <button level="17" index="4">第五关</button>
    175. <button level="20" index="5">第六关</button>
    176. <button level="24" index="6">第七关</button>
    177. <button level="29" index="7">第八关</button>
    178. <button level="34" index="8">第九关</button>
    179. <button level="40" index="9">第十关</button>
    180. </div>
    181. </div>
    182. <div class="box"></div>
    183. <audio muted autoplay src="audio/失败.mp3"></audio>
    184. <audio muted autoplay src="audio/胜利2.mp3"></audio>
    185. <audio autoplay loop class="BGAudio"></audio>
    186. <script>
    187. const html = document.documentElement;
    188. const body = document.body;
    189. const box = document.querySelector('.box');
    190. let allGoods = document.querySelectorAll('.goods');
    191. const selectLevel = document.querySelector('.selectLevel');
    192. const disorganize = document.querySelector('.disorganize');
    193. const reset = document.querySelector('.reset');
    194. const BGAudio = document.querySelector('.BGAudio');
    195. const controlBGM = document.querySelector('.controlBGM');
    196. const recall = document.querySelector('.recall');
    197. const surplus = document.querySelector('.surplus');
    198. const levelBox = document.querySelector('.levelBox');
    199. const levelBoxDiv = document.querySelector('.levelBox>div');
    200. const levelBoxBtn = document.querySelectorAll('.levelBox>div button');
    201. const chronoscope = document.querySelector('.chronoscope');
    202. const lightUp = document.querySelector('.lightUp');
    203. let boxGoodsLeft = 0;
    204. let boxVolume = 0;
    205. let spacing = 65;
    206. let disorganizeNum = 3;
    207. let recallNum = 3;
    208. let chronoscopeNum = 0;
    209. let range = 350;
    210. let lightUpNum = 3;
    211. const mutedSVG =
    212. '',
    213. notMutedSVG =
    214. '';
    215. const goodsList = [
    216. 'zoon1', 'zoon2', 'zoon3', 'zoon4', 'zoon5', 'zoon6', 'zoon7', 'zoon8', 'zoon9',
    217. 'fruit1', 'fruit2', 'fruit3', 'fruit4', 'fruit5', 'fruit6', 'fruit7', 'fruit8', 'fruit9',
    218. 'cake1', 'cake2', 'cake3', 'cake4', 'cake5', 'cake6', 'cake7', 'cake8', 'cake9',
    219. ]
    220. function randomNum(min, max) {
    221. min = Math.ceil(min);
    222. max = Math.floor(max);
    223. return Math.floor(Math.random() * (max - min + 1)) + min;
    224. }
    225. if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
    226. const equipment = document.querySelector('.equipment');
    227. equipment.setAttribute('href', 'css/mobile.css');
    228. spacing = 48;
    229. range = 0;
    230. }
    231. function createGoods(oneGoods) {
    232. const goods = document.createElement('div');
    233. goods.classList.add('goods');
    234. goods.style.backgroundImage = `url(imgs/${oneGoods}.png)`;
    235. goods.setAttribute('mark', oneGoods)
    236. goods.style.top = randomNum(155, window.innerHeight - 222) + 'px';
    237. goods.style.left = randomNum(20 + range, window.innerWidth - 70 - range) + 'px';
    238. body.appendChild(goods);
    239. goods.setAttribute('onclick', 'goodsClick(this)');
    240. }
    241. function goodsClick(self) {
    242. if (boxVolume >= 7 || self.classList.contains('grey')) return;
    243. createdAudio('audio/点击.mp3');
    244. const newGoods = self.cloneNode();
    245. newGoods.style.top = 0;
    246. newGoods.style.left = boxGoodsLeft + 'px';
    247. newGoods.style.padding = 0;
    248. newGoods.removeAttribute('onclick');
    249. boxGoodsLeft += spacing;
    250. boxVolume++;
    251. newGoods.style.opacity = 0;
    252. box.appendChild(newGoods);
    253. self.style.transition = 'top .2s, left .2s';
    254. self.style.padding = 0;
    255. self.style.top = box.offsetTop + 2 + 'px';
    256. self.style.left = boxGoodsLeft + box.offsetLeft - self.offsetWidth + 'px';
    257. setTimeout(() => {
    258. newGoods.style.opacity = 1;
    259. self.remove();
    260. coverGoods();
    261. }, 100);
    262. let count = 0;
    263. let children = [...box.children];
    264. children.forEach(item => item.getAttribute('mark') == newGoods.getAttribute('mark') && count++);
    265. let deleteNum = 3;
    266. if (count >= 3) {
    267. createdAudio('audio/得分.mp3');
    268. surplus.innerText = allGoods.length - 3;
    269. boxVolume -= 3;
    270. children.forEach(item => {
    271. if (item.getAttribute('mark') == newGoods.getAttribute('mark') && deleteNum > 0) {
    272. deleteNum--;
    273. item.style.animation = 'fade .3s linear';
    274. setTimeout(() => {
    275. item.remove();
    276. children = [...box.children];
    277. boxGoodsLeft = spacing * children.length;
    278. children.forEach((item, index) => {
    279. item.style.transition = 'left .2s';
    280. item.style.left = index * spacing + 'px';
    281. });
    282. }, 200);
    283. }
    284. });
    285. }
    286. boxVolume >= 7 && gameFinish('很遗憾你输了', 'audio/失败.mp3');
    287. setTimeout(() => {
    288. allGoods = document.querySelectorAll('.goods');
    289. if (allGoods.length <= 0) {
    290. gameFinish(`恭喜你通过了${selectLevel.innerText}\n用时${chronoscopeNum}秒`, 'audio/胜利2.mp3');
    291. const levelRecord = JSON.parse(localStorage.getItem('sheep_level_record'));
    292. levelRecord[selectLevel.getAttribute('index')]++;
    293. localStorage.setItem('sheep_level_record', JSON.stringify(levelRecord));
    294. }
    295. }, 300);
    296. }
    297. function gameFinish(str, audio) {
    298. setTimeout(() => {
    299. alert(str);
    300. selectLevel.click();
    301. }, 200);
    302. surplus.innerText = allGoods.length;
    303. createdAudio(audio);
    304. disorganizeNum = 0;
    305. recallNum = 0;
    306. lightUpNum = 0;
    307. }
    308. function gameStart(number) {
    309. boxVolume = 0;
    310. boxGoodsLeft = 0;
    311. allGoods = document.querySelectorAll('.goods');
    312. allGoods.forEach(item => item.remove());
    313. disorganizeNum = 3;
    314. disorganize.innerText = `洗牌 ${disorganizeNum}`;
    315. recallNum = 3;
    316. recall.innerText = `撤回 ${recallNum}`;
    317. lightUpNum = 3;
    318. lightUp.innerText = `点亮 ${lightUpNum}`;
    319. chronoscopeNum = 0;
    320. chronoscope.innerText = chronoscopeNum;
    321. for (let i = 0; i < number; i++) {
    322. const num = randomNum(0, goodsList.length - 1);
    323. for (let i = 0; i < 3; i++) createGoods(goodsList[num]);
    324. }
    325. allGoods = document.querySelectorAll('.goods');
    326. allGoods.forEach((item, index) => {
    327. item.style.animation = `enter .3s`;
    328. item.style.zIndex = index + 1;
    329. });
    330. surplus.innerText = allGoods.length;
    331. setTimeout(coverGoods, 300);
    332. }
    333. disorganize.addEventListener('click', () => {
    334. if (disorganizeNum <= 0) return;
    335. disorganizeNum--;
    336. disorganize.innerText = `洗牌 ${disorganizeNum}`;
    337. allGoods.forEach(item => {
    338. if (!item.getAttribute('onclick')) return;
    339. item.style.transition = 'top .25s, left .25s';
    340. item.style.top = randomNum(155, window.innerHeight - 222) + 'px';
    341. item.style.left = randomNum(20 + range, window.innerWidth - 70 - range) + 'px';
    342. });
    343. setTimeout(coverGoods, 300);
    344. });
    345. disorganize.innerText = `洗牌 ${disorganizeNum}`;
    346. reset.addEventListener('click', () => gameStart(selectLevel.getAttribute('level')));
    347. function createdAudio(src) {
    348. const audio = document.createElement('audio');
    349. document.body.appendChild(audio);
    350. audio.autoplay = true;
    351. audio.setAttribute('src', src);
    352. audio.play();
    353. audio.addEventListener('ended', e => e.target.remove());
    354. }
    355. controlBGM.addEventListener('click', () => {
    356. if (BGAudio.getAttribute('src')) {
    357. BGAudio.setAttribute('src', '');
    358. controlBGM.innerHTML = mutedSVG;
    359. } else {
    360. BGAudio.setAttribute('src', 'audio/audio2.mp3');
    361. BGAudio.play();
    362. controlBGM.innerHTML = notMutedSVG;
    363. }
    364. });
    365. controlBGM.innerHTML = mutedSVG;
    366. recall.addEventListener('click', () => {
    367. let len = box.children.length;
    368. if (len <= 0 || recallNum <= 0) return;
    369. recallNum--;
    370. recall.innerText = `撤回 ${recallNum}`;
    371. let lastChild = box.children[len - 1];
    372. const newGoods = lastChild.cloneNode();
    373. newGoods.style.padding = '23px';
    374. newGoods.style.top = randomNum(155, window.innerHeight - 222) + 'px';
    375. newGoods.style.left = randomNum(20 + range, window.innerWidth - 70 - range) + 'px';
    376. newGoods.setAttribute('onclick', 'goodsClick(this)');
    377. body.appendChild(newGoods);
    378. boxGoodsLeft -= spacing;
    379. boxVolume--;
    380. lastChild.remove();
    381. });
    382. recall.innerText = `撤回 ${recallNum}`;
    383. selectLevel.addEventListener('click', () => {
    384. levelBox.style.display = 'block';
    385. const levelRecord = JSON.parse(localStorage.getItem('sheep_level_record'));
    386. levelRecord.forEach((item, index) => item && levelBoxBtn[index].classList.add('win'));
    387. });
    388. levelBoxDiv.addEventListener('click', () => levelBox.style.display = 'none');
    389. levelBoxBtn.forEach(item => {
    390. item.addEventListener('click', e => {
    391. const level = e.target.getAttribute('level');
    392. gameStart(level);
    393. selectLevel.setAttribute('level', level);
    394. selectLevel.setAttribute('index', e.target.getAttribute('index'));
    395. selectLevel.innerText = e.target.innerText;
    396. });
    397. });
    398. const levelRecord = new Array(levelBoxBtn.length);
    399. for (let i = 0; i < levelRecord.length; i++) levelRecord[i] = 0;
    400. localStorage.getItem('sheep_level_record') || localStorage.setItem('sheep_level_record', JSON.stringify(
    401. levelRecord));
    402. setInterval(() => chronoscope.innerText = ++chronoscopeNum, 1000);
    403. function isIntersect(element1, element2) {
    404. const rect1 = element1.getBoundingClientRect();
    405. const rect2 = element2.getBoundingClientRect();
    406. return !(rect1.right - 5 < rect2.left || rect1.left > rect2.right - 5 || rect1.bottom - 5 < rect2.top || rect1
    407. .top > rect2.bottom - 5);
    408. }
    409. function coverGoods() {
    410. for (let i = 0; i < allGoods.length; i++) {
    411. allGoods[i].classList.remove('grey');
    412. for (let j = i + 1; j < allGoods.length; j++) {
    413. if (isIntersect(allGoods[i], allGoods[j]) && allGoods[i] != allGoods[j]) {
    414. if (parseInt(allGoods[i].style.zIndex) > parseInt(allGoods[j].style.zIndex)) {
    415. allGoods[j].classList.add('grey');
    416. } else {
    417. allGoods[i].classList.add('grey');
    418. }
    419. }
    420. }
    421. }
    422. }
    423. lightUp.addEventListener('click', () => {
    424. if (lightUpNum <= 0) return;
    425. allGoods.forEach(item => item.classList.remove('grey'));
    426. lightUpNum--;
    427. lightUp.innerText = `点亮 ${lightUpNum}`;
    428. });
    429. lightUp.innerText = `点亮 ${lightUpNum}`;
    430. gameStart(selectLevel.getAttribute('level'));
    431. // cheating
    432. let pressTime = 0;
    433. levelBoxDiv.addEventListener('touchstart', () => pressTime = +new Date());
    434. levelBoxDiv.addEventListener('touchend', () => {
    435. pressTime = +new Date() - pressTime;
    436. if (pressTime > 3000) disorganizeNum = 9;
    437. });
    438. </script>
    439. </body>
    440. </html>

     搞到这里,我已经悟了。你们呢?

    没猜错的话有粉丝是不是已经运行了一遍发现报错了呢?

    别急  别急  别急!(重要的事情说三遍)

    我们刚说目录下有那么几个文件夹 肯定是要放东西的呀 不然建文件夹有啥作用呢?是吧

    不过大家可以在网页按F12看一下控制台

    也就是这个地方看看红色的报错是什么   百度了解一下

    接下来对目录操作

    目录文件放入

    有能力的粉丝自己进行探索怎么拿到缺失部分

    没能力的私信dd~~~

    文件东西放入了就可以正常执行代码,快去试试吧!

     注:本案例是根据网上代码进行了优化改动 禁止网上传阅!!!

  • 相关阅读:
    SpringMVC框架的详细解读
    欧几里得聚类提取
    Linux提权的几种常用方法
    Unity 2021 LTS / Unity 2022 LTS New Shader Graph Node 参考样本
    Node.js 中解析 HTML 的方法介绍
    【NSFileManager常用方法之判断 Objective-C语言】
    Cocos Creator 3.x 热更新
    〖Python 数据库开发实战 - Redis篇④〗- Redis命令行客户端与图形客户端的简单使用
    全国计算机等级考试三级数据库技术
    python计算脚长 青少年电子学会等级考试 中小学生python编程等级考试一级真题答案解析2022年9月
  • 原文地址:https://blog.csdn.net/qq_45690359/article/details/127169410