Sorry for the double post; the last post is already extremely long, and I don't want to lengthen it any more.

Current code (will update tonight, after I change it):

Code:

#include <tice.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphx.h>
#include <keypadc.h>
#include <debug.h>
#include <fileioc.h>

int playerOne   = 8000;
int playerTwo   = 8000;
int playerThree = 8000;
int playerFour  = 8000;
int playerFive  = 8000;
int playerSix   = 8000;
int playerSeven = 8000;
int playerEight = 8000;
int playerVar;
int i;

int quitVar;
int a;
int key;

typedef uint8_t sk_key_t;
char buf[20];
uint24_t x = 8000;

void main()
{
    gfx_Begin();

    gfx_FillScreen(gfx_blue);
    gfx_SetTextXY(150, 150);
    gfx_PrintStringXY("Input how many people are playing:", 5, 15);
    gfx_FillScreen(gfx_blue);
    while (!(key = os_GetCSC()))
    {
        ; // selects how many people are playing
    while (playerVar == 0)
    {
        switch (key)
        {
            case sk_2:
                playerVar = 2;
                break;
            case sk_3:
                playerVar = 3;
                break;
            case sk_4:
                playerVar = 4;
                break;
            case sk_5:
                playerVar = 5;
                break;
            case sk_6:
                playerVar = 6;
                break;
            case sk_7:
                playerVar = 7;
                break;
            case sk_8:
                playerVar = 8;
                break;
        }
    }
        sprintf(buf, "Player %u", x);
        for(i = playerVar; i >=1; i--){
    gfx_PrintStringXY(buf, 10, i * 10);
}
    while (key != sk_Clear) {
    while (!(key = os_GetCSC())){

    if (key == sk_Clear)
    {
        gfx_End();
        exit(0);
    }

    if (key == sk_1)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerOne -= 100;
            }
            else if (!(key == sk_Add))
            {
                playerOne += 100;
            }
        }
        gfx_SetTextXY(10,10);
        gfx_PrintInt(playerOne,4);
    }

    if (key == sk_2)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerTwo -= 100;
            }
            else if (!(key == sk_Add))
            {
                playerTwo += 100;
            }
        }
        gfx_SetTextXY(10,20);
        gfx_PrintInt(playerTwo,4);
    }
    if (key == sk_3)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerThree-=100;
            }
            else if (!(key == sk_Add))
            {
                playerThree+= 100;
            }
        }
        gfx_SetTextXY(10,30);
        gfx_PrintInt(playerThree,4);
    }
    if (key == sk_4)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerFour-=100;
            }
            else if (!(key == sk_Add))
            {
                playerFour+=100;
            }
        }
        gfx_SetTextXY(10,40);
        gfx_PrintInt(playerFour,4);
    }
    if (key == sk_5)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerFive-=100;
            }
            else if (!(key == sk_Add))
            {
                playerFive+=100;
            }
        }
        gfx_SetTextXY(10,50);
        gfx_PrintInt(playerFive,4);
    }
    if (key == sk_6)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerSix-=100;
            }
            else if (!(key == sk_Add))
            {
                playerSix+=100;
            }
        }
        gfx_SetTextXY(10,60);
        gfx_PrintInt(playerSix,4);
    }
    if (key == sk_7)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerSeven-=100;
            }
            else if (!(key == sk_Add))
            {
                playerSeven+=100;
            }
        }
        gfx_SetTextXY(10,70);
        gfx_PrintInt(playerSeven,4);
    }
    if (key == sk_8)
    {
        while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerEight-=100;
            }
            else if (!(key == sk_Add))
            {
                playerEight+=100;
            }
        }
        gfx_SetTextXY(10,80);
        gfx_PrintInt(playerEight,4);
    }
        key=os_GetCSC();
    }
    }
    }
}


Any problems, optimizations, etc. are welcome.
The biggest optimization you can get is probably storing the playerX values in an array, instead of separate variables. Then you don't need all the
Code:
while (!(key = os_GetCSC()))
        {
            while (!(key == os_GetCSC()))
            {
                key=os_GetCSC();
            }
            if (key == sk_Sub)
            {
                playerThree-=100;
            }
            else if (!(key == sk_Add))
            {
                playerThree+= 100;
            }
        }
        gfx_SetTextXY(10,30);
        gfx_PrintInt(playerThree,4);
but only once.
Thanks, PT_, I have known about this for a while. I know that I could use an array, and simplify it, but I want to understand arrays more thoroughly first. Plus, this is easier to think out.

If you could help me understand arrays better, then yes, I will happily change the code. But not until then.


EDIT:
Link to code.

EDIT #2
Code has been optimized, thanks to PT_.
  
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 3 of 3
» 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