コード例 #1
0
ファイル: Program.cs プロジェクト: saadati944/pingpong
        static void Draw(bool first = false)
        {
            if (first)
            {
                drawBox();
                drawScoreboard(true);
                lasth = Console.WindowHeight; lastw = Console.WindowWidth;
                drawCharacter(_player_1);
                drawCharacter(_player_2);
                drawCharacter(_ball);
            }
            doMoves();
            if (lasth != Console.WindowHeight || lastw != Console.WindowWidth)
            {
                drawBox();
                drawScoreboard(true);

                scaleup(_ball);
                scaleup(_player_1);
                scaleup(_player_2);

                lasth = Console.WindowHeight; lastw = Console.WindowWidth;
                clearCharacter(_player_1_last);
                drawCharacter(_player_1);
                _player_1_last = _player_1.copy();
                clearCharacter(_player_2_last);
                drawCharacter(_player_2);
                _player_2_last = _player_2.copy();
                clearCharacter(_ball_last);
                drawCharacter(_ball);
                _ball_last = _ball.copy();
            }
            else
            {
                drawScoreboard();
                if (!_player_1.equals(_player_1_last))
                {
                    clearCharacter(_player_1_last);
                    drawCharacter(_player_1);
                    _player_1_last = _player_1.copy();
                }
                if (!_player_2.equals(_player_2_last))
                {
                    clearCharacter(_player_2_last);
                    drawCharacter(_player_2);
                    _player_2_last = _player_2.copy();
                }
                clearCharacter(_ball_last);
                drawCharacter(_ball);
                _ball_last = _ball.copy();
            }
            //drawCharacter(_player_1);
            //drawCharacter(_player_2);
            //drawCharacter(_ball);
            check();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: saadati944/pingpong
        static void assignCharacters()
        {
            int h = Console.WindowHeight, w = Console.WindowWidth;

            _ball          = new consoleCharacter(0, 0, ball_char);
            _player_1      = new consoleCharacter(1, 1, player_1_char);
            _player_2      = new consoleCharacter(2, w - 3, player_2_char);
            _ball_last     = new consoleCharacter(0, 0, "");
            _player_1_last = new consoleCharacter(0, 0, "");
            _player_2_last = new consoleCharacter(0, 0, "");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: saadati944/pingpong
        static void drawCharacter(consoleCharacter ch)
        {
            Console.SetCursorPosition(ch.Left, ch.Top);
            int i = 0;

            foreach (char x in ch.Character)
            {
                if (x == '\n')
                {
                    ++i;
                    Console.SetCursorPosition(ch.Left, ch.Top + i);
                }
                else
                {
                    Console.Write(x);
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: saadati944/pingpong
        static void scaleup(consoleCharacter ch)
        {
            int h = Console.WindowHeight, w = Console.WindowWidth;

            if (ch.Character == ball_char)
            {
                ch.Top  = (int)((float)ch.Top / (float)lasth * (float)Console.WindowHeight);
                ch.Left = (int)((float)ch.Left / (float)lastw * (float)Console.WindowWidth);
                if (ch.Top < 1)
                {
                    ch.Top = 1;
                }
                else if (ch.Top > h - 3)
                {
                    ch.Top = 3;
                }
                if (ch.Left < 3)
                {
                    ch.Left = 3;
                }
                else if (ch.Left > w - 7)
                {
                    ch.Left = w - 7;
                }
            }
            else
            {
                if (ch.Left != 1)
                {
                    ch.Left = w - 3;
                }
                ch.Top = (int)((float)ch.Top / (float)lasth * (float)h);
                if (ch.Top < 1)
                {
                    ch.Top = 0;
                }
                else if (ch.Top > h - 3)
                {
                    ch.Top = h - 3;
                }
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: saadati944/pingpong
        static void clearCharacter(consoleCharacter ch)
        {
            if (ch.Left >= Console.WindowWidth || ch.Top >= Console.WindowHeight)
            {
                return;
            }
            Console.SetCursorPosition(ch.Left, ch.Top);
            int i = 0;

            foreach (char x in ch.Character)
            {
                if (x == '\n')
                {
                    ++i;
                    Console.SetCursorPosition(ch.Left, ch.Top + i);
                }
                else
                {
                    Console.Write(' ');
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: saadati944/pingpong
 public bool equals(consoleCharacter v)
 {
     return(v.Top == Top && v.Left == Left && v.Character == Character);
 }