bool Core::posFood(const Food &food) { if ((food.getPosX() == _pos[0].getPosX()) && (food.getPosY() == _pos[0].getPosY())) setFood(true); else setFood(false); return (true); }
void CTeris_1View::upDateMoveAndNextBox() { CTeris_1Doc* pDoc = GetDocument(); pDoc->box.RemoveAt(1); CBox *tmp=(CBox *)pDoc->box.GetAt(1); tmp->NextResetMove(); //delete tmp; if(GetDocument()->mode==CXY){ CBox *b=(CBox *)pDoc->box.GetAt(0); b->LOCAL[CXYx][CXYy].canSee=SEE; switch(GetDocument()->Num){ case 1: setFood(); break; case 2: setBlock(); break; } } initialNextBox(); }
void CTeris_1View::StartCXY() { GetDocument()->DeleteContents(); this->initialBigBox(); this->initialMoveBox(); this->initialNextBox(); GetDocument()->mode=CXY; GetDocument()->score=0; this->Invalidate(); flag=TRUE; switch(GetDocument()->Num){ case 1://贪吃蛇 MessageBox("我相信,贪吃蛇,你一定玩过.\r但是,贪吃的俄罗斯方块你玩过吗?\r程先生是一个很奇怪的人.\r所以他设计的方块很奇怪\rtips:通关当且仅当获得1024分."); setFood(); break; case 2://黑洞模式 MessageBox("有一天,程先生想到一个奇怪的游戏。"); setBlock(); break; case 4://坦克大战 MessageBox("小时候,程先生有一台小霸王。\r里面有一个游戏叫做,坦克大战。\rtips:通关当且仅当获得1024分"); break; case 3://华容道 MessageBox("相信你已经觉得程先生是一个想象力丰富的人.\r所以,你应该知道,这一关,应该不同"); break; } }
void Game::Start() { RF_Engine::instance->Debug(type); bg = dynamic_cast<mainProcess*>(RF_Engine::instance->taskManager[father])->bg; pL = new RF_Parallax_Layer(); pL->getMirroring() = Vector2<int>(REPEAT,REPEAT); pL->size = Vector2<int>(bg->screen->w,bg->screen->h); pL->transform.position = Vector2<int>(0,0); pL->transform.scale = Vector2<float>(1.0f,1.0f); pL->transform.rotation = 0; for(i=0; i<bg->screen->w * bg->screen->h; i++) { pL->data.push_back(0x000000); } for(i = 0; i < 80; i++) { for(j = 0; j < 60; j++) { gamegrid[i][j] = 0; } } rectSize.x = bg->screen->w / 80; rectSize.y = bg->screen->h / 60; pL->drawAlone(bg); snake = Vector3<int>(40,30,3); snake_direction = 1; fC = 0; setFood(); }
void Feed::catEat(User &user, Cat &cat) { if(user.phrase.compare("feed") == 0 && cat.getHunger() < 30) { std::cout << "select your cat's meal" << std::endl; setFood(/*cat string*/); std::cout << std::endl; std::getline(std::cin, user.phrase) }
void *mainGameLoop() { setFood(); do { situation = judge(direction);//judge if knock the wall or facing a food. debugPrint(1); if(situation == 1)//If not hit the wall & not have a food, print out the screen. { snakeMove(direction);//Draw the screen array. printScreen(screen,speed);//Print out the screen for 2 seconds. //debugPrint(2); } if(situation == 2)//If facing a food, longer the snake by change food into the head of the snake. { snakeEat(direction); setFood(); printScreen(screen,speed); } else ; } while (situation != -1); return ((void *)0); }
//-------------------------------------------------------------- void ofApp::resetGame(){ gameOver = false; onTitle = false; snake.setup(GRID_SIZE); resetGameTimer = gameOverTime; int hue = ofRandom(256); int hue2 = (hue + 128) % 256; offColor.setHsb(hue, 50, 250); onColor.setHsb(hue2, 250, 100); ofBackground(offColor); setFood(); }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ if (!publicRelease){ if (key == 'f'){ setFood(); } if (key == 'e'){ endGame(); } if (key == 'c'){ captureScreen = !captureScreen; return; } if (key == 'v'){ captureOneScreenshot = true; } if (key == 'p'){ debugPause = !debugPause; } if (key == 'm'){ debugMute = !debugMute; } if (key == 'r'){ resetGame(); } } snake.keyPressed(key); if (onTitle){ resetGame(); //onTitle = true; //kill me } }
void Game::SnakeUpdate() { switch(snake_direction) { case 0: snake.y--; break; case 1: snake.x++; break; case 2: snake.y++; break; case 3: snake.x--; break; } if(snake.x >= 80){ snake.x = 0;}else if(snake.x < 0){ snake.x = 79;} if(snake.y >= 60){ snake.y = 0;}else if(snake.y < 0){ snake.y = 59;} if(gamegrid[snake.x][snake.y] == -1) { snake.z += 2; setFood(); shake_x += 1; } if(gamegrid[snake.x][snake.y] < -1) { snake.z -= 5; shake_x = 0; shake_y = 0; effect_timer = -1; } if(gamegrid[snake.x][snake.y] > 0) { losed = true; dosTextos.x = RF_Engine::instance->write("You lose",{255,255,255},Vector2<int>((bg->screen->w>>1)-50, (bg->screen->h>>1)-50));
//Constructor initializes the m x n Array of cField* (environment of our anthill simulation) cArea::cArea(void):round(0),FOODamount(0),AnthillPosition(NULL),cSubject(1) { //FOODamount=0; //AnthillPosition=0; attach(cPainter::Instance()); for (int z=0; z< LINES ; z++) { for (int sp= 0; sp< COLUMNS; sp++) { Array_ofFieldptrs[z][sp]= new cField(); } } for (int z=0; z< LINES ; z++) { for (int sp= 0; sp< COLUMNS; sp++) { if (z!=0)//linking Northptr to field above { Array_ofFieldptrs[z][sp]->setpNorth(Array_ofFieldptrs[z-1][sp]); } if(sp<COLUMNS-1)//linking Eastptr to field on the right { Array_ofFieldptrs[z][sp]->setpEast(Array_ofFieldptrs[z][sp+1]); } if(z<LINES-1)//linking Southptr to field below { Array_ofFieldptrs[z][sp]->setpSouth(Array_ofFieldptrs[z+1][sp]); } if(sp!=0)//linking Westptr to the field on the left { Array_ofFieldptrs[z][sp]->setpWest(Array_ofFieldptrs[z][sp-1]); } } } factory=cCreator::Instance(); int sp=COLUMNS, z=LINES; int xhill =0; int yhill=0; Anthill = (cAnthill*) setAntHill(z, sp, xhill, yhill); // zum testen nur einmal food! für später mit random schleife verteilen! for (int i = 0; i < 1; i++) { setFood(z, sp,xhill,yhill); } //for (int z=0; z< LINES ; z++) //{ // for (int sp= 0; sp< COLUMNS; sp++) // { // Array_ofFieldptrs[z][sp]->notify();//das Notify eines jeden Fields wird aufgerufen // } //} }
//-------------------------------------------------------------- void ofApp::update(){ float pulseSpeed = 10; maxVol = ofMap(snake.score, 0, 40, 0.3, 0.9, true); if (onTitle){ maxVol = 0.15; } if (gameOver && resetGameTimer < 0){ maxVol = 0.2; } if (debugMute) maxVol = 0; //turn everythign off for (int x=0; x<GRID_SIZE; x++){ for (int y=0; y<GRID_SIZE; y++){ grid[x][y] = false; gridf[x][y] = 0; } } if (!gameOver && !onTitle){ //did the snake eat the food? if (foodX == snake.curX && foodY == snake.curY){ snake.eat(); setFood(); } //update the snake if (!debugPause){ snake.update(); } //check if we're dead if (snake.justDied){ snake.justDied = false; endGame(); } //turn on the parts of the snake grid[snake.curX][snake.curY] = true; gridf[snake.curX][snake.curY] = 1; for (int i=0; i<snake.trailX.size(); i++){ grid[snake.trailX[i]][snake.trailY[i]] = true; gridf[snake.trailX[i]][snake.trailY[i]] = 0.5 + 0.5*abs(sin(ofGetElapsedTimef() * pulseSpeed + i *0.2) ); } //and the food grid[foodX][foodY] = 1;//ofGetFrameNum()%2==0; gridf[foodX][foodY] = ofGetFrameNum() % 6 > 2 ? 1 : 0; //gridf[foodX][foodY] = 0.5 + 0.5*abs(cos( ofGetElapsedTimef() * pulseSpeed * 3)); } if (gameOver && !onTitle){ if (resetGameTimer > 0){ gridf[snake.curX][snake.curY] = ofGetFrameNum() % 20 > 10; } else{ for (int x=0; x<GRID_SIZE; x++){ for (int y=0; y<GRID_SIZE; y++){ if (scoreGrid[x][y]){ gridf[x][y] = ofGetFrameNum() % 20 > 10; } } } } resetGameTimer--; if (resetGameTimer <= -showScoreTime){ onTitle = true; } } if (onTitle){ for (int x=0; x<GRID_SIZE; x++){ for (int y=0; y<GRID_SIZE; y++){ if (titleGrid[x][y]){ //gridf[x][y] = 0.5 + 0.5 * abs(sin(ofGetElapsedTimef() + x*GRID_SIZE+y)); gridf[x][y] = ofRandom(0.2,1);// ofRandomuf() < 0.8 ? 1 : 0; } } } } //also update and add the sparks if any are present for (int i=sparks.size()-1; i>=0; i--){ sparks[i].update(); if (sparks[i].deathTimer <= 0){ sparks.erase( sparks.begin()+i ); }else{ gridf[sparks[i].curX][sparks[i].curY] += sparks[i].curVal; gridf[sparks[i].curX][sparks[i].curY] = MIN(gridf[sparks[i].curX][sparks[i].curY], 1); } } }