• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checkers

 
bella
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im doing an exercise called checkers that draws a checkerboard with five red and with eight black checkers on it in various (randomly chosen) locations. and the checkerboard has to be stored as a two-dimensional array.

has anyone written a program that could help me with this task?
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, belinda. While we enjoy talking about all things Java, we realize that the only way to learn how to code is to write code. If we did your homework for you it wouldn't be fair to you or the other people in your class who have done their own work. Now we will help you if you have any specific questions (i.e. how to work with a 2-D array), but you will have to show us examples or code that you've tried so far as a measure of good faith.
Unless you are asking questions specifically about applets (java programs which run in browsers), your question will probably get answered quicker in our Beginner's Forum.
 
bella
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well basically this is what iv done so far

import javax.swing.JApplet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import java.applet.Applet;

public class Checkers extends Applet
{
//two final variables that have the number of columns and rows
private final int COL = 8;
private final int ROW = 8;

//defines some variables
private int width;
private int height;
private int colWidth;
private int rowHeight;

Checker[][] board;

public void init()
{
//init the 2 dimensional array
board = new Checker [ROW][COL];

//gets the width and height from the HTML
String stringWidth = getParameter("width");
String stringHeight = getParameter("height");

//converts this from string to and int number
width = Integer.parseInt(stringWidth);
height = Integer.parseInt(stringHeight);

colWidth = width/COL;
rowHeight = height/ROW;
}

public void paint(Graphics page)
{
//two for loop so create the grid lines
for (int i = 0; i <= COL; i++)
{
page.drawLine (i * colWidth, 0 , i * colWidth, height); //vertical lines
}

for (int i = 0; i <= ROW; i++)
{
page.drawLine (i * rowHeight, 0, i * rowHeight, width); //horizontal lines
}
}
}


im just at a loss of what to do next. but ill go to the beginner's forum, i didnt no there was one.
 
Ryan McGuire
Ranch Hand
Posts: 1093
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I'll wait until I see your post there to reply.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic