src/main/java/ru/alphatech/icfpc/cards/Zombie.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 19:13:07 +0400
changeset 102 cc814352ab43
parent 74 b277f6c31f5f
permissions -rw-r--r--
Call Count.
     1 package ru.alphatech.icfpc.cards;
     2 
     3 import ru.alphatech.icfpc.game.ICFPCException;
     4 import ru.alphatech.icfpc.game.IValue;
     5 import ru.alphatech.icfpc.game.Player;
     6 import ru.alphatech.icfpc.game.Value;
     7 
     8 public class Zombie extends AbstractCard
     9 {
    10 	@Override
    11 	public String getName() {
    12 		return "zombie";
    13 	}
    14 	
    15 	@Override
    16 	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
    17 	{
    18 		incAndTest();
    19 		
    20 		return new AbstractCard()
    21 		{
    22 			@Override
    23 			public String getName() {
    24 				return "";
    25 			}
    26 			
    27 			@Override
    28 			public IValue returnValue(final IValue x, Player proponent, Player opponent)
    29 			{
    30 				incAndTest();
    31 				
    32 				if (iobj instanceof Value)
    33 				{
    34 					int i = ((Value)iobj).getValue();
    35 
    36 					if (i >= 0 && i <= 255)
    37 					{
    38 						int v = opponent.getSlot(255 - i).getVitality();
    39 
    40 						if(v <= 0)
    41 						{
    42 							opponent.getSlot(255 - i).putValue(x);
    43 							opponent.getSlot(255 - i).setVitality(-1);
    44 
    45 							return new I();
    46 						}
    47 						else
    48 						{
    49 							throw new ICFPCException();
    50 						}
    51 					}
    52 					else
    53 					{
    54 						throw new ICFPCException();
    55 					}
    56 				}
    57 				else
    58 				{
    59 					throw new ICFPCException();
    60 				}
    61 			}
    62 		};
    63 	}
    64 }