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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:29:12+00:00 2026-05-26T10:29:12+00:00

I’m a student doing an extra-grade project, and my prof has asked me to

  • 0

I’m a student doing an extra-grade project, and my prof has asked me to create a program that deals with classes.

So, I’ve created a class called “Piece” with the following code:

namespace GG
{
    class Piece
    {
        public int rank;
        public int player; 
    }
}

I instantiated it in my main program (the Form), like so:

namespace GG
{
    public partial class frmPGame : Form
    {
        public frmPGame()
        {
            InitializeComponent();
        }

        Piece[,] gameBoard = new Piece[9, 8];

        public void clearGameBoard()
        {
            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 9; x++)
                {
                    gameBoard[x, y] = new Piece();
                    gameBoard[x, y].rank = -1;
                    gameBoard[x, y].player = 0;
                }
            }
        }
    }
}

Anyway, the form has pictures, and, depending on what’s inside the 2D array I’ve created, the picture can change. However, I also do some math in my main program, which makes it cluttered and long. I’d like to ask if I can, somehow, pass the gameBoard object to another class, along with its contents.

Basically the program flow right now is:

  • Create Object
  • Do math in Main using Object
  • Change form pictures

And, I’d like to, if possible, change it into:

  • Create Object
  • Do math in Math class
  • Return / Pass Object from math class to Main
  • Change form pictures

I know it looks like I’m complicating stuff, but my professor told me the only thing the main should do is render the pictures. The class should handle the math-related stuff.

Could I have some advice on this, please? Do I instantiate the “Piece” Class in my “mathClass”?

  • 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-26T10:29:12+00:00Added an answer on May 26, 2026 at 10:29 am

    I’ll propose two variants. Remember that arrays are reference types. If you pass one of them to a method, the method can modify it directly.

    First variant:
    Here the game board isn’t “described” as a full object. It’s an array with some (static) utility methods put in a GameBoardMath class.

    namespace GG
    {
        public partial class frmPGame : Form
        {
            public frmPGame()
            {
                GameBoardMath.ClearGameBoard(gameBoard); // Clear the game board
    
                InitializeComponent();
            }
    
            Piece[,] gameBoard = new Piece[9, 8];    
        }
    
        public class GameBoardMath
        {
            public static void ClearGameBoard(Piece[,] gameBoard)
            {
                int lenX = gameBoard.GetLength(0);
                int lenY = gameBoard.GetLength(1);
    
                for (int y = 0; y < lenY; y++)
                {
                    for (int x = 0; x < lenX; x++)
                    {
                        gameBoard[x, y] = new Piece();
                        gameBoard[x, y].rank = -1;
                        gameBoard[x, y].player = 0;
                    }
                }
            }
        }
    }
    

    Second variant: Here we consider the GameBoard to be a “full” class.

    public class GameBoard
    {
        public readonly Piece[,] Board;
    
        public GameBoard(int x, int y)
        {
            Board = new Piece[x, y];
    
            ClearGameBoard();
        }
    
        public void ClearGameBoard()
        {
            int lenX = Board.GetLength(0);
            int lenY = Board.GetLength(1);
    
            for (int y = 0; y < lenY; y++)
            {
                for (int x = 0; x < lenX; x++)
                {
                    Board[x, y] = new Piece();
                    Board[x, y].rank = -1;
                    Board[x, y].player = 0;
                }
            }
        }
    }
    

    To use it, in your Form:

    GameBoard gameBoard = new GameBoard(9, 8);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into

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.