Example #1
0
        /// <summary>
        /// Draws game objects
        /// </summary>
        /// <param name="graphics">The canvas to draw to</param>
        public void Draw(Graphics graphics)
        {
            graphics.DrawLine(dashedLinePen, topCentre, bottomCentre);
            scoreRight.DrawScore(graphics);
            scoreLeft.DrawScore(graphics);
            rightPaddle.Draw(graphics);
            leftPaddle.Draw(graphics);
            ball.DrawSelf(graphics);

            if (winConditions == true)
            {
                DisplayVictory(graphics);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(120, 30);

            // Game logic'ish
            int gameDiffDefault    = 80;
            int gameDiff           = gameDiffDefault;
            int timePassed         = 0;
            int timePassedModifier = 0;

            do // Main app loop
            {
                sessionEnd = false;
                newGame    = " ";

                // Get and store player names for the session
                Console.WriteLine("Player 1: ");
                player1Name = Console.ReadLine();
                player1Name = PlayerNames.GetP1Name(player1Name, maxNameLength);
                Console.WriteLine("Player 2: ");
                player2Name           = Console.ReadLine();
                player2Name           = PlayerNames.GetP2Name(player2Name, maxNameLength);
                Console.CursorVisible = false;

                Console.Clear();

                // Session loop
                do
                {
                    roundEnd = false;
                    Console.CursorVisible = false;

                    // Assign default map to array and board into map-array
                    AssignMap();
                    AssignBoard();

                    // Reset gamestate
                    player1Score            = 0;
                    player2Score            = 0;
                    arrayBall_X             = arrayBall_X_Ini;
                    arrayBall_Y             = arrayBall_Y_Ini;
                    ballDirection_Leftright = ballDirection_Leftright_Ini;
                    ballDirection_Updown    = ballDirection_Updown_Ini;

                    // Draw Map + Board + Player Names
                    DrawMap();
                    DrawNames.DrawPlayerNames(player1Name, player2Name);
                    Score.DrawScore(player1Score, player2Score);

                    do // Game loop ----------------------------------------------------------------------------
                    {
                        DrawPaddles();
                        while (!newBall) // Round loop
                        {
                            PaddleMovement();
                            MoveBall();
                            Thread.Sleep(gameDiff);
                            if (timePassed == 10 + timePassedModifier && gameDiff != 35)
                            {
                                gameDiff  -= 5;
                                timePassed = 0;
                                timePassedModifier++;
                            }
                            timePassed++;
                        }

                        // Reset ball status
                        if (playerLastScore == 0)
                        {
                            arrayBall_X             = arrayBall_X_Ini;
                            arrayBall_Y             = arrayBall_Y_Ini;
                            ballDirection_Leftright = ballDirection_Leftright_Ini;
                        }
                        else
                        {
                            arrayBall_X             = 17;
                            arrayBall_Y             = 52;
                            ballDirection_Leftright = ballDirection_Leftright_Ini;
                            ballDirection_Leftright = ballDirection_Leftright_Ini * -1;
                        }

                        // Reset game diff
                        gameDiff   = gameDiffDefault;
                        timePassed = 0;

                        Score.DrawScore(player1Score, player2Score);

                        // Winner + check for rematch/new game/quit
                        Win(player1Score, player2Score);
                        newBall = false;
                    } while (!roundEnd);// --------------------------------------------------------------------

                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.SetCursorPosition(5, 28);
                    Console.Write("Player {0} has won! Press Enter to continue!", winningPlayer);
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.ReadLine();
                    Console.SetCursorPosition(5, 28);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write("Press N+Enter for a new game, press Q+Enter to quit, or" +
                                  " press Enter for a rematch!", winningPlayer);
                    NewGame();

                    Console.Clear();
                } while (!sessionEnd); // End of round
            } while (!gameEnd);        // End of app
        }