Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:52:51+00:00 2026-06-17T03:52:51+00:00

I’m making a simple tic tac toe game as an exercise in LWJGL. When

  • 0

I’m making a simple tic tac toe game as an exercise in LWJGL.

When I write methods to draw the board squares and pieces such as the x and o pieces, should I put them in one graphicsLib class that can then be called by the various objects such as the board? or is it considered best practice to have each object contain the code to draw its own element? I’m looking to make the code as extensible as possible.

Specifically, I have a Board class which is a collection of objects of type Square, and the square objects are assigned an enum state CLEAR, X, or O. I then run a switch statement on the state that will call the appropriate method to draw the square. Should I put each method in its own object or have one large graphics object (say public class graphicsLib) that then supplies the methods to draw the various elements?

What is the best way to organize this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:52:52+00:00Added an answer on June 17, 2026 at 3:52 am

    Where possible, use an object-oriented approach when you can. When I’m writing something like this, I would generally have each of my objects provide at least two methods:

    public void update(int delta);
    public void render();
    

    That way my objects and the many instantiations of them all know how to update themselves and render themselves. You could then structure your code such that your Board class’s update and render methods will call update and render on its children Squares (See example below). This provides some benefits:

    1. Drawing/updating of objects is cohesively close to the representation of that object (Separation of concerns).
    2. As your “model” classes become complex, your rendering functions are close to that data, so your APIs stay stable. If you had one class for drawing, you could imagine you’d have to pass a lot of data to the drawing class and each of those calls would have to be customized and changed as your model changes.
    3. You won’t have one gigantic class that provides an API for drawing everything. This would become large and unwieldy quickly.
    4. You have a built-in structure for the Painter’s Algorithm since your have a hierarchy of when things are drawn based on a parent/child relationship. You only need to manage your siblings correctly at each parent’s render method.

    Here’s the example of the hierarchy rendering.

    public class Board {
        List<Square> squares;
    
        public render() {
            // Render your board first
            ...
    
            // Render child squares
            for (Square square : squares) {
                square.render();
            }
        }
    }
    

    So as you could imagine, your main game loop could simply tell your board object to render and you’re done. You don’t need to have any intimate knowledge of what else the board might need to render.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.