개체 비교에 대한 간단한 Adobe Flash 게임

user3003490
  • 게임 레이아웃

저는 9 개의 재료 사진이 있고 모든 요리에이 재료 중 2 개만있는 간단한 음식 게임을 작업하고 있습니다. 정확한 그림을 지정하거나 하드 코딩 할 수 있습니다. 나는 그들을 섞을 필요도 없습니다.

사용자가 2 개의 올바른 재료를 성공적으로 클릭하면 다음과 같은 출력이 표시되어 올바른 재료를 얻었음을 알려줍니다. 하나 또는없는 경우 게임이 재설정됩니다.

  • 문제

지금까지 게임의 레이아웃은했지만 게임의 액션 스크립트 부분이 부족한 쉘을 해봤고, 메모리 게임에 대한 조사를 좀 해봤지만 코딩에 많은 차이가 있다고 느낍니다.

아래 그림 :

1) 사용자는 왼쪽에있는 사각형 2 개를 클릭하여 시작합니다 (예 : sp1 및 sp3).

2) 정확하면 사용자는 두 번째 접시에서 시작하기 위해 다른 프레임으로 이동합니다.

3) 조합이 잘못된 경우 파란색 상자에 "잘못된"메시지가 표시되고 게임이 재설정됩니다.

편집 : 추가 링크를 FLA에 - 감사 사용자 배트맨 - https://www.dropbox.com/s/9oz9uikfbyp3rhi/thespicegame.fla?dl=0

편집 됨 : 스위치 사용을 제안했습니다. 작업을 시도 할 것입니다.

Edited:
     function checkPicture(e:MouseEvent):void
{
    // Start your custom code
    // This example code displays the words "Mouse clicked" in the Output panel.
    if(e.currentTarget == sp1){
        if(e.currentTarget == sp2){
            trace("working");
        }else{          
            trace("notworking");        
        }
    }
}
BadFeelingAboutThis

이 작업을 수행하는 방법에는 여러 가지가 있습니다. 구현에 관계없이 수행해야하는 작업을 요약하려면 다음을 수행하십시오.

  1. 각 요리에 맞는 두 가지 향신료를 연결해야합니다.

  2. 클릭 한 두 항목을 메모리에 저장해야합니다.

  3. After the second item is clicked, you need to compare to the two items in memory with whatever mechanism you use to associate the correct spices with current dish.

Since it would appear you are a student and just learning, I'll tailor my solution to your current frame and library based game - keeping in mind the best solution would involve much more programming using class files and no timeline code.

  1. Associate your correct spices with a dish. The easiest way to do this, is create a dictionary using the dish buttons as the key. Put this (and all subsequent code unless noted) on your first game frame (frame 4 currently).

    //create a dictionary to store all the correct spices
    var correctSpices:Dictionary = new Dictionary();
    correctSpices[meeBtn2] = [sp1, sp3]; //assign an array containing the correct spices
    correctSpices[chickBtn2] = [sp1, sp3];
    correctSpices[satayBtn2] = [sp1, sp3];
    correctSpices[laskaBtn2] = [sp1, sp3];
    correctSpices[rojakBtn2] = [sp1, sp3];
    
  2. Create a variable to hold the first ingredient that was clicked. Also create a variable that stores the current dish:

    var firstSpice; //to hold the first spice clicked
    
    var currentDish; //to hold the current dish
    
  3. Populate the current dish on whatever frame is for that dish:

    currentDish = chickBtn2; //put this on the frame where chicken is the dish
    
  4. You need to populate the first click spice variable when a spice is clicked. I don't see any click listeners on your spice buttons, so let's assume you have the following:

    sp1.addEventListener(MouseEvent.CLICK, spiceClick, false,0,true);
    sp2.addEventListener(MouseEvent.CLICK, spiceClick, false, 0, true);
    //...etc with all spices
    

    Or the shorthanded sloppy way to do all 9 in 3 lines:

    for(var i:int=1; i<= 9;i++){
        this["sp" + i].addEventListener(MouseEvent.CLICK, spiceClick, false, 0, true);
    }
    

    Then in the click handler:

    function spiceClick(e:Event):void {
    
        //If the firstSpice variable is null (empty), assign it the click events current target (which is the item you attached the listener to)
        if(firstSpice == null){
            firstSpice = e.currentTarget;
            firstSpice.mouseEnabled = false; //make it so you can't click this one anymore
            return; //exit this function since we want to wait for the second item to be clicked
        }
    
        //the second item was clicked if we made it this far, check the results
    
        if(correctSpices[currentDish].indexOf(firstSpice) > -1){
            //first one was correct, now check the one just clicked
            if(correctSpices[currentDish].indexOf(e.currentTarget) > -1){
                //second one was correct
                nextLevel();
            }else{
                //second one was wrong
            }
        }else{
            //first one was wrong
        }
    }
    
    function nextLevel(){
        //reset all the mouse enabled properties so you can click all the buttons again
        for(var i:int=1; i<= 9;i++){
            this["sp" + i].mouseEnabled = true;
        }
    
        //clear the firstSpice var
        firstSpice = null;
    
        nextFrame(); //goto the next frame
    }
    

Keep in mind, this code will persist for all future frames. As long you have no keyframes or empty frames on your buttons, the mouse listeners and everything will stay the same for all subsequent frames

To that end, I would recommend just adding another layer for the current dish text, and then just hide or disable the dish button when you need to (that way you only attach the mouse listener once).

So on every game frame, you'd have this code:

if(currentDish) currentDish.visible = true; //if there was previously a hidden dish button, make it visible again
currentDish = chickBtn2; //assign whatever the current dish btn is for each frame
currentDish.visible = false; //hide the current dish button so it can't be clicked

EDIT

Here is the code I used for testing: (all on frame 4)

import flash.utils.setTimeout;
import flash.utils.Dictionary;


meeBtn2.addEventListener(MouseEvent.CLICK, dishBtnClick);
chickBtn2.addEventListener(MouseEvent.CLICK, dishBtnClick);
satayBtn2.addEventListener(MouseEvent.CLICK, dishBtnClick);
laskaBtn2.addEventListener(MouseEvent.CLICK, dishBtnClick);
rojakBtn2.addEventListener(MouseEvent.CLICK, dishBtnClick);

function dishBtnClick(event:MouseEvent):void
{
    switch(event.currentTarget){
        case meeBtn2:
            gotoAndStop(4);
            break;

        case chickBtn2:
            gotoAndStop(5);
            break;

        case satayBtn2:
            gotoAndStop(6);
            break;

        case laskaBtn2:
            gotoAndStop(7);
            break;

        case rojakBtn2:
            gotoAndStop(8);
            break;
    }
}



//create a dictionary to store all the correct spices
var correctSpices:Dictionary = new Dictionary();
correctSpices[meeBtn2] = [sp1, sp3];
correctSpices[chickBtn2] = [sp1, sp3];
correctSpices[satayBtn2] = [sp1, sp3];
correctSpices[laskaBtn2] = [sp1, sp3];
correctSpices[rojakBtn2] = [sp1, sp3];


var firstSpice; //to hold the first spice clicked

var currentDish; //to hold the current dish

currentDish = meeBtn2; //put this on the frame where chicken is the dish

for(var i:int=1; i<= 9;i++){
    this["sp" + i].addEventListener(MouseEvent.CLICK, spiceClick, false, 0, true);
}

function spiceClick(e:Event):void {

    //If the firstSpice variable is null (empty), assign it the click events current target (which is the item you attached the listener to)
    if(firstSpice == null){
        firstSpice = e.currentTarget;
        firstSpice.mouseEnabled = false; //make it so you can't click this one anymore
        return; //exit this function since we want to wait for the second item to be clicked
    }

    //the second item was clicked if we made it this far, check the results

    var ctr:int = 0; //a counter to count how many are correct
    if(correctSpices[currentDish].indexOf(firstSpice) > -1){
        //the first one was correct, add 1 to the counter
        ctr++;
    }

    if(correctSpices[currentDish].indexOf(e.currentTarget) > -1){
        //second one was correct
        ctr++;
    }

    switch(ctr){
        case 2:
            //both items were correct
            output1.text = "Great Job!";

            //go to the next level in 2 seconds
            flash.utils.setTimeout(nextLevel, 2000);
            break; //don't look at any more case statements

        case 1:
            output1.text = "Almost There";
            reset();
            break;

        case 0:
            output1.text = "Try harder...";
            reset();
    }

}
function reset(){
    //reset all the mouse enabled properties so you can click all the buttons again
    for(var i:int=1; i<= 9;i++){
        this["sp" + i].mouseEnabled = true;
    }

    //clear the firstSpice var
    firstSpice = null;
}

function nextLevel(){
    reset();

    nextFrame(); //goto the next frame
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

간단한 게임에서 KeyListener로 개체 이동 시도

분류에서Dev

Adobe Flash에 대한 대안이 있습니까?

분류에서Dev

2016 : Adobe Flash 용 Firefox 대체

분류에서Dev

신비하게 실패한 탭의 간단한 sed 교체

분류에서Dev

신비하게 실패한 탭의 간단한 sed 교체

분류에서Dev

"오류 : 임시 개체의 주소 가져 오기"에 대한 가장 간단한 수정?

분류에서Dev

다양한 속성 집합에 대한 두 개체 비교

분류에서Dev

Adobe Flash에서 어떻게 확대 / 축소합니까?

분류에서Dev

DOM 개체에 대한 참조 교체

분류에서Dev

단일 개체에 대한 사용자 지정 비교기 사용

분류에서Dev

간단한 RequestMapping 교체

분류에서Dev

AS2에 Adobe Flash CC 게시

분류에서Dev

단위 테스트에서 유사한 개체 비교

분류에서Dev

파일에서 간단한 대체

분류에서Dev

간단한 게임을위한 객체 지향 접근법

분류에서Dev

Adobe는 새 버전의 Flash 출시를 중단합니다. Ubuntu에서 Flash 지원은 어떻게됩니까?

분류에서Dev

/ 람다 비교에 대한 간단한의 JMH 측정 확인

분류에서Dev

간단한 게임에서 끔찍한 FPS

분류에서Dev

우아한 방식으로 게임 엔진에서 파괴 된 개체에 대한 포인터 관리

분류에서Dev

데이터 프레임에 대한 간단한 목록

분류에서Dev

extbase의 비 개체에 대한 findAll

분류에서Dev

개체에 대한 참조

분류에서Dev

string []에 대한 개체

분류에서Dev

ArrayList에 대한 개체

분류에서Dev

GUID / UUID에 대한 개체

분류에서Dev

어떻게 javax의 직접 간단한 문자열 매개 변수에 대한 @NotBlank 유효성을 검사?

분류에서Dev

간단한 XML 비교

분류에서Dev

개념 예제에 대한 간단한 C ++ 인터페이스

분류에서Dev

간단한 테이블에 대한 MySql 합계 및 개수

Related 관련 기사

  1. 1

    간단한 게임에서 KeyListener로 개체 이동 시도

  2. 2

    Adobe Flash에 대한 대안이 있습니까?

  3. 3

    2016 : Adobe Flash 용 Firefox 대체

  4. 4

    신비하게 실패한 탭의 간단한 sed 교체

  5. 5

    신비하게 실패한 탭의 간단한 sed 교체

  6. 6

    "오류 : 임시 개체의 주소 가져 오기"에 대한 가장 간단한 수정?

  7. 7

    다양한 속성 집합에 대한 두 개체 비교

  8. 8

    Adobe Flash에서 어떻게 확대 / 축소합니까?

  9. 9

    DOM 개체에 대한 참조 교체

  10. 10

    단일 개체에 대한 사용자 지정 비교기 사용

  11. 11

    간단한 RequestMapping 교체

  12. 12

    AS2에 Adobe Flash CC 게시

  13. 13

    단위 테스트에서 유사한 개체 비교

  14. 14

    파일에서 간단한 대체

  15. 15

    간단한 게임을위한 객체 지향 접근법

  16. 16

    Adobe는 새 버전의 Flash 출시를 중단합니다. Ubuntu에서 Flash 지원은 어떻게됩니까?

  17. 17

    / 람다 비교에 대한 간단한의 JMH 측정 확인

  18. 18

    간단한 게임에서 끔찍한 FPS

  19. 19

    우아한 방식으로 게임 엔진에서 파괴 된 개체에 대한 포인터 관리

  20. 20

    데이터 프레임에 대한 간단한 목록

  21. 21

    extbase의 비 개체에 대한 findAll

  22. 22

    개체에 대한 참조

  23. 23

    string []에 대한 개체

  24. 24

    ArrayList에 대한 개체

  25. 25

    GUID / UUID에 대한 개체

  26. 26

    어떻게 javax의 직접 간단한 문자열 매개 변수에 대한 @NotBlank 유효성을 검사?

  27. 27

    간단한 XML 비교

  28. 28

    개념 예제에 대한 간단한 C ++ 인터페이스

  29. 29

    간단한 테이블에 대한 MySql 합계 및 개수

뜨겁다태그

보관