PLANE * newplane(void) { PLANE *p; if ((p = (PLANE *) calloc(1, sizeof (PLANE))) == NULL) loser(NULL, "Out of memory"); return (p); }
void perdeu(){ clock_t tempo; float FPS = 15.0; tempo = clock(); explosao(xnave[e] - 40, ynave[e] - 30); blit(buffer, screen, 0,0,0,0,1280,720); //Limpa a tela clear_bitmap(buffer); //Limpa a tela draw_sprite(buffer, background[back], 0, 0); //Coloca a imagem na tela draw_sprite(screen, inimigo[p], 15,yini); //Põe a nave na tela loser(); while (!key[KEY_ENTER]){ textout(screen, font, "Voce perdeu! Tecle 'Enter' para comecar novamente", 450,350, makecol(255,0,0 ) ); char txt[15]; sprintf(txt,"x + %d = %d", b, a); //Inicializa o texto char txt2[15]; sprintf(txt2,"Score = %d", score); //Inicializa o texto textout(screen,font,txt,5,5,makecol(255,0,0)); //Exibe o texto textout(screen,font,txt2,5,20,makecol(255,0,0)); //Exibe o texto if ( (double)(clock() - tempo) >= 1000/FPS ) { if (p == 10){ p++; } else { if (p == 11){ p++; } else { if (p == 12){ p++; } else { if (p == 13){ p = 10; } } } } blit(buffer, screen, 0,0,0,0,1280,720); //Limpa a tela clear_bitmap(buffer); //Limpa a tela draw_sprite(buffer, background[back], 0, 0); //Coloca a imagem na tela draw_sprite(screen, inimigo[p], 15,yini); //Põe a nave na tela tempo = clock(); } } c = 0; yini = 40.0; score = 0; nivel = 1.0; back = 0; }
void update(int dummy) { int i, dir_diff, unclean; PLANE *pp, *p1, *p2; clck++; erase_all(); /* put some planes in the air */ do { unclean = 0; for (pp = ground.head; pp != NULL; pp = pp->next) { if (pp->new_altitude > 0) { delete(&ground, pp); append(&air, pp); unclean = 1; break; } } } while (unclean); /* do altitude change and basic movement */ for (pp = air.head; pp != NULL; pp = pp->next) { /* type 0 only move every other turn */ if (pp->plane_type == 0 && clck & 1) continue; pp->fuel--; if (pp->fuel < 0) loser(pp, "ran out of fuel."); pp->altitude += SGN(pp->new_altitude - pp->altitude); if (!pp->delayd) { dir_diff = pp->new_dir - pp->dir; /* * Allow for circle commands */ if (pp->new_dir >= 0 && pp->new_dir < MAXDIR) { if (dir_diff > MAXDIR/2) dir_diff -= MAXDIR; else if (dir_diff < -(MAXDIR/2)) dir_diff += MAXDIR; } if (dir_diff > 2) dir_diff = 2; else if (dir_diff < -2) dir_diff = -2; pp->dir += dir_diff; if (pp->dir >= MAXDIR) pp->dir -= MAXDIR; else if (pp->dir < 0) pp->dir += MAXDIR; } pp->xpos += displacement[pp->dir].dx; pp->ypos += displacement[pp->dir].dy; if (pp->delayd && pp->xpos == sp->beacon[pp->delayd_no].x && pp->ypos == sp->beacon[pp->delayd_no].y) { pp->delayd = 0; if (pp->status == S_UNMARKED) pp->status = S_MARKED; } switch (pp->dest_type) { case T_AIRPORT: if (pp->xpos == sp->airport[pp->dest_no].x && pp->ypos == sp->airport[pp->dest_no].y && pp->altitude == 0) { if (pp->dir != sp->airport[pp->dest_no].dir) loser(pp, "landed in the wrong direction."); else { pp->status = S_GONE; continue; } } break; case T_EXIT: if (pp->xpos == sp->exit[pp->dest_no].x && pp->ypos == sp->exit[pp->dest_no].y) { if (pp->altitude != 9) loser(pp, "exited at the wrong altitude."); else { pp->status = S_GONE; continue; } } break; default: loser(pp, "has a bizarre destination, get help!"); } if (pp->altitude > 9) /* "this is impossible" */ loser(pp, "exceeded flight ceiling."); if (pp->altitude <= 0) { for (i = 0; i < sp->num_airports; i++) if (pp->xpos == sp->airport[i].x && pp->ypos == sp->airport[i].y) { if (pp->dest_type == T_AIRPORT) loser(pp, "landed at the wrong airport."); else loser(pp, "landed instead of exited."); } loser(pp, "crashed on the ground."); } if (pp->xpos < 1 || pp->xpos >= sp->width - 1 || pp->ypos < 1 || pp->ypos >= sp->height - 1) { for (i = 0; i < sp->num_exits; i++) if (pp->xpos == sp->exit[i].x && pp->ypos == sp->exit[i].y) { if (pp->dest_type == T_EXIT) loser(pp, "exited via the wrong exit."); else loser(pp, "exited instead of landed."); } loser(pp, "illegally left the flight arena."); } } /* * Traverse the list once, deleting the planes that are gone. */ for (pp = air.head; pp != NULL; pp = p2) { p2 = pp->next; if (pp->status == S_GONE) { safe_planes++; delete(&air, pp); } } draw_all(); for (p1 = air.head; p1 != NULL; p1 = p1->next) for (p2 = p1->next; p2 != NULL; p2 = p2->next) if (too_close(p1, p2, 1)) { static char buf[80]; (void)snprintf(buf, sizeof buf, "collided with plane '%c'.", name(p2)); loser(p1, buf); } /* * Check every other update. Actually, only add on even updates. * Otherwise, prop jobs show up *on* entrance. Remember that * we don't update props on odd updates. */ if ((atcrandom() % sp->newplane_time) == 0) addplane(); }
QString Result::description() const { QString w(winner().toString()); QString l(loser().toString()); QString str; if (m_type == Resignation) str = tr("%1 resigns").arg(l); else if (m_type == Timeout) { if (l.isEmpty()) str = tr("Draw by timeout"); else str = tr("%1 loses on time").arg(l); } else if (m_type == Adjudication) { if (w.isEmpty()) str = tr("Draw by adjudication"); else str = tr("%1 wins by adjudication").arg(w); } else if (m_type == IllegalMove) str = tr("%1 makes an illegal move").arg(l); else if (m_type == Disconnection) { if (l.isEmpty()) str = tr("Draw by disconnection"); else str = tr("%1 disconnects").arg(l); } else if (m_type == StalledConnection) { if (l.isEmpty()) str = tr("Draw by stalled connection"); else str = tr("%1's connection stalls").arg(l); } else if (m_type == Agreement) { if (w.isEmpty()) str = tr("Draw by agreement"); else str = tr("%1 wins by agreement").arg(w); } else if (m_type == NoResult) str = tr("No result"); else if (m_type == ResultError) str = tr("Result error"); if (m_description.isEmpty()) { if (m_type == Win) str = tr("%1 wins").arg(w); else if (m_type == Draw) str = tr("Drawn game"); } else { if (!str.isEmpty()) str += ": "; str += m_description; } Q_ASSERT(!str.isEmpty()); str[0] = str.at(0).toUpper(); return str; }