Slide Puzzle Game in JavaScript HTML CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • How to code a slide puzzle game using javascript html and css! In this tutorial, we will make a Doraemon themed slide puzzle! ドラえもんスライドパズル!
    Code: github.com/ImK...
    Demo: imkennyyip.git...
    Website: www.kennyyipco...
    Java Game Programming Projects Playlist:
    • Java Game Programming ...
    JavaScript Game Programming Projects Playlist:
    • JavaScript Game Progra...
    Subscribe for more coding tutorials 😄!
    Rest in Peace, Abiko Motoo (安孫子 素雄) March 10, 1934 - April 7, 2022, co-creator of Doraemon :'(

ความคิดเห็น • 68

  • @davidgm7042
    @davidgm7042 2 ปีที่แล้ว +8

    I've done (almost) all of your game projects and I can't thank you enough. Your videos have helped a lot to learn and practice HTML, CSS and JS. I just wanted to say thanks and to tell you your videos are amazing! Keep up the good work!

  • @chetanrathi8070
    @chetanrathi8070 ปีที่แล้ว

    clean, calm, clear, simple = Kenny Yip Coding = AWESOME!

  • @penjanikaira3538
    @penjanikaira3538 ปีที่แล้ว +3

    Kindly do a video on how you can make that one work on phones (puzzling on the phone)

  • @KennyYipCoding
    @KennyYipCoding  2 ปีที่แล้ว

    Check out the playlist of web project tutorials here!
    th-cam.com/play/PLnKe36F30Y4bLhA-st9sC4ZthyV7nsL2Q.html
    Got a tutorial suggestion? Let me know down below!

    • @karthikm.1804
      @karthikm.1804 2 ปีที่แล้ว

      how about Pacman

    • @coded_tom4599
      @coded_tom4599 2 ปีที่แล้ว

      Make Roulette. Basically you get to choose odd or even and red or black. If you win you get 1 point per beat and if you lose you get one point per lose subtracted.

    • @bluefoxw
      @bluefoxw ปีที่แล้ว

      a coloring book :D

  • @namanchimnani
    @namanchimnani 2 ปีที่แล้ว +2

    Try playing with dnd-kit for drag and drop functionality if doing this in react! It makes the job easier. Great video btw 👏

  • @KennyYipCoding
    @KennyYipCoding  2 ปีที่แล้ว

    Previous Puzzle Game Tutorial: th-cam.com/video/S6GNtMGNcUE/w-d-xo.html

  • @cha5848
    @cha5848 2 ปีที่แล้ว +1

    Thanku so much for explaining everything so clearly...please keeping making these videos

  • @sandyjoseph4467
    @sandyjoseph4467 ปีที่แล้ว +1

    i have wrote the same code but there is a problem in having the pictures results what should i do please??????????

  • @joysardar6109
    @joysardar6109 4 หลายเดือนก่อน +1

    Sir please make more videos 🙏... For gaming ... Pls 🙏

  • @teksapport9351
    @teksapport9351 ปีที่แล้ว +1

    how do i make a function that displays a win when i put the pieces in the correct order? thanks a lot!

  • @annbur3791
    @annbur3791 ปีที่แล้ว +1

    I have another question, where did u define which tile is curr or other?

  • @jurassicworld5205
    @jurassicworld5205 ปีที่แล้ว +2

    It won't let me move the images why?

  • @jamesabeo8851
    @jamesabeo8851 หลายเดือนก่อน

    Please how you get a new image into smaller pieces please

  • @annbur3791
    @annbur3791 ปีที่แล้ว

    i do not know why this does not function, i'm doing a 4x5 puzzle, and it shows almost everything, but... i can not swap any of the pieces

  • @SB-iy8fv
    @SB-iy8fv 10 หลายเดือนก่อน

    hey, thank you for uploading this!!!
    i wanted to ask if the game wokd still work if i switch the images for videos, and the result is one video.

    • @KennyYipCoding
      @KennyYipCoding  10 หลายเดือนก่อน +1

      It would be better to do it with gif. With video players, it may take longer to load.

  • @blossomvelder
    @blossomvelder ปีที่แล้ว

    I can't thank you enough for this tutorial, I've learnt a lot and also created a slide puzzle game of my own using your help on the tutorial. What I need to know now is how to I make this game playable even on a mobile phone since it seems to only work on desktop? How can it be made compatible for mobile use?

  • @syedayeshaparveen5263
    @syedayeshaparveen5263 6 หลายเดือนก่อน +1

    How could I move the images ..it's already set up and am unable to play..say me pls

    • @KennyYipCoding
      @KennyYipCoding  5 หลายเดือนก่อน +1

      It’s in the video tutorial

    • @KennyYipCoding
      @KennyYipCoding  5 หลายเดือนก่อน +1

      Also the completed code is in the video description if you want to test it out locally and compare your code

  • @darmawanhadi8174
    @darmawanhadi8174 2 ปีที่แล้ว

    if i want to appear a alert because i have done arrange that picture, how i write to the script sir? i confuse about that

  • @TimeLords910
    @TimeLords910 ปีที่แล้ว

    i'll take it back it does work i though if i clicked around it would move itself but now realised it was drag and drop

  • @silvermist99
    @silvermist99 ปีที่แล้ว +2

    I did the whole code correct but the pictures aren't moving
    Can you help me and tell me why

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว +1

      Maybe you didn’t add the function for onclick, the source code is in the GitHub link for you to check if you’d like

    • @silvermist99
      @silvermist99 ปีที่แล้ว

      @@KennyYipCoding where do I write it
      Cause there isn't a on click function

    • @silvermist99
      @silvermist99 ปีที่แล้ว

      @@KennyYipCoding and thank you for replying 💫💫

  • @vigneshwarvenugopal922
    @vigneshwarvenugopal922 6 หลายเดือนก่อน +1

    Thank you so much dude.,

  • @alminaab
    @alminaab ปีที่แล้ว +1

    Hi Kenny! I finished the code, but I also wanted to add a finish scene with 'you won'... i tried multiple things for hours but i couldnt figure it out. Could you help me out pls?

    • @rulenumber337
      @rulenumber337 ปีที่แล้ว

      im trying it also, have u solve it bro? share it please

    • @markinios2
      @markinios2 ปีที่แล้ว +1

      set this as a global variable (this is used because the original imgOrder gets destroyed during the onload and we need to know the correct order):
      var startingImgOrder = ["4", "2", "8", "5", "1", "6", "7", "9", "3"];
      const imgCorrectOrder = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
      put this under "tile.id = r.toString() + "-" + c.toString()" (this is used to store the actual number of the image for future use):
      tile.name = imgOrder[0];
      put this in the "if (isAdjacent)" if statement (for every move it switches the numbers in the array and checks if the array is the same as the correct order):
      let currImgNameIndex = startingImgOrder.indexOf(currTile.name);
      let otherImgNameIndex = startingImgOrder.indexOf(otherTile.name);

      startingImgOrder[currImgNameIndex] = otherTile.name;
      startingImgOrder[otherImgNameIndex] = currTile.name;
      if (startingImgOrder.every((val, index) => val === imgCorrectOrder[index])) {
      alert("You Won!")
      }

    • @musagozail2581
      @musagozail2581 ปีที่แล้ว

      @@markinios2 didnt work for me, can you share link of a working demo?

    • @gelamariconseno8951
      @gelamariconseno8951 ปีที่แล้ว

      @@markinios2 didn't work for me too. can you share your demo?

  • @skweeby4966
    @skweeby4966 ปีที่แล้ว

    Hi, really good tutorial, I liked it and I subscribed. I just want to know how could I do so that when the puzzle is solved a popup or text appears saying the puzzle is complete. Thanks a lot !

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      You can add something like alert(“puzzle completed”) to show a pop up on the web page with the message “puzzle completed”

  • @codewithme4862
    @codewithme4862 2 ปีที่แล้ว +1

    from where i can arrange this photos

  • @VirginMagdalene
    @VirginMagdalene ปีที่แล้ว

    Hello! Thank you for this awesome tutorial! I do have one issue, the image isn't populating. I saw in a previous comment to make sure the image folder is linked but in going over the code (even checking the code on GitHub) I don't see where to link the images outside of adding it to the HTML multiple times. Where do I link the images so they appear on the board thru javascript? Any help would be greatly appreciated! Thank you again!

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      It should be in the JS code where we set the img src

  • @rulenumber337
    @rulenumber337 ปีที่แล้ว

    Can we add congratiolations message after assembled? how do we do it?

  • @egivaysantosh1761
    @egivaysantosh1761 ปีที่แล้ว

    hello Sir,can anyone help me in sorting all the individual images into one puzzled image??
    howww??

  • @mookpatcharida
    @mookpatcharida ปีที่แล้ว

    What principles or concepts of AI are you using?

  • @matteobuonanno1943
    @matteobuonanno1943 ปีที่แล้ว

    When I put in all the addEventListener it doesn't display the tiles and I tried also copying the whole thing instead of doing it on my puzzle but it didn't work anyways!

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      did you change any variable names or make a typo or something? did you link your javascript code in the html file? you can also right click-inspect to see if there are any error logs in the console output. For reference, you can also check the completed code link in the description.

  • @grishmitaagrawal8496
    @grishmitaagrawal8496 3 หลายเดือนก่อน +1

    Thankyou so muchhh

  • @oximy
    @oximy 2 ปีที่แล้ว

    Can you make a video on how to make all the games into one website?

  • @vidhansharma9167
    @vidhansharma9167 ปีที่แล้ว

    sir how can we set puzzle complete statement

  • @Unknown-cj8fv
    @Unknown-cj8fv ปีที่แล้ว

    does it work on mobile?

  • @gintoki100
    @gintoki100 2 ปีที่แล้ว

    If your doing multiple images and when you refresh it gets the random image to do it how would you approach it?

    • @KennyYipCoding
      @KennyYipCoding  2 ปีที่แล้ว +2

      i would create a function to start with the solved puzzle ordering, so a 3x3 array like [[1,2,3],[4,5,6],[7,8,9]], then i would have a random adjacent tile swap with the blank tile, 3. repeat this as many times as you want, and then that will be the randomized ordering.

    • @CodingMation
      @CodingMation 9 หลายเดือนก่อน +1

      ​@@KennyYipCoding
      Bro can you make this game for mobile by touch events.
      Please
      If you not make then give me some hint.

  • @mosesvijayraj3456
    @mosesvijayraj3456 2 ปีที่แล้ว

    i did everything and i am getting a blank image but the border and all are visiblecan you please help me out sir

    • @KennyYipCoding
      @KennyYipCoding  2 ปีที่แล้ว

      Make sure you got the path to the images folder correctly.

    • @mosesvijayraj3456
      @mosesvijayraj3456 2 ปีที่แล้ว

      ​@@KennyYipCoding i saw it sir and rectified but swapping is not happening sir

    • @KennyYipCoding
      @KennyYipCoding  2 ปีที่แล้ว +1

      Try comparing your code to the finished one on GitHub. Might be missing something. Not too sure tbh

    • @hostile_user
      @hostile_user 2 ปีที่แล้ว

      @@mosesvijayraj3456 same happening with me too; did you got your problem solved?

  • @TimeLords910
    @TimeLords910 ปีที่แล้ว

    i tested your code but it seems to not function

    • @KennyYipCoding
      @KennyYipCoding  ปีที่แล้ว

      there’s no “click” to drag and drop through mobile I think, if that’s what you’re using but on a computer it should work fine

    • @TimeLords910
      @TimeLords910 ปีที่แล้ว

      @@KennyYipCoding it was on computer i also ran your code in vscode with live-server

  • @jeeadvanced1230
    @jeeadvanced1230 2 ปีที่แล้ว +2

    Thanks ❤❤❤❤❤❤

  • @hihahahuhujs
    @hihahahuhujs ปีที่แล้ว

    Amazing

  • @orefusado
    @orefusado 2 ปีที่แล้ว

    amazing

  • @aditom02
    @aditom02 2 ปีที่แล้ว

    thanks a lot

  • @jinkaicai3330
    @jinkaicai3330 ปีที่แล้ว

    喜欢

  • @imrulkayes5941
    @imrulkayes5941 ปีที่แล้ว

    otherTile.src; shows undefiend on dragEnd()

  • @azadrizwin1741
    @azadrizwin1741 2 ปีที่แล้ว

    does it work on mobile ?