Solved

Programming with objects

Posted on 2003-11-06
3
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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