Advertisement
afterlife88

Untitled

Mar 27th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. private IEnumerator<KeyboardState> GetBehaviour()
  2.         {
  3.             KeyboardState state = null;
  4.             // random moves
  5.             while (true)
  6.             {
  7.                 var avalibleList = GetPath();
  8.                 var randomMove = _random.Next(avalibleList.Count);
  9.                 BombSet = false;
  10.                 if (avalibleList[randomMove] == Keys.SPACE)
  11.                     BombSet = true;
  12.                 state = GetDownKeyboardState(avalibleList[randomMove]);
  13.                 //if (num <= 24)
  14.                 //{
  15.                 //  state = GetDownKeyboardState(Keys.LEFT);
  16.                 //}
  17.                 //if (num > 24 && num <= 48)
  18.                 //{
  19.                 //  state = GetDownKeyboardState(Keys.UP);
  20.                 //}
  21.                 //if (num > 48 && num <= 72)
  22.                 //{
  23.                 //  state = GetDownKeyboardState(Keys.RIGHT);
  24.                 //}
  25.                 //if (num > 72 && num <= 98)
  26.                 //{
  27.                 //  state = GetDownKeyboardState(Keys.DOWN);
  28.                
  29.                 //}
  30.                 //if (num > 98 && num <= 100)
  31.                 //{
  32.                 //  state = GetDownKeyboardState(Keys.SPACE);
  33.                 //  BombSet = true;
  34.                 //}
  35.                 for (int i = 0; i < ConstantValues.CountToMoveOnActualPosition; i++)
  36.                 {
  37.                     yield return state;
  38.                 }
  39.             }
  40.         }
  41.         /// <summary>
  42.         /// Check if can make next step to avoid walls and bricks
  43.         /// </summary>
  44.         /// <returns></returns>
  45.         private List<Keys> GetPath()
  46.         {
  47.             var avalibleMoves = new List<Keys>();
  48.             var num = _random.Next(100);
  49.             if (this.Movable(this.X - 1, this.Y))
  50.             {
  51.                 avalibleMoves.Add(Keys.LEFT);
  52.             }
  53.             if (this.Movable(this.X, this.Y - 1))
  54.             {
  55.                 avalibleMoves.Add(Keys.UP);
  56.             }
  57.             if (this.Movable(this.X + 1, this.Y))
  58.             {
  59.                 avalibleMoves.Add(Keys.RIGHT);
  60.             }
  61.             if (this.Movable(this.X, this.Y + 1))
  62.             {
  63.                 avalibleMoves.Add(Keys.DOWN);
  64.             }
  65.             if (num > 70 && num <= 100)
  66.                 avalibleMoves.Add(Keys.SPACE);
  67.             return avalibleMoves;
  68.            
  69.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement