2012-04-26 4 views
0

雲、 アヒル、 は 表示 と 波スコアのカウントダウン数は 各 が に クラス を有するべきでは その 移動 と 挙動を支配します。 アヒル は 彼ら に をクリックするActionscript3:アヒル

は 「ショット」 と が も としてアレイ から ステージから除去される アヒルである ( arrayName.splice()を使用 の場合は) は べき 数 ダウン この として発生 ディスプレイを獲得します。 は を残し アヒルの

数 は 内 プロパティ が アヒル を とき メイン で を調整 表示の クラス と スコアは ショットあるべきです。 すべて アヒル が 「ショット」 ゲームのとき

は 「あなたは 勝利」 メッセージをアニメーション化する必要があります。 これは はイベント会合 が が機能をアニメーション とFRAME イベントをENTER ことリスナーを除去 と を添加することによって を行うことができます。 (この のみ 価値 ので、 は それ ため 最後を残します)。 も であるべき アヒル は「ショット」 波と 雲ある

はそれら それぞれのアレイから 図AND から除去しました。

ゲーム は が が または が 多く 回を失っ獲得した プレーヤー 後にリセットする必要があります。 は(ない 一回だけ )

私はこれに行わのほとんどを持って、私はスコアボードとのトラブルを抱えています。すべてをリセットする方法についてのヒント、そしてあなたが勝利のサインをコードすることも助けになります。

import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.text.TextField; 

[SWF(width="800", height="600", backgroundColor="#E6FCFF")] 

public class Main extends Sprite 
{ 
    private var _sittingDucks:Array = []; //always set your arrays with [] at the top 
    public var _scoreDisplay:TextField 


    public function Main() 
    { 
     //adding the background, and positioning it 
     var background:Background = new Background(); 
     this.addChild(background); 
     background.x = 30; 
     background.y = 100; 

     for(var i:uint = 0; i < 5; i++) 
     { 
      //adding the first cloud, and positioning it 
      var clouds:Clouds = new Clouds(); 
      this.addChild(clouds); 
      clouds.x = 130 + Math.random() * 600; //130 to 730 
      clouds.y = 230; 
      clouds.speedX = Math.random() * 3; 
      clouds.width = clouds.height = 200 * Math.random()//randomly changes the clouds demensions 
     } 

     var waves:Waves = new Waves(); 
     this.addChild(waves); 
     waves.x = 0; 
     waves.y = 510; 
     waves.speedX = Math.random() * 3; 


     for(var j:uint = 0; j < 8; j++) 
     { 
      var ducks:Ducks = new Ducks(); 
      this.addChild(ducks); 
      ducks.x = 100 + j * 100; 
      ducks.y = 475; 
      _sittingDucks.push(ducks); 
      ducks.addEventListener(MouseEvent.CLICK, ducksDestroy); 
     } 

     var waves2:Waves = new Waves(); 
     this.addChild(waves2); 
     waves2.x = 0; 
     waves2.y = 520; 
     waves2.speedX = Math.random() * 3; 

     var setting:ForeGround = new ForeGround(); 
     this.addChild(setting); 
     setting.x = 0; 
     setting.y = 50; 
     setting.width = 920; 

     var board:ScoreDisplay = new ScoreDisplay(); 
     this.addChild(board); 
     board.x = 570; 
     board.y = 35; 

    } 
    private function ducksDestroy(event:MouseEvent):void 
    { 
     //store the crow we clicked on in a new array 
     var clickedDuck:Ducks = Ducks(event.currentTarget); 

     //remove it from the crows array 
     //find the address of the crow we are removing 
     var index:uint = _sittingDucks.indexOf(clickedDuck); 

     //remove it from the array with splice 
     _sittingDucks.splice(index, 1); 

     //remove it from my document's display list 
     this.removeChild(clickedDuck); 
    } 
} 


import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.text.TextField; 
import ScoreDisplayBase; // always import the classes you are using 

public class ScoreDisplay extends ScoreDisplayBase 
{ 
    private var txt:TextField; // where is it initialized? 
    private var score:uint = 0; 

