#Beginner Games you can code in Java?

1 messages · Page 1 of 1 (latest)

mighty otter
#

So, I want to be a game developer, and I know that Java isn’t necessarily used for making games that much anymore, but I’m going to be retaking a class for Java soon, so I want to see what I can do with it since (assuming the class goes the exact same way as last time) we do not make any games in this class. Since I’m working with a tutor who knows my learning style (typically more hands on), she suggested that I look up a simple tutorial for making a simple game in Java. Unfortunately, said tutorials for Java are surprisingly lacking when compared to languages like Python and C++. I also would like to mention that I do use IntelliJ, but lately have been using the good ol’ Notepad/Command Line way of coding, mostly for fun, but also because so far it’s actually helped me focus a little better on what I’m doing (though I’m not really sure why). If anyone can provide any resources for beginner projects that involve coding games in Java, I’d greatly appreciate it. Thanks in advance

robust knollBOT
#

<@&987246964494204979> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
So, I want to be a game developer, and I know that Java isn’t necessarily used for making games that much anymore, but I’m going to be retaking a class for Java soon, so I want to see what I can do with it since (assuming the class goes the exact same way

I want to practice my skills by creating some simple games. What are some beginner games that I can code in Java?

Here are a few ideas for simple games you can code in Java:

  1. Tic Tac Toe: A classic two-player game where players take turns placing X's and O's on a 3x3 grid.

  2. Hangman: A word guessing game where players try to guess a hidden word one letter at a time.

  3. Guess the Number: A game where the computer generates a random number and the player has to guess it within a certain number of tries.

  4. Blackjack: A card game where players try to get as close to 21 as possible without going over.

  5. Snake: A classic arcade game where players control a snake that grows longer as it eats food, while avoiding running into walls or itself.

These games are relatively simple to code and can help you practice fundamental programming concepts in Java such as loops, conditionals, and user input. Once you feel comfortable with these games, you can start exploring more advanced game development concepts and tools in other languages like Unity or Unreal Engine.

frigid hemlock
#

i recommend using LibGDX (a simple library for game development in java)

mighty otter
frigid hemlock
#

oh so you do not know java yet?

#

"LibGDX" is just the name of the library if you were confused by that, or do you not know what a library is?

lament oar
#

Simple console games are an excellent first step.

frigid hemlock
#

but honestly as a beginner you would first code like console games, and a graphical game when you know at least the basics (but better be more advanced than just the basics)

weary vale
mighty otter
frigid hemlock
weary vale
#

I'm sorry I wasn't asking that to hurt your feelings, I was asking to understand what to recommend better

#

And hearing that I'd follow the others' recommendation starting with a console app

#

try to make a terminal tictactoe app

#

try to make it have an AI which will play against you

frigid hemlock
#

an "ai" you can easily have the full search tree of a tic tac to game in memory and let the computer make the optimal move

#

simple alpha beta search

mighty otter
# frigid hemlock you should describe a little bit more what you want and on which level you are. ...

Something really basic (pun not intended). Like, I’m only wanting to code a game at this point because as I showed, I’m a hands on learner. A textbook alone isn’t going to teach me anything, and most of the exercises in said textbooks felt like they weren’t teaching me that much (it just felt like copy and pasting…). I don’t know how else to describe it really. The only thing I know for sure is that I ideally don’t want the game to be text based, since that feels like I’d be coding literally any other application where you have to have user input

frigid hemlock
#

do you already know coding? e.g. do you know C++?

mighty otter
mighty otter
weary vale
#

yea c++ is really fucking hard

near glade
#

its not. its just that people prefer to teach c++. from the 90s - often bc they dont know better

#

thats like showing someone java 4. thats "hard" as well

frigid hemlock
#

i want to know C++ from the 90s, i like it. all the modern things i can use later, but i do want the raw memory and not abstract everything nice away with smart pointers and RAII

near glade
#

modern c++ isnt much harder than modern java or python. it just has a focus on topics that people might not find relevant, especially as beginner.

#

most notably lifetime and ownership of objects

#

c++, like many languages that arent java or python, suffers from good and free learning material being available. so the road can be bumpy

frigid hemlock
mighty otter
frigid hemlock
#

yes it is a library for game development

#

like pygame in python

#

but libgdx sets up the project for you

#

when you download it

mighty otter
#

Is it something you can get in the same way as JOptionPane where you can just kinda implement it with the import statement or do I have to get it separately (I remember having to do the latter for pygame)

frigid hemlock
#

there is a setup jar

weary vale
# near glade its not. its just that people prefer to teach c++. from the 90s - often bc they ...

i mean ok i might be much less smart than you are but like

auto switch_to_new_thread(std::jthread& out)
{
    struct awaitable
    {
        std::jthread* p_out;
        bool await_ready() { return false; }
        void await_suspend(std::coroutine_handle<> h)
        {
            std::jthread& out = *p_out;
            if (out.joinable())
                throw std::runtime_error("Output jthread parameter not empty");
            out = std::jthread([h] { h.resume(); });
            std::cout << "New thread ID: " << p_out->get_id() << '\n';
        }
        void await_resume() {}
    };
    return awaitable{&out};
}
 
struct task
{
    struct promise_type
    {
        task get_return_object() { return {}; }
        std::suspend_never initial_suspend() { return {}; }
        std::suspend_never final_suspend() noexcept { return {}; }
        void return_void() {}
        void unhandled_exception() {}
    };
};
 
task resuming_on_new_thread(std::jthread& out)
{
    std::cout << "Coroutine started on thread: " << std::this_thread::get_id() << '\n';
    co_await switch_to_new_thread(out);
    // awaiter destroyed here
    std::cout << "Coroutine resumed on thread: " << std::this_thread::get_id() << '\n';
}
 
int main()
{
    std::jthread out;
    resuming_on_new_thread(out);
}

Can you point out the undefined behavior here? (this is an example from the reference)

robust knollBOT
frigid hemlock
#

lol

weary vale
#

Here's a tip: It's a use-after-free

frigid hemlock
#

you are invading a help thread

weary vale
#

anyways TL;DR my point is java is great choice to start to learn programming, and c++ is much harder

weary vale
#

Which brings me back to the tic-tac-toe suggestion as a warmup to get more familiar with the language

#

and the AI idea to get more familiar with implementing slightly more complex logic

mighty otter
frigid hemlock
#

i like C++, and just because things like UB, and direct memory access and getting segmentation faults because you made a mistake can be a little harder that is no point against it, there is nothing bad in learning a non trivial language

frigid hemlock
#

you download it

#

and execute the setup jar

#

this sets up a project for you

mighty otter
frigid hemlock
#

swing is in the standard library that is why you can just directly import it

#

other libraries you have to install first, e.g. via a package manager like Maven or Gradle, or include a jar in the build path

#

but the libgdx setup jar does that for you

mighty otter
frigid hemlock
#

libgdx has a official site there you find the download
and for maven and gradle projects there is "maven repository"

frigid hemlock
near glade
#

im more thinking of pointer arithmetic, raw c-arrays and all the stuff around rule-of-5, virtual and whatnot that is the main focus of any c++ beginner course, giving everyone a headache and thinking programming is more complex than it has to be, while essentially not being at a focus in modern day programming with c++ at all

#

its focused on the internals and how the language works rather than teaching people how to program first

#

but thats also bc most learning material available for c++ has that as target audience and not programming beginners. but is then being used to teach those

near glade