search
HomeWeb Front-endH5 TutorialFront-end implementation of Lianliankan mini-game example code

After playing Lian Lian Kan for so long, the blogger discovered for the first time that Lian Lian Kan can only have 2 turns at most. orz…

I searched for Lianliankan’s connection algorithm judgment on the Internet, but I didn’t find a very comprehensive one. After my own exploration, I drew the following picture (the picture is a bit ugly...)

1. Two objects are on the same straight line and can be directly connected (no explanation is needed for this)

2.2 The objects are on the same straight line, there are obstacles in the middle, and they cannot be directly connected (2 turns)

[Loop through the intersection points in the yellow line, such as points A and B, and then determine whether there are obstacles on the blue line. If If not, it can be connected. If so, continue to loop to find new points A and B】

3. The two objects are not on the same straight line , a turn

[The two objects extend the x and y axes at their respective locations. As shown in the figure below, the intersection points are A and B. You only need to determine whether there are obstacles directly from 2 intersection points to 2 objects. If not, you can connect]

4. The 2 objects are not there On the same straight line, the connecting line has 2 turns

[The same principle is as shown in the figure below. If there are no obstacles from the intersection points A and B to the object, they can be connected. The ordinate of point A is the same as that of point B】

In another case, A and B are the intersection points of the x-axis and the middle y-axis where the two objects are located, A and B The x-coordinates of For each axis, just increase the y-axis according to the same principle. Can cover all connection judgment~

After talking about the logic of connection judgment, let’s write about the overall game framework. The game basically uses native javascript and is developed using the createjs game engine.

Code idea:

1. Draw the game drawing and determine how many palace pictures it will be. Since it is a small game on the mobile side, it is based on the minimum screen size (iphone4 320*480 ), determined to be a 7*9 palace diagram.

1. Create a two-dimensional array. If there is an object at a certain coordinate, set it to 1, otherwise it is 0

2. To determine whether there is an object at the position, you only need to determine the corresponding Whether the value on the two-dimensional array is 1, if it is 1, there is an object, otherwise there is not.

As for drawing lines and eliminating identical objects, as long as you know the connection logic, you will definitely draw lines and eliminate objects by yourself, so this article will only talk about connection judgment~

When judging whether a line can be connected, you must start with the simplest method, as follows:

Can the same straight line be connected in a straight line--->If a point is surrounded, it will not connect. ---> Two points are on a straight line, they cannot be connected in a straight line but they can be connected ---> They are not in the same straight line but they can be connected

getPath: function (p1, p2) {//开始搜索前对p1,p2排序,使p2尽可能的在p1的右下方。if (p1.x > p2.x) {var t = p1;
                p1 = p2;
                p2 = t;
            }else if (p1.x == p2.x) {if (p1.y > p2.y) {var t = p1;
                    p1 = p2;
                    p2 = t;
                }
            }//2点在同一直线上,可以直线连通if (this.hasLine(p1, p2).status) {return true;
            }//如果两点中任何一个点被全包围,则不通。else if (this.isWrap(p1, p2)) {return false;
            }//两点在一条直线上,不能直线连接但是可以连通else if (this.LineLink(p1, p2)) {return true;
            }//不在同一直线但是可以连通else if (this.curveLink(p1, p2)) {return true;
            }    
}

