Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners initialising a checkers board

Have Programming Question? Ask it here!
 
 
 


Louise
initialising a checkers board
0 Answer(s)      a year and 10 months ago
Posted in : Java Beginners


Hi there

I am new to java and i am trying to place checkers pieces into a checker board which is set up as an array. What i have done so far is create an array and fill it with nothing. I have then created a copy and now want to place the appropriate pieces into the array

Here is my code

 public class Checkerboard  {
      // Constructors
      private Object checkerboard;;

// Creates a checkerboard where all the squares are empty. public Checkerboard() { Checker checkerboard[][] = new Checker[8][8]; for (int i=0; i < 8; i++) for (int j=0; j < 8; j++) checkerboard[i][j] = new Checker(null); }

public Checkerboard(Checkerboard old) { if (old == null) { System.out.println("Fatal error: copying null Checker"); System.exit(1); } this.checkerboard = old.checkerboard; } public void initialise() { Checker checkerboard[][] = new Checker[8][8]; for (int i=0; i < 1; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(true); for (int i=1; i < 2; i++) for (int j=1; j < checkerboard.length; j=+2) checkerboard[i][j] = new Checker(true); for (int i=2; i < 3; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(true); for (int i=5; i < 6; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(false); for (int i=6; i < 7; i++) for (int j=1; j < checkerboard.length; j=+2) checkerboard[i][j] = new Checker(false); for (int i=7; i < checkerboard.length; i++) for (int j=0; j < 7; j=+2) checkerboard[i][j] = new Checker(false); } }

My checker piece is in another class and is boolean type (red = true, black = false). I know I need to access the Checker piece, but I'm really not sure how to do this. And it seems really messy to have 6 for loops. Any advice would be very helpful.

Thanks


Advertisement
View Answers

Related Tutorials/Questions & Answers:
initialising a checkers board
initialising a checkers board  Hi there I am new to java and i am trying to place checkers pieces into a checker board which is set up as an array. What i have done so far is create an array and fill it with nothing. I have
initialising a checkers board
initialising a checkers board  Hi there I am new to java and i am trying to place checkers pieces into a checker board which is set up as an array. What i have done so far is create an array and fill it with nothing. I have
Advertisements
Style and Correctness Checkers
Java NotesStyle and Correctness Checkers PMD Description: PMD checks for a long list of possibly bad programming practices and possible error conditions in source programs. My feeling about it is mixed
scoring board - Ajax
scoring board  Need code in Ajax to create a scoring board to display score on it.  Hi,You can use <meta http-equiv="refresh" content="600"> tag of HTML to automatically refresh the page
How to make an electronic advertising board, make an electronic advertising board, electronic advertising board
How to make an electronic advertising board       This is an electronic advertising board... according to your electronic advertising board size. Choose Color: Set
Initialising Fields before Superconstructor call - Java Tutorials
Initialising Fields before Superconstructor call 2004-03-20 The Java Specialists' Newsletter [Issue 086b] - Initialising Fields before Superconstructor call (Follow-up) Author: Dr. Heinz M. Kabutz If you are reading
Initialising Fields before Superconstructor call - Java Tutorials
Initialising Fields before Superconstructor call 2004-03-19 The Java Specialists' Newsletter [Issue 086] - Initialising Fields before Superconstructor... a look at my website if this interests you. Initialising Fields before
Java, MouseEvents, MouseClick, GameOfLife board - Java Beginners
Java, MouseEvents, MouseClick, GameOfLife board  Hi, I am working on Java programming and I have a project called Game of Life. I created a board... a dead cell). I tried to add cells to the board by mouseClick and it seems
How to show database values in Graph.(Like Cricket score board Graph)
How to show database values in Graph.(Like Cricket score board Graph)  Hi, Can Any one help out! How to show database values in Graph. i mean while....(Like Cricket score board Graph)   import java.sql.*; import
If you came on board with us, what changes would you make in the system?
If you came on board with us, what changes would you make in the system?       This seemingly innocent question has many landmines hidden in it. You might be very close
eSpell
eSpell       Eclipse Spell Checker Plug-in 2 Generic spell checker plug-in for the Eclipse 2.1 platform. Includes special purpose spell checkers for Java, JavaScript
Visit to Fatehpur Sikri
Fatepur Sikri. But the better option would be to board a bus from Idgah Bus Station..., it is recommended to board a bus before dark since transportation from Fathepur Sikri at night
Graphic interface java help
Graphic interface java help  A modified checkers program with class name Checkers using double buffering. Somehow the program must have two top squares and two bottom squares. There should be two checkers of different color
Java Programming: Solution to Programming Exercise
) is similar to Tic-Tac-Toe, except that it played on a much larger board and the object... pieces on a board. A piece can be placed in any empty square. The first player.... Your applet will be simpler than the Checkers applet from Section 8.5. Play
Java Programming: Section 8.5
moves on the board. In my program, a move in a Checkers game is represented.... For example, a chess board is a grid with 8 rows and 8 columns. If a class named... of a chess board could be represented by a two-dimensional array
Java Programming: Chapter 8 Exercises
that it played on a much larger board and the object is to get five squares in a row rather than three. Players take turns placing pieces on a board. A piece can... the Checkers applet from Section 8.5. Play alternates strictly between the two
Javascript matrix error
) whenever it is called function valid(n){ //n is a number 0-9 if(board...; } } where board is a global 3x3 Array matrix var board = new Array(3); board[0]=new Array(3); board[1]=new Array(3
c/c++ - Development process
c/c++  Ive been asked to develop a backgammon game using C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks
c/c++ - Development process
c/c++  Ive been asked to develop a backgammon game using C language. I don't know which code to use to move checkers and to roll die. I would appreciate to get some help. Thanks
Constructor in Servlet.
Constructor in Servlet.  how to write a constructor in Java Servlet?   Servlet is like a POJO .You can create constructor in servlet. You can also use constructor for initialising purpose but it is not a useful approach
disable keyboard in java applet
disable keyboard in java applet  How to disable key board of my client in an java applet embedded in a website while the applet is running.? Plz help
Grand Strategy
Grand Strategy       Grand Strategy is a free, web-based game inspired by the board game Risk. Read full Description
TOPCASED workshop
provides model editors, model checkers and model transformations, but is also
Tic Tac Toe extended - Java Beginners
; public class TicTacToe { private char board[][]; //Represents a board... col; String r = ""; String str = ""; char size = board[n][n]; char position = board[row][col]; boolean status; int moveCounter
help me
to join.The checkers will take random amounts of time to process each customer
java program - Java Beginners
in this question This program represents the peg jumping puzzle. The board starts... for a move to be valid. The jumped peg is then removed from the board. The game is over.... ----------------------- Board Positions o A + + B C + + + D E F + + + + G H I J + + + + + K L M N O
ATLFlow
it as an planing and execution board. For more information: http
Generating Random Numbers to Fill array. Java Beginner needing help!
*/ public class TwoDArrayExamples { private char[][] board; public...(System.in); char play = 0; while (play != 'q...()); } } private void initializeArray(){ board = new char [3][3
Arrays -- Multi-dimensional
-dimensional array Let's declare a board for playing the game of tic-tac-toe. It will have...) and contain an int in each element. int[][] board = new int[3][3]; Initial values... of values. int[][] board = new int[][] {{0,0,0},{0,0,0},{0,0,0}}; You must
Netbeans program
. The constructor should initialize the empty board to all zeros. It should have a method...). If it is not a valid move the board does not change and it returns a Boolean value of false... that will display the current state of the board. The last method should
Increase Web Traffic,How to Increase Web Traffic,Increase Website Traffic,Free Tips to Increase Website Traffic
engines are Web Directory and Discussion Board/Forums. Driving traffic to your... Traffic by Discussion Board/Forums Discussion Board and Forums are also a good way... Board to discuss about the technologies/articles on your website. In this way
java
java  I Want my jTextfield not to accept any keys from key board but display the calculation part in it ....can you plez help me..... private void... not to accept any keys from key board but display the calculation part
RECYCLING SYSTEM IN JAVA WITH BLUEJ
three parameters, initialising the two text fields and the deposit value field
Java Programming: Solution to Programming Exercise
the checkerboard. In that exercise, the code for drawing the board was in the paint... the programming into a drawing surface class named Board. Besides this nested class... simply creates a Board and uses if for the content pane of the applet
JQuery
to select option using key-board (means using key-down
Developer discussion forums
questions. A good discussion board software discussed all the programming
8 - Java Beginners
8  Unit board is PIC18F4520 Purpose of euiqpment is to make test heart beat; fast/slow/moderate heartbeat I need to activate the speaker when testing for heartbeat. Should be able to start buzzing when testing is done. Should
Lunar Linux 1.6.0 has been released
. The installer is now also capable of installing and initialising software RAID
Query on Java Swing - Table Cell Issue - Swing AWT
the key board focus is moving from one cell to another table cell but I am
SMF
made template engine puts you in full control of the lay-out of your message board
Five-in-a-row
for improvement. Some possible exercises: This game may have originated on a Go board... in the north, a graphical display of the board in the center, and a status field... on a Go board where the pieces are placed on the intersections
provide code - Swing AWT
( this ); layeredPane.addMouseMotionListener( this ); // Add a chess board... ); } // Add a few pieces to the board JLabel piece = new JLabel( new... the chess piece back onto the chess board public void mouseReleased(MouseEvent
Risk Management Practices for Banks, Risk Management Practices for Banks that Outsource Services
, or board member of the outsourcer bank, or their relatives should not have... that there is no unwarranted influence or control of bank activities. The board and senior... the board will be responsible for the approval of its framework. It should
VoIP Development
development tools. The board has 4 FXS ports and 1 FXO port. It includes the Z.Voice... using ZSP tools. The board can be interfaced to a host using Host Port Interface (HPI) or can be interfaced to a PC using USB. The board uses LSI403LP
how can i set an object in focus
on the Board . Basically i am working on snake game project, and i want is when...; public GameBoard board; public Snake snake; public int score; public... Snake(board); resetGame(); canvas.addKeyListener
java program - Java Beginners
and then put on board. What u exactly want?, hardcode and put here
SCORE Mixed Language Development System
Board Support Package. We also support VxSim as a target. Features
Stymied with Java code - Java Beginners
) moves=0; cell=0; int board[]=new int[9]; while((moves<9... including 0 cell } //After getting out of switch display the board
Advertisements
 

 

 

DMCA.com