Esempio n. 1
0
        public void HandleLogic(out bool bGameHasFinished)
        {
            Collide collide = Collide.none;

            bGameHasFinished = false;


            foreach (Shape shape in m_Shapes)
            {
                if (shape is ICollide)
                {
                    collide = ((ICollide)shape).DoesCollide(m_ball.X, m_ball.Y);
                    if (collide != Collide.none)
                    {
                        break;
                    }
                }
            }

            switch (collide)
            {
            // --- first is more probable to happen
            case Collide.none:
                // do nothing here
                break;

            case Collide.player_top:
                Ball.BounceHorizontal();
                Ball.Vertical = DirectionVertical.Up;
                break;

            case Collide.player_bottom:
                Ball.BounceHorizontal();
                Ball.Vertical = DirectionVertical.Down;
                break;

            case Collide.player_middle:
                Ball.BounceHorizontal();
                Ball.Vertical = DirectionVertical.None;
                break;


            case Collide.border_left:
                // --- assume auto is on right
                m_results.PlayerAutoScore++;
                Console.Beep();
                Ball.BounceHorizontal();
                if (m_results.PlayerAutoScore == m_nGameEnds)
                {
                    bGameHasFinished = true;
                }
                break;

            case Collide.border_right:
                // --- assume human is on left
                m_results.PlayerHumanScore++;
                Console.Beep();
                Ball.BounceHorizontal();
                if (m_results.PlayerHumanScore == m_nGameEnds)
                {
                    bGameHasFinished = true;
                }
                break;

            case Collide.border_top_or_bottom:
                Ball.BounceVertical();
                break;

            default:
                // do nothing here
                break;
            }

            moveBall(1, m_nHorizontalCycles);
            movePlayerAuto();
        }