コード例 #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
ファイル: Program.cs プロジェクト: GSmanXVI/DesignPatterns
 public void Load(PlayerMemento memento)
 {
     HP       = memento.HP;
     Stamina  = memento.Stamina;
     Location = memento.Location;
 }