//判断同一条线能否连通,x轴相同或者y轴相同hasLine: function (p1, p2) {this.path = [];//同一点if (p1.x == p2.x && p1.y == p2.y) {return {
                    status: false};
            }if (this.onlineY(p1, p2)) {var min = p1.y > p2.y ? p2.y : p1.y;
                min = min + 1;var max = p1.y > p2.y ? p1.y : p2.y;for (min; min  p2.x ? p2.x : p1.x;
                j = j + 1;var max = p1.x > p2.x ? p1.x : p2.x;for (j; j <div class="cnblogs_code">Connection judgment</div><p></p> <div class="cnblogs_code"></div>

The above is the detailed content of Front-end implementation of Lianliankan mini-game example code. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
详解:Windows 10是否内置了扫雷小游戏详解:Windows 10是否内置了扫雷小游戏Dec 23, 2023 pm 02:07 PM

我们在使用win10操作系统的时候,想要知道win10更新了之后是不是还保存有以前老版本中的自带游戏扫雷,据小编所知,我们可以在商店中进行下载安装,只要在商店中搜索microsoftminesweeper即可。具体步骤就来和小编一起看一下吧~windows10有扫雷游戏吗1,首先打开win10开始菜单,点击。然后搜索,点击搜索。2,点击排在第一位的。3,然后就可能需要输入微软账户,即Microsoft账户。没有Microsoft账户的可以安装提示注册即可。输入账户密码,点击下一步。4,然后开始下

如何在PHP中实现SEO优化如何在PHP中实现SEO优化May 20, 2023 pm 01:30 PM

随着互联网的发展,SEO(SearchEngineOptimization,搜索引擎优化)已经成为了网站优化的重要一环。如果您想要使您的PHP网站在搜索引擎中获得更高的排名,就需要对SEO的内容有一定的了解了。本文将会介绍如何在PHP中实现SEO优化,内容包括网站结构优化、网页内容优化、外部链接优化,以及其他相关的优化技巧。一、网站结构优化网站结构对于S

win10系统的小游戏扫雷在哪里win10系统的小游戏扫雷在哪里Jul 02, 2023 pm 03:37 PM

  win10系统的小游戏扫雷在哪里?很多用户在使用Win7系统的时候最喜欢玩的就是Win7自带的扫雷了,甚至有些小伙伴会为了比拼扫雷的速度一直在玩。但是不少用户在升级了Windows10系统后发现电脑的扫雷不见了,很多小伙伴不知道怎么详细操作,小编下面整理了Win10扫雷小游戏的位置分享,如果你感兴趣的话,跟着小编一起往下看看吧!  Win10扫雷小游戏的位置分享  1,首先打开win10开始菜单,点击【应用商店】。然后搜索【microsoftminesweeper】,点击搜索。  2,点击排

如何在谷歌浏览器中游玩小游戏如何在谷歌浏览器中游玩小游戏Jan 30, 2024 pm 12:39 PM

谷歌浏览器怎么玩小游戏?谷歌浏览器之中是有着非常多充满人文关怀的功能设计的,各位可以在其中获得非常多样化的乐趣。在谷歌浏览器之中,有这一个非常好玩的彩蛋小游戏,即小恐龙游戏,很多小伙伴都非常喜欢这个游戏,但却不清楚该怎么触发进行游玩,下面就由小编为大家带来恐龙小游戏进入教程。谷歌浏览器怎么玩小游戏方法一:【电脑断网】如果你的电脑使用有线网络,请拔掉网线;如果你的电脑使用无线网络,请在电脑右下角点击无线网络连接断开。②在你电脑断网的前提下,打开谷歌浏览器(GoogleChrome)即可出现谷歌浏览

如何在PHP中实现ERP系统如何在PHP中实现ERP系统May 20, 2023 pm 06:21 PM

随着电子商务和企业管理的发展,许多企业开始寻找更好的方法来处理其日常业务流程。ERP系统是一种能够整合企业各种业务流程的软件工具。它提供了全面的功能,包括生产、销售、采购、库存、财务等方面,帮助企业提高效率、控制成本和提高客户满意度。而在PHP编程语言中,也能够实现ERP系统,这就需要我们掌握一些基本的知识和技术。下面,我们将深入探讨如何在PHP中实现ERP

如何在PHP中实现CRM系统如何在PHP中实现CRM系统May 20, 2023 pm 12:31 PM

随着企业的发展,客户管理变得越来越重要。为了提高客户满意度和忠诚度,越来越多的企业采用客户关系管理系统(CRM)来帮助其管理客户关系。而PHP是一种流行的编程语言,因其简单易学、灵活和强大而被广泛应用于Web开发。那么,如何在PHP中实现CRM系统呢?本文将为您介绍实现CRM系统的步骤和技巧。Step1:需求分析在开始开发CRM系统之前,您需要进行需求分析

在PHP中如何实现物联网开发?在PHP中如何实现物联网开发?May 12, 2023 am 11:51 AM

随着物联网技术的发展和普及,越来越多的应用场景需要使用PHP语言进行物联网开发。PHP作为一种广泛应用于Web开发的脚本语言,它的易学易用、开发速度快、可扩展性强等特点,使其成为开发物联网应用的一种优秀选择。本文将介绍在PHP中实现物联网开发的常用技术和方法。一、传输协议和数据格式物联网设备通常使用TCP/IP或UDP协议进行数据传输,而HTTP协议是一个优

UniApp实现小游戏原生组件的扩展与使用技巧UniApp实现小游戏原生组件的扩展与使用技巧Jul 04, 2023 pm 07:21 PM

UniApp实现小游戏原生组件的扩展与使用技巧引言:UniApp是一款跨平台的前端开发框架,它支持同时开发多个主流小程序平台的应用。在UniApp中,我们可以通过扩展小游戏原生组件来提升应用的性能和用户体验。本文将介绍UniApp实现小游戏原生组件扩展与使用的技巧,并给出相应的代码示例供大家参考。一、为什么要扩展小游戏原生组件小游戏原生组件具有更好的性能和更

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool