Code Snake Game in Java

  Рет қаралды 108,616

Kenny Yip Coding

Kenny Yip Coding

Күн бұрын

Пікірлер: 124
@KennyYipCoding
@KennyYipCoding Жыл бұрын
Check out the playlist of web project tutorials here! kzbin.info/aero/PLnKe36F30Y4Y1XQOqNsL9Fgg_p6nYhcng Code Snake Game in JavaScript: kzbin.info/www/bejne/mJKlomh9drFjlbc Code Snake Game in Python: kzbin.info/www/bejne/fKXUiHalZsR8ask Got a tutorial suggestion? Let me know down below!
@hansmalm2801
@hansmalm2801 Жыл бұрын
This is just perfect videos for beginners that have learned the lauguage and how it works but needs to see how you use the code in easy small programs. There are tons of "learn how to program"-videos but with no usable examples. That is just like learning some chord on the guitar but no song to play. YT needs a lot more songs to play, like this. You also have a perfect voice for this and no messing around with side tracks. This is the equalivent to BASIC programs that you could find in paper magazines in the 80s. Just perfect! Keep them coming. Thank you.
@dillonpaul1498
@dillonpaul1498 Жыл бұрын
Thank you for the opportunity of coding a snake game, it was very beneficial to my coding journey as a student an I do look forward to future projects. You made my entire week awsome.😊
@hnudj9635
@hnudj9635 Жыл бұрын
The way u explanation for use of each line of code is ❤❤❤ best i have ever seen, thanks you
@riccardogarista5092
@riccardogarista5092 Жыл бұрын
Thanks for the flawless tutorial!
@tuxat_
@tuxat_ 6 ай бұрын
thanks for explaining all the complicated parts! really helped me out a lot!
@current_goliath
@current_goliath Жыл бұрын
Great tutorial, thanks for the clear and concise logic.
@MakkalSelvan-Thalapathy
@MakkalSelvan-Thalapathy Жыл бұрын
Support from India❤️
@BabyBunny-Cottontail
@BabyBunny-Cottontail Жыл бұрын
I'm so grateful for your videos! It's so much more fun learning Java when there's some GUI and fun games your working with. I've been slowly learning Java for the past year now, but it's all CLI apps in every tutorial. I'm following your tutorial now and I'm learning so much from them, but I know I'll be coming back in a couple of month and do them all over again when I know even more and probably understand even more of all the things your doing. I just wish you could explain even more of what your doing and why. For an example: why do you need to add "true" at the end when you're changing the tiles for the snake and the food from 2D to 3D? Keep up the good work and I promise to recommend this channel to all my classmates (I'm currently studying QA-testing and were using Java)
@KennyYipCoding
@KennyYipCoding Жыл бұрын
I try not to overexplain sometimes so i might not explain 1-2 parameters, but on some IDEs (or if you use vscode), hovering over the function will tell you what the params mean. Basically the boolean value for 3D indicates whether it should be 3D raised or etched. Meaning, should it look like the top of a cube (true), or should it look like a cube shape hole in the ground (false).
@dovydasbalciunas5002
@dovydasbalciunas5002 Жыл бұрын
May I ask how did you learn to code? Did you learn by creating games?@@KennyYipCoding
@dovydasbalciunas5002
@dovydasbalciunas5002 Жыл бұрын
How are you doing in learning Java?
@KennyYipCoding
@KennyYipCoding 6 ай бұрын
@@dovydasbalciunas5002 yes! so people focus too much on syntax and "correctness", instead it is better to learn by building projects :) So I can pretty much code 2D games in any programming language because I understand the concepts, even if I'm not an expert on said language.
@babymonster43
@babymonster43 6 ай бұрын
Thank you so much TTTOTTTT i really needed this for our final project
@_I_like_kebeb
@_I_like_kebeb 7 ай бұрын
the best snake video on entire you tube
@kimi59
@kimi59 Жыл бұрын
Hmm, at the point of 20:30, I get an error on the line: gameLoop = new Timer(100, this); It says that "The constructor Timer(int, SnakeGame) is undefined And, the line: gameLoop.start(); Has the error "The method start() is undefined for the type Timer" Any idea what this might mean?
@omerkose3848
@omerkose3848 Жыл бұрын
+1 "
@omerkose3848
@omerkose3848 Жыл бұрын
bro did you solve it I'm getting the same error
@rostom.00
@rostom.00 3 ай бұрын
hello i had the same problem but as soon as i deleted "import java.util.Timer;" the code ran properly and i had no issues.Try it.
@alejandroj.4441
@alejandroj.4441 2 ай бұрын
He uses javax.swing.Timer not util.Timer
@sammo7017
@sammo7017 Жыл бұрын
I followed your tutorial on how to code a snake game in Javascript, I think Java is harder but let's see 😁❤️ Thanks for your videos 💙
@KennyYipCoding
@KennyYipCoding Жыл бұрын
Let me know how it goes!
@sujalsangle
@sujalsangle 4 ай бұрын
Thank you for this video. it was very helpful and understandable. Love from India ❤❤😊😊
@cubes709
@cubes709 2 ай бұрын
THANK YOU this helped me make a java game for the first time YAY
@VietNguyen-vj4su
@VietNguyen-vj4su 5 ай бұрын
Thanks! you have a knack for story telling, which is good for in this line of work (media).
@pland4r133
@pland4r133 Жыл бұрын
maaaaaaaaan i love your videos you are taking me to the next level
@HospiceCarlTaneo
@HospiceCarlTaneo Жыл бұрын
I have a question, if i press two directions at the same time when going the opposite direction, it bugs out and ends the game, how do i fix this?
@damiaotiktok023
@damiaotiktok023 9 ай бұрын
Obrigado que tutorial incrível, ficou muito bom esse jogo. Assisti vários vídeos de como criar um jogo da cobrinha, e eu percebi que existe várias inúmeras maneiras de fazer um jogo mesmo sendo parecido, más com instruções diferentes, Obrigado vc explicou muito bem .
@omerkose3848
@omerkose3848 Жыл бұрын
at the point of 20:30, I get an error on the line: gameLoop = new Timer(100, this); It says that "The constructor Timer(int, SnakeGame) is undefined And, the line: gameLoop.start(); Has the error "The method start() is undefined for the type Timer"
@Dr_Mossig
@Dr_Mossig Жыл бұрын
Same here
@COZYTapezz
@COZYTapezz 11 ай бұрын
I figured out our issue we IMPORTED THE WRONG TIMER
@Dr_Mossig
@Dr_Mossig 11 ай бұрын
@@COZYTapezz How do we import the right one?
@Dr_Mossig
@Dr_Mossig 11 ай бұрын
I found how to fix it!
@srushtivaghasia4223
@srushtivaghasia4223 6 ай бұрын
​@@COZYTapezzthank you
@RachaitaBhattacharjee
@RachaitaBhattacharjee 2 ай бұрын
In 27:53 the green dot is not moving. What to do?
@KennyYipCoding
@KennyYipCoding 2 ай бұрын
go back a few minutes, you most likely missed a step Did you setFocusable and addKeyListener in the constructor? Did you add requestFocus in app.java? Have you updated the x and y positions of the snake when a key is pressed? Either the key presses are not being detected OR they are being detected but nothing happens. It would help to add debugging print statements
@RachaitaBhattacharjee
@RachaitaBhattacharjee 2 ай бұрын
​@@KennyYipCoding how do I add the debugging print statements?
@jorgerivera3733
@jorgerivera3733 2 ай бұрын
I get a bug on line #22 "Tile" snakeHead variable. I only get the "TIle" as abc **Resolved. The class path was misspelled.
@DuB_2k
@DuB_2k 11 ай бұрын
The grid isn't showing up. There are no errors as the program runs. I'm not sure if its because im on a mac and hes using windows but the program produces nothing when I run it.
@cubes709
@cubes709 2 ай бұрын
same im on mac too grid dont work
@cubes709
@cubes709 2 ай бұрын
just before you add the lines add a g.setColor(Color.white); it worked for me
@noahfeazell3336
@noahfeazell3336 9 ай бұрын
Question: Why do you need to declare all the stuff for the frame. and then declare stuff again in another class so it can be drawn on?
@TheBestCats-l3w
@TheBestCats-l3w 19 күн бұрын
Amazing Tysm I’m making this tm can’t wait 😊
@hyf1099
@hyf1099 Жыл бұрын
Tks for the video, but I get bug: when i press left down right sequence fastly, game over. Can u fix that, it happen when score is greater than two
@robtai6225
@robtai6225 11 ай бұрын
can you build a platformer game in java?
@tonyguerra136
@tonyguerra136 5 ай бұрын
Hello Kenny, I am wondering why when I type in line #9.....frame.setVisible (true); and line #11....frame.setsetLocationRelativeTo(null); a "b:" and a "c:" are added automatically to the "true" and "null" like (b:true) and (c:null). Is it there an "auto-correction command" in the VS that I can deselect? Wonderful videos and thanks for teaching me VS and Java.
@KennyYipCoding
@KennyYipCoding 5 ай бұрын
I think you might be referring to the parameter help box. kzbin.info/www/bejne/eHOTmI18pdqegLcsi=W-lNBaE7m-T-l-cT In my pinned comment for the how to set up java in vs code video, you will find instructions on how to disable this feature
@SilphiistderGoat
@SilphiistderGoat 6 ай бұрын
Does this code work on BlueJ too?
@stevensaleh4263
@stevensaleh4263 Жыл бұрын
Thank you so much bro finally i made snake game 😊❤
@kartikkakkar9410
@kartikkakkar9410 Ай бұрын
what if I want to change just the color of the snake head? how can I do that?
@KennyYipCoding
@KennyYipCoding Ай бұрын
Let’s say you want to change it to blue. Set the color of g to blue right before drawing the snake head. Then right before drawing the snake body parts, ser the color of g to green
@SiddhantShedge
@SiddhantShedge 7 ай бұрын
Just did the project and it did help me clear my java fundamentals!I just had one idea,how can I increase the speed of the snake each time it eats the food?
@ronin6397
@ronin6397 7 ай бұрын
Hmm looks complicated.. The speed increases with a lower level of the Timer. Maybe you can use and adapt to the same system as the velocity.
@SiddhantShedge
@SiddhantShedge 7 ай бұрын
@@ronin6397 thanks for your suggestion!
@devincaruso8128
@devincaruso8128 Жыл бұрын
This seems like a really cool video! I'm new to programming and often don't know what I'm doing, but I'm trying to copy the code down, and I get the error: package javax.swing does not exist(compiler.err.doesnt.exist) after typing import javax.swing.*; I have the java extension pack and a JDK that works for other programs, but not here. Does anyone know what might be happening? Thanks!
@samarmahato3054
@samarmahato3054 Жыл бұрын
Thank you ❤ from India
@KainatKhan-w6n
@KainatKhan-w6n 18 күн бұрын
can you let me know if you implemneted any data structures if so then how many ?
@KennyYipCoding
@KennyYipCoding 18 күн бұрын
@@KainatKhan-w6n for the snake game ? Do you know what a data structure is?
@KainatKhan-w6n
@KainatKhan-w6n 17 күн бұрын
@@KennyYipCoding i do know after looking at repo i found linkedlist implemented so i was asking if any others are used because i have requirements while submitting my project
@KennyYipCoding
@KennyYipCoding 16 күн бұрын
@@KainatKhan-w6n link list implemented in this snake game? I did not upload any implementation or use any linked list in java
@codinghack2
@codinghack2 Жыл бұрын
Perfect It really helped 😊
@andrejklester5851
@andrejklester5851 8 ай бұрын
Do you have javafx experiance, it is possibile too? Snake game?
@luuhgentile
@luuhgentile Жыл бұрын
First of all thank you very much for this tutorial! Apreciate it! I have a dual boot machine, I tried this tutorial first on Ubuntu and it didn't work, it didn't open the window when I executed the program on 3:44, then I switched to windows 10 and it worked fine. Do you think is there something wrong with my machine or with how I installed java on Ubuntu? Or does this code doesn't work on Ubuntu?
@nihalchandrav.c273
@nihalchandrav.c273 8 ай бұрын
Can we do this in scanner class?
@lavaflame059
@lavaflame059 9 ай бұрын
Thanks for the latest info.
@nehemiahpaulpichay23
@nehemiahpaulpichay23 4 ай бұрын
Is there any idea how can I put a button that says "Start Over" and the game resets from the start again. When u lose, u have to close and run it again, wonder how can I do that, beginner btw peace.
@KennyYipCoding
@KennyYipCoding 4 ай бұрын
Doing it with a button is unnecessary, you can add a check for a key in the key pressed function, and check if gameOver, if so, flip gameOver back to false and reset variables back to starting state. Ex) set score back to 0, clear the snake body parts array, place the food randomly.
@nehemiahpaulpichay23
@nehemiahpaulpichay23 4 ай бұрын
@@KennyYipCoding thanks big time
@olehliashyk6988
@olehliashyk6988 Жыл бұрын
Hi bro! Thnx for lessons. I have a problem with class "tile". This class not found in my IDE. Why? My IDE tell me "do not find symbol "tile".
@KennyYipCoding
@KennyYipCoding Жыл бұрын
I wouldn’t be able to tell. Did you make a typo? Ex) Tile, not tile. It should also say which line your issue is coming from
@olehliashyk6988
@olehliashyk6988 Жыл бұрын
@@KennyYipCoding I'm writing on mac os, maybe that's the problem?
@olehliashyk6988
@olehliashyk6988 Жыл бұрын
@@KennyYipCoding I understand that Tile and tile are completely different things, but I can't use it myself, because the IDE does not recognize it
@KennyYipCoding
@KennyYipCoding Жыл бұрын
@@olehliashyk6988 perhaps a problem with your project setup? is Tile in a different class file?
@olehliashyk6988
@olehliashyk6988 Жыл бұрын
@@KennyYipCoding I don't have a Tile class at all. I thought it was the same as JFTame etc. And because of that I can't continue my studies (((
@nathanmandala8465
@nathanmandala8465 Жыл бұрын
hey thanks for the amazing video! Next time, could you explain a little bit why you written some of the code? Thanks from Canada!
@KennyYipCoding
@KennyYipCoding Жыл бұрын
Hi! Thanks for watching! Let me know what parts of the code were confusing for feedback!
@BabyBunny-Cottontail
@BabyBunny-Cottontail Жыл бұрын
​@@KennyYipCoding Yeah, I agree. Sometimes you just add something and I wonder why and how you knew that. Still, your videos are great! There's hardly anyone doing any usable Java tutorials that's not CLI
@mrsxber1916
@mrsxber1916 Жыл бұрын
Appreciate this tutorial bro
@lucapepel5851
@lucapepel5851 Жыл бұрын
10/10 Thank you very much!
@eddibressan8805
@eddibressan8805 10 ай бұрын
Thank you for the helpful video
@pahmya1906
@pahmya1906 Жыл бұрын
i have a question, if we use random for the food, will it spaw inside the snake ?
@KennyYipCoding
@KennyYipCoding Жыл бұрын
Yes but it is very unlikely to collide with the snake’s head given the total number of square available.
@emilianogonzalezperez2772
@emilianogonzalezperez2772 Жыл бұрын
where are you from?
@fgprince7052
@fgprince7052 Жыл бұрын
Sir please upload java from beginning please sir Love from India❤
@Kanha0321
@Kanha0321 Жыл бұрын
I have made something similar too can I share its link?
@Sweet_Solos
@Sweet_Solos Жыл бұрын
That was very good tutorial i learned alot by following along and tweaking! I just have a quick observation regarding the draw(Graphics g) function you created for both the snake and the food graphics. Coming from JS i find it so odd the behavior of both the .setcolor and .fillRect methods, because at first I was so confused of how these methods were targeting the desired tiles but then i figured it out after reading the docs, apparently all subsequent graphics after .setColor will be drawn with said color until specified otherwise. It just seems unecessaribly verbose if I wanted to generate a more complex pattern but i guess thats just Java.
@KennyYipCoding
@KennyYipCoding Жыл бұрын
Yes you can think of setColor as pinking a color pencil, and you only switch colors after calling setColor (picking another pencil) again! I also have a snake tutorial in JS if you want to see how it’s done in JS
@uyg8
@uyg8 11 ай бұрын
perfect brother keep up
@Sandi22
@Sandi22 9 ай бұрын
Really cool. Thanks
@urdukahaniya570
@urdukahaniya570 Жыл бұрын
is anyone know how to restart game from which key
@tencent200
@tencent200 11 ай бұрын
u just have to make one in the keyPressed function. Here is a code just paste it in there: if (e.getKeyCode() == KeyEvent.VK_SPACE){ snakeHead = new Tile(5, 5); snakeBody = new ArrayList(); placeApple(); velocityX = 0; velocityY = 0; gameOver = false; }
@robtai6225
@robtai6225 11 ай бұрын
awesome content
@honzeus2010
@honzeus2010 10 ай бұрын
I can´t run the code,I think it´s because the javax.swing feature is not working, but I´ve written it exactly how you did, so I am confused a little bit. Sorry if there is a mistake on my side, but I´d be really happy if you could help me with that. I set up Java in vscode like you in your tutorial, but I could´ve done a mistake, so I please help me if you can. Also thank xou for creating videos like this.
@n4nalife
@n4nalife 2 ай бұрын
I use Eclipse, but if you have a 'modul-info' file, you have to put there (between the brackets): requires java.desktop;
@08-quocat6
@08-quocat6 Ай бұрын
i can't understand why the tile move along with snake head, help me guys!!!!! it's been a day
@karidad.19
@karidad.19 Жыл бұрын
Thank you❤️
@n0lerr1
@n0lerr1 5 ай бұрын
Thenks bro i love you
@mehraritvik
@mehraritvik Жыл бұрын
nice
@sadiulhakim7814
@sadiulhakim7814 5 ай бұрын
Awesome
@imalkesara4466
@imalkesara4466 7 ай бұрын
Thank u
@RogeliollNLape
@RogeliollNLape Жыл бұрын
new subs here
@subham5267
@subham5267 3 ай бұрын
27:00
@Sarmz1
@Sarmz1 3 ай бұрын
6:53
@subham5267
@subham5267 3 ай бұрын
12:27
@furkant.6681
@furkant.6681 4 ай бұрын
thankss
@williamkakooza4603
@williamkakooza4603 9 ай бұрын
The best way to appreciate you is by Subscribing. Thanks for this video. Can you please create a soccer game development tutorial.
@gasparcalix2095
@gasparcalix2095 Жыл бұрын
grate
@AayushEditzzz..
@AayushEditzzz.. 9 ай бұрын
AI:🗿🗿
@MicroDev-ql3kn
@MicroDev-ql3kn 4 ай бұрын
he i like you but java dont and thank you for letting me see thise because now i now java is not a fit form me but a fun learning experiense (love ur vids btw)
@ДаулетТилеуов
@ДаулетТилеуов Жыл бұрын
сду перваши вы тут?
@meyirbeksagymbai895
@meyirbeksagymbai895 Жыл бұрын
аххавхах
@timdelarboulas4796
@timdelarboulas4796 7 ай бұрын
Thank you for this video, it help to learn how write java code :) ! I try tobuild a restart function after a game over. For exemple, when you press the space key, it restart the snake game. I failed but, can you advice or give food for thought please ? Thank you in advance. I tried this : boolean restart = false; public void keyPressed(KeyEvent e) { ... // restart function if (e.getKeyCode() == KeyEvent.VK_SPACE && gameOver) { restart = true; } } @Override public void actionPerformed(ActionEvent e) { ... if (gameOver) { gameLoop.stop(); if (restart) { gameOver = false; gameLoop.restart(); } } }
@tencent200
@tencent200 11 ай бұрын
nice video. if it bothers you that the snake goes in with and and one more body tile in the boarder and doesn't die, just do - 1 at the boardWith and boardHeight like this: if (snakeHead.x*tileSize < 0 || snakeHead.x*tileSize > boardWidth - 1|| snakeHead.y*tileSize < 0 || snakeHead.y*tileSize > boardHeight - 1){ gameOver = true; }
Code Minesweeper in Java
49:50
Kenny Yip Coding
Рет қаралды 25 М.
Making a Game with Java with No Experience
8:41
Goodgis
Рет қаралды 674 М.
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Code Tic Tac Toe in Java
33:23
Kenny Yip Coding
Рет қаралды 34 М.
Writing My Own Database From Scratch
42:00
Tony Saro
Рет қаралды 261 М.
I Made an Electronic Chessboard Without Turns
14:32
From Scratch
Рет қаралды 1,1 МЛН
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 900 М.
ASMR Programming - Coding Pacman - No Talking
1:21:19
Servet Gulnaroglu
Рет қаралды 3 МЛН
*Next-door 10x Software Engineer* [FULL]
4:50
Programmers are also human
Рет қаралды 853 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,6 МЛН
20 Programming Projects That Will Make You A God At Coding
14:27
The Coding Sloth
Рет қаралды 1,5 МЛН
Getting Pranked Without Knowing It
8:50
Daily Dose Of Internet
Рет қаралды 2,3 МЛН