src/main/java/ru/alphatech/icfpc/cards/Dec.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 15:04:59 +0400
changeset 68 a84a3c755d93
parent 64 8ce8964b584f
child 74 b277f6c31f5f
permissions -rw-r--r--
Cards done. Only interpretation of zero card is under question mark.
     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 Dec implements ICard
     9 {
    10 	@Override
    11 	public IValue returnValue(IValue iobj, Player proponent, Player opponent)
    12 	{
    13 		if(iobj instanceof Value)
    14 		{
    15 			int i = ((Value)iobj).getValue();
    16 
    17 			if (i >= 0 && i <= 255)
    18 			{
    19 				int v = proponent.getSlot(255 - i).getVitality();
    20 				
    21 				if (v > 0)
    22 				{
    23 					proponent.getSlot(255 - i).setVitality(v - 1);
    24 				}
    25 
    26 				return new I();
    27 			}
    28 			else
    29 			{
    30 				throw new ICFPCException();
    31 			}
    32 		}
    33 		else
    34 		{
    35 			throw new ICFPCException();
    36 		}
    37 	}
    38 }