Re: [問題] ActionScript 3.0 的作業
※ 引述《morphise (QQQQQ)》之銘言:
: 目前老師出了一個設計小遊戲的題目
: 老師要我們在畫面上繪製幾個方塊
: 然後每個方塊從紅橙黃綠藍靛紫七種顏色中隨機挑選
: 每個方塊被按到的時候就會按照上面的顏色順序變換
: 變到紫色後就在跳回紅色
: 然後我希望是使用者要在這七個方塊的顏色搭配上達到一定的組合後
: 才可以進行下一步
: 舉例來說就是要一直按方塊來改顏色達到像是這個組合才成功 ▉▉▉▉▉▉▉
: 目前我用tweenLite to 來變換顏色
: 但是卻沒辦法設定哪一個方塊顏色被改了 而且改成甚麼
: 所以也沒辦法用if來看是否達到正確組合
: 板上有人可以指點一下方向應該是大概要怎麼做嗎?
: (因為才剛上4,5堂課
: 所以老師只教了基本的東西
: 我想破頭都想不到要怎麼用老師教的東西做這個作業)
我用了最陽春的笨方法寫出來了
以下是程式內容
不知道有沒有人知道有什麼方法可以不要寫五個functions來跑?XD
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
public class Main extends Sprite
{
public var allBlocks:Array;
public var totalItems:uint;
public var red:Number = 0xff0000;
public var green:Number = 0x00ff00;
public var blue:Number = 0x0000ff;
public var yellow:Number = 0xffff00;
public var pink:Number = 0xff00ff;
public var color:Array;
public var answer:Number = 0;
public function Main()
{
allBlocks = new Array();
color = new Array();
totalItems = 5;
for (var i:uint; i < totalItems; i++)
{
var randomNum:Number = Math.round(Math.random());
if (randomNum <= .2) color[i] = red;
if (.2< randomNum && randomNum <= .4) color[i] = green;
if (.4< randomNum && randomNum <= .6) color[i] = blue;
if (.6< randomNum && randomNum <= .8) color[i] = yellow;
if (.8< randomNum && randomNum <= 1) color[i] = pink;
var tempBlocks:DrawBlocks = new DrawBlocks (color[i]);
tempBlocks.x = 30 + stage.stageWidth/5 * i;
tempBlocks.y = stage.stageHeight/2;
allBlocks.push(tempBlocks);
addChild (allBlocks[i]);
}
trace("To unlock, you need to find the combination below");
trace("Red Green Blue Yellow Pink");
if (color[0] == red) answer = answer +1;
if (color[1] == green) answer = answer +1;
if (color[2] == blue) answer = answer +1;
if (color[3] == yellow) answer = answer +1;
if (color[4] == pink) answer = answer +1;
endGame(answer);
trace(answer);
allBlocks[0].addEventListener(MouseEvent.MOUSE_DOWN, firstMouseClickHandler);
allBlocks[1].addEventListener(MouseEvent.MOUSE_DOWN, secondMouseClickHandler);
allBlocks[2].addEventListener(MouseEvent.MOUSE_DOWN, thirdMouseClickHandler);
allBlocks[3].addEventListener(MouseEvent.MOUSE_DOWN, forthMouseClickHandler);
allBlocks[4].addEventListener(MouseEvent.MOUSE_DOWN, fifthMouseClickHandler);
}
public function firstMouseClickHandler (e:MouseEvent) : void
{
TweenPlugin.activate([TintPlugin]);
var checktimes:Boolean = true;
if (color[0] == pink)
{
color[0] = red;
checktimes = false;
}
if (color[0] == yellow) color[0] = pink;
if (color[0] == blue) color[0] = yellow;
if (color[0] == green) color[0] = blue;
if (color[0] == red && checktimes == true)
{
color[0] = green;
answer = answer - 1;
}
if (color[0] == red) answer = answer + 1;
checktimes = true;
TweenLite.to(e.target, .1, {tint:color[0]});
trace(answer);
endGame (answer);
}
public function secondMouseClickHandler (e:MouseEvent) : void
{
TweenPlugin.activate([TintPlugin]);
var checktimes:Boolean = true;
if (color[1] == pink)
{
color[1] = red;
checktimes = false;
}
if (color[1] == yellow) color[1] = pink;
if (color[1] == blue) color[1] = yellow;
if (color[1] == green)
{
color[1] = blue;
answer = answer - 1;
}
if (color[1] == red && checktimes == true) color[1] = green;
if (color[1] == green) answer = answer + 1;
checktimes = true;
TweenLite.to(e.target, .1, {tint:color[1]});
trace(answer);
endGame (answer);
}
public function thirdMouseClickHandler (e:MouseEvent) : void
{
TweenPlugin.activate([TintPlugin]);
var checktimes:Boolean = true;
if (color[2] == pink)
{
color[2] = red;
checktimes = false;
}
if (color[2] == yellow) color[2] = pink;
if (color[2] == blue)
{
color[1] = yellow;
answer = answer - 1;
}
if (color[2] == green) color[2] = blue;
if (color[2] == red && checktimes == true) color[2] = green;
if (color[2] == blue) answer = answer + 1;
checktimes = true;
TweenLite.to(e.target, .1, {tint:color[2]});
trace(answer);
endGame (answer);
}
public function forthMouseClickHandler (e:MouseEvent) : void
{
TweenPlugin.activate([TintPlugin]);
var checktimes:Boolean = true;
if (color[3] == pink)
{
color[3] = red;
checktimes = false;
}
if (color[3] == yellow)
{
color[1] = pink;
answer = answer - 1;
}
if (color[3] == blue) color[3] = yellow;
if (color[3] == green) color[3] = blue;
if (color[3] == red && checktimes == true) color[3] = green;
if (color[3] == yellow) answer = answer + 1;
checktimes = true;
TweenLite.to(e.target, .1, {tint:color[3]});
trace(answer);
endGame (answer);
}
public function fifthMouseClickHandler (e:MouseEvent) : void
{
TweenPlugin.activate([TintPlugin]);
var checktimes:Boolean = true;
if (color[4] == pink)
{
color[4] = red;
checktimes = false;
answer = answer - 1;
}
if (color[4] == yellow) color[4] = pink;
if (color[4] == blue) color[4] = yellow;
if (color[4] == green) color[4] = blue;
if (color[4] == red && checktimes == true) color[4] = green;
if (color[4] == pink) answer = answer + 1;
checktimes = true;
TweenLite.to(e.target, .1, {tint:color[4]});
trace(answer);
endGame (answer);
}
public function endGame ( corrects:uint) : void
{
if ( corrects == 5 )
trace("UNLOCKED!");
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 76.124.81.21
→
03/14 09:24, , 1F
03/14 09:24, 1F
→
03/14 09:24, , 2F
03/14 09:24, 2F
→
03/14 09:26, , 3F
03/14 09:26, 3F
→
03/14 11:03, , 4F
03/14 11:03, 4F
推
03/14 12:41, , 5F
03/14 12:41, 5F
→
03/14 12:43, , 6F
03/14 12:43, 6F
→
03/14 12:43, , 7F
03/14 12:43, 7F
→
03/14 12:51, , 8F
03/14 12:51, 8F
→
03/14 12:51, , 9F
03/14 12:51, 9F
推
03/14 16:51, , 10F
03/14 16:51, 10F
→
03/14 16:52, , 11F
03/14 16:52, 11F
推
03/14 20:20, , 12F
03/14 20:20, 12F
→
03/16 17:08, , 13F
03/16 17:08, 13F
→
03/16 17:09, , 14F
03/16 17:09, 14F
→
03/17 09:55, , 15F
03/17 09:55, 15F
→
03/17 09:56, , 16F
03/17 09:56, 16F
→
03/17 09:57, , 17F
03/17 09:57, 17F
→
03/17 09:57, , 18F
03/17 09:57, 18F
→
03/17 10:29, , 19F
03/17 10:29, 19F
→
03/17 11:52, , 20F
03/17 11:52, 20F
→
03/17 12:25, , 21F
03/17 12:25, 21F
→
03/17 12:26, , 22F
03/17 12:26, 22F
→
03/17 12:26, , 23F
03/17 12:26, 23F
→
03/17 12:27, , 24F
03/17 12:27, 24F
→
03/17 12:28, , 25F
03/17 12:28, 25F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):