/***************************************************************************** * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * @(#) Colloidal for Ndless 2.0 (Colloidal Engine file) * main (launcher) * * Copyright (C) August 15, 2011 Joe Kim (SolusIpse) * Contact: solusipse0x5@gmail.com * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. *****************************************************************************/ #include #include "utils.h" #include "Colloidal.h" int main(int argc, char *argv[]) { int i; unsigned long score = 0; show_msgbox( "Colloidal", "_______________________________\n" " Colloidal \n" " © 2011 Joe Kim \n" "_______________________________\n" "Dodge the blocks. Game ends " "when you are hit by a block " "with a different color.\n" "Blocks with the same color as " "you halve your score\n" "Arrows: Move\n" "Tab and Ctrl: Switch colors\n" "0,1,4,7: Lightest gray thru Black\n" "ESC - Exit" ); void *scrbuf = malloc(SCREEN_BYTES_SIZE); if(scrbuf!=NULL) { memcpy(scrbuf, SCREEN_BASE_ADDRESS, SCREEN_BYTES_SIZE); for (i = 0; i < 0x0F; ++i) { fade(scrbuf, 1); sleep(70); if (isKeyPressed(KEY_NSPIRE_ESC)) { free(scrbuf); return 0; } } free(scrbuf); } score = colloidal(); unsigned long oldscore=0; FILE * pFile; char *thisfolder=malloc(sizeof(char)*80); if(thisfolder!=NULL) { memset(thisfolder,0,sizeof(char)*80); strcpy(thisfolder, argv[0]); *(strrchr(thisfolder, '/')+1) = 0 ; strcat(thisfolder, "Colloidal.HighScore.tns") ; pFile = fopen (thisfolder,"rb"); if (pFile!=NULL) { fread(&oldscore,1,sizeof(unsigned long),pFile); fclose (pFile); } } sleep(500); if(oldscore==0 || score>oldscore) { oldscore=score; show_msgbox("Congratulations!","New High Score!"); } char *scorechar = malloc(sizeof(char)*50); //arbitrarily sized buffer, should probably malloc in the future. char *scorechar2= malloc(sizeof(char)*50); if(scorechar!=NULL && scorechar2!=NULL) { memset(scorechar2, 0, sizeof(char)*50) ; strcat(scorechar2,"Your Score: "); itoa2(score,scorechar); strcat(scorechar2,scorechar); itoa2(oldscore,scorechar); strcat(scorechar2,"\nHigh Score: "); strcat(scorechar2,scorechar); show_msgbox("Your Score:",scorechar2); free(scorechar2); free(scorechar); } pFile = fopen (thisfolder,"wb"); if (pFile!=NULL) { fwrite(&oldscore,1,sizeof(unsigned long),pFile); fclose (pFile); } if(thisfolder!=NULL) free(thisfolder); return 0; }