This site requires JavaScript, please enable it in your browser!
Greenfoot back
ProfessionalNoob
ProfessionalNoob wrote ...

2015/4/7

Have card attack only once?

1
2
ProfessionalNoob ProfessionalNoob

2015/4/11

#
danpost wrote...
Ahhh -- I understand what you meant now. Another way would be to use a List object. If the card is not on the list, it can attack; once it attacks, it is added to the list; at the end of the turn, clear the list.
I'm not very familiar with lists, but is there a way to do such a thing ONLY if the card has the Deployment boolean set to true?
danpost danpost

2015/4/11

#
ProfessionalNoob wrote...
I'm not very familiar with lists, but is there a way to do such a thing ONLY if the card has the Deployment boolean set to true?
The card cannot attack if that boolean is false. If you only add cards to the list when they attack, then the boolean for that card should already be true.
ProfessionalNoob ProfessionalNoob

2015/4/11

#
Here's what I got: I don't know much about arraylists
 CurrentMana ++;          //Increasing current and max mana
               MaxMana++; 
                              if (position == 6) return;                   //Cannot have more than six cards.
               int value = Greenfoot.getRandomNumber(6-position);        //Value used for cards indexing.

               Cards card = playerCards[value];
               ArrayList<Cards> array = new ArrayList<Cards>(); 
            if(getY() > 400)                             //Determines player position for card positioning.
            {
               getWorld().addObject(card, 40 + (50*(position+1)^2), getY()+60);
            }
            
            if(getY() < 400)
            {
                getWorld().addObject(card, 40 + (50*(position+1)^2), getY() -40);
            }
            position++;                          //Increases value of position.
            playerCards[value] = playerCards[6-position];        //changes value based on position.
            playerCards[6-position] = card;              //Turns array value into a single variable. 
            
            if(card.hasAttacked) 
            {
                array.add(card); 
            }
            if(array.contains(card))
            {
                card.attacking = false; 
            }
            array.clear(); 
            if(card.Deployment && Greenfoot.mouseClicked(this))
            {
                loseHealth(card.attack);         //Looses health if card attacks plaer.
            }
                
The above is in player. The card class is:
    
    if(Deployment && Greenfoot.mouseClicked(this) && attacking)          //Method for attacking
    {
        //changed comment in next line, I think you misunderstood what it does
    if (attacker == null) attacker = this;          //set attacker
    else if(attacker != this)        //if there already is an attacker, attack this with the attacker
    {
         loseHealth(attacker.attack);
         attacker.loseHealth(attack);               //If you are attacking someone, have both loose health.
         attacker = null;
     }
    }
danpost danpost

2015/4/11

#
I would suggest using a static ArrayList in the Cards class using the following line outside any method in the class:
public static ArrayList<Cards> array = new ArrayList<Cards>();
Then, in your last code snippet at line 10, add
array.add(this);
array.add(attacker);
At the place where you determine the turn is over, use:
Cards.array.clear();
ProfessionalNoob ProfessionalNoob

2015/4/11

#
Everything works fine but the player turn part. In the world class:
  public void act()
    {
        int value = turn%playerCount;    
        if("up"!=(key))
        {//Changing value depending on player selected
        if (Greenfoot.mouseClicked(Player[turn%playerCount]))
        {  
            Card.setImage(BackCard);        //Making sure that players cannot see their opponent's hand. 
            Player[turn%playerCount].CardSelect();  //Running the cardselect method.
            Player[turn%2].showCards();         //Shows the card for the current player.
            Player[(turn+1)%2].hideCards();     //Hides the card for the other.
            turn ++;      
            Cards.array.clear();
        }
    }
   
    if(Greenfoot.mouseClicked(Spells[0]))
    {
        Player[0].gainArmor(2); 
    }
    
    if(Greenfoot.mouseClicked(Spells[1]))
    {
        Spells[1].act();
    }
   }
Should I just use another way to end a turn? Thanks for your help so far.
You need to login to post a reply.
1
2