Advanced

Practice coding in Java by writing a game

Posted by bob on · 1 comment
Opensource.com
Mail this story
Print this story

My article about learning different programming languages lists five things you need to understand when starting a new language. An important part of learning a language, of course, is knowing what you intend to do with it. I've found that simple games are both fun to write and useful in exploring a language's abilities. In this article, I demonstrate how to create a simple guessing game in Java. read more

Full Story

  Nav
» Read more about: Groups: Games; Story Type: News Story

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (1)

Original compilation is

javac src/Guess.java -d com/example/guess

[boris@sever33fedora JAVAGAME]$ javac src/Guess.java -d .

[boris@sever33fedora JAVAGAME]$ ls com/example/guess

Main.class

[boris@sever33fedora JAVAGAME]$ jar cfme Guess.jar Manifest.txt com.example.guess.Main com/example/guess/Main.class

[boris@sever33fedora JAVAGAME]$ ls -l

total 8

drwxrwxr-x. 3 boris boris 21 Dec 16 10:33 com

-rw-rw-r--. 1 boris boris 1426 Dec 16 10:45 Guess.jar

-rw-rw-r--. 1 boris boris 22 Dec 16 10:01 Manifest.txt

drwxrwxr-x. 2 boris boris 24 Dec 16 10:22 src

[boris@sever33fedora JAVAGAME]$ jar tvf Guess.jar

0 Wed Dec 16 10:45:16 MSK 2020 META-INF/

99 Wed Dec 16 10:45:16 MSK 2020 META-INF/MANIFEST.MF

1572 Wed Dec 16 10:43:40 MSK 2020 com/example/guess/Main.class

[boris@sever33fedora JAVAGAME]$ java -jar Guess.jar

number is 49

Guess a number between 1 and 100

48

Too low

Guess a number between 1 and 100

50

Too high

Guess a number between 1 and 100

49

That's right!

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post