Javascript-форум (https://javascript.ru/forum/)
-   Javascript под браузер (https://javascript.ru/forum/css-html/)
-   -   Помогите убрать рандом (https://javascript.ru/forum/css-html/62204-pomogite-ubrat-random.html)

bkmz_ha 30.03.2016 01:13

Помогите убрать рандом
 
Всем доброго времени суток!
Есть такой код на колесо, состоящее из 8 секторов после выпадения сектор убирается. Есть сектор, при выпадении которого, идет возврат всех секторов.

Возможно ли убрать рандом, чтобы сектора выпадали подряд по кругу? Или хотя бы чтобы можно было самому выбирать, насколько градусов повернуть колесо? Заранее благодарю!

turnWheel = function() {
	var turn, degree, bonus, random_deg,
			chestX, chestY;

	turn = request(JSON_TURN, {hash: userSign}, 'POST');
	if (turn.error) {
		getModal('server_error', turn);
	}

	if (turn.bonus_used == 1) {
		getModal('end_game', turn);
	}

	degree = parseInt(cellCoords[turn.last_turn - 1].deg);
	bonus = Number(turn.total_bonus).toFixed();
	random_deg = Math.floor(Math.random() *2 + 3)*360 + degree;

	for (var i = 0; i < cells.length; i++) {
		createjs.Tween.get(cells[i]).to({rotation: -(random_deg )}, random_deg/360*1500, createjs.Ease.cubicOut);
		cells[i].rotation = 0;
	}

	createjs.Tween.get(wheel).to({rotation: random_deg}, random_deg/360*1500, createjs.Ease.cubicOut).call(function() {

		if (turn.loss == 0) {
			wheel.rotation = degree;
			chestX = cellCoords[turn.last_turn - 1].dx;
			chestY = cellCoords[turn.last_turn - 1].dy;

			if (turn.last_turn < 8) {
				if (turn.last_turn == 7) {
					createjs.Tween.get(cells[turn.last_turn - 1]).to({x: chestX, y: chestY}, 400).call(function() {

						createjs.Tween.get(bonusShadow).to({alpha:1}, 200).call(function() {});
						createjs.Tween.get(bonusDouble).to({alpha:1}, 200).call(function() {

							setTimeout(function(){
								createjs.Tween.get(bonusShadow).to({alpha:0}, 200).call(function() {});
								createjs.Tween.get(bonusDouble).to({alpha:0}, 200).call(function() {
									chestValue.text = bonus + '%';
									cells[turn.last_turn - 1].rotation = degree;
									cells[turn.last_turn - 1].visivle = false;
									updateCells(turn.fields);
								});
							}, 650);
						});


					});
				} else {
					createjs.Tween.get(cells[turn.last_turn - 1]).to({x: chestX, y: chestY}, 400).call(function() {
						chestValue.text = bonus + '%';
						cells[turn.last_turn - 1].rotation = degree;
						cells[turn.last_turn - 1].visivle = false;
						updateCells(turn.fields);
					});
				}

			} else {

				createjs.Tween.get(bonusShadow).to({alpha:1}, 200).call(function() {});
				createjs.Tween.get(bonusReload).to({alpha:1}, 200).call(function() {

					setTimeout(function(){
						createjs.Tween.get(bonusShadow).to({alpha:0}, 200).call(function() {});
						createjs.Tween.get(bonusReload).to({alpha:0}, 200).call(function() {

							updateCells(turn.fields);
							for (var index in turn.fields) {
								cells[index-1].visible = true;
								cells[index-1].alpha = 1;
								cells[index-1].x = cellCoords[index - 1].x;
								cells[index-1].y = cellCoords[index - 1].y;
							}
						});
					}, 650);
				});

			}
		} else {
			getModal('end_game', turn);
		}
	});

};

updateCells = function(cells_value) {
	for (var index in cells_value) {
		if (index < 7) {
			cells[index-1].getChildAt(1).text = cells_value[index]+'%';
		}
		if (cells_value[index] == 0) {
			cells[index-1].visible = false;
		} else {
			cells[index-1].visible = true;
		}
		cells[index-1].x = cellCoords[index-1].x;
		cells[index-1].y = cellCoords[index-1].y;
	}
	rotation = false;
};

m1lk1way 30.03.2016 08:48

навскидку попробуйте в переменной поменять выделенную часть на нужное количество градусов.
random_deg = *!*Math.floor(Math.random() *2 + 3)*360*/!* + degree;

bkmz_ha 30.03.2016 10:10

Цитата:

Сообщение от m1lk1way (Сообщение 412410)
навскидку попробуйте в переменной поменять выделенную часть на нужное количество градусов.
random_deg = *!*Math.floor(Math.random() *2 + 3)*360*/!* + degree;

Пробовал, все равно выдает не то, что нужно.
И еще такой вопрос, через что лучше редактировать "на лету" через браузер js?

m1lk1way 30.03.2016 18:53

bkmz_ha,
Ну весь ваш код разбирать было бы глупо, я указал вам строку где происходит ваш рандом. Теперь вам нужно разобрать механику. Вот псевдокод:
random_deg= (всё что в скобках даёт либо 3 либо 4) * умножается на 360 (не понимаю зачем) и добавляется переменная degree (видимо это положение указателя в данный момент, до прокрутки).

Не понятно, что значит "на лету". Если вы про дебаг, то консоль браузера отлично с этим справляется.


Часовой пояс GMT +3, время: 20:52.