I was trying to program a very basic form of pong in C on my computer, and when I sent it to my calculator, it was a fail. I thought I did everything correct, but it seemed not so.

If any of you sees a bug or something that is missing then please let me know. Thanks!

Here is the code:


Code:
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

/* Standard headers */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <keypadc.h>

/* Put function prototypes here */
void printText(const char *text, uint8_t x, uint8_t y);
void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos);

/* Put all your code here */
void main(void) {
    /* uint8_t is an unsigned integer that can range from 0-255. */
    /* It performs faster than just an int, so try to use it (or int8_t) when possible */
    uint8_t count;

    /* Initialize some strings */
    const char *ball = "O";
    const char *paddle = "---";
    int ballX = 1;
    int ballY = 1;
    int paddleX = 3;
    int lose = 0;
    int ballXDir = 1;
    int ballYDir = 1;
    kb_key_t key;
    const char *game = "Game Over!";


    /* Clear the homescreen */
    os_ClrHome();
    while(lose==0){
        printText(ball, ballX, ballY);
        printText(paddle, paddleX, 9);

        if (ballY==9 && !(paddleX==ballX || paddleX+1==ballX || paddleX+2==ballX))
            lose = 1;
        kb_Scan();
        if (kb_ScanGroup(kb_group_6) == kb_Clear)
            lose=1;
        if (kb_ScanGroup(kb_group_6) == kb_Right)
            paddleX+=2;
        if (kb_ScanGroup(kb_group_6) == kb_Left)
            paddleX-=2;
        if (ballX=0)
            ballXDir=1;
        if (ballX=25)
            ballXDir=-1;
        if (ballY=0)
            ballYDir=1;
        if (ballY=9)
            ballYDir=-1;
        ballX+=ballXDir;
        ballY+=ballYDir;
        while (!os_GetCSC());

    }
    printText(game,0,0);
}

/* Draw text on the homescreen at the given X/Y location */
void printText(const char *text, uint8_t xpos, uint8_t ypos) {
    os_SetCursorPos(ypos, xpos);
    os_PutStrFull(text);
}

/* Draw small text at the given X/Y location */
void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos) {
    os_FontSelect(0); // sets small font (1 == big, see docs)
    os_FontDrawText(text, xpos, ypos);
}
Use [ code ] blocks please.
Do you have any more information, like where you got this code from and what exactly it is doing wrong?
The only thing that I can see are the lines:

Code:
if (ballX=0)

The = operator assigns variables. The == does comparison.
So use

Code:
if (ballX==0)

instead
Thanks for that catch. I will post a link within the next few hours with the compiled program, so you can see what it does.
Well, I mean, I can compile it myself; it's just more convenient if you tell me what the issue is before sending code to debug. Like, does it exit/win/lose immidiately, or fail to respond to input, or fail to output anything, or what? In a larger program it would be impossible for me to check every feature to see what is broken and where.
commandblockguy wrote:
Well, I mean, I can compile it myself; it's just more convenient if you tell me what the issue is before sending code to debug. Like, does it exit/win/lose immidiately, or fail to respond to input, or fail to output anything, or what? In a larger program it would be impossible for me to check every feature to see what is broken and where.


ok. I will tell you one of the bugs on the program. I start the program, and everything outputs in its normal place. The ball then outputs on the bottom corner of the screen, and the program stops. I then press clear, and the game says "game over" (the game over is supposed to happen but the ball acts so weird).
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement