예제 #1
0
        public void move(PlayerMemento playerMemento, DIRECTIONS direction)
        {
            if (direction == DIRECTIONS.RIGHT)
            {
                playerMemento.XIndex += 1;
            }
            if (direction == DIRECTIONS.UP)
            {
                playerMemento.YIndex -= 1;
            }
            if (direction == DIRECTIONS.LEFT)
            {
                playerMemento.XIndex -= 1;
            }
            if (direction == DIRECTIONS.DOWN)
            {
                playerMemento.YIndex += 1;
            }

            if (playerMemento.XIndex < 0 || playerMemento.XIndex > 5 || playerMemento.YIndex < 0 || playerMemento.YIndex > 5)
            {
                PlayerMemento p = LoadPrev(playerMemento);
                if (p.XIndex < 0 || p.XIndex > 5 || p.YIndex < 0 || p.YIndex > 5)
                {
                    exitSimulation();
                }
                else
                {
                    playerMemento.value  = p.value;
                    playerMemento.XIndex = p.XIndex;
                    playerMemento.YIndex = p.YIndex;
                }
            }
        }
예제 #2
0
        static void PrintBoard(PlayerMemento player)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("-------------------");
            int boardSize = 5;

            for (int i = 0; i < boardSize; i++)
            {
                Console.WriteLine();
                for (int j = 0; j < boardSize; j++)
                {
                    if (i == player.YIndex && j == player.XIndex)
                    {
                        Console.Write('P');
                    }
                    else
                    {
                        Console.Write('.');
                    }
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("-------------------");
        }
예제 #3
0
 public PlayerMemento LoadPrev(PlayerMemento playerMemento)
 {
     if (careTake.GetLast(false) != null)
     {
         playerMemento = careTake.GetLast(true);
     }
     return(playerMemento);
 }
예제 #4
0
        public void AddMemento(PlayerMemento memento)
        {
            if (allMementos.Count - 1 > index)
            {
                allMementos.RemoveRange(index, allMementos.Count - index);
            }

            allMementos.Add(memento);
            index = allMementos.Count;
        }
예제 #5
0
 public PlayerMemento getNext(bool changeIndex)
 {
     if (index < allMementos.Count - 1)
     {
         PlayerMemento playerMemento = allMementos[index + 1];
         if (changeIndex)
         {
             index += 1;
         }
         return(playerMemento);
     }
     return(null);
 }
예제 #6
0
 public PlayerMemento GetLast(bool changeIndex)
 {
     if (index > 0)
     {
         PlayerMemento playerMemento = allMementos[index - 1];
         if (changeIndex)
         {
             index -= 1;
         }
         return(playerMemento);
     }
     return(null);
 }
예제 #7
0
        static void Main()
        {
            Context       context       = new Context();
            PlayerMemento playerMemento = new PlayerMemento(1, 1, 1);

            // Context ctx = new Context();
            //  ctx.Save()
            PrintBoard(playerMemento);
            // context.Save(playerMemento.value, playerMemento.XIndex, playerMemento.YIndex);
            context.move(playerMemento, Context.DIRECTIONS.UP);
            context.move(playerMemento, Context.DIRECTIONS.UP);
            PrintBoard(playerMemento);
            playerMemento = context.LoadPrev(playerMemento);
            playerMemento = context.LoadPrev(playerMemento);
            playerMemento = context.LoadPrev(playerMemento);
            PrintBoard(playerMemento);
        }
예제 #8
0
 public void Load(PlayerMemento memento)
 {
     Coord   = memento.Coord;
     HP      = memento.HP;
     Stamnia = memento.Stamnia;
 }
예제 #9
0
 public void decreaseNumber(PlayerMemento playerMemento)
 {
     playerMemento.value -= 1;
 }
예제 #10
0
 public void increaseNumber(PlayerMemento playerMemento)
 {
     playerMemento.value += 1;
 }
예제 #11
0
 public void Load(PlayerMemento memento)
 {
     HP       = memento.HP;
     Stamina  = memento.Stamina;
     Location = memento.Location;
 }