src/main/java/ru/alphatech/icfpc/cards/Dec.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 19:13:07 +0400
changeset 102 cc814352ab43
parent 79 0bfd181c663e
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.Run;
     7 import ru.alphatech.icfpc.game.Value;
     8 
     9 public class Dec extends AbstractCard
    10 {
    11 	@Override
    12 	public String getName() {
    13 		return "dec";
    14 	}
    15 	
    16 	@Override
    17 	public IValue returnValue(IValue iobj, Player proponent, Player opponent)
    18 	{
    19 		incAndTest();
    20 		
    21 		if(iobj instanceof Value)
    22 		{
    23 			int i = ((Value)iobj).getValue();
    24 
    25 			if (i >= 0 && i <= 255)
    26 			{
    27 				int v = proponent.getSlot(255 - i).getVitality();
    28 				
    29 				if(Run.getAutoMode())
    30 				{
    31 					if(v > 0 && v < 65535)
    32 					{
    33 						proponent.getSlot(255 - i).setVitality(v + 1);
    34 					}
    35 				}
    36 				else
    37 				{
    38 					if (v > 0)
    39 					{
    40 						proponent.getSlot(255 - i).setVitality(v - 1);
    41 					}
    42 				}
    43 
    44 				return new I();
    45 			}
    46 			else
    47 			{
    48 				throw new ICFPCException();
    49 			}
    50 		}
    51 		else
    52 		{
    53 			throw new ICFPCException();
    54 		}
    55 	}
    56 }