    public function ScoreDisplay() 
    { 
     super(); // do you init txt here? 
    } 

    public function scoreUpdate():void 
    { 
     score += 10; // ok, so I suppose that your score does not represent the remaining ducks as you said, just only a score 
     txt.text = score.toString(); 
    } 
} 
+2

この宿題ですか? –

+1

私の息子の小さなゲームを作成しています – Plextor3009

+0

Dropboxは私の(そして私は確かに他人の)corp netによってブロックされています。質問に関連するコードを提供したい場合や、リンク先が異なる場合があります。 –

答えて

2

Aaaalrighty:

  1. あなたがScoreDisplayのコンストラクタでのTextField TXTを作成したいです。それをインスタンス化し、テキストを初期スコア(0)に設定し、addChild(txt)に設定します。

  2. スコアを後で設定するには、ディスプレイを参照する方法が必要です。

    //you want a reference to the ScoreDisplay, not this 
    public var _scoreDisplay:TextField //no 
    public var _scoreDisplay:ScoreDisplay //yes 
    

    メインコンストラクタで作成する場合は、参照を保持する必要があります。

    _scoreDisplay = :ScoreDisplay = new ScoreDisplay(); 
    this.addChild(_scoreDisplay); 
    _scoreDisplay .x = 570; 
    _scoreDisplay .y = 35; 
    
  3. あなたがゲームをリセットすることができるようにしたい場合は、私はアヒルの作成を取り、メインクラスのコンストラクタ外の方法でそれを置くことをお勧めします。また、ScoreDisplayでスコア(および表示)を0に設定する 'リセット'関数を作成する必要があります。

    private function spawnDucks() { 
        for(var j:uint = 0; j < 8; j++) 
        { 
         var ducks:Ducks = new Ducks(); 
         this.addChild(ducks); 
         ducks.x = 100 + j * 100; 
         ducks.y = 475; 
         _sittingDucks.push(ducks); 
         ducks.addEventListener(MouseEvent.CLICK, ducksDestroy); 
        } 
    } 
    

    これをコンストラクタで呼び出すと、ゲームをリセットする必要があるときに再度呼び出すことができます。

  4. ducksDestroy(event:MouseEvent)は、スコアを再計算し、勝ったかどうかを確認し、メッセージを表示してゲームをリセットする場所になります。表示するには何らかのポップアップが必要ですが、どこで始めるべきかわからない場合は、hereはまともなものです。

    private function ducksDestroy(event:MouseEvent):void 
    { 
        //store the crow we clicked on in a new array 
        var clickedDuck:Ducks = Ducks(event.currentTarget); 
    
        //remove it from the crows array 
        //find the address of the crow we are removing 
        var index:uint = _sittingDucks.indexOf(clickedDuck); 
    
        //remove it from the array with splice 
        _sittingDucks.splice(index, 1); 
    
        //remove it from my document's display list 
        this.removeChild(clickedDuck); 
    
        //update the score 
        _scoreDisplay.scoreUpdate(); 
    
        //Check if all the ducks are gone 
        if (_sittingDucks.length == 0) { 
         //All the ducks are dead, we've won the game! 
    
         //create some kind of popup to display. 
         //add it to the screen, have some form 
         //of button (or a timer) take it away 
    
         //whatever takes the popup away, have it call 'reset' 
    
        } 
    } 
    
    private function reset():void 
    { 
        //write a reset method to clear the score 
        _scoreDisplay.reset(); 
    
        //create some ducks and you're ready to go! 
        spawnDucks(); 
    } 
    
+0

私はこれを試して、あなたに知らせるつもりです。私は、カウントダウンボードのテキストが動的に設定されていることを伝えたいと思いました。そのすべてが変更された場合でも、ボードクラスにはまだテキストフィールドが作成されますか? – Plextor3009

+0

@ user1276896動的のみとは、宣言されていないプロパティを指定できることを意味します。基本Objectクラスと同様です。 –

+0

申し訳ありません私は一日中これに取り組んでいると答えていません。スコアリングが機能する。助けてくれてありがとう。私は今、ゲーム全体をリセットするボタンを取得しようとしています。 – Plextor3009

関連する問題