Hi, I am making a fighting card game for my school project. I want the player to be able to choose a card that is on the slot and then choose a card from opponent which is also on the slot by mouse clicking .
When I want the card that is already on a slot to be selected to attack, then click on that card, it will only move to the next empty slot.
Another problem is in chooseToAttack() method. All the cards will have yellow border after the player's first turn when the mouse pointer is on those card. I only want the cards that are on the slots to have yellow border.
Sorry, I am not even sure about what I've got so far. I'd appreciate some help.
/** * Check to see if it is player's turn or bot's turn. */ public void checkTurn() { if (myTurn) { choose(); if (!slotEmpty1 || !slotEmpty2 || !slotEmpty3) { chooseToAttack(); } } else { return; } } /** * Choose a card to place in the empty slot if it is player's turn. */ private void choose() { Actor card = getOneObjectAtOffset (getX(), 750, Cards.class); if (Greenfoot.mouseMoved(card)) { onThis = Greenfoot.mouseMoved(this); } if (onThis && !selected) { setLocation(this.getX(),633); } else if (!onThis && !selected) { setLocation(this.getX(),750); } if (Greenfoot.mouseClicked(this)) { select(); myTurn = false; selected = true; } } /** * Put the selected card into the empty slot if it is player's turn */ public void select() { if (slotEmpty1) //go to slot1 { this.setLocation(slotX[0],slotY[1]); getWorld().addObject(new HealthBar(health, currentHealth), slotX[0], slotY[1]-90); } else if (!slotEmpty1 && slotEmpty2)/ //go to slot2 { this.setLocation(slotX[1],slotY[1]); getWorld().addObject(new HealthBar(health, currentHealth), slotX[1], slotY[1]-90); } else if (!slotEmpty1 && !slotEmpty2 && slotEmpty3) //go to slot3 { this.setLocation(slotX[2],slotY[1]); getWorld().addObject(new HealthBar(health, currentHealth), slotX[2], slotY[1]-90); } else if (!slotEmpty1 && !slotEmpty2 && !slotEmpty3) //if all full, don't do anything { } } /** * Player choose a card on one of the slots to attack bot * When the mouse is on the card, it will create yellow border */ public void chooseToAttack() { Actor cardOnSlot = getOneObjectAtOffset (getX(), slotY[1], Cards.class);//getOneIntersectingObject(Slot.class);//getOneObjectAtOffset (slot.getX(), slot.getY(), Slot.class); if (Greenfoot.mouseMoved(cardOnSlot)) { onSlot = Greenfoot.mouseMoved(this); } if (onSlot && !selectedToAttack) { GreenfootImage image = getImage(); image.setColor(new Color(255,202,24)); image.drawRect(0,0,120+20,175+20); setImage(image); } else if (!onSlot && !selectedToAttack) { setImage(character); } if (Greenfoot.mouseClicked(cardOnSlot)) { chooseBotToAttack(); GreenfootImage image = getImage(); image.setColor(new Color(255,202,24)); image.drawRect(0,0,120+30,175+30); setImage(image); selectedToAttack = true; } } /** * Choose a bot card to attack */ public void chooseBotToAttack() { if (Greenfoot.mouseMoved(Bot.class)) { onSlot = Greenfoot.mouseMoved(this); } if (onSlot && !selectedToAttack) { GreenfootImage image = getImage(); image.setColor(new Color(255,202,24)); image.drawRect(0,0,120+20,175+20); setImage(image); } else if (!onSlot && !selectedToAttack) { setImage(character); } if (Greenfoot.mouseClicked(this)) { attack(); GreenfootImage image = getImage(); image.setColor(new Color(255,202,24)); image.drawRect(0,0,120+30,175+30); setImage(image); myTurn = false; selectedToAttack = true; } }