In this tutorial I do something kind of crazy. I try to teach programming logic by writing code right out of my head. You probably won’t understand everything in this video, but that’s OK.
I continue making a simple game in Java. I specifically make a method that allows my monsters to move on the game board without landing on each other and blocks them from falling off the board.
If you missed part 1 definitely check out Java Video Tutorial pt 1.
The code follows the video. It is heavily commented and will help you better understand the video, so definitely look at it.
If you like videos like this share it [nttfblike]
Code From the Video
MONSTERTWO.JAVA
LESSONTEN.JAVA
getting an error:
“Exception in thread “main” java.lang.Error: Unresolved compilation problem:
ArrayUtils cannot be resolved”
in this line…
“int arrayItemIndex = ArrayUtils.indexOf(Monsters, m);”
You need to install the ArrayUtils library. I show you how in this article How to install Java libraries That will fix the error
okay, working now…
thanks..
I understand the need for ‘this.’ in front of member variables when you need to disambiguate member variables from method arguments of the same name. You seem to use ‘this.’ in many places where they are not strictly necessary. Is this just a personal preference (possbily to help remind you that what follows is a member variable) or is there another reason?
Also, thanks for the great videos. I’m actually watching the videos and translating your code into C++ as a vehicle to learn C++ programming. Working out very well (so far)!
I over did it with this in these early videos. You are correct that they aren’t normally needed except in the situation you mentioned. For some reason people get confused by this so I wanted to make sure the used it when needed even if it was over used. In later tutorials I stop doing that.
I’ll eventually make a c++ tutorial. I just want to finish java first. I wish I would have made complete tutorials in the past like I do now. C++ will be covered completely as well when I get to it.
I have the exact same code… i think, yet my board is not drawn properly. It just prints a single row with all the symbols from the board.
Feel free to skip to the next tutorial in the series. I review everything as it continues
Omar,
I think your problem is that you are using println() instead print() in both while loops: while(k <= 30){ System.out.print('-'); k++; }
Also try double quotes instead of single quotes in System.out.print('-'); I don't why that last part let it work for me, but it worked.
Hi Derek,
In your code you have:
// Randomly generate move direction N, S, E, or W
int randMoveDirection = (int) (Math.random() * 4);
I haven’t run the program to see the functionality of it yet. But shouldn’t it be (Math.random() * 5; since there are 4 directions a monster can move? In earlier tutorials I believe you indicated that when using Math.random() it must be one value above the numbers you wish to generate.
Great tutorials, by the way. I’m loving it!
You may be correct. I can’t remember this tutorial very well. I didn’t particularly like the way parts 8 and 10 came out.
I constantly try new ways of teaching. Here was one of the first times I started to program 100% out of my head. I was trying to teach the way a person thinks when programming. I think I failed here, but eventually by doing this I have succeeded in later tutorials.
I now regularly program 100% out of my head. I hope that in trying to improve my overall tutorials, that you don’t feel that you have wasted your time. I promise that aside from parts 8 and 10 that the rest of the tutorial series is very good. At least they are as good as I could make them. I hope that makes sense
You are awesome Dude. Keep doing this.
Thank you 🙂 Ill keep covering java until I’ve covered everything
Your tutorials are really awesome!!! I just wish you could provide some kind of practice questions or task after a series of tutorials so that would be great..
Any ways you are great man!! Cheers
Thank you 🙂 Sorry I didn’t do that in the past. I have been practicing with ideas on how I could provide homework and make the videos more interactive.
Java Video Tutorial 10 is not working… Is there anyway you can get it back up?
Feel free to skip it all together. The rest of the tutorial is much better. I consider parts 8 and 10 to be failed experiments. Sorry about that.
Hi Derek,
Thank you very much for the great tutorials. You are making the world to be a better place and I really appreciate your hard work.
I have a request from you. I understand your tutorials. But, how can we practice. I mean to have problems to think on our own as an assignments.
Thank you.
You’re very welcome 🙂 For practice one path would be to look at my Android development tutorials. I make one app after another there.
I thought of the Java tutorial as a type of video API. I thought the best way to watch it was to print out the code and then take notes as you watch in your own words. Then you could go back and use what you learned for anything.
In the Android tutorials I have started to teach while making apps. This is much harder for me, but people seem to enjoy that style. I’ll continue to try and get better 🙂
Hi Derek,
Don’t keep saying this Lesson 10 is a “failure”….I don’t think this “over kill” coding of the fly is bad at all. I enjoy it a lot.
You showed an excellent coding practice, based upon your rich experience.
James
Thank you 🙂 I just thought it was a mistake to cover logic when I had very limited tools to work with at this point. I’m glad you found it useful.
what does the Arrayutils.indexof() do ??
and thanks for everything man , keep going !!
You’re very welcome 🙂 It finds the index for a specific value that you provide