Candy Crush in React

Sdílet
Vložit
  • čas přidán 16. 07. 2024
  • ⭐ Sign up for my Full Stack Developer Course: www.codewithania.com
    In this video I show you how to make a game of Candy Crush in React!
    00:00 Introduction
    01:37 Setting up our project
    07:25 Creating our Game Board
    24:48 Checking for matches
    42:46 Moving Candies down
    48:42 Dragging and Dropping in React
    01:07:20 Adding Images in React
    01:11:43 Adding the score
    01:17:25 Checking for blanks
    01:19:23 Suggestions for refactoring
    01:20:00 Where to go next? Saving High Scores ( • Video )
    Final code available here: github.com/kubowania/candy-cr...
    Learn how to add Game State in a database: • Video
    ___
    ⭐ Use promo code ANIAKUBOW for 3 months free of WebStorm IDE here (I get no commission from this link, but am in a partnership): jb.gg/get_webstorm
    ⭐ New to code and none of this is making sense? Watch my '12hr+ CZcams Coding Bootcamp' in which you will learn HTML, CSS and JavaScript Fundamentals completely from scratch. It's on my channel and its 100% free.
    ⭐ In most videos I use Tabnine as my A.I autocompletion tool. You can download it for free here (I get no commission from this link, but am in a partnership): bit.ly/tabnine-top-tool
    ⭐ You can get a blockchain domain with my affiliate link here: bit.ly/get-a-crypto-domain
    ⭐ If you would like to buy me a coffee, well thank you very much that is mega kind! : www.buymeacoffee.com/aniakubow
    ⭐ Sign up for weekly coding tips from my newsletter partnership: bit.ly/JS-tips
    You can also find me on:
    Twitter: / ania_kubow
    Instagram: / aniakubow
    #codingbootcamp​ #coding

