示例#1
0
        // @TODO: This function belongs in the framework, not something so close to the consumer.  Move it.
        public void UpdatePosition(World w)
        {
            String direction = consumer.ExecuteTurn(w);

            switch (direction.ToUpper())
            {
                case Direction.North:
                    if (this.position.Y - 1 >= 0)
                    {
                        this.position.Y--;
                    }
                    else
                    {
                        throw new InvalidPositionUpdateException();
                    }
                    break;
                case Direction.South:
                // @TODO: Determine max edge of world grid.
                //if (this.position.Y - 1 >= 0)
                    {
                        this.position.Y++;
                    }
                    //else
                    //{
                    //    throw new InvalidPositionUpdateException();
                    //}
                    break;
                case Direction.East:
                    // @TODO: Determine max edge of world grid.
                    this.position.X++;
                    break;
                case Direction.West:
                    if (this.position.X - 1 >= 0)
                    {
                        this.position.X--;
                    }
                    else
                    {
                        throw new InvalidPositionUpdateException();
                    }
                    break;
                default:
                    throw new InvalidPositionUpdateException();
            }
        }
示例#2
0
 public Form1()
 {
     InitializeComponent();
     graphicsObj = this.CreateGraphics();
     world = new World();
 }