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 6834035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:03:40+00:00 2026-05-26T23:03:40+00:00

I am implementing a simple board game (Breakthrough) using OpenGL (plus GLUT and GLUI).

  • 0

I am implementing a simple board game (Breakthrough) using OpenGL (plus GLUT and GLUI).

I’m thinking of implementing a Board class, which will have a vector<vector<Cell> > as one of its attributes. Cell represents a space in the game board. It can contain a GameObject. GameObject will be a pure abstract class. It mandates that its derivative classes implement render(), for example. Possible derivative classes will be:

  • Blank, representing an empty space
  • Pawn, representing a pawn (the only possible pieces in Breakthrough)

The board will be rendered by first rendering the board, then iterating through each Cell, getting its contents and calling render() for each of them.

The only possible way I can think of to achieving this is making the GameObject in Cell a pointer (board[y][x].getContents()->render(), where getContents() returns the GameObject*)

Is this the best way to do this? Is this an appropriate usage of pointers?

  • 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-05-26T23:03:41+00:00Added an answer on May 26, 2026 at 11:03 pm

    Let me promote my comment into an answer. This doesn’t mean that it’s in any sense complete, only that this allows me to spell out some code examples. My original comment:

    That’s OK, though you probably would do better with a std::unique_ptr<GameObject> or a std::shared_ptr<GameObject> so you don’t get lost amids the manual lifetime management issues. Finally, how about a flat 1-D array accessible in strides?

    Here’s how I might go about this:

    #include <vector>
    #include <memory>
    
    struct GameObject { virtual void render() const = 0; virtual ~GameObject() { } };
    
    class Cell
    {
      std::unique_ptr<GameObject> m_go;
    
    public:
      void render() const { m_go->render(); }
      Cell() : m_go(new BlankCell) { }
      // more functions to reassign the cell value etc.
    };
    
    class Board
    {
      std::vector<Cell> m_board;
      std::size_t       m_length;
    
    public:
      Board(std::size_t length) : m_board(length * length), m_length(length) { }
      Cell & cell(std::size_t i, std::size_t j) { return m_board(j + i * m_length); }
      Cell const & cell(std::size_t i, std::size_t j) const { return const_cast<Board*>(this)->cell(i, j); }
      // more...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am implementing the simple bubble sort algorithm using CUDA, and i have a
i am currently implementing a simple ray tracer in c++. I have a class
I'm implementing a simple referral system. I have middleware which sets a session variable
I'm implementing a simple threaded application in which I have a server thread, and
I am implementing a simple version of a linux shell in c. I have
Ok...... I'm implementing a simple OpenGL ES application on the iPhone and I recently
I am implementing a very simple file database. I have 2 basic operations: void
I have tried to find out the working solution for implementing simple events booking
I'm implementing a simple game for an assignment that would ideally run both on
I am implementing a simple cache using LinkedHashMap based on the instructions found here

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.