#include #include #include #include #include #include static void *xfb = NULL; static GXRModeObj *rmode = NULL; using namespace std; void init(void); int getnumber(void); int cycle(void); int random(int min, int max); //--------------------------------------------------------------------------------- int main(int argc, char **argv) {//--------------------------------------------------------------------------------- init(); //sets up Wiimote, Video, and terminal. Also displays a message. int guess = 0; while(1) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); cout << "\x1b[2;0H"; cout << "(C) 2008 Vader347" << endl; cout << "Press RIGHT to increase by 1, LEFT to decrease by 1." << endl << "Once you have the number you want, press A." << endl; cout << "Press Home at anytime to return to loader" << endl; if ( pressed & WPAD_BUTTON_HOME ) exit(0); guess = getnumber(); //get user input returns double int range = cycle(); int max; switch (range) { case 1: max = 10; break; case 2: max = 100; break; case 3: max = 1000; break; } int nRandom = random(1, max); if (nRandom == guess) { cout << "You Win" << "Now go waste your time somewhere else" << endl; sleep(3); exit(0); } if (guess < nRandom) cout << "higher" << endl; if (guess > nRandom); cout << "lower" << endl; VIDEO_WaitVSync(); } return 0; } void init(void) { VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); } int getnumber(void) { int number = 0 ; while(1) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if ( pressed & WPAD_BUTTON_HOME ) exit(0); if ( pressed & WPAD_BUTTON_UP ) { number = (number + .000001); cout <<"\r"<< number; } if ( pressed & WPAD_BUTTON_DOWN ) { number = (number - .000001); cout <<"\r" << number; } if ( pressed & WPAD_BUTTON_RIGHT ) { number++; cout << "\r" << number; } if ( pressed & WPAD_BUTTON_LEFT ) { number--; cout << "\r" << number; } if ( pressed & WPAD_BUTTON_A && number != 0 ) break; VIDEO_WaitVSync(); } return number; } int cycle(void) { string choice; int nCycle = 1; while(1) { VIDEO_WaitVSync(); WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if ( pressed & WPAD_BUTTON_UP ) nCycle++; if ( pressed & WPAD_BUTTON_DOWN ) nCycle--; if ( pressed & WPAD_BUTTON_A ) break; if ( pressed & WPAD_BUTTON_HOME ) exit(0); if ( nCycle > 3 ) nCycle = 1; if ( nCycle < 1 ) nCycle =4; switch (nCycle) { case 1: choice = "1-10"; break; case 2: choice = "1-100"; break; case 3: choice = "1-1000"; break; } cout << "\r" << choice; VIDEO_WaitVSync(); } return nCycle; } int random(int min, int max) { int range=(min-max)+1; int randomint = rand() % range + min; return randomint; }