//------------------------------------------------------------------------------ // public: //------------------------------------------------------------------------------ void Game::init() { HGE * hge( Engine::hge() ); b2World * b2d( Engine::b2d() ); hgeResourceManager * rm( Engine::rm() ); ViewPort * vp( Engine::vp() ); Engine::em()->init(); vp->offset().x = 0.0f; vp->offset().y = 0.0f; vp->centre().x = 0.0f; vp->centre().y = 0.0f; vp->bounds().x = 1280.0f; vp->bounds().y = 720.0f; vp->setAngle( 0.0f ); vp->setScale( 10.0f ); clearArena(); clearPiece(); m_index = 0; m_rotate = 0; m_col = 6; m_row = 1; m_num = 0; m_replaying = false; m_timer = 0.0f; }
//------------------------------------------------------------------------------ // public: //------------------------------------------------------------------------------ void Game::init() { HGE * hge( Engine::hge() ); b2World * b2d( Engine::b2d() ); hgeResourceManager * rm( Engine::rm() ); ViewPort * vp( Engine::vp() ); Engine::em()->init(); vp->offset().x = 0.0f; vp->offset().y = 0.0f; vp->centre().x = 0.0f; vp->centre().y = 0.0f; vp->bounds().x = 1280.0f; vp->bounds().y = 720.0f; vp->setAngle( 0.0f ); vp->setScale( 10.0f ); m_brain.clear(); m_lines.clear(); m_dial.clear(); _clearCurrent(); m_row = 0; m_col = 0; m_dialSize = 0; m_coolDown = 1; m_lines.push_back( "Welcome to the d-board, by RocketHands!\n" ); m_lines.push_back( "You can enter text using the cursor keys, or by\n" ); m_lines.push_back( "plugging in a game controller.\n" ); m_lines.push_back( "Try entering \"the cat sat on the mat\" below:\n" ); for( std::vector< std::string >::iterator i = m_lines.begin(); i != m_lines.end(); ++i ) { m_brain.learn( i->c_str() ); } m_lines.push_back( "" ); m_brain.select( 't' ); m_brain.select( 'h' ); m_brain.select( 'e' ); m_brain.select( ' ' ); m_brain.select( 'c' ); m_brain.select( 'a' ); m_brain.select( 't' ); m_brain.select( ' ' ); m_row = 8; m_col = 5; _clearCurrent(); m_current[m_brain.getMode()] = 0; }
/*Main Method */ void main(int argc, char*argv[]){ int addition = 0; int subtraction = 0; int mult = 0; char * firstArg; char * secArg; char * firstForm; char * secForm; int negFirst = 0; int negSec = 0; int firstFinal = 0; int secFinal = 0; char * firstBin; char * secBin; /*check arguments*/ if (argc != 5){ fprintf(stderr, "Argc is off---should be 5\n"); return; } /*Check for addition and subtraction*/ char sign = *argv[1]; switch (sign){ case '+': addition = 1; break; case '-': subtraction = 1; break; case '*': mult = 1; break; default: fprintf(stderr, "Only addition, subtraction and multiplication allowed\n"); } firstArg = argv[2]; secArg = argv[3]; firstForm = firstArg; secForm = secArg; /*check for negatives*/ if(firstArg[0] == '-'){ negFirst = 1; firstForm+=1; } if(secArg[0] == '-'){ negSec = 1; secForm+=1; } switch(firstForm[0]) { case 'd': /*decimal to binary*/ firstForm++; firstFinal = atoi(firstForm); firstBin = (char*) malloc(3*(strlen(firstForm))); d2b(firstBin, firstFinal); break; case 'o': /*octal to binary */ firstForm++; firstBin = (char*) malloc(3*(strlen(firstForm))); o2b(firstBin, firstForm); break; case 'b': /*no conversion necessary */ firstForm++; firstBin = firstForm; break; case 'x': /*hexadecimal to binary */ firstForm++; firstBin = (char*) malloc(4*(strlen(firstForm))); x2b(firstBin, firstForm); break; default: fprintf(stderr, "not a valid conversion base option\n"); return; } switch(secForm[0]) { case 'd': /*decimal to binary*/ secForm++; secFinal = atoi(secForm); secBin = (char*) malloc(3*(strlen(secForm))); d2b(secBin, secFinal); break; case 'o': /*octal to binary */ secForm++; secBin = (char*) malloc(3*(strlen(secForm))); o2b(secBin, secForm); break; case 'b': /*no conversion necessary */ secForm++; secBin = secForm; break; case 'x': /*hexadecimal to binary */ secForm++; secBin = (char*) malloc(4*(strlen(secForm))); x2b(secBin, secForm); break; default: fprintf(stderr, "not a valid conversion base option\n"); return; } /* int diff; diff = abs(strlen(firstBin) - strlen(secBin)); char* shorter; char* shorterBin; char* longerBin; * if strings are different lengths, * we must do some adjusting* if(diff > 0){ if(strlen(firstBin) > strlen(secBin)){ longerBin = firstBin; shorterBin = secBin; shorter = (char*) malloc(strlen(shorterBin)); } else{ longerBin = secBin; shorterBin = firstBin; shorter = (char*) malloc(strlen(shorterBin)); } * add zeros to the front of the shorter binary string * so they can be compared * strcpy(shorter, "0"); int k; for(k=0; k<diff-1; k++){ strcat(shorter, "0"); } strcat(shorter, shorterBin); } else{ longerBin = firstBin; shorter = secBin; } if (addition){ binAdd(sum, longerBin, shorter); sum = reverse(sum); printf("binSum: %s\n", sum); } if (subtraction){ binSub(sum, longerBin, shorter); printf("Subtraction sum: %s\n", sum); } */ /*decimal aritmatic*/ int decAns = 0; if (addition){ if(negFirst){ decAns += -1*b2d(firstBin); }else{ decAns += b2d(firstBin); } if(negSec){ decAns += -1*b2d(secBin); }else{ decAns += b2d(secBin); } }else{ if (subtraction){ if(negFirst){ int addme = -1*b2d(firstBin); decAns = decAns + addme; }else{ decAns += b2d(firstBin); } if(negSec){ int addme = -1*b2d(secBin); decAns = decAns - addme; }else{ decAns -= b2d(secBin); } }else{ if (mult){ printf("need to complete multiplication"); } } } /*convert to final output form*/ char * ans = (char*) malloc(2*(strlen(firstBin))); char * temp = (char*) malloc(2*(strlen(firstBin))); char output = *argv[4]; switch (output){ case 'd': /*no conversion necessary*/ printf("Answer: %d\n", decAns); break; case 'o': /*binary to octal*/ d2b(temp, decAns); b2o(ans, temp); printf("Answer: %s\n", ans); break; case 'x': /*binary to hexadecimal*/ d2b(temp, decAns); b2x(ans, temp); printf("Answer: %s\n", ans); break; case 'b': /*decimal to binary*/ d2b(ans, decAns); printf("Answer: %s\n", ans); break; default: fprintf(stderr, "not a valid conversion output"); } }
int main(void){ b2d(); return 0; }