Java Video Tutorial 10

[ad_1]
Code is Here:

Best Java Book :

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.


Posted

in

by

Tags:

Comments

24 responses to “Java Video Tutorial 10”

  1. Alex Chapman Avatar

    can't help thinking this would have been easier with 2 classes one for the board and another for the players

  2. Mehdi Asadi Avatar

    Dear Derek, Thank you , I'm following your all Tutorials Seriously to become Java Programmer one day, but;
    My Concern and big confusing Question is :
    Q. – how I determine to divide " CODING " for each Class ; Because I don't get & understand why we write some coding in " Main class " and a lot more Coding but in the " Monster Class " , So how should I find out these Coding belongs to each specific Class ???

    please, solve this my big Problem in coding with your Explanation to be understandable that based on what Logic Roles in java We should Separate and Determine Coding in Main or Monster Class??

    Best regards, Matt

  3. Drew M Avatar

    The library that comes with ArrayUtils has changed a lot over time (or I might have just installed the wrong libraries) because org.apache.commons.lang3.ArrayUtils cannot be used. It can't resolve org.apache and I made sure I imported the libraries into their own folder under the same project. Is there an alternative way to go through this or does it go under a new name?

  4. Georges Miranda Spyrides Avatar

    Hey Derek, I'm having a bit of trouble to install the Apache commons library on IntelliJ IDEA. Do you recommend any source to solve that problem?

  5. Vladimir Skoupil Avatar

    Hi Derek. Best tutorial on Java. I appreciate it. Thank You very much. God Bless You. Keep doing this.

    If I am not wrong, maybe one correction. I think instead of:
    int maxXBoardSpace = battleBoard.length – 1;
    int maxYBoardSpace = battleBoard[0].length – 1;

    It should be:
    int maxXBoardSpace = battleBoard[0].length – 1;
    int maxYBoardSpace = battleBoard.length – 1;

    Your code works just because you have the same dimensions for X and Y axis.

    You can test it on static char[][] battleBoard = new char[5][10];
    With your code you will easily go to java.lang.ArrayIndexOutOfBoundsException

  6. Lukasz0596 Avatar

    Hey can somone help me i get all time error " Exception in thread "main" java.lang.NullPointerException
    at BattleBoard.MonABoa.onMySpace(MonABoa.java:176)
    at BattleBoard.MonABoa.moveMonster(MonABoa.java:150)
    at BattleBoard.Glowny.main(Glowny.java:25)"
    I tryed copy this fuctions and just change some word to my code from lesson 8 but all time same problem
    (Sry for English :<)

  7. David Shukurov Avatar

    thank you very much Derek , you are just the best! I've got a question how fix this two final exceptions? Because sometimes it runs properly but in 99% it gives me this two shits. Thank you again dude!

  8. guibator Avatar

    Hey Derek, first of all thanks for your tutorial.. It's by far the best way to learn Java for me and I am sure for many others. I have a question. In your code, you are printing randMoveDirection and randMoveDistance inside the while loop. Wouldn't it print multiple times in case the random numbers would have returned a place where some other monster were already there, forcing the while loop to make another itiration? Another question: I tried to declare randMoveDirection and randMoveDistance outside the while loop, initialize them inside the while loop (with randMoveDirection = (int) (Math.random() * 4);) and then print them outside the while loop but then I get an error saying that I haven't initialize those variables.. Why is that? Sorry for bad english. Thanks!!

  9. amir hershcoviz Avatar

    Hi there , I still dont understand how you move only one index of a monster to a method, when a monster needs a x and y index location. I mean arrayItemIndex that is past to movemonster method. thanks

  10. Jake Kudur Avatar

    hello! don't you have lesson of making turtle in java, which was written on Logo once?

  11. Angelo Miranda Avatar

    Thanks for the Java Tuts, im mainly a FE trying to dive in to Back End now. This is very helpful Derek. Any suggestion on what I should create first?

  12. element74 Avatar

    I understand everything in this video except I am still not understanding why it is important we put void for movemonster function. My question is "why is void important?" or "why do we need void?" The program obviously doesn't run unless you put void.
    p.s. I have very little programming experience and I've never seen anything like void before. I've used AutoIT, matlab, python, stata, and R.

  13. element74 Avatar

    It would have made more sense if you called the object isSpaceClosed instead of isSpaceOpen. That confused me for a few seconds until you further explained what it was for.

  14. element74 Avatar

    1:14 I don't believe we ever used a class object name in the beginning of an enhanced for statement. You always labeled it as datatype, such as string or int or string[ ] or int[ ]. I had to pause the video to make sense of it. From the previous videos i only know that m has to be either storing an array or a value. Since there is no [ ], then I would assume it is storing a value. But from what you have typed in that line, I would assume that it is storing a LIST of values. Is that right? I think this is why some people are confused.
    p.s. I will finish the video right now with that assumption.

  15. Leví Solito Avatar

    I have the same letter for my monsters (B). How can I change that to see a different letter?

  16. Evgeni Kuzmov Avatar

    11:21 can't you declare it just like "if < [10][10]" or smth instead of
    doing all that huge block of code if else < maxYposition and stuff (you know, the whole while loop/end of moveMonster)

  17. Evgeni Kuzmov Avatar

    ty for the tutorials! 😉 I have a question : this.getMovement() + 1 (line 129). isn't "+ 1" means it's s only moving to right direction aka to the east?

  18. Xiankai Zhang Avatar

    just the pace of ur talking! just what I want

  19. BLOOD WOLF Avatar

    I still have errors after fixing the boolean alive.
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2
    at MonsterTwo.moveMonster(MonsterTwo.java:83)
    at Lesson10.main(Lesson10.java:24)
    And all the {} are getting difficult to keep track of.

  20. A Wild Toaster Avatar

    All the characters are coming up as R for me instead of the first letter of the name given; I also realized I only have 3 out of the 4 players showing up. Besides that I fixed my other problem.

  21. Piotr Musiał Avatar

    I imported lib like in this link but I've got a problem: "The import org.apache cannot be resolved" How to fix it? I'm using Eclipse Neon

  22. Catia Mauk Avatar

    Can someone explain me this:

    Why is:
    // Set the value in the array to the first letter of the monster
    battleBoard[this.yPosition][this.xPosition] = this.nameChar1;

    and not:
    battleBoard[this.xPosition][this.yPosition] = this.nameChar1;

    Thx!

  23. Avery Lucas Avatar

    Just finished mine. I programmed attacking, gave the map its own class and let it handle the monster array. Then created 11 ninjas with all random stats and made them fight to the death. I created a tick function that ran through all the monsters and moved them. After that it was simply a matter of using a while loop while the numOfMonsters was more than 1. *Made sure to lower numOfMonsters by one everytime one died. Gonna move on to the next tutorial thing now. Maybe I will come back to this once we get to guis. 😀 Thanks for the tutorial. So far its been great fun. 😀

  24. Alex Brown Avatar

    As everyone has already stated, your videos are a tremendous help. I am learning java now and have almost finished my first text base little game thanks to listening to your videos. I am stuck though and was wondering if you could offer any suggestions. I have a class that creates an object with three parameters(string, string ,int). Then I create a class that makes an arraylist to hold my objects. My problem is checking if my arraylist at the time contains one specific string value. How would I do this in my main method? I have been confused for days now sadly.

Leave a Reply

Your email address will not be published. Required fields are marked *