In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article Xiaobian for you to introduce in detail "html5 how to achieve neural cat games", the content is detailed, the steps are clear, the details are handled properly, I hope this "html5 how to achieve neural cat games" article can help you solve your doubts, following the editor's ideas slowly in-depth, let's learn new knowledge.
Game design ideas
Find passable neighbors from the cat's current location in six directions, and then start from these neighbors, and then find their respective passable neighbors, and keep looking like this, while looking for them, while judging whether any of the neighbors currently found are on the edge of the game area, if so, the search process ends early, and the result is that the cat is not surrounded. If no one is on the edge of the game area until all the passable neighbors are found, the result is that the cat is surrounded.
Reference code
Cat.html
App.js
Var stage = new createjs.Stage ("gameView")
Createjs.Ticker.setFPS (30)
Createjs.Ticker.addEventListener ("tick", stage)
Var gameView = new createjs.Container ()
GameView.x = 30
GameView.y = 30
Stage.addChild (gameView)
Var circleArr = [[], []]
Var currentCat
/ / define 7 states to represent the moving position
Var MOVE_NONE =-1 century moving left = 0 million moving left = 1 million moving right = 2 moving right = 3 moving right = 4 moving falling right = 5
Function getMoveDir (cat) {
/ / judge the position where you can go.
Var distanceMap = []
/ / left
Var can = true
For (var x = cat.indexX;x > = 0bot xmuri -) {
If (circleArr [x] [cat.indexY] .getCircleType () = = Circle.TYPE_SELECTED) {
Can = false
DistanceMap [move _ LEFT] = cat.indexX-x
Break
}
}
If (can) {
Return MOVE_LEFT
}
/ / left up
Can = true
Var x = cat.indexX, y = cat.indexY
While (true) {
If (circleArr [x] [y] .getCircleType () = = Circle.TYPE_SELECTED) {
Can = false
DistanceMap [move _ UP_LEFT] = can.indexY-y
Break
}
If (y% 2 = = 0) {
Xmuri-
}
Ymuri-
If (Y8 | | xmaxValue) {
MaxValue = distanceMap [dir]
MaxDir = dir
}
}
If (maxValue > 1) {
Return maxDir
} else {
Return MOVE_NONE
}
}
Function circleClicked (event) {
If (event.target.getCircleType ()! = Circle.TYPE_CAT) {
Event.target.setCircleType (Circle.TYPE_SELECTED)
} else {
Return
}
/ / indicates that the game is over on the edge.
If (currentCat.indexX = = 0 | | currentCat.indexX = = 8 | | currentCat.indexY==0 | | currentCat.indexY==8) {
Alert ("Game over")
Return
}
Var dir = getMoveDir (currentCat)
Switch (dir) {
/ / judge which direction he is going to go
Case MOVE_LEFT:
CurrentCat.setCircleType (Circle.TYPE_UNSELECTED)
CurrentCat = circleArr [currentCat.indexX-1] [currentCat.indexY]
CurrentCat.setCircleType (Circle.TYPE_CAT)
Break
Case MOVE_UP_LEFT:
CurrentCat.setCircleType (Circle.TYPE_UNSELECTED)
CurrentCat = circleArr [currentCat.indexY% 2? currentCat.indexX:currentCat.indexX- 1] [currentCat.indexY-1]
CurrentCat.setCircleType (Circle.TYPE_CAT)
Break
Case MOVE_UP_RIGHT:
CurrentCat.setCircleType (Circle.TYPE_UNSELECTED)
CurrentCat = circleArr [currentCat.indexY% 2? currentCat.indexX+1:currentCat.indexX] [currentCat.indexY-1]
CurrentCat.setCircleType (Circle.TYPE_CAT)
Break
Case MOVE_RIGHT:
CurrentCat.setCircleType (Circle.TYPE_UNSELECTED)
CurrentCat = circleArr [currentCat.indexX+1] [currentCat.indexY]
CurrentCat.setCircleType (Circle.TYPE_CAT)
Break
Case MOVE_DOWN_RIGHT:
CurrentCat.setCircleType (Circle.TYPE_UNSELECTED)
CurrentCat = circleArr [currentCat.indexY% 2? currentCat.indexX+1:currentCat.indexX] [currentCat.indexY+1]
CurrentCat.setCircleType (Circle.TYPE_CAT)
Break
Case MOVE_DOWN_LEFT:
CurrentCat.setCircleType (Circle.TYPE_UNSELECTED)
CurrentCat = circleArr [currentCat.indexY% 2? currentCat.indexX:currentCat.indexX-1] [currentCat.indexY+1]
CurrentCat.setCircleType (Circle.TYPE_CAT)
Break
/ / No direction to go. Game over.
Default:
Alert ("Game over")
}
}
Function addCircles () {
/ / generate game background
For (var indexY = 0; indexY)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.