Komentáře • 315

  • @picture_of_a_swan
    @picture_of_a_swan Před 2 lety +30

    This is actually something I've been waiting for months. I subscribed when I saw the Candy Crush with Javascript and followed along with the video. I've been waiting for you to show us a neat project with ReactJs, because that's what I've been working with mostly.

    • @fuXas1000
      @fuXas1000 Před 2 lety +1

      You need to know plain js at first to learn react properly.

    • @picture_of_a_swan
      @picture_of_a_swan Před 2 lety

      @@fuXas1000 Not really. But I did code with the Javascript Candy Crush video too, I just meant that I've moved on from JS to ReactJS

  • @ZurioSi
    @ZurioSi Před 2 lety +7

    That's an amazing project to practice React, I'll definitely try it on my own and then come back to see how you did it.

  • @muhaiminsheik6401
    @muhaiminsheik6401 Před 2 lety +7

    This is one of the best practices in ReactJs. I definitely try it my own. Keep rocking Ania..I'll support...

  • @RICO-sr2fn
    @RICO-sr2fn Před 2 lety +3

    I discovered your channel 2 days ago, but your tutorials are legendary

  • @nickpawsey
    @nickpawsey Před 2 lety

    This looks like a fun project. I subscribed and saved video to come back to during my Christmas break. Keep up the good work Ania!

  • @Vishalraj_1
    @Vishalraj_1 Před 2 lety +1

    I have completed the video and code along with you. It's amazing, I will add styling to this project and share it with you over twitter soon. Thanks for the Video, I hope we will see more videos on ReactJS.

  • @banjolekan8482
    @banjolekan8482 Před 2 lety +1

    Amazing content as always.
    Well done Ania :)

  • @SkyeHyuuga
    @SkyeHyuuga Před 2 lety

    Wow! Thank you so much for this :D After following your vanilla Javascript candy crush tutorial, i had a go at making it again in React, but had some errors... this helps so much! :D

  • @blackbeardyt3008
    @blackbeardyt3008 Před 2 lety

    CZcams recommended to watch this! and after watching the first few minutes! I did subscribed! Very well explained! Thanks a ton!

  • @CortVermin
    @CortVermin Před 2 lety +3

    i love these tutorials :D already addicted.

  • @navidtehseen
    @navidtehseen Před rokem

    I love how you explain everything part by part.. thank you 😊

  • @upl1nk.v01d2
    @upl1nk.v01d2 Před 2 lety

    another lovely Ania's development video with artistic manner. :)

  • @thomasmiller7319
    @thomasmiller7319 Před 2 lety

    Thank you! That was better than great. Looking forward to more great and helpful content!

  • @claytonstrickland8336
    @claytonstrickland8336 Před 2 lety

    Really enjoyed the project. I did add a bit of styling to make the counter look better and put a black background on the board which looks great. I'm going to add a restart so that it can be run again without having to update the site. Thank you.

  • @PATRICKCHUAD
    @PATRICKCHUAD Před 2 lety +1

    This is amazing video tutorial on react. I've followed along and have understood every logic you have explained. The explanation are also very simple and clear. I will
    Now be more confident to try react. Just realize react can do games , no need to learn ios or android dev haha. You deserve more subscriber!!! Maybe a million !

  • @ziaashraf3706
    @ziaashraf3706 Před 2 lety

    I watched the same for js. Omg i really wanted one in react. Thanks Ania.

  • @Lavkushkumar-cn9me
    @Lavkushkumar-cn9me Před 2 lety

    Thank you so much for this project ❤️

  • @benacker8525
    @benacker8525 Před 2 lety

    Recently I found your channel. Really amazing content!!!

  • @rangabharath4253
    @rangabharath4253 Před 2 lety

    Awesome as always Ania 😀👌

  • @hakizimanafred6482
    @hakizimanafred6482 Před 2 lety +1

    You're a real queen. see you at 300k subs hopefully by the end of the year!

  • @JonathanSteadman2003
    @JonathanSteadman2003 Před 2 lety +1

    Well done!!! Great video.👍

  • @maskman4821
    @maskman4821 Před 2 lety

    This is a pretty cool game and tutorial, really awesome 🤩

  • @Lavkushkumar-cn9me
    @Lavkushkumar-cn9me Před 2 lety

    Love this project ❤️❤️

  • @melania239
    @melania239 Před 2 lety +1

    Ana you are just amazing 💜💜💜 Im on my way to React. Thanks to you :)

  • @ericterrykc
    @ericterrykc Před 7 měsíci

    Crushed it, Ania!😂

  • @crasaqmohamed7741
    @crasaqmohamed7741 Před 2 lety

    Thank you for this great tutorial!

  • @taedhall7253
    @taedhall7253 Před 2 lety +1

    I love this segment of you videos on coding. Candy crush is a fantasy favorite. Very fine coding.

  • @brianclark7913
    @brianclark7913 Před 2 lety +9

    This was a lot of fun! As a MERN bootcamp grad and recent AAS/CIS grad it was very straightforward and easy to understand. I wouldn't be able to replicate on my own just yet, but I'm close, and I think that first job is right around the corner too, especially as things like this get more and more clear over time 🤞 At least my son thinks I'm a genius coder right now so that's a win anyway.

    • @mahrukhsajjad2020
      @mahrukhsajjad2020 Před rokem

      Hi, I am following this tutorial and got stucked can u help me

    • @mahrukhsajjad2020
      @mahrukhsajjad2020 Před rokem

      I can't switch colours

    • @brianclark7913
      @brianclark7913 Před rokem

      @@mahrukhsajjad2020 Sorry no. I haven't done anything programming related in over half a year. 10's of thousands of dollars, 500+ applications and years of applying were enough for me. I honestly don't even remember making this comment, but if me now could tell me then what I know now I wouldn't have bothered with it anyway.

  • @astwas
    @astwas Před 2 lety +12

    I guess I gotta first learn react as a fresh beginner, but I've saved this video so I can revisit in the future and follow along.
    Thank you for all your effort in these videos!

    • @aniakubow
      @aniakubow  Před 2 lety +5

      Yay! Thanks for watching Ard!

  • @designsrs
    @designsrs Před 2 lety

    Simply Amazing. This is called the real Code.

  • @jlpatriot91
    @jlpatriot91 Před 2 lety

    Thank you for another wonderful tutorial :)

  • @sakudacastro
    @sakudacastro Před 2 lety

    nice job! thank you for share with us!

  • @Rahul-ps9jw
    @Rahul-ps9jw Před 2 lety +1

    Super , I'm Waiting ⏳⏳⏳

  • @mohammedaltaf878
    @mohammedaltaf878 Před 2 lety

    You are an amazing developer!!

  • @VishalPatel-tu7jx
    @VishalPatel-tu7jx Před 2 lety +1

    Ma'am you are doing a great job and motivate us to learn more

    • @aniakubow
      @aniakubow  Před 2 lety +1

      Thank you so much Vishal! 🙏

  • @ambrogiolorenzetti4628

    thanks so much, Tr.Ania...I have learned from you a lot...

  • @hasibulhasansiju
    @hasibulhasansiju Před 2 lety +1

    Thank you so much.. I love this kind of videos

  • @affTorugo
    @affTorugo Před 2 lety

    you're one of a kind, thanks for this

  • @sojuthomas7727
    @sojuthomas7727 Před rokem

    Thank you Ania ❤️

  • @augustogorgen
    @augustogorgen Před 2 lety

    Nice tutorial, thanks for sharing!

  • @shivammakwan6409
    @shivammakwan6409 Před 2 lety

    That was superbb❤👌🏻

  • @esaraviam
    @esaraviam Před 2 lety

    Thanks very much for sharing your knoledge, please keep like that!!

  • @bohdanyunakov5898
    @bohdanyunakov5898 Před 2 lety

    Omg, I remember when I followed on your channel it was only 5k subs. Great Job!!

  • @shlomiyahbes4882
    @shlomiyahbes4882 Před 2 lety

    Thank you Ania 🏆👑 you are the best

  • @ericxls93
    @ericxls93 Před rokem +5

    Very good - you make it look so easy! Would be nice if you actually complete the full game (essentially covering more topics) - maybe part 2 😊

    • @Jonatandb
      @Jonatandb Před rokem +2

      She already made the second part! 😎👉🏻 czcams.com/video/ARL0NuIQNjY/video.html&ab_channel=CodewithAniaKub%C3%B3w

  • @aer0449
    @aer0449 Před 2 lety +1

    Thank you so much for your assistance it really means a lot me ... 😄

  • @daisywuwoo1
    @daisywuwoo1 Před 2 lety

    Thanks for sharing, i've been doing the similar thing in my free time as front end developer, can try with Tetris in React as well :)

  • @tsholofelomokheleli
    @tsholofelomokheleli Před 2 lety

    wow, this is great, the best way to learn react

  • @glcorreia
    @glcorreia Před 2 lety +3

    As a person trying to change careers and learning as much as I can, I can't tell you enough how useful and amazing your content is. Thank you!

  • @keeprunning5457
    @keeprunning5457 Před rokem

    gracias ania!

  • @NivBarchechet
    @NivBarchechet Před rokem

    it was very fun thank you for the knowldge !

  • @med219
    @med219 Před 2 lety

    Good job very good tutorial. Good explanation and simple

  • @Jazaltron
    @Jazaltron Před 2 lety

    Awesome video, thank you very much

  • @gers861
    @gers861 Před 2 lety

    Amazing video thank you

  • @chairguy3418
    @chairguy3418 Před 2 lety

    Wonderful 😍❤️

  • @321123580
    @321123580 Před 2 lety

    Hi, thank you for the tutorial, it is very helpful

  • @vendeeshwaran1130
    @vendeeshwaran1130 Před 2 lety

    Amazing content.

  • @nikitashkaruba610
    @nikitashkaruba610 Před 2 lety

    Nice video! :)

  • @Joshua-te1fg
    @Joshua-te1fg Před 2 lety

    amazing thank you

  • @prashantkumar2963
    @prashantkumar2963 Před 2 lety

    Nice video Ania Didi !

  • @sponefromrainbow4869
    @sponefromrainbow4869 Před 2 lety

    Unique video!

  • @calllamana5843
    @calllamana5843 Před 2 lety

    Can't wait

  • @j.c-mtl1150
    @j.c-mtl1150 Před 2 lety

    Love your thumbnails, you are so gorgeus and funny

  • @azad9655
    @azad9655 Před 2 lety

    You are a great explainer

  • @Shizzymynizzy
    @Shizzymynizzy Před 2 lety

    Ania you're a content making machine!

    • @aniakubow
      @aniakubow  Před 2 lety +1

      Super kind of you to say Scott!

  • @okamix_x9443
    @okamix_x9443 Před 2 lety

    Nice video 😮

  • @jonas-re4sk
    @jonas-re4sk Před 2 lety

    This is great, I love Candy and you are my Crush.

  • @yosikimhi
    @yosikimhi Před 2 lety

    Hi, thanks for this. notValid arrays are not changing in any iteration so they can be outside the loops 🙂

  • @manuuarizaa
    @manuuarizaa Před 2 lety +2

    in 39:07 I think that notValid array is incorrect, the correct values should be
    6
    7
    14
    15
    22
    23
    30
    31
    38
    39
    46
    47
    54
    55
    62 => instead of 63
    63 => instead of 64
    I'm going to continue watching the video, I don't know if this error is corrected during the tutorial, but if you can put a mark can be useful.
    Thanks for your videos, they are amazing!

  • @josephinenatanielmayumisan1196

    Ania Kubów, how are you? I'm very happy for your video to be released, we wait for you huu

  • @adyluk2221
    @adyluk2221 Před 2 lety

    ​THANKS ANIA , I LOVE YOU 👍🍷💖

  • @grzesieksgs
    @grzesieksgs Před 2 lety +32

    Nice tutorial, althought I've spotted one thing.
    When You are adding useEffect dependencies in at 32:04, theres quite crucial mistake.
    checkFor... methods are defined inside of component, therefore on each rerender new reference is created for every of these methods. Therefore setInterval is always executed once, it triggers rerender, and on next rerender useEffect is called, clearing already defined interval, and setting up new interval.
    You don't need the interval at all, since You want to perform a check only when currentColorArrangement reference changes, so thats Your only dependency.
    Going further, You could parametrize all checkFor... methods, and define them outside of Your component. This approach doesn't cause confusion about should these methods be added to dependencies array, and it tends to increase readability of Your components.
    Good luck with next tutorials!

    • @aniakubow
      @aniakubow  Před 2 lety +17

      Hi, many thanks for your suggestion! This is what it’s all about :) This is not a mistake however - maybe more of a dirty fix haha . Using the currentColorArrangement to trigger the useEffect was my original plan. In theory as you say, this should work. However sadly using the currentColorArrangement reference was not enough to make the game function as intended - mainly due to the candies needing to drop continuously.
      If you trigger the useEffect every time the currentColorArrangement changes, it will only move down all the candies once (by calling moveIntoSquareBelow once) - when in fact we need this function to be called more times than that. We need it to be called continuously to then in turn change the currentColorArrangement array. I hope that makes sense. Sorry it’s hard to explain over text sometimes.
      In addition to this I needed to change the array using setState inside the useEffect - which causes too many re-renders. Hence me using the setInterval to fix the issue, so that I control the rerenders.
      If you have any working though solutions though please feel free to make a pull request so others can see :) thanks so much gor the contribution - you rock! 💚 if anyone else has any other solutions then please share too :)

  • @josephwong2832
    @josephwong2832 Před 2 lety

    Ania you are awesome!!

  • @benrobo8
    @benrobo8 Před 2 lety +5

    If I may say this, you're one of the talented women in tech I've seen on CZcams. ❤️👍👍 keep it up, you are an inspiration to others out there.

  • @technmania9418
    @technmania9418 Před 2 lety

    amazed 😯

  • @shahedtheboss
    @shahedtheboss Před 2 lety

    Your coding tutorials are as beautiful as you❤️

  • @renarsdilevka6573
    @renarsdilevka6573 Před 2 lety +3

    What i really appreciate, Ania, that this video is live coding. Tell me now if i am mistaken but in other videos for JS topic i noticed that you coded before and then just narrated in the video. Otherwise really great content, keep getting better in what you love the most.

    • @aniakubow
      @aniakubow  Před 2 lety +3

      In my early videos yea, but people said they prefer live coding so now i do that (and edit out long pauses etc) :D

    • @renarsdilevka6573
      @renarsdilevka6573 Před 2 lety +1

      @@aniakubow And that is why i will watch it all, Ania :) Great stuff :) All the best :)

  • @BrunoAlfaro
    @BrunoAlfaro Před 2 lety

    Te Amo! saludos desde Chile

  • @annakubow7751
    @annakubow7751 Před 2 lety +1

    Znowu wspaniale Aneczko!

  • @Cage5
    @Cage5 Před 2 lety +3

    I definately like the programming works and tutorials when it's about making a game. Especially, when a gorgeous woman gives the lectures. So keep going Ania!

  • @yanhu2011
    @yanhu2011 Před 6 měsíci

    Great tutorial! I learned a lot from this. One question - in several places the 'currentColor' array element is alterred directly . It is a state variable and I'm confused on why it's being updated directly instead of using the state setter. It's certainly working but i thought it's against the best practice to change the state variable directly.

  • @marcelooscarjose8515
    @marcelooscarjose8515 Před 2 lety

    TDD and Patterns should focus on your next projects, also templates to manage UI. Nice work !!!

  • @tristanalexander6825
    @tristanalexander6825 Před 2 lety

    I know we're here to code but your eyes are so captivating 😊, thanks for this though

  • @lucasalvarani317
    @lucasalvarani317 Před 2 lety

    Grazie!

  • @ionut-ciprianandrei5946
    @ionut-ciprianandrei5946 Před 2 lety +1

    Hi, great tutorial! I have noticed that the score keeps updating n * row +1 times )when the blank squares are falling.
    If the match happens on the 3rd row, the score increases with by 4 times the value of the matching squares , ie value= 3, the updated score will be + 32..
    And the app is continuously re-rendered even though there aren't other matching squares.
    I tried to use useCallback hook for each function that was called inside the useEffect but that didn't change the outcome. Any ideas how to fix that?
    Thanks

  • @billymartin6497
    @billymartin6497 Před rokem

    Great video. Learned a lot. I have two bugs I'm trying to figure out. Maybe someone can solve them.
    #1 Dragging with a touch screen instead of a mouse.
    #2 when the game starts or when the screen refreshes due to no legal moves, any matches that occur get added to the score. My game starts with 30 points sometimes.

  • @justcoding2491
    @justcoding2491 Před 2 lety

    You stole my ❤️❤️😘

  • @vkiperman
    @vkiperman Před 2 lety

    I love webstorm!

  • @edgargiobanny
    @edgargiobanny Před 2 lety

    Great thank you very much for the video the truth, I hope I can apply it in something greetings

  • @mohammadsalahuddin6939

    I am a big fan
    And Your sincere Student tooo

  • @FitoFx
    @FitoFx Před 2 lety

    thanks

  • @cirobarbagelata7194
    @cirobarbagelata7194 Před 2 lety

    Hey, nice video! A simple question, what extension do u use for automatic inferred types like in min 50:00

  • @hardwired89
    @hardwired89 Před 2 lety

    more react content wohooo ❤️

  • @kingmounir2740
    @kingmounir2740 Před 2 lety

    It's realy cool i like it react JS the best program of projects 😍😊

  • @dappinstitute
    @dappinstitute Před 2 lety

    Rock star status... you are Ania!

    • @aniakubow
      @aniakubow  Před 2 lety +1

      Thank you so much 😊😄💃

  • @TheFenzakosu
    @TheFenzakosu Před rokem

    An alternative way for checking of candies in a row :
    const checkForRowOfThree = () => {
    let row = 1;
    for (let i = 0; i < 62; i++) {
    if (row * width - 2 === i) {
    continue;
    }
    if (row * width - 1 === i) {
    row++;
    continue;
    }
    const rowOfThree = [i, i + 1, i + 2];
    const decidedColor = currentColorArrangement[i];
    if (
    rowOfThree.every(
    (square) => currentColorArrangement[square] === decidedColor
    )
    ) {
    rowOfThree.forEach((square) => (currentColorArrangement[square] = ""));
    }
    }
    };
    const checkForRowOfFour = () => {
    let row = 1;
    for (let i = 0; i < 61; i++) {
    if (row * width - 3 === i) {
    continue;
    }
    if (row * width - 2 === i) {
    continue;
    }
    if (row * width - 1 === i) {
    row++;
    continue;
    }
    const rowOfFour = [i, i + 1, i + 2, i + 3];
    const decidedColor = currentColorArrangement[i];
    if (
    rowOfFour.every(
    (square) => currentColorArrangement[square] === decidedColor
    )
    ) {
    rowOfFour.forEach((square) => (currentColorArrangement[square] = ""));
    }
    }
    };

  • @nadeemakramansari1331
    @nadeemakramansari1331 Před 2 lety

    You remind me of Angela from App Brewery. Great video dear. ...

  • @yadusolparterre
    @yadusolparterre Před 2 lety

    Thanks Ania for the good video. If I can allow myself a few pieces of advice:
    1. Your constants like width need to be written ALL CAPS. Also, a better name for "width" would have been "TILES_PER_ROW"
    2. A coherent CSS naming convention like BEM would have been welcome
    3. Instead of magic numbers like 560px or 70px in CSS, some CSS variables would have been better, eg:
    ::root {
    --numberOfTiles: 8;
    --tileSideLength: 70
    }
    .app__game {
    --gameSide: calc(var(--numberOfTiles) * var(--tileSideLength) * 1px)
    width: var(--gameSide);
    length: var(--gameSide);
    }
    4. It is bad practice to use index as keys
    5. I don't see the use of using nested flexboxes.
    6. Instead of using the magic number 47, you could have used:
    const ROWS_TO_CHECK = 6
    const TILES_TO_CHECK = ROWS_TO_CHECK * TILES_PER_ROW - 1
    7. Since you have two functions that are very similar (checkColumnsOfThree, checkColumnsOfFour, checkRowOfThree, checkRowOfFour), some refactoring or currying would have been in order
    8. For the tiles that you do not want to check, a formula would have been more elegant, along with a better name
    const allIndexes = [...Array.from({length: TILES_PER_ROW ** 2})].map((_,i) => i)
    const redundantIndexes = allIndexes.filter(index => [0,TILES_PER_ROW-1].includes(index % TILES_PER_ROW-1))
    // [6,7,14,15...]

  • @jamesmackinlay4477
    @jamesmackinlay4477 Před 2 lety

    I learned how to write APIs because of your video's.

  • @CameronRounder
    @CameronRounder Před 2 lety

    I tried making a game like this using a 2D array. Now wondering if there would be an advantage to using a 2D array over a single array. A single array for tracking the board wasn't even on my radar when I designed. Seems to simplify the entire app, especially in state management when you want to copy the array and reset.