Пример #1
0
        void correctRotation(int pos_X, int pos_Y, CarPos carDestination)
        {
            switch (carDestination)
            {
            case CarPos.TOP:
                if (pos_X == 12 && pos_Y == 12)
                {
                    //niemozliwe
                }
                if (pos_X == 13 && pos_Y == 12)
                {
                    carRot = CarRotation.UP;
                }
                if (pos_X == 12 && pos_Y == 13)
                {
                    carRot = CarRotation.RIGHT;
                }
                if (pos_X == 13 && pos_Y == 13)
                {
                    carRot = CarRotation.UP;
                }
                break;

            case CarPos.RIGHT:
                if (pos_X == 12 && pos_Y == 12)
                {
                    carRot = CarRotation.DOWN;
                }
                if (pos_X == 13 && pos_Y == 12)
                {
                    //niemozliwe
                }
                if (pos_X == 12 && pos_Y == 13)
                {
                    carRot = CarRotation.RIGHT;
                }
                if (pos_X == 13 && pos_Y == 13)
                {
                    carRot = CarRotation.RIGHT;
                }
                break;

            case CarPos.LEFT:
                if (pos_X == 12 && pos_Y == 12)
                {
                    carRot = CarRotation.LEFT;
                }
                if (pos_X == 13 && pos_Y == 12)
                {
                    carRot = CarRotation.LEFT;
                }
                if (pos_X == 12 && pos_Y == 13)
                {
                    //niemozliwe
                }
                if (pos_X == 13 && pos_Y == 13)
                {
                    carRot = CarRotation.UP;
                }
                break;

            case CarPos.BOTTOM:
                if (pos_X == 12 && pos_Y == 12)
                {
                    carRot = CarRotation.DOWN;
                }
                if (pos_X == 13 && pos_Y == 12)
                {
                    carRot = CarRotation.LEFT;
                }
                if (pos_X == 12 && pos_Y == 13)
                {
                    carRot = CarRotation.DOWN;
                }
                if (pos_X == 13 && pos_Y == 13)
                {
                    //niemożliwe
                }
                break;
            }
        }
Пример #2
0
        public Car(CarPos carPos, CarDirection carDirection, String carGraphic, Program program1, Road carRoad, SemaphoreSlim godOfRoad)
        {
            program = program1;
            road    = carRoad;
            roadGod = godOfRoad;
            speed   = randSpeed.Next(100, 500);
            carDir  = carDirection;
            switch (carDirection)
            {
            case CarDirection.FORWARD:
                switch (carPos)
                {
                case CarPos.TOP:
                    carDestination = CarPos.BOTTOM;
                    break;

                case CarPos.RIGHT:
                    carDestination = CarPos.LEFT;
                    break;

                case CarPos.BOTTOM:
                    carDestination = CarPos.TOP;
                    break;

                case CarPos.LEFT:
                    carDestination = CarPos.RIGHT;
                    break;
                }
                break;

            case CarDirection.TURN_RIGHT:
                switch (carPos)
                {
                case CarPos.TOP:
                    carDestination = CarPos.LEFT;
                    break;

                case CarPos.RIGHT:
                    carDestination = CarPos.TOP;
                    break;

                case CarPos.BOTTOM:
                    carDestination = CarPos.RIGHT;
                    break;

                case CarPos.LEFT:
                    carDestination = CarPos.BOTTOM;
                    break;
                }
                break;

            case CarDirection.TURN_LEFT:
                switch (carPos)
                {
                case CarPos.TOP:
                    carDestination = CarPos.RIGHT;
                    break;

                case CarPos.RIGHT:
                    carDestination = CarPos.BOTTOM;
                    break;

                case CarPos.BOTTOM:
                    carDestination = CarPos.LEFT;
                    break;

                case CarPos.LEFT:
                    carDestination = CarPos.TOP;
                    break;
                }
                break;
            }

            switch (carDestination)
            {
            case CarPos.TOP:
                carColor = new Terminal.Gui.Attribute(Color.BrightGreen, Color.Black);
                break;

            case CarPos.RIGHT:
                carColor = new Terminal.Gui.Attribute(Color.BrightYellow, Color.Black);
                break;

            case CarPos.BOTTOM:
                carColor = new Terminal.Gui.Attribute(Color.BrightRed, Color.Black);
                break;

            case CarPos.LEFT:
                carColor = new Terminal.Gui.Attribute(Color.BrightBlue, Color.Black);
                break;
            }
            //pozniej zalezne od kierunku
            graphic       = carGraphic;
            positionMutex = new Mutex();
            lockPosition();
            pos_X       = road.getStartPointX(carPos);
            pos_Y       = road.getStartPointY(carPos);
            posOrigin_X = pos_X;
            posOrigin_Y = pos_Y;
            unlockPosition();
            switch (carPos)
            {
            case CarPos.TOP:
                carRot = CarRotation.DOWN;
                break;

            case CarPos.RIGHT:
                carRot = CarRotation.LEFT;
                break;

            case CarPos.BOTTOM:
                carRot = CarRotation.UP;
                break;

            case CarPos.LEFT:
                carRot = CarRotation.RIGHT;
                break;
            }
        }