Beispiel #1
0
void updatePlayMenu(GUI *g, Controls *c, game_t *gm)
{
    MenuWidget *m;

    NOT(g);
    NOT(c);
    NOT(gm);

    m = &g->playMenu;
    updateMenuWidget(m, c);

    if (goBack(c)) {
        g->next = guiFocusMenu;
        return;
    }

    if (submitted(c)) {
        switch (m->focus) {
        case playMenuFocusHumanVsHuman: {
            initGame1vs1Human(gm);
            initTextLog(&g->gameGui.textLog);
            resetNewGameGui(g, gm);
            initScoreBoard(&g->scoreBoard, gm);
            toTransScreenFadePausePixelate(g, guiFocusGameGUI, 1.0f);
            break;
        }
        case playMenuFocusHumanVsAI: {
            initGame1vs1HumanAI(gm);
            initTextLog(&g->gameGui.textLog);
            resetNewGameGui(g, gm);
            initScoreBoard(&g->scoreBoard, gm);
            toTransScreenFadePausePixelate(g, guiFocusGameGUI, 1.0f);
            break;
        }
        case playMenuFocusOptions: {
            g->next = guiFocusOptions;
            break;
        }
        default:
            break;
        }
    }
}
Beispiel #2
0
void initInterface(Player * players, int nOfPlayers)
{
    char name[100];
    char buff[100];
    int points;
    int level, curY = 0;
    int status = 0;
    system("mode con:cols=50 lines=50");
    system("cls");
    setFontSize(15, 20);
    if(nOfPlayers > 0)
        initScoreBoard(players, nOfPlayers);
    strcpy(name, "DEFAULT");
    system("cls");
    setCursorPosition(CONSOLESIZE/2 - 10,curY++);
    puts("Write your name:");
    setCursorPosition(CONSOLESIZE/2 - 15,curY++);
    fgets(buff, 100, stdin);
    buff[strlen(buff) - 1] = '\0';
    if(strlen(buff)>1)
        strcpy(name, buff);
    while(!status)
    {
        printf("Hi, %s, what level do you want to take? (0..9)\n", name);
        fgets(buff, 100, stdin);
        status = sscanf(buff, "%i", &level);
        if(!status || level>9 || level < 0)
        {
            status = 0;
            puts("Try again:");
            curY++;
        }
    }
    puts("Press anything to start...");
    getch();
    points = initSnake(level);
    curY = 0;
    setConsoleColor(COLORDEF);
    setCursorPosition(0,curY++);
    Player p;
    strcpy(p.name, name);
    p.points = points;
    addToScoreBoard(&p, &nOfPlayers);
    free(players);
    players = getScoreBoard(&nOfPlayers);
    while(1)
    {
        setConsoleColor(COLORDEF);
        system("cls");
        setCursorPosition(0,0);
        printf("HOORAY! You've got %i points. Type NO if you want to stop\n Type SCORE if you want to look through the scoreboard\nType anything else if you want to try again\n", points);
        fgets(buff, 100, stdin);
        if(!strcmp(buff, "NO\n"))
            break;
        else if(!strcmp(buff, "SCORE\n"))
            initScoreBoard(players, nOfPlayers);
        else
        {
            points = initSnake(level);
            p.points = points;
            addToScoreBoard(&p, &nOfPlayers);
            free(players);
            players = getScoreBoard(&nOfPlayers);
        }
    }
}