Draughts Game.

Hi,
I am creating a draughts game. I have the board set up, with opposing pieces created using a 2D array of type player (player 1 and player 2) and size 8*8. Each piece is therefore an object of the player class.
I am unsure how to king a piece. By using a piece class, i have set up my four types of piece relating to the appropriate player (eg - WHITE_PIECE, WHITE_KING for player1). I need to find out how to upgrade a player's single piece when it needs crowned.
Thanks.

In your other thread that you had posted earlier we had discussed the flaws in your design.
Object oriented isn't just a methodology we follow because we are told to. It truly is there to help make designing an application easier and more intuitive and organized.
When you design your classes, think in terms of objects in real life... What are your fundamental objects in a game of Checkers (Draughts for your Euro weenies)?
A Player, has a name, has a color distinction, white or black player.
A Game, keeps track of whose turn, has two Players, has a Board, has behavior to cofirm if one player has won the game.
A Board, has 64 Squares, has Checkers, has game logic that determines legal moves, checks for a King condition on a Checker, behavior to remove a piece if it got jumped, determines if a player can make multiple jumps, other game logic...
A Square, is either white or black, has a Checker or not
A Checker, is either white or black, has a flag for whether or not it is a King.
I think you get the point. This is just to get you started but you should write this rough design down then possibly draw a class diagram with the information you have. Be thorough and complete, you should have enough detail to where all the manageable peices of the code are broken down to simple coding tasks.
We have told you this once before that you are causing yourself a lot of grief trying to get this game to work with your current design.

Similar Messages

  • Multiple paint methods

    Hi
    I'm working on a draughts game and to make it a little nicer looking I've used graphics for the board squares.
    My paint method is double buffered so when a peice is dragged it lags a little because it has to buffer so many images. The only images I need to buffer are the ones that move i.e. the draughts.
    Is there a way to draw the squares in a separate paint method so they don't get buffered? Or is java limited to one paint method per class?

    It's going to lag no matter how many paint methods you use. (Thats even if there ARE other paint methods) If it's lagging because of how many images must be drawn, then perhaps you should write an algorithm that repaints only the areas that have changed. ie: Only repaint wherever the single peice is moved.
    -Adam

  • Can I play Game Center Games with other family members sharing one Apple ID

    I have several IOS devices sharing the same Apple ID that my sons and wife use. I have set up a game center account using that ID and can find no way that we can play head to head games on those multiple devices against each other using that one Apple ID login, even if I create multiple Nicknames. Am I missing something?

    An Apple ID is just an account that uses an email address and password. It does not have to be tied to iTunes. You can create one here. Create one each for your sons and wife.

  • How to repaint a JPanel in bouncing balls game?

    I want to repaint the canvas panel in this bouncing balls game, but i do something wrong i don't know what, and the JPanel doesn't repaint?
    The first class defines a BALL as a THREAD
    If anyone knows how to correct the code please to write....
    package fuck;
    //THE FIRST CLASS
    class CollideBall extends Thread{
        int width, height;
        public static final int diameter=15;
        //coordinates and value of increment
        double x, y, xinc, yinc, coll_x, coll_y;
        boolean collide;
        Color color;
        Rectangle r;
        bold BouncingBalls balls; //A REFERENCE TO SECOND CLASS
        //the constructor
        public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c, BouncingBalls balls) {
            width=w;
            height=h;
            this.x=x;
            this.y=y;
            this.xinc=xinc;
            this.yinc=yinc;
            this.balls=balls;
            color=c;
            r=new Rectangle(150,80,130,90);
        public double getCenterX() {return x+diameter/2;}
        public double getCenterY() {return y+diameter/2;}
        public void move() {
            if (collide) {
            x+=xinc;
            y+=yinc;
            //when the ball bumps against a boundary, it bounces off
            //bounce off the obstacle
        public void hit(CollideBall b) {
            if(!collide) {
                coll_x=b.getCenterX();
                coll_y=b.getCenterY();
                collide=true;
        public void paint(Graphics gr) {
            Graphics g = gr;
            g.setColor(color);
            //the coordinates in fillOval have to be int, so we cast
            //explicitly from double to int
            g.fillOval((int)x,(int)y,diameter,diameter);
            g.setColor(Color.white);
            g.drawArc((int)x,(int)y,diameter,diameter,45,180);
            g.setColor(Color.darkGray);
            g.drawArc((int)x,(int)y,diameter,diameter,225,180);
            g.dispose(); ////////
        ///// Here is the buggy code/////
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.canvas.repaint();
    //THE SECOND CLASS
    public class BouncingBalls extends JFrame{
        public Graphics gBuffer;
        public BufferedImage buffer;
        private Obstacle o;
        private List<CollideBall> balls=new ArrayList();
        private static final int SPEED_MIN = 0;
        private static final int SPEED_MAX = 15;
        private static final int SPEED_INIT = 3;
        private static final int INIT_X = 30;
        private static final int INIT_Y = 30;
        private JSlider slider;
        private ChangeListener listener;
        private MouseListener mlistener;
        private int speedToSet = SPEED_INIT;
        public JPanel canvas;
        private JPanel p;
        public BouncingBalls() {
            super("fuck");
            setSize(800, 600);
            p = new JPanel();
            Container contentPane = getContentPane();
            final BouncingBalls xxxx=this;
            o=new Obstacle(150,80,130,90);
            buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
            gBuffer=buffer.getGraphics();
            //JPanel canvas start
            final JPanel canvas = new JPanel() {
                final int w=getSize().width-5;
                final int h=getSize().height-5;
                @Override
                public void update(Graphics g)
                   paintComponent(g);
                @Override
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    gBuffer.setColor(Color.ORANGE);
                    gBuffer.fillRect(0,0,getSize().width,getSize().height);
                    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
                    //paint the obstacle rectangle
                    o.paint(gBuffer);
                    g.drawImage(buffer,0,0, null);
                    //gBuffer.dispose();
            };//JPanel canvas end
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            addButton(p, "Start", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    CollideBall b = new CollideBall(canvas.getSize().width,canvas.getSize().height
                            ,INIT_X,INIT_Y,speedToSet,speedToSet,Color.BLUE,xxxx);
                    balls.add(b);
                    b.start();
            contentPane.add(canvas, "Center");
            contentPane.add(p, "South");
        public void addButton(Container c, String title, ActionListener a) {
            JButton b = new JButton(title);
            c.add(b);
            b.addActionListener(a);
        public boolean collide(CollideBall b1, CollideBall b2) {
            double wx=b1.getCenterX()-b2.getCenterX();
            double wy=b1.getCenterY()-b2.getCenterY();
            //we calculate the distance between the centers two
            //colliding balls (theorem of Pythagoras)
            double distance=Math.sqrt(wx*wx+wy*wy);
            if(distance<b1.diameter)
                return true;
            return false;
        synchronized void repairCollisions(CollideBall a) {
            for (CollideBall x:balls) if (x!=a && collide(x,a)) {
                x.hit(a);
                a.hit(x);
        public static void main(String[] args) {
            JFrame frame = new BouncingBalls();
            frame.setVisible(true);
    }  And when i press start button:
    Exception in thread "Thread-2" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-3" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-4" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    and line 153 is: balls.canvas.repaint(); in Method run() in First class.
    Please help.

    public RepaintManager manager;
    public BouncingBalls() {
            manager = new RepaintManager();
            manager.addDirtyRegion(canvas, 0, 0,canvas.getSize().width, canvas.getSize().height);
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.manager.paintDirtyRegions(); //////// line 153
       but when push start:
    Exception in thread "Thread-2" java.lang.IllegalMonitorStateException
    at java.lang.Object.notifyAll(Native Method)
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-3" java.lang.IllegalMonitorStateException
    at java.lang.Object.notifyAll(Native Method)
    at fuck.CollideBall.run(CollideBall.java:153)
    i'm newbie with Concurrency and i cant handle this exceptons.
    Is this the right way to do repaint?

  • Balls don't move in bouncing balls game.Please Help !?

    I want to repaint the canvas panel in this bouncing balls game, but i do something wrong i don't know what, and the JPanel doesn't repaint?
    The first class defines a BALL as a THREAD
    If anyone knows how to correct the code please to write....
    package ****;
    //THE FIRST CLASS
    class CollideBall extends Thread{
        int width, height;
        public static final int diameter=15;
        //coordinates and value of increment
        double x, y, xinc, yinc, coll_x, coll_y;
        boolean collide;
        Color color;
        Rectangle r;
        bold BouncingBalls balls; //A REFERENCE TO SECOND CLASS
        //the constructor
        public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c, BouncingBalls balls) {
            width=w;
            height=h;
            this.x=x;
            this.y=y;
            this.xinc=xinc;
            this.yinc=yinc;
            this.balls=balls;
            color=c;
            r=new Rectangle(150,80,130,90);
        public double getCenterX() {return x+diameter/2;}
        public double getCenterY() {return y+diameter/2;}
        public void move() {
            if (collide) {
            x+=xinc;
            y+=yinc;
            //when the ball bumps against a boundary, it bounces off
            //bounce off the obstacle
        public void hit(CollideBall b) {
            if(!collide) {
                coll_x=b.getCenterX();
                coll_y=b.getCenterY();
                collide=true;
        public void paint(Graphics gr) {
            Graphics g = gr;
            g.setColor(color);
            //the coordinates in fillOval have to be int, so we cast
            //explicitly from double to int
            g.fillOval((int)x,(int)y,diameter,diameter);
            g.setColor(Color.white);
            g.drawArc((int)x,(int)y,diameter,diameter,45,180);
            g.setColor(Color.darkGray);
            g.drawArc((int)x,(int)y,diameter,diameter,225,180);
            g.dispose(); ////////
        ///// Here is the buggy code/////
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.canvas.repaint();
    //THE SECOND CLASS
    public class BouncingBalls extends JFrame{
        public Graphics gBuffer;
        public BufferedImage buffer;
        private Obstacle o;
        private List<CollideBall> balls=new ArrayList();
        private static final int SPEED_MIN = 0;
        private static final int SPEED_MAX = 15;
        private static final int SPEED_INIT = 3;
        private static final int INIT_X = 30;
        private static final int INIT_Y = 30;
        private JSlider slider;
        private ChangeListener listener;
        private MouseListener mlistener;
        private int speedToSet = SPEED_INIT;
        public JPanel canvas;
        private JPanel p;
        public BouncingBalls() {
            super("****");
            setSize(800, 600);
            p = new JPanel();
            Container contentPane = getContentPane();
            final BouncingBalls xxxx=this;
            o=new Obstacle(150,80,130,90);
            buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
            gBuffer=buffer.getGraphics();
            //JPanel canvas start
            canvas = new JPanel() {
                final int w=getSize().width-5;
                final int h=getSize().height-5;
                @Override
                public void update(Graphics g)
                   paintComponent(g);
                @Override
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    gBuffer.setColor(Color.ORANGE);
                    gBuffer.fillRect(0,0,getSize().width,getSize().height);
                    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
                    //paint the obstacle rectangle
                    o.paint(gBuffer);
                    g.drawImage(buffer,0,0, null);
                    //gBuffer.dispose();
            };//JPanel canvas end
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            addButton(p, "Start", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    CollideBall b = new CollideBall(canvas.getSize().width,canvas.getSize().height
                            ,INIT_X,INIT_Y,speedToSet,speedToSet,Color.BLUE,xxxx);
                    balls.add(b);
                    b.start();
            contentPane.add(canvas, "Center");
            contentPane.add(p, "South");
        public void addButton(Container c, String title, ActionListener a) {
            JButton b = new JButton(title);
            c.add(b);
            b.addActionListener(a);
        public boolean collide(CollideBall b1, CollideBall b2) {
            double wx=b1.getCenterX()-b2.getCenterX();
            double wy=b1.getCenterY()-b2.getCenterY();
            //we calculate the distance between the centers two
            //colliding balls (theorem of Pythagoras)
            double distance=Math.sqrt(wx*wx+wy*wy);
            if(distance<b1.diameter)
                return true;
            return false;
        synchronized void repairCollisions(CollideBall a) {
            for (CollideBall x:balls) if (x!=a && collide(x,a)) {
                x.hit(a);
                a.hit(x);
        public static void main(String[] args) {
            JFrame frame = new BouncingBalls();
            frame.setVisible(true);
    }  This code draws only the first position of the ball:
    http://img267.imageshack.us/my.php?image=51649094by6.jpg

    I'm trying to draw everything first to a buffer:
    buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
    gBuffer=buffer.getGraphics();
    The buffer is for one JPanel and then i want to draw this buffer every time when balls change their possitions(collide or just move).
    The logic is something like this:
    startButton -> (ball.start() and add ball to List<balls>),
    ball.start() -> ball.run() -> (move allballs, paint to buffer and show buffer)
    In the first class:
    BouncingBalls balls; //A REFERENCE TO SECOND CLASS
    In the second class:
    private List<CollideBall> balls=new ArrayList();
    the tames are the same but this isn't an error.
    Edited by: vigour on Feb 14, 2008 7:57 AM

  • Game and Ball Hit problem

    Hello everyone, I am working on a game and was wondering if I could get some help. I have a ball that bounces around in a box, and place one small ball in the applet. I want to create an effect that when the ball that is moving comes into connect with the static ball, the moving ball bounces in the opposite direction. I used this:
    if(x_pos - 100 < 2 & y_pos - 100 < 2 || 100-x_pos < 2 && 100 - y_pos < 2)
    where x_pos and y_pos are for the moving ball, and 100 is the radius of the static ball. Should I use the Pythagoras theorem to do it?
    Thank You In Advance for any help.

    Use java.awt.Shape and its contains() method. It's a standard collision detection idiom.

  • It hangs when playing games

    My system is Windows 7 - 64 bit operating system
    I've used Firefox for many many years and always praised it compared to EI. I am afraid I wont be able to praise it much more. It stinks. It hangs mostly when I am playing games or looking at pictures or videos. Its worse when on Facebook but also happens on other web site. I did all the troubleshooting, updates, remove old versions and re install, disable add ons all and all Its driving me insane. Can you solve the problem with a new versionof Firefox or do we have to flush the darn browser for good.
    Thank you

    anyone has a solution until a new version comes out?

  • When i login on game center it say enter your birth date when i enter it and i perss next the birth day will come again and again what should do

    when i login on game center it say enter your birth date when i enter it and i perss next the birth day will come again and again what should do

    Start a game with Game Center and go from there.

  • Why is it that when I login with my Game centre account, it shows the wrong country?

    My country/region is set to Singapore but whenever I login to my game centre account for games, it shows the china flag and words come out in Chinese. How can I change this?

    Do the songs have an iCloud icon?
    If so, the songs with an iCloud icon were purchased from the iTunes Store and have not been downloaded. You must select on the iCloud icon for a song to download it.

  • Problem with Preloader in my Flash AS2 Game

    I have been using this tutorial to make a preloader:
    http://www.republicofcode.com/tutori.../preloader_bc/
    I have run into one problem though.
    When I simulate the download, it just shows the background color of the game while it loads, and when it finished loading, it shows the loading screen fully loaded. I have followed the tutorial exactly, except added my file names into the AS2 code.
    Here is the ActionScript in Frame 1 I have for the preloader:
    if (_root.getBytesTotal() != _root.getBytesLoaded()){
    stopAndGoto(1);
    preloaderBar._xscale=(_root.getBytesLoaded()/_root.getBytesTotal())*100;
    loaderTxt.text=Math.round((_root.getBytesLoaded()/_root.getBytesTotal())*100)+"%";
    Any hints or answers to what i'm doing wrong?
    Thanks, MrA615.

    Your description of what you've done and the code you show does not match what the tutorial says to do and what code to use... (there is no stopAndGoTo() function in Flash).
    Right-click the second frame on the upper layer labeled Actions and select Actions. Copy and paste the code below to make our preloader functional.
    if (_root.getBytesTotal() != _root.getBytesLoaded()){
    gotoAndPlay(1);
    bar_mc._xscale=(_root.getBytesLoaded()/_root.getBytesTotal())*100;
    loader_txt.text=Math.round((_root.getBytesLoaded()/_root.getBytesTotal())*100)+"%";

  • Since I installed 7.6, my IPod (5th Gen) can't find my games

    EVERYTHING was fine until I installed 7.6. After doing so I had to restore my IPod 4 times, and now the $30 worth of games that I once had on there, cannot be found. They're in/on my computer, and they're in my ITunes Library but it says that my "games cannot be found." I found them, and they were once there on my IPod (5th generation 30GB), but not they won't sync up somehow. I tried the draggin them out of the library onto my desktop, then dragging them to the devices section to my IPod, still doesn't work.
    Has this happened to anyone else? Anyone have any suggestions?

    I am running Windows XP with a 5th generation Ipod and have had similar issues. (itunes would not sync games to ipod; Received error stating games could not be found yet they were in the Games Folder of iTunes Library.) I followed the itunes trouble shooting procedures and did not resolve my problem. I discussed this with itunes tech support for over a week and got no where.
    I have been monitoring this message board and have yet to find a solution.
    Keep us informed regarding your progress.

  • Can I move games from one iPod to a new iPod?

    Can I transfer games in progress from ipod3 to new ipod4?

    Yes.  Transfer these Apps to your iTunes library by choosing File -> Transfer Purchases and then sync them to the new iPod or simply download these same applications on your new iPod when it arrives.
    If you want to retain app data as well, you'll want to backup the old iPod and restore the new iPod from that same backup.  See this article for more assistance.
    iTunes: Backing up, updating, and restoring iOS software
    B-rock

  • How can I move a game center username from one Apple ID to another?

    I've tried to do this but it doesn't seem possible. For instance, trying to choose the username from another Apple ID you own correctly tells you that it's already in use. However, logging in with the Apple ID that has the username you want and trying to change the Apple ID tells me that the Apple ID I want to move the username to already has a username even though it doesn't because I'm at the stage of choosing a username in that other account. In this case I get the error message: "This change is not allowed because that Apple ID is already in use. You can try again using a different name or leave your Apple ID unchanged."
    I read about one potential solution to this and that is changing the username you want in the Apple ID you no longer want associated with Game Centre, thereby releasing it and then quickly try to grab it again in the Apple ID you do want it on. I'm a bit nervous about trying this though because I do like the username enough that I'd rather stay with the existing Apple ID than risk losing it.
    Has anyone tried doing this and had success? Maybe Apple blocks you from using a username for a period of time after it's been associated with an account, so I'm not sure I want to do this.
    I wish Apple would just let us consolidate Apple ID/accounts and give us more control over our accounts (including the ability to close old/redundant Apple IDs)! It's a cause of endless frustration for so many people!!!

    slenpree wrote:
    I would really really like to move it form the first apple ID to my iCloud one so I just sign into one appleID for everything.
    Many Thanks,
    Jonny
    You need more help then anyone here can give, as far as I know. Good luck.

  • I have multiple ipods on my account...how do I find out which one purchased over $250 worth of games?

    I have multiple ipods on my account (kids) and one or more of them purchased over $250 worth of games.  I need to know which child(ren) did this so they can pay accordingly.  The accout only tells what day they were purchased but doesn't say which ipod purchased.  Any help would be greatly appreciated.

    It could be:
    iTunes Store & Mac App Store: About credit-card authorization holds
    You could contact itunes support and ask.  Click Support at the top if this page, then click the link under Contact Us

  • How can I replace an older save file with a new one on game center?

    Greetings,
    I have been trying to change an older game saved file that I have created with my old Ipad with the new one that I have created on my new Ipad, both game files are played under my apple ID but I have no idea how to replace my older one with the new one.
    The new file is superior to the old one so I wish to add the new saved file to my game center.
    The game I am playing is Clash of Clans both file are created on apple products.
    Let me know if there is a sulotion for that case.
    Regards

    Make sure the site folder created by iWeb is named exactly the same as the site folder currently on the server.
    OT

Maybe you are looking for

  • I hate it when they change all the keyboard shortcuts. Is there a fix for these?

    I don't understand why Adobe thinks that consistency is a bad thing, but it seems that everytime they update they go jerking with my keyboard shortcuts. Last time it was Indesign, this time it Photoshop that has me complaining. Usually I can change t

  • Way to force .pdf to open in Reader and not in browser

    I saw where there was an Acrobat action called Convert PDF2FDF auto-save Action on the AcrobatUsers.com Action Exchange. which didn't work, it came in corrupted and unusable.  Does anyone know of an action or anything that will force a .pdf hosted on

  • Purchasing Problem

    Hello, Last Saturday I bought two songs from itunes store with my credit card and items were purchased in my credit card details. Today I got a Iphone 5S and trying to download applications. When I login , it gives "your payment method was declined.

  • Internet sharing, do we have to pay for it?

    Do we have to pay AT&T for it to make it work? Is it like a service? Solved! Go to Solution.

  • Failed to convert user externalID servermgr_xcode

    since i upgraded to 10.9 and server 3.0 i get flooded with the following messages. [CSODService.m:78 9d38000 +0ms] Failed to convert user externalID servermgr_xcode to uuid_t for membership check So I installed Xcode and integrated it via servermgr i