Changeset 9996ed5 in mainline for tetris/scores.c


Ignore:
Timestamp:
2006-06-05T20:40:44Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e9073f2
Parents:
0aa024b1
Message:

Tetris has now a new menu.
Hiscore table added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tetris/scores.c

    r0aa024b1 r9996ed5  
    4747/* #include <fcntl.h> */
    4848/* #include <pwd.h> */
    49 /* #include <stdio.h> */
     49 #include <stdio.h>
    5050/* #include <stdlib.h> */
    51 /* #include <string.h> */
     51#include <string.h>
    5252/* #include <time.h> */
    5353/* #include <term.h> */
     
    7777/* static int gotscores; */
    7878/* static struct highscore scores[NUMSPOTS]; */
     79static struct highscore scores[NUMSPOTS];
    7980
    8081/* static int checkscores(struct highscore *, int); */
     
    8384/* static void printem(int, int, struct highscore *, int, const char *); */
    8485/* static char *thisuser(void); */
     86
     87void showscores(int firstgame)
     88{
     89        int i;
     90       
     91        clear_screen();
     92        moveto(10, 0);
     93        printf("\tRank \tLevel \tName\t                     points\n");
     94        printf("\t========================================================\n");
     95        for (i = 0; i < NUMSPOTS - 1; i++) {
     96                printf("\t%6d %6d %-16s %20d\n", i+1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score);
     97        }
     98        if (!firstgame) {
     99                printf("\t========================================================\n");
     100                printf("\t  Last %6d %-16s %20d\n", scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score);
     101        }
     102        printf("\n\n\n\n\tPress any key to return to main menu.");
     103        getchar();
     104}
     105
     106/** Copy from hiscore table score with index src to dest
     107 *
     108 */
     109static void copyhiscore(int dest, int src)
     110{
     111        strcpy(scores[dest].hs_name, scores[src].hs_name);
     112        scores[dest].hs_score = scores[src].hs_score;   
     113        scores[dest].hs_level = scores[src].hs_level;
     114}
     115
     116void insertscore(int score, int level)
     117{
     118        int i,j;
     119        int key;
     120
     121       
     122        clear_screen();
     123        moveto(10 , 10);
     124        puts("Insert your name: ");
     125        strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME);
     126        i = 6;
     127
     128        moveto(10 , 28);
     129        printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
     130        key = getchar();       
     131        while(key != '\n') {
     132                if (key == '\b') {
     133                        if (i > 0)
     134                                scores[NUMSPOTS - 1].hs_name[--i] = '\0';       
     135                } else {
     136                        if (i < (MAXLOGNAME - 1))
     137                                scores[NUMSPOTS - 1].hs_name[i++] = key;       
     138                                scores[NUMSPOTS - 1].hs_name[i] = '\0';
     139                }
     140               
     141                moveto(10 , 28);
     142                printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................");
     143       
     144                key = getchar();       
     145        }
     146       
     147        scores[NUMSPOTS - 1].hs_score = score; 
     148        scores[NUMSPOTS - 1].hs_level = level;
     149       
     150        i = NUMSPOTS-1;
     151        while ((i > 0) && (scores[i - 1].hs_score < score))
     152                i--;
     153
     154        for (j = NUMSPOTS - 2; j > i; j--) {
     155                copyhiscore(j,j-1);
     156        }
     157        copyhiscore(i, NUMSPOTS - 1);   
     158}
     159
     160void initscores(void)
     161{
     162        int i;
     163        for(i = 0; i < NUMSPOTS; i++) {
     164                strncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME);
     165                scores[i].hs_score = (NUMSPOTS - i) * 200;     
     166                scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1);
     167        }
     168}
    85169
    86170/*
     
    345429 *   before it can be shown anyway.
    346430 */
     431/*
    347432void
    348433showscores(int level)
     
    350435        return;
    351436}
    352 
     437*/
    353438/*      struct highscore *sp; */
    354439/*      int i, n, c; */
Note: See TracChangeset for help on using the changeset viewer.