jeudi 1 octobre 2015

I'm not satisfied with the way my toon is moving, advice?

I'm having a bit of an issue with my movement of a little toon for my program. I grabbed this code from a different site and modified it to my needs but the movements suck and it kind of putters at the outer bounds of the field and I'm not sure how to go about fixing that? Advice?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MorgSimulator
{
    class Program
    {
        static void Main(string[] args)
        {
            Morg A = new MorgA();
            A.MovingTime();

            Console.ReadKey();
        }
    }

    class Morg
    {
        public Morg()
        {
        }

        protected MoveBehavior moveBehavior;

        public void MovingTime()
        {
            moveBehavior.move();
        }
    }

    class MorgA : Morg
    {
        public MorgA()
        {
            moveBehavior = new Ooze();
        }
    }

    interface MoveBehavior
    {
        void move();
    }

    class Ooze : MoveBehavior
    {
        public void move()
        {
            int row = 40, col = 25;
            Console.CursorVisible = false;
            Console.SetCursorPosition(col, row);

            int direction = 0;
            Random r = new Random();

            for (int i = 0; i < 25; i++)   // count of movement
            {
                Console.Write("<(._.)>");
                System.Threading.Thread.Sleep(100);
                Console.Clear();

                direction = r.Next(5);

                while (direction == 0)
                    direction = r.Next(5);

                switch (direction)
                {
                    case 1:
                        if (row + 1 >= 80)
                            row = 0;
                        Console.SetCursorPosition(col, row++);
                        break;
                    case 2:
                        if (row - 1 <= 0)
                            row = 79;
                        Console.SetCursorPosition(col, row--);
                        break;
                    case 3:
                        if (col + 1 >= 50)
                            col = 0;
                        Console.SetCursorPosition(col++, row);
                        break;
                    case 4:
                        if (col - 1 <= 0)
                            col = 49;
                        Console.SetCursorPosition(col--, row);
                        break;
                }
            }
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire