4. Enemy AI
A basic type of AI in games is one that finds and seeks the player.
To achieve this, coders must get the enemy object and then move it towards the player object.
In addition to randomly spawning enemies in a game, you can also increase the difficulty by upping the spawn rate.
Take a look!
5. Class files
All Java code is contained within class files, so, your child will need to create a class file in their newly-created project.
Important: Class names should be capitalized, and each new word in the title should also be capitalized. The names cannot contain spaces.
Example of a correctly-named class: “AdventureGame”
6. Main method
Before your child can begin coding, they’ll need to add a method inside of the class, which is the first bit of code that’s called when you run your program. Think of it like a starting point for the rest of the code!
To create a main method in IntelliJ, underneath “public class [ClassName]” your child can type “psvm” and then press the tab button.
(psvm is a shortcut that creates the main method.)
7. Variables
A variable stores information about a program while it's running.
Example: In an RPG (a type of video game), a character's name, level, and hit points are all stored in their own variable.
Any time your child is playing a game and they level up (or take damage), a variable changes to reflect what happened.
To use a variable, a coder must declare the proper variable type:
Integers: An integer is a type of variable and represents a whole number. For example, -17, 4, 0, and 42 are all integers. You declare an integer in Java using the “int” keyword.
Doubles: A double is a number that can have a decimal. For example, -12.5, 4.0, 0.001, and 4.2 are all doubles. You declare a double in Java using the “double” keyword.
Strings: You use a String to store text. For example, "carrot," "apple pie," "pear," and "orange juice" are all Strings. You declare a String in Java by typing “String” followed by the variable name.
Important: It's considered good practice to declare all variables at the beginning of the code. When everyone codes this way, they know exactly where to look to find them!
8. Order of Operations
Operators perform mathematical calculations while a program is running.
Example: Say, for instance, if a character earns experience, the action needs to be added to the total experience count. If an arrow hits an enemy, the damage it takes needs to be subtracted.
So, operators are used for whenever a value needs to be changed.
Multiple operators can be performed at once, and Java arithmetic operators follow the mathematical order of operations
Some basic operators and their order of precedence are listed in the table below.
9. If Statements
An if statement allows coders to execute code if some condition is met.
Example: When a monster is attacked in an RPG, they’ll need to check if that monster has been defeated.
Using if statements, kids can write a program in which they determine if a character is strong enough to slay a dragon.
10. For loops
A for loop runs a section of code repeatedly until a condition is met, like a while loop. However, they use a different syntax and are useful when you're using an array.
Example: In an RPG, a player's inventory could be stored as an array of strings. While exploring a dungeon, they encounter a locked door—a for loop can be used to determine if the player is carrying a key to the door.
11. While loops
The programs explained so far have run in a straight line from start to finish. In an adventure game, once a player makes a choice, there is no way they can turn back and make another choice.
A while loop is code that repeats itself based on a condition.
Example: A while loop can continue to run until monster health is equal to 0. Now, players will continue to descend into the depths of the dungeon until they run out of health!
Ready to put it all together?
With the above basics, you and your kids should have a better idea on whether or not embarking on an adventure into the world of Java programming fits their interests.
So, next steps?
One, here is a list of ways to practice Java online.
After that, online coding courses and summer coding camps are great options, allowing students to dive into the details en route to building a lifelong passion for tech, like Java, alongside new friends in a pressure-free, creative environment.
And kids who might thrive in a more personal atmosphere? Java tutoring is available for a 1-on-1 learning experience with curriculum customized to their unique interests and skill level.
So, again—know of someone who enjoys something like playing Pokémon? Maybe learning how to make a text adventure RPG is in their future. Or, if they are interested in social media, perhaps they can try to recreate an algorithm for different user search functions.
With hands-on exposure to Java fundamentals and the opportunity to dig deep into programming logic, instruction in any form can help students build the confidence needed to keep learning during summer and long after summer ends.