![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
|
Banned
Регистрация: Nov 2012
Сообщений: 43
|
Цитата:
|
|
|||||
|
Нуб нубам
модератор форума
Регистрация: Jan 2006
Адрес: Бердск, НСО
Сообщений: 6,445
|
Если "хм" означает "ничего не понял, но все равно спасибо", то лучше спрашивайте, что осталось непонятным.
__________________
Reality.getBounds(this); |
|
|||||
|
Banned
Регистрация: Nov 2012
Сообщений: 43
|
Цитата:
Видимо в этом случае лучше использовать "Splice". Добавлено через 6 минут Чтобы не создавать новую ветку - в чем проблема? package { import flash.display.*; import flash.events.*; import flash.utils.*; public class LiveGame extends MovieClip{ private var timer:Timer; public function LiveGame() { //Build Massive var mama:Array = new Array(20); for(var j:int = 0; j < 21; j++){ mama[j] = new Array(29); } //Generate position for(var i:int = 0; i < 20; i++){ for(var i2:int = 0; i2 < 27; i2++){ var perem:Number = Math.random(); if(perem > 0.7){ var some:Enemy = new Enemy(0); some.alive = true; } else { var some:Enemy = new Enemy(1); some.alive = false; } some.x = (i2 + 1) * 20 - 10; some.y = (i + 1) * 20 - 10; mama[i][i2] = some; //!!!! trace(i + " " + i2 + " " + mama[i][i2]); //Show me massive addChild(some); } } //add TIMER timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, checker); timer.start(); } //Check function url to Timer option time private function checker(e:TimerEvent):void{ trace("Generation: " + e.target.currentCount); //Check LIve here for(var j:int = 0; j < 20; j++){ for(var j2:int = 0; j2 < 27; j2++){ var liver_a:int = 0; trace(mama[j][j2]); } } } //removeListener's private function destroy():void{ timer.removeEventListener(TimerEvent.TIMER, checker); } } } package { import flash.display.*; import flash.events.*; import flash.utils.*; public class Enemy extends Sprite{ private var size:Number = 8; //Size of circle private var colors:Array = [0x000000, 0xFFFFFF]; //Color of circle; private var graph:Shape = new Shape(); //Graph circle class public var alive:Boolean = false; //Alive status public function Enemy(stat:int = 0) { // constructor code graph.graphics.beginFill(colors[stat], 0.9); graph.graphics.drawCircle(0, 0, size); graph.graphics.endFill(); addChild(graph); } public function draw(stat:int):void{ trace("change color"); graph.graphics.beginFill(colors[stat], 0.9); graph.graphics.endFill(); } } } ЗЫ строка 51 это - trace(mama[j][j2]); |
|
|||||
|
Banned
Регистрация: Nov 2012
Сообщений: 43
|
В чем ошибка?
package { import flash.display.*; import flash.events.*; import flash.utils.*; public class LiveGame extends MovieClip{ private var timer:Timer; public function LiveGame() { //Build Massive var mama:Array = new Array(20); for(var j:int = 0; j < 21; j++){ mama[j] = new Array(29); } // constructor code var setk:Setka = new Setka(); addChild(setk); //Generate enemy position for(var i:int = 0; i < 20; i++){ for(var i2:int = 0; i2 < 27; i2++){ var perem:Number = Math.random(); if(perem > 0.7){ var some:Enemy = new Enemy(0); some.alive = true; } else { var some:Enemy = new Enemy(1); some.alive = false; } some.x = (i2 + 1) * 20 - 10; some.y = (i + 1) * 20 - 10; mama[i][i2] = some; //!!!! trace(i + " " + i2 + " " + mama[i][i2]); //Show me massive addChild(some); } } //add TIMER timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, checker); timer.start(); } //Check function url to Timer option time private function checker(e:TimerEvent):void{ trace("Generation: " + e.target.currentCount); //Check LIve here for(var j:int = 0; j < 20; j++){ for(var j2:int = 0; j2 < 27; j2++){ var liver_a:int = 0; trace(mama[j][j2]); //РУГАЕТСЯ НА ЭТУ СТРОЧКУ!!!! } } } } } package { import flash.display.*; import flash.events.*; import flash.utils.*; public class Enemy extends Sprite{ private var size:Number = 8; //Size of circle private var colors:Array = [0x000000, 0xFFFFFF]; //Color of circle; private var graph:Shape = new Shape(); //Graph circle class public var alive:Boolean = false; //Alive status public function Enemy(stat:int = 0) { // constructor code graph.graphics.beginFill(colors[stat], 0.9); graph.graphics.drawCircle(0, 0, size); graph.graphics.endFill(); addChild(graph); } public function draw(stat:int):void{ trace("change color"); graph.graphics.beginFill(colors[stat], 0.9); graph.graphics.endFill(); } } } |
|
|||||
|
Нуб нубам
модератор форума
Регистрация: Jan 2006
Адрес: Бердск, НСО
Сообщений: 6,445
|
В том, что никакой переменной some нет. Вы создаете ее только в блоке, выполняемом по условию. Компилятор не обладает мозгом, чтобы рассмотреть все Ваши варианты условий и выяснить, будет ли создана переменная some в любом случае. Переменная должна быть создана ВНЕ условий, а вот ее значение можно устанавливать внутри условных блоков.
__________________
Reality.getBounds(this); |
|
|||||
|
Banned
Регистрация: Nov 2012
Сообщений: 43
|
Цитата:
var some:Enemy = new Enemy(); if(perem > 0.7){ some.alive = true; } else { some.alive = false; } Возникли новые вопросы) package { import flash.display.*; import flash.events.*; import flash.utils.*; public class LiveGame extends MovieClip{ private var timer:Timer; private var mama:Array = new Array(20); public function LiveGame() { //Build Massive for(var j:int = 0; j < 21; j++){ mama[j] = new Array(29); } // constructor code var setk:Setka = new Setka(); addChild(setk); //Generate enemy position for(var i:int = 0; i < 20; i++){ for(var i2:int = 0; i2 < 27; i2++){ var perem:Number = Math.random(); var some:Enemy = new Enemy(); if(perem > 0.7){ some.alive = true; } else { some.alive = false; } some.x = (i2 + 1) * 20 - 10; some.y = (i + 1) * 20 - 10; mama[i][i2] = some; //!!!! trace(i + " " + i2 + " " + mama[i][i2]); //Show me massive addChild(some); } } //add TIMER timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, checker); timer.start(); } //Check function url to Timer option time private function checker(e:TimerEvent):void{ trace("Generation: " + e.target.currentCount); //Check LIve here var liver_a:int = 0; for(var j:int = 0; j < 20; j++){ for(var j2:int = 0; j2 < 27; j2++){ //CHECK LIVER AROUND //-- if(j > 0 && j2 > 0){ //РУГАЕТСЯ НА ЭТУ МАССУ УСЛОВИЙ, ПОЧЕМУ:? if(mama[j - 1][j2 - 1].alive == true){ liver_a ++; } } //0- if(j2 > 0){ if(mama[j][j2 - 1].alive == true){ liver_a ++; } } //+- if(j < 20 && j2 > 0){ if(mama[j + 1][j2 - 1].alive == true){ liver_a ++; } } //-0 if(j > 0){ if(mama[j - 1][j2].alive == true){ liver_a ++; } } //+0 if(j < 20){ if(mama[j + 1][j2].alive == true){ liver_a ++; } } //-+ if(j > 0 && j2 < 27){ if(mama[j - 1][j2 + 1].alive == true){ liver_a ++; } } //0+ if(j2 < 27){ if(mama[j][j2 + 1].alive == true){ liver_a ++; } } //++ if(j < 20 && j2 < 27){ if(mama[j + 1][j2 + 1].alive == true){ liver_a ++; } } } } trace(liver_a); } //removeListener's private function destroy():void{ timer.removeEventListener(TimerEvent.TIMER, checker); } } } Последний раз редактировалось PasserBy; 25.11.2012 в 22:19. |
|
|||||
|
Нуб нубам
модератор форума
Регистрация: Jan 2006
Адрес: Бердск, НСО
Сообщений: 6,445
|
Последнее условие уберите. Мало того что оно бессмысленно, поскольку выполнится всегда (само условие дублирует условия циклов), так еще и при крайних значениях итераторов Вы выходите за границы массива. Попросту говоря, у Вас нет в массиве врагов никаких экземпляров врага по индексам mama[19+1=20][n] или mama[n][26+1=27]. 27 ячеек имеют индексы 0-26, например, а не 1-27. В ячейке 27 нет врага, там undefined или null, а у них нет свойства "живой".
__________________
Reality.getBounds(this); |
|
|||||
|
Banned
Регистрация: Nov 2012
Сообщений: 43
|
Цитата:
Так внутренний массив состоит из 27 элементов, то есть если элемент 27 условие 27+ 1 не выполняется...к тому же обратите внимание на следующее .. рабочий пример // North if ( y > 0 ) if ( _cells[x][y-1].ok ) bros++; // North East if ( x < _max && y > 0 ) if ( _cells[x+1][y-1].ok ) bros++; // North West if ( x > 0 && y > 0 ) if ( _cells[x-1][y-1].ok ) bros++; // South if ( y < _max ) if ( _cells[x][y+1].ok ) bros++; // South East if ( x < _max && y < _max ) if ( _cells[x+1][y+1].ok ) bros++; // South West if ( x > 0 && y < _max ) if ( _cells[x-1][y+1].ok ) bros++; // East if ( x < _max ) if ( _cells[x+1][y].ok ) bros++; // West if ( x > 0 ) if ( _cells[x-1][y].ok ) bros++; Последний раз редактировалось Котяра; 29.12.2012 в 21:12. |
|
|||||
|
Регистрация: Jul 2007
Сообщений: 393
|
В плотном массиве из 27 элементов - элементы имеют индексы от 0 до 26 включительно. Нумерация элементов всегда с 0 в as3. Не Паскаль, да.
|
|
|||||
|
Banned
Регистрация: Nov 2012
Сообщений: 43
|
В контексте поставленной задачи необходимо оставить последнее условие, а также , верно, обозначить иные границы проверки элементов массива, другое дело, умники и умницы, какие и где?
|
![]() |
![]() |
Часовой пояс GMT +4, время: 07:51. |
|
|
« Предыдущая тема | Следующая тема » |
|
|