GameIOExample

import java.util.Scanner; //Don't forget this line if you want to read keyboard input. It must be before and outside of any class code. public class GameIOExample //This is the start of a class called GameIOExample. Classes will be explained in a lesson coming soon. { public static void main(String[] args) /*Every runnable program needs ONE main method. For now, if you want to make changes, put your changes inside the curly braces under the "public static void main" part (so for this program, between lines 6 and 20)*/ { System.out.println("Please press the Enter key to start."); Scanner readInput = new Scanner(System.in); String keyPress = readInput.nextLine(); if(keyPress.equals("")) //Is the keyPress variable an empty String, or... { System.out.println("Long, long ago, you decided that you wanted to make video games. You weren't sure how to reach your goal. Then one day you heard about this game jam. Congratulations! You are now on your way to becoming a game developer!"); } else //...did the player type something before pressing enter? { System.out.println("All you had to do was press Enter!!!"); } } }
In this snippet, we take a first look at how to get input and output in Java. This is our first step to creating an interactive game.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.