This site requires JavaScript, please enable it in your browser!
Greenfoot back
IMARCUS
IMARCUS wrote ...

2020/3/6

HELPP!!!

IMARCUS IMARCUS

2020/3/6

#
Can someone help me figure out whats wrong with my world class in this checkers game.
import greenfoot.*;  

import java.util.LinkedList;
import java.util.List;


public class Board extends World
{
   
    public static final int CELLSIZE = 60;
    public static final int MIN_X = 0, MAX_X = 7;
    public static final int MIN_Y = 0, MAX_Y = 7;
 
    private Class currentTurn = DarkMan.class;
    
    
    public Board()
    {        
        
        super(MAX_X + 1, MAX_Y + 1, CELLSIZE);
        GreenfootImage background = new GreenfootImage(CELLSIZE * 2, CELLSIZE * 2);
        background.setColor(Color.WHITE);
        background.fillRect(0, 0, background.getWidth(), background.getHeight());
        background.setColor(Color.BLACK);
        background.fillRect(CELLSIZE, 0, CELLSIZE, CELLSIZE);
        background.fillRect(0, CELLSIZE, CELLSIZE, CELLSIZE);
        setBackground(background); 

        startNewGame();
    }
    
    
    public void startNewGame()
    {
        removeObjects(getObjects(Actor.class));
        
        for(int x = MIN_X; x <= MAX_X; x += 2) {
            addObject(new LightMan(DarkMan.class), x + 1, MIN_Y);
            addObject(new LightMan(DarkMan.class), x,     MIN_Y + 1);
            addObject(new LightMan(DarkMan.class), x + 1, MIN_Y + 2);
            
            addObject(new DarkMan(LightMan.class), x,     MAX_Y - 2);
            addObject(new DarkMan(LightMan.class), x + 1, MAX_Y - 1);
            addObject(new DarkMan(LightMan.class), x,     MAX_Y);
        }
        currentTurn = DarkMan.class;
    }
    
    
    public void act()
    {
        List<Actor> actors = getObjects(Man.class);
        List<Man> available = new LinkedList<Man>();
        for(Actor actor : actors) {
            Man man = (Man) actor;
            if(man.isMoveAvailable()) {
                available.add(man);
            }
        }
        
        
        if(available.size() > 0) {
            Man selected = selectMan(available);
            if(selected.play()) {
               
            }
            else {
                throw new IllegalStateException(selected.toString());
            }
        }
        else {
        
        }
    }
    
    
    public Class getCurrentTurn()
    {
        return currentTurn;
    }
    
    
    public void switchSides()
    {
        if(currentTurn.equals(DarkMan.class)) {
            currentTurn = LightMan.class;
        }
        else {
            currentTurn = DarkMan.class;
        }
        if(getObjects(currentTurn).size() == 0) {
        
            System.out.print( "Game Over!");

        }
    }
    
 
    private Man selectMan(List<Man> available)
    {
        Man selected = available.get(0);
        int pathLength = selected.getMovePath().size();
        for(int index = 1; index < available.size(); index++) {
            List<Location> possiblePath = available.get(index).getMovePath();
            if(possiblePath.size() > pathLength) {
                selected = available.get(index);
                pathLength = possiblePath.size();
            }
            else if(possiblePath.size() == pathLength &&
                        Greenfoot.getRandomNumber(1) == 0) {
                
                selected = available.get(index);
            }
            else {
                
            }                    
        }
        return selected;
    }
        
}
IMARCUS IMARCUS

2020/3/6

#
I'm getting an error on line 35
danpost danpost

2020/3/6

#
IMARCUS wrote...
I'm getting an error on line 35
What is the error you are getting? (copy/paste in entirety)
You need to login to post a reply.