我试图完成贴纸书项目的最后一次迭代,但我无法弄清楚最后两个组成部分:
以下是Main
中的贴纸选择和贴纸放置代码。我试图做一些事情,如果我右键单击现有贴纸,slot
变量将等于所选对象的插槽,然后使用switch
命令删除{{1} } index已被选中。我不知道如何接近第二颗子弹。
slot
如果有帮助,这是我的班级及其方法。
//Create a Sticker array called stickerArr that holds 10 stickers
Sticker[] stickerArr = new Sticker[10];
//Declare integer variables called xClick and yClick
//Declare integer variables called slot and choosePic and make them equal to 0
int slot = 0;
int xClick, yClick;
int choosePic = 0;
while(true) { //start infinite while loop that executes everything within the loop
xClick = EZInteraction.getXMouse();
yClick = EZInteraction.getYMouse();
//Start an if statement to select the appropriate picture
//A different integer is set to choosePic so that we can place the selected picture later
if (EZInteraction.wasMouseLeftButtonPressed()) { //start the sticker selection if-statement
if (dolphin.isPointInElement(xClick, yClick)){
choosePic = 1;
sound1.play();
}
else if (fish.isPointInElement(xClick, yClick)){
choosePic = 2;
sound2.play();
}
else if (shark.isPointInElement(xClick, yClick)) {
choosePic = 3;
sound3.play();
}
else if (jellyfish.isPointInElement(xClick, yClick)) {
choosePic = 4;
sound4.play();
}
//Only execute if the background (fishbowl picture) is under the mouse.
while(fishbowl.isPointInElement(xClick, yClick)){ // start fishbowl-while
xClick = EZInteraction.getXMouse();
yClick = EZInteraction.getYMouse();
if(EZInteraction.wasMouseLeftButtonPressed()) { //start choosePic-if
//Start a switch statement for choosePic
//Whatever picture was selected will decide what sticker object is placed on the canvas
//Each sticker object will have an image name, a sound, and an x and y coordinate to be used for the save load function
switch(choosePic) { //start switch
case 1: stickerArr[slot] = new Sticker("dolphin.png", "sound1.wav", xClick, yClick);
sound1.play();
slot++;
break;
case 2: stickerArr[slot] = new Sticker("fish.png", "sound2.wav", xClick, yClick);
sound2.play();
slot++;
break;
case 3: stickerArr[slot] = new Sticker("shark.png", "sound3.wav", xClick, yClick);
sound3.play();
slot++;
break;
case 4: stickerArr[slot] = new Sticker("jellyfish.png", "sound4.wav", xClick, yClick);
sound4.play();
slot++;
break;
default: // do nothing
break;
} // end switch
}// end choosePic-if
if(EZInteraction.wasMouseRightButtonPressed()){
slot = ???; // I'm trying to set 'slot' to whichever index was selected when the user clicks on any existing sticker on the canvas
switch(slot) { //for whatever slot was selected, the objects information will be deleted and cleared from the txt file
case 1: break;
case 2: break;
case 3: break;
case 4: break;
case 5: break;
case 6: break;
case 7: break;
case 8: break;
case 9: break;
case 10: break;
}
}
} // end fishbowl-while
//Refresh screen
EZ.refreshScreen();
} //end infinite while
这是我整个代码的一部分。我并不认为一切都很重要。
程序摘要:创建一个交互式模拟贴纸,左键单击调色板上的图片选择图像,然后左键单击画布/背景上的贴纸对象。每个贴纸对象都有自己的一组信息(图像名称,声音,x和y)。此信息将用于已实现的保存,加载和清除功能。以上两点,都是留下来实现的。