Я провожу практический урок, где использую вложенный оператор if на сайте code.org, где он хочет, чтобы я закрасил область стены в полосатый цвет по своему выбору. Я правильно написал код, как показано ниже, но по какой-то причине всякий раз, когда я запускаю программу, художник не начинает рисовать. что здесь происходит? я что-то упускаю?
import org.code.neighborhood.*;
/*
* A Painter that paints rows in The Neighborhood
*/
public class RowPainter extends Painter {
/*
* Sets the x and y values to the starting x and y location,
* direction to the specified starting direction, and paint
* to the specified starting paint amount
*/
public RowPainter(int x, int y, String direction, int paint) {
super(x, y, direction, paint);
}
/*
* Turns the RowPainter object to the right
*/
public void turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
/*
* Moves the RowPainter object forward in the direction it is facing if it can move
*/
public void moveIfCanMove() {
if (canMove()) {
move();
}
}
/*
* Paints a row in The Neighborhood with firstColor
* then moves to the next row with secondColor
*/
public void paintArea(String firstColor, String secondColor) {
while (canMove()) {
paintEast(firstColor);
paintWest(secondColor);
moveIfCanMove();
if (!canMove()) {
paintEast(firstColor);
paintWest(secondColor);
moveToNextRow();
}
}
}
public void paintEast(String color) {
if ((getY() == 3%4) && (isFacingEast())){
paint(color);
}
}
public void paintWest(String color) {
if ((getY() == 12%4) && (isFacingEast())){
if (hasPaint()){
paint(color);
}
}
}
public void moveToNextRow() {
if (canMove("south")) {
if (facingEast()) {
turnRight();
moveIfCanMove();
turnRight();
}
else {
turnLeft();
moveIfCanMove();
turnLeft();
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/799 ... wont-paint
Программа запускается, но Painter не рисует? ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1772763644
Anonymous
Я провожу практический урок, где использую вложенный оператор if на сайте code.org, где он хочет, чтобы я закрасил область стены в полосатый цвет по своему выбору. Я правильно написал код, как показано ниже, но по какой-то причине всякий раз, когда я запускаю программу, художник не начинает рисовать. что здесь происходит? я что-то упускаю?
import org.code.neighborhood.*;
/*
* A Painter that paints rows in The Neighborhood
*/
public class RowPainter extends Painter {
/*
* Sets the x and y values to the starting x and y location,
* direction to the specified starting direction, and paint
* to the specified starting paint amount
*/
public RowPainter(int x, int y, String direction, int paint) {
super(x, y, direction, paint);
}
/*
* Turns the RowPainter object to the right
*/
public void turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
/*
* Moves the RowPainter object forward in the direction it is facing if it can move
*/
public void moveIfCanMove() {
if (canMove()) {
move();
}
}
/*
* Paints a row in The Neighborhood with firstColor
* then moves to the next row with secondColor
*/
public void paintArea(String firstColor, String secondColor) {
while (canMove()) {
paintEast(firstColor);
paintWest(secondColor);
moveIfCanMove();
if (!canMove()) {
paintEast(firstColor);
paintWest(secondColor);
moveToNextRow();
}
}
}
public void paintEast(String color) {
if ((getY() == 3%4) && (isFacingEast())){
paint(color);
}
}
public void paintWest(String color) {
if ((getY() == 12%4) && (isFacingEast())){
if (hasPaint()){
paint(color);
}
}
}
public void moveToNextRow() {
if (canMove("south")) {
if (facingEast()) {
turnRight();
moveIfCanMove();
turnRight();
}
else {
turnLeft();
moveIfCanMove();
turnLeft();
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79901930/program-runs-but-painter-wont-paint[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия