Code is Here: http://goo.gl/Ic9sk
How to Install Java Libraries: http://goo.gl/Dqco3
Best Java Book : http://goo.gl/FtKp0m
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.
Amazon Auto Links: No products found.
would this have worked the same if you didnt put monsters into an array in main?
@ 10:33 wouldn’t you want
public boolean getAlive()
{
return alive;
}
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.
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
10:35 i dont get it alive is a boolean value and you assign it to return int?
Yeah man, I did it! It looks awesome. Thanks again, can’t wait to finish game.
nothing much goin on here just fartin’ out some tuts lol
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?
like:
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”);
board.add(m);
Then the board could check where is a free position for the monster.
Sorry for my bad english.
Why are you using “this” inside the constructor? The variables xPosition and yPosition are unique and set to public.
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.
sir Please make simple video how to play this monster game actually. I am unable to understand how it will work
nice videos
great video!, but why at line 29 you used system.out.println() method?
You’re literally more lovely than my college Professor 😀
why did u created tempbattleboard ? and where is it being used in the program?
You helped me a lot
getting some serious semantic satiation on the word ‘monster’
Are you still answering questions?
@derek
Error
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
im just following huh!
never understand a single thing
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.
How Eclipse autofill your commands like in 3:53.
Should i turn something on or press a button for that?
14:23 why is it != “*” ? it should be equal to *
What kind of game is this? I don’t get
its too hard for beginner
Since we’ve already incremented the number of monsters inside the constructor, why do we have to use the block below?
public MonsterTwo()
{
numOfMonsters++;
}
Shouldn’t you first create a Monstertwo object and only then call a method upon it?
@10:04, why did you make “numOfMonsters” static?
I’m so confusing about this lesson
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?!
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.
what is the difference of battleboard.length vs battleboard[i].length?
@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.
import java.util.Arrays could not be resolved… im runing on xp (still).. can somebody help
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.
at 13:31, for lines 144 and 145, will randNumX and randNumY only receive random integers between [0,8]?
Ouch! Error: Brain not found.
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
Which shortcut did you use to create line you had above 3 times?
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
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
Can anyone explain to me how this thing works and what exactly it does because I do not get it?
char[] row : battleBoard
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!
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?