src/main/java/ru/alphatech/icfpc/cards/Zombie.java
author akhmetovlz
Sun, 19 Jun 2011 17:22:00 +0400
changeset 86 22bad86100ac
parent 74 b277f6c31f5f
child 102 cc814352ab43
permissions -rw-r--r--
Merge with 5940c7605d039b10b1bfeda7d971be29f03987e2
     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 implements ICard
     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 		return new ICard()
    19 		{
    20 			@Override
    21 			public String getName() {
    22 				return "";
    23 			}
    24 			
    25 			@Override
    26 			public IValue returnValue(final IValue x, Player proponent, Player opponent)
    27 			{
    28 				if (iobj instanceof Value)
    29 				{
    30 					int i = ((Value)iobj).getValue();
    31 
    32 					if (i >= 0 && i <= 255)
    33 					{
    34 						int v = opponent.getSlot(255 - i).getVitality();
    35 
    36 						if(v <= 0)
    37 						{
    38 							opponent.getSlot(255 - i).putValue(x);
    39 							opponent.getSlot(255 - i).setVitality(-1);
    40 
    41 							return new I();
    42 						}
    43 						else
    44 						{
    45 							throw new ICFPCException();
    46 						}
    47 					}
    48 					else
    49 					{
    50 						throw new ICFPCException();
    51 					}
    52 				}
    53 				else
    54 				{
    55 					throw new ICFPCException();
    56 				}
    57 			}
    58 		};
    59 	}
    60 }