Solved

Programming with objects

Posted on 2003-11-06
3
351 Views
Last Modified: 2010-04-07
Can you advice me on whether i should represent each square as an object and putting this objects in an array, i'll will like your opinion on this please if you have a better idea it is welcome please.
0
Comment
Question by:Drake009
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 70 total points
ID: 9698459
Each squiare of what? A quilt? The blocks of a city? On a checker board?

Your question, without any context, is so vague that it cannot be answered.

Post some description of the problem you are addressing where squares fit into it, what you know about objects, whether or not the implementation of those objects matters, etc.

-bcl
0
 

Author Comment

by:Drake009
ID: 9699481
On a chess board sir, whether i should represent the squares as objects implementing in java. I wanted to implement as an array of squares so that the function which scans the board will have an easier task i hope.
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9701107
(1) You probably didn't want to accept my answer (at least no the one above which conveys nothing more than a question about your question). You can go to the Community Service area and post that you accepted the wrong answer to have the question reopened.

(2) I am going to stick to higher-level design issues here (actually language independent). When you get further along you can ask Java specific questions in the Java topic area (feel free to ask any getting started questions you have here and I can help some).

(3) Let us consider what a chess square is, what attributes it has. It has location, color, and, optionally, content. A computer program has to abstract away the meaningless attributes and focus on representing the important ones. It seem obvious that whether a square is glued paper or painted or a different species of wood from its neighbors is probalby not relavent to a chess playing program (might come into play in the display but we'll ignore that for the moment).  You will want to have a square draw itself on the screen so there is a screen location (which might well change over the course of the game if the player can change her view) and a board location (e3 or king's pawn six) that won't change over time (unless you design a very unorthodox version of chess...could be interesting).

So, collecting these attributes together into a class makes sense. Then you can define the operations you need a square to support. One is draw. How it draws is not important at this point, only that it can draw itself in the right spot on the screen. You'l also need to be able to move a piece to the square (and probably have the square ask the piece to draw itself given the coordinates of the center of the square...that means a piece is probably an object, too). You'll want to be able to ask whether the square is occupied and then whether it is occupied by white (or black). You will, of course, need to be able to create 64 squares, specifying their color, board location, and initial contents (or leave initial contents for later with the "moveTo" method).

So, the interface for a square looks something like this:

Square(int row, int column, Color baseColor);
moveTo(Piece p); // move piece p to this square
moveFrom(); // move any piece away from this square
isOccupied(); // is the square occupied
isOccupant(Color c); // is there an occupant of Color c in the square?
Draw();

If you permit different views you'll also want to be able to set the screen location with a separate funciton.

Hope this helps get you started.

-bcl
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question