2012-11-13 68 views
1

嗨,我正在構建一個老虎機遊戲,我有一些問題,我很新的處理。隨機圖片並獲得獎勵(處理中)

我做了這個代碼,並需要「輪子」是隨機的,但它們都具有相同的圖像(垂直)

我知道你將無法看到所以這裏的圖片是一些鏈接,如果你想要他們。

http://tinypic.com/r/i1jq7t/6(diamond1)

http://tinypic.com/r/29fe5cg/6(cherry1)

http://tinypic.com/r/sen1jo/6(bell1)

int numFrames = 3; // The number of frames in the animation 
int frame = 0; 
int spincount = 0; 
int state = 0; 
PImage[] images1 = new PImage[3]; 

PImage[] images2 = new PImage[3]; 

PImage[] images3 = new PImage[3]; 

void setup() { 
    size(1080, 720); 
    frameRate(12); 

    // wheel 1 
    images1[0] = loadImage("bell1.png"); 
    images1[1] = loadImage("cherry1.png"); 
    images1[2] = loadImage("diamond1.png"); 


    // wheel 3 
    images3[0] = loadImage("cherry1.png"); 
    images3[1] = loadImage("bell1.png"); 
    images3[2] = loadImage("diamond1.png"); 


    // wheel 2 
    images2[0] = loadImage("diamond1.png"); 
    images2[1] = loadImage("bell1.png"); 
    images2[2] = loadImage("cherry1.png"); 

} 

void draw() { 
    background(o); 
    //test state to see if I should be spinning 
    if(state == 1) { 
    spin(); 
    } 

} 

//if a key is pressed then set the wheel to spin 
void keyReleased() { 
state = 1; 
} 


void spin() { 
    //spin for 5 times the break out 
    if (frame == 3) { 
    frame = 0; 
    spincount ++; 
     if (spincount == 10) { 
     state = 0; 
     spincount = 0; 
     //check if its a win and do stuff 
     winner(); 
     } 
    } 
    // wheel 1 
    image(images1[frame], 20, 0); 
    image(images1[frame], 20, 170); //this is the image to test 
    image(images1[frame], 20, 340); 

    // wheel 2 

    image(images3[frame], 200, 0); 
    image(images3[frame], 200, 170); //this is the image to test 
    image(images3[frame], 200, 340); 

    // wheel 3 

    image(images2[frame], 400, 0); 
    image(images2[frame], 400, 170); //this is the image to test 
    image(images2[frame], 400, 340); 


    frame ++; 

    } 



void winner() { 

    //are the names of the images the same 
    //if ((images3[frame].get(0,0)) == (images2[frame].get(0,0)) == (images1[frame].get(0,0))) { 
     // display a question from you list of questions by generating a random number and selecting the text 

     // wait for an answer 
     for (int i = 0; i < 400; i = i+1) { 
     if (keyPressed == true) { 
      // whats the key is it correct 
     } 
     if (i > 400) { 
     //display times up 
     } 
     } 
    } 
// } 

我也有剛剛接到 「中獎」(問題如果水平圖像的像素左邊角球比賽進入「贏家」。

我真的很感謝任何人都可以提供的幫助

+0

你在用什麼語言?另外,你的標籤並不真正相關。 – MikeTheLiar

+1

這是很多代碼。考慮將其編輯爲[簡短,自包含,正確的示例](http://sscce.org/),以便人們更容易幫助您。 – durron597

回答

0

您的代碼有幾個問題。

在繪圖函數中,您可能想要繪製黑色背景,但您當前具有字母「o」而不是數字0(零)。

您可能希望在繪圖函數中將當前的車輪狀態繪製到屏幕上,現在,除非您正在旋轉,否則您只有一個黑色窗口。

您無法直接比較顏色。

下面是一些修改後的代碼得到它的工作:

int numFrames = 3; // The number of frames in the animation 
int maxSpin = 10; 
int frame = 0; 
int spincount = 0; 
boolean spinning = false; 
boolean checkWinner = false; 
PImage[] images1 = new PImage[3]; 
PImage[] images2 = new PImage[3]; 
PImage[] images3 = new PImage[3]; 

void setup() { 
    size(1080, 720); 
    frameRate(12); 

    // wheel 1 
    images1[0] = loadImage("bell1.png"); 
    images1[1] = loadImage("cherry1.png"); 
    images1[2] = loadImage("diamond1.png"); 


    // wheel 3 
    images3[0] = loadImage("cherry1.png"); 
    images3[1] = loadImage("bell1.png"); 
    images3[2] = loadImage("diamond1.png"); 


    // wheel 2 
    images2[0] = loadImage("diamond1.png"); 
    images2[1] = loadImage("bell1.png"); 
    images2[2] = loadImage("cherry1.png"); 
} 

void draw() { 
    background(0); 
    //test state to see if I should be spinning 

    // wheel 1 
    image(images1[frame], 20, 0); 
    image(images1[frame], 20, 170); //this is the image to test 
    image(images1[frame], 20, 340); 

    // wheel 2 

    image(images3[frame], 200, 0); 
    image(images3[frame], 200, 170); //this is the image to test 
    image(images3[frame], 200, 340); 

    // wheel 3 

    image(images2[frame], 400, 0); 
    image(images2[frame], 400, 170); //this is the image to test 
    image(images2[frame], 400, 340); 

    if (spinning) { 
    spin(); 
    } 

    //this draws circles stroked in the color of the pixel at their center 
    //this is just to show how the code works, you can remove this 
    noFill(); // make the circles transparent 
    loadPixels(); // required before using pixels[] 
    color wheel1 = pixels[170*width+20]; 
    color wheel2 = pixels[170*width+200]; 
    color wheel3 = pixels[170*width+400]; 
    stroke(wheel1); 
    ellipse(20, 170, 10, 10); 
    stroke(wheel2); 
    ellipse(200, 170, 10, 10); 
    stroke(wheel3); 
    ellipse(400, 170, 10, 10); 
} 

//if a key is pressed then set the wheel to spin 
void keyReleased() { 
    if(!spinning) spinning = !spinning; 
} 


void spin() { 
    //spin for maxSpin times then break out 

    if (frame == numFrames-1) { 
    spincount ++; 
    if (spincount == maxSpin) { 
     spinning = !spinning; 
     spincount = 0; 
     //check if its a win and do stuff 
     winner(); 
    } 
    else frame = 0; 
    } 
    else frame++; 
} 



void winner() { 
    loadPixels(); 
    color wheel1 = pixels[171*width+21]; 
    color wheel2 = pixels[171*width+201]; 
    color wheel3 = pixels[171*width+401]; 
    if(hue(wheel1) == hue(wheel2) && hue(wheel2) == hue(wheel3)) println("winner"); 
    else println("not a winner"); 
} 

這inclues您所需的檢查上的圖像的角上的顏色的方法,但我會建議只是跟蹤哪些是當前顯示的圖像中心。

我希望這至少能讓你朝着正確的方向前進。