dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Java to Pseudocode?

  1. #1
    Join Date
    Jul 2019
    Posts
    1

    Java to Pseudocode?

    Hi, I’m working on a school project and I’m confused on how to convert a snippet of my code to pseudocode.

    I’ve remade the game of “Flappybird”.

    If anyone knows how to convert either:

    Code:
    int speed = 5;
    ticks++;
    	
    if (started)
    {
        // move columns backwards
        for (int i = 0; i < columns.size(); i++)
        {
            if (gameOver)
                return;
    
            Rectangle column= columns.get(i);
            column.x -= speed;
        }
    }
    OR:

    Code:
    // check if bird collides with columns
    for (Rectangle column : columns)
    {
        if (column.y == 0 && bird.x +bird.width / 2 > column.x + column.width / 2 - 5 && bird.x +bird.width / 2 < column.x + column.width / 2 + 5)
        {
            score++;
            if (score > highScore)
                highScore = score;
        }
    
        if (column.intersects(bird))
        {
            gameOver = true;
        }
    		
        if (bird.y +yMotion > HEIGHT - 120)
            bird.x = column.x - bird.width;
    }
    Thanks.
    Mitch
    Last edited by 2kaud; July 16th, 2019 at 01:15 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,764

    Re: Java to Pseudocode?

    [When posting code, please use code tags. Go Advanced, select the formatted code and click '#']

    Normally, you would write first the pseudo-code and then convert to Java. If you have already written the Java code, why back-convert to pseudo-code?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.2.2)

  3. #3
    Join Date
    Feb 2017
    Posts
    458

    Re: Java to Pseudocode?

    Quote Originally Posted by mitchburrows View Post
    Hi, I’m working on a school project and I’m confused on how to convert a snippet of my code to pseudocode.
    As has been mentioned, pseudo-code is usually written before the real code but if you still want to do it here's an instruction,

    https://www.geeksforgeeks.org/how-to...a-pseudo-code/

    Another option is to add comments to your code. The purpose of comments is to make code easier to understand by adding information that's not obvious from the code itself. Well commented real code is sometimes used as pseudo-code even though it technically maybe isn't. Especially the C language has traditionally often served this purpose.
    Last edited by wolle; July 16th, 2019 at 07:40 AM.

  4. #4
    Join Date
    Jul 2019
    Location
    USA
    Posts
    3

    Re: Java to Pseudocode?

    Thanks, This is helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)