Racer (Part 3/28)

  • 3
  • Locked
Let's proceed to drawing the race track in the drawField() method. To set the color of a specific cell, use the setCellColor(int, int, Color) method. The passed arguments are the x and y coordinates and the color. Keep in mind that the playing field consists of three zones that must be painted usin
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Mike S
Level 24 , Saint Louis, United States
4 January, 00:55
I felt like I had all of the steps worked out and the code made sense to me. But when I ran and verified... it blew up in my face. A lot of exceptions and red font on the console, not a single green check, and not even a coherent-looking grid. Any hints to help me advance on this one?
package com.codegym.games.racer;

import com.codegym.engine.cell.Game;
import com.codegym.engine.cell.*;

//Let's create the game's main class: RacerGame
//we'll make our class inherit the Game class
public class RacerGame extends Game {

    public final static int WIDTH = 64;
    public final static int HEIGHT = 64;
    public final static int CENTER_X = WIDTH / 2;
    public final static int ROADSIDE_WIDTH = 14;

    public void initialize(){
        setScreenSize(64, 64);

    private void createGame(){

    private void drawScene(){

    private void drawField(){
        //setcellcolor() for every cell down middle of road
        for(int y = 0; y < 65; y++){
            setCellColor(CENTER_X, y, Color.WHITE);
        //setcellcolor() for the road
        //25 is beginning of road, 39 is end
        /*for(int x = ROADSIDE_WIDTH; x < (WIDTH - ROADSIDE_WIDTH); x++){
            for(int y = 0; y < HEIGHT; y++){
                if(x == CENTER_X)
                setCellColor(x, y, Color.DIMGREY);
        //setcellcolor() for left side of road
        for(int x = 0; x < ROADSIDE_WIDTH; x++){
            for(int y = 0; y < HEIGHT; y++){
                setCellColor(x, y, Color.GREEN);
        //setcellcolor() for right side of road
        for(int x = WIDTH; x >= (WIDTH - ROADSIDE_WIDTH); x--){
            for(int y = 0; y < HEIGHT; y++){
                setCellColor(x, y, Color.GREEN);
Justin Smith
Level 37 , Greenfield, USA, United States
26 November 2021, 15:50
This part is very cranky about how it validates how you draw the colors. There are several ways to approach it but if you aren't doing it exactly like the solution it will tell you that the road surface must be a single color (which isn't even really true because the line in the middle is part of the road surface). You must nest the if statements inside the double for loop. If you instead nest for loops inside if statements, it will work but won't validate. If you have it working right and you are sure but it still won't validate, just look at the solution and reorganize your conditionals the way it wants it. It would be nice if the validation could check by evaluating the colors when it's run.