Java Video Tutorial 8

Code is Here:

How to Install Java Libraries:

Best Java Book :

I thought it would be fun to teach Java while I make a video game. This is a simple game, but it will teach a lot of the logic needed to make your own game.

This tutorial will teach you about arrays, class fields, class methods, how to set a default value for an array, and a ton of logic.


Michael DeGuire says:

would this have worked the same if you didnt put monsters into an array in main?

Bad Content says:

@ 10:33 wouldn’t you want
public boolean getAlive()
return alive;

Strange ! says:

I’ve found a mistake in the code, when generating random positions for the monsters
you set maxXBoardSpace = battleBoard.length – 1, it means maxXBoardSpace would be 9
But mistake is randNumX = (int) (Math.random() * maxXBoardSpace) , so randNumX would be from 0 to 8 so it’s never gonna fill 9’th row and 9th column.

Brian Smith says:

Hey Derek, amazing videos, you are really good!! two questions: how do you know what you have to import? and all my classes always have package at the top how come yours dont have that? thanks

ashiinsane90 says:

10:35 i dont get it alive is a boolean value and you assign it to return int?

Bruno Ribeiro says:

Yeah man, I did it! It looks awesome. Thanks again, can’t wait to finish game.

Darren Murphy says:

nothing much goin on here just fartin’ out some tuts lol

Mr Misiu says:

Hi. I find that tutorial great. But when a MonsterTwo is created without executing MonsterTwo.buildBattleBoard() before, there will be an endless loop because there will be never a true condition in line 147, because the chars a empty (never *).
Would it be better two seperate the BattleBoard in a own class?
BattleBoard board = new Board(10,10);
// in the constructor of the bord could be an private array of monsters be initaliced
MonsterTwo m = new MonsterTwo(1000, 20, 1, “Frank”);
Then the board could check where is a free position for the monster.

Sorry for my bad english.

Dragos Oltean says:

Why are you using “this” inside the constructor? The variables xPosition and yPosition are unique and set to public.

ledzeppeman says:

Hey Derek, I know I’ve commented a lot recently, but simple question:

After I followed your link about how to install java libraries, I was able to successfully use the libraries, BUT now my autocomplete isn’t working. To be specific, I use “sysout” + (ctrl + space) to autofill println statements. It still works in other java projects. This behavior is repeatable in freshly made projects; do you have any idea why that might be?

Thanks so much.

BHS Sen says:

sir Please make simple video how to play this monster game actually. I am unable to understand how it will work

Ugaaska Umadda Somaliyeed says:

nice videos

Sarthak Dash says:

great video!, but why at line 29 you used system.out.println() method?

Mingyu Liu says:

You’re literally more lovely than my college Professor 😀

nalin reddy veeramala says:

why did u created tempbattleboard ? and where is it being used in the program?

Teash says:

You helped me a lot

naked flames says:

getting some serious semantic satiation on the word ‘monster’

alberto cassio says:

Are you still answering questions?

Shawn Logan Angelo Lapuz says:


import java.util.Arrays cannot be resolved

im watching all your video tutorial and copying your codes until lesson 8. and it reall helped me. also i followed the steps how to install eclipse and additional libraries you recommended but still i cant resolve the import java.util.Arrays error

DrHanna says:

im just following huh!
never understand a single thing

Pacal says:

I’m getting an error in the line:
for(char[] row : battleBoard)

The error suggests “Change project compliance and JRE to 1.5”. This is weird since I’m using java 10, so it’s a lot higher and when I change it, it doesn’t help anyway. My library dissapears completely and things like just “String” are marked as errors.

peter panschick says:

How Eclipse autofill your commands like in 3:53.

Should i turn something on or press a button for that?

Evgeni Kuzmov says:

14:23 why is it != “*” ? it should be equal to *

Jaka Perdana says:

What kind of game is this? I don’t get

Sohail Khan says:

its too hard for beginner

Felipe Pagginelli P. says:

Since we’ve already incremented the number of monsters inside the constructor, why do we have to use the block below?

public MonsterTwo()

Daniel Passy says:

Shouldn’t you first create a Monstertwo object and only then call a method upon it?

Joseph Yoon says:

@10:04, why did you make “numOfMonsters” static?

Ruyang Guo says:

I’m so confusing about this lesson

Samed F. B. says:

randNumX = (int) (Math.random() * maxXBoardSpace);
// Why maxXBoardSpace (which is 9) and not use battleBoard.length (=10)? Because this code would generate a number from 0 to 8?!

S.k.R s.K.r says:

HEY, I AM ruuning the code but my ‘ -‘ as well as |*| all comes in a single coloumn instead of 10×10 .
Help me out here .
Except that all is awesome thanks.

Janel Logrono says:

what is the difference of battleboard.length vs battleboard[i].length?

Ashish Adhikari says:

@3:40, in the buildBattleBoard() method’s for each, you refer to char[] row as “individual stars that’re gonna go into the cells”. Doesn’t row refer to each complete row in your 2D array and not each cell? As far as I know, Arrays.fill([] array, value) fills all CELLS in an ARRAY with the given value, i.e. row in the for each must be a row and not a cell.

Johnny Batafljeska says:

import java.util.Arrays could not be resolved… im runing on xp (still).. can somebody help

Ben says:

At 13:56, correct me if I’m wrong, but shouldn’t randNumY be in the first brackets of the array. Maybe I had some fluke, but after I finished tutorial 10 my program was having problems with the random placement of the monsters and I’m pretty sure when I flipped the randNumX and randNumY it fixed the problem. Again I’m new to this so I could be wrong.

Ian Prado says:

at 13:31, for lines 144 and 145, will randNumX and randNumY only receive random integers between [0,8]?

Mark Evangelista says:

Ouch! Error: Brain not found.

dedZombie says:

The most fun I had learning Java, and it’s still so early into tutorials ^_^ I keep looking forward to the stuff waiting me ahead. Thank you so much Derek <3

Samuel says:

Which shortcut did you use to create line you had above 3 times?

Abhinav Srivastav says:

char[][] tempBattleBoard = new char[10][10];

i cant get it.. why we are creating this char array, if we have already created in our base class.
plz explain

shashgo says:

Derek, awesome tutorials. Right now there are two things Im not too clear about. One is the enhanced for loop; I am more comfortable with the use of two variables to do the nested loops, rather than this new for of the for loop. So, is this enhanced for loop just another way of doing the looping, and can I still use the other way of using two variables to nest the loops? The other question I had was about this program; according to me, it just creates the board and puts the four monsters in random spots, am I correct?

Also, on another tangent, do you also make tutorials on cyber security, like talking about TCP/IP, networking, etc

Tranculent says:

Can anyone explain to me how this thing works and what exactly it does because I do not get it?

char[] row : battleBoard

Dale Goodrich says:

Hey Derek…awesome videos…really enjoying them! One quick question about the Do-While loop you build to find an initial position for the monster in the constructor method. The While statement says while(battleBoard[randNumX][randNumY] != ‘*’; but then when you find a position that works, exit the loop and assign the monster to that position, the statement says battleBoard[this.yPosition][this.xPosition] = this.nameChar1;Why are the arguments in the while statement randNumX followed by randNumY but then they’re switched in the assignment statement to this.yPosition followed by this.Xposition? My gut says the arguments in the while statement should be switched…[ranNumY] followed by [randNumX]. Correct?Thanks!

Evgeni Kuzmov says:

why on is it battleBoard.length – 1; why minus 1
and why next is [0]?

19:30 line 38. so are there four two monsters? sound confusing

what is battleBoard? An object, variable or a method?

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!