Пример #1
0
int main(){

	int opt, flag = -1;
	SetConsoleTitle("Firework Columns");
	rank rrank;
	rrank.read();

	while(1){
		opt = 1;
		g_title();
		_getch();
		g_menu();
		while(k_menu(&opt) == 1){
			flag *= -1;
			g_cheat(flag);
		}

		switch(opt){
			case 1:
				playset game;
				game.cheat = flag;
				g_setf(flag);
				if(game.set() == 0) break;
				g_gamef();
				game.initialize();
				game.random();
				game.drop();
				if(game.opt == 4) break;
				if(k_wait() == 0) break;
				game.record(&rrank);
				g_rank();
				rrank.srank();
				if(k_wait() == 0) break;
				break;
			case 2:
				g_help();
				k_wait();
				break;
			case 3:
				g_rank();
				rrank.srank();
				k_wait();
				break;
			case 4:
				exit(0);
				break;
		}

	}
	return 0;
}
Пример #2
0
/****************************************************************************
 *
 *                   Procedure draw_graph
 *
 * Arguments: prim: pointer to primitive_type
 *             obj: pointer to object_type
 *
 * Returns: none
 *
 * Action: Draws in a graph.
 *   This takes care of the user specified scaling and translating.
 *
 ****************************************************************************/
void draw_graph(prim_type *prim,object_type *obj)
{
  static XPoint *points=0;
  static point_type2D *fpoints=0;
  static int num_points=0;
  static char integ_last_time=0;
  int i,j;
  graph_type *the_graph;
  point_type2D origin,dim;
  char numstring[20];
  float xloc,yloc;
  float inv_xscale,inv_yscale;
  float scaled_fermi;
  float xscale,yscale;
  int lineshown;
  float xref,yref;
  float xval,yval;
  float *max_x,*max_y,*min_x,*min_y;
  float *old_max_x,*old_max_y,*old_min_x,*old_min_y;

  /* check to see what type of graph this is */
  if(prim->prop_graph){
    the_graph = prim->prop_graph->the_data;
    max_x = &(prim->prop_graph->max_x);
    max_y = &(prim->prop_graph->max_y);
    min_x = &(prim->prop_graph->min_x);
    min_y = &(prim->prop_graph->min_y);
    old_max_x = &(prim->prop_graph->old_max_x);
    old_max_y = &(prim->prop_graph->old_max_y);
    old_min_x = &(prim->prop_graph->old_min_x);
    old_min_y = &(prim->prop_graph->old_min_y);
  } else{
    if( prim->graph )  the_graph = prim->graph;
    else if(prim->band_graph) the_graph = prim->band_graph->the_data;
    else if(prim->walsh_graph) the_graph = prim->walsh_graph->the_data;
    else FATAL_BUG("Bogus primitive passed to draw_graph.");
    max_x = &(the_graph->max_x);
    max_y = &(the_graph->max_y);
    min_x = &(the_graph->min_x);
    min_y = &(the_graph->min_y);
    old_max_x = &(the_graph->old_max_x);
    old_max_y = &(the_graph->old_max_y);
    old_min_x = &(the_graph->old_min_x);
    old_min_y = &(the_graph->old_min_y);
  }

  /* check to see if we need to re-determine the location of tic marks */
  if( *old_max_x != *max_x ||
     *old_max_y != *max_y ||
     *old_min_x != *min_x ||
     *old_min_y != *min_y ||
     (prim->prop_graph && (prim->prop_graph->integs_for_tics && !integ_last_time))){

    /********

      if we're using the integration for the X axis, then we need to
      update the graph max and min values.

      *******/
    if( prim->prop_graph && prim->prop_graph->integs_for_tics ){
      /*******

        check to see if we've already updated them

        ********/
      if(!integ_last_time){
        *max_x = prim->prop_graph->the_integration->max_x;
        *max_y = prim->prop_graph->the_integration->max_y;
        *min_x = prim->prop_graph->the_integration->min_x;
        *min_y = prim->prop_graph->the_integration->min_y;

        /******

          make sure that we aren't gonna get horked when we display COOP
          integrations by displaying COOP's on the same scale as the
          integration

          *******/
        if( prim->prop_graph->type == COOP_PROP ){
          prim->prop_graph->the_data->max_x = *max_x;
          prim->prop_graph->the_data->min_x = *min_x;
        }
        prim->prop_graph->the_data->max_y = *max_y;
        prim->prop_graph->the_data->min_y = *min_y;

        integ_last_time = 1;
      } /* if(!integ_last_time) */
      else{
        /*******

          if we got this far, then it means that the user updated the
          max and/or min values, so we need to change the integration
          max and min values to reflect the change.

          ********/
        prim->prop_graph->the_integration->max_x = *max_x;
        prim->prop_graph->the_integration->min_x = *min_x;
        prim->prop_graph->the_integration->max_y = *max_y;
        prim->prop_graph->the_integration->min_y = *min_y;

        if( prim->prop_graph->type == COOP_PROP ){
          prim->prop_graph->the_data->max_x = *max_x;
          prim->prop_graph->the_data->min_x = *min_x;
        }
        prim->prop_graph->the_data->max_y = *max_y;
        prim->prop_graph->the_data->min_y = *min_y;
      }
    } /*  if( prim->prop_graph && prim->prop_graph->integs_for_tics ) */
    else{
      /******

        reset the max and min values to those of the
        data...

        ******/
      if( prim->prop_graph ){
        if( integ_last_time ){
          *max_x = prim->prop_graph->the_data->max_x;
          *min_x = prim->prop_graph->the_data->min_x;
          *max_y = prim->prop_graph->the_data->max_y;
          *min_y = prim->prop_graph->the_data->min_y;
        }
        if( prim->prop_graph->the_integration){
          if( prim->prop_graph->type == COOP_PROP ){
            prim->prop_graph->the_integration->max_x = *max_x;
            prim->prop_graph->the_integration->min_x = *min_x;
          }
          prim->prop_graph->the_integration->max_y = *max_y;
          prim->prop_graph->the_integration->min_y = *min_y;
        }
      }
      the_graph->max_x = *max_x;
      the_graph->min_x = *min_x;
      the_graph->max_y = *max_y;
      the_graph->min_y = *min_y;

      integ_last_time = 0;
    }
    preprocess_graph_data(the_graph);
    if( prim->prop_graph && prim->prop_graph->the_integration){
      preprocess_graph_data(prim->prop_graph->the_integration);
    }

/*
    the_graph->old_max_x = the_graph->max_x;
    the_graph->old_max_y = the_graph->max_y;
    the_graph->old_min_x = the_graph->min_x;
    the_graph->old_min_y = the_graph->min_y;
*/
    *old_max_x = *max_x;
    *old_max_y = *max_y;
    *old_min_x = *min_x;
    *old_min_y = *min_y;

  }


  /* check to see if we need memory for the Xpoints */
  if( !points || num_points < the_graph->num_p ){
    if( points ) free(points);
    num_points = the_graph->num_p;
    points = (XPoint *)calloc(num_points+2,sizeof(XPoint));
    if( !points ) fatal("Can't allocate memory for point storage in draw_graph.");
    if( fpoints ) free(fpoints);
    fpoints = (point_type2D *)calloc(num_points+2,sizeof(point_type2D));
    if( !fpoints ) fatal("Can't allocate memory for fpoint storage in draw_graph.");
  }

  /* determine the location of the origin on screen */
  origin.x = obj->cent.x + obj->trans.x + g_xmax / 2;
  origin.y = obj->cent.y - obj->trans.y + g_ymax / 2;
  dim.x = DEF_GRAPH_X * obj->scale.x;
  dim.y = DEF_GRAPH_Y * obj->scale.y;

  /* scaling terms */
  inv_xscale = (the_graph->max_x - the_graph->min_x) / DEF_GRAPH_X;
  inv_yscale = (the_graph->max_y - the_graph->min_y) / DEF_GRAPH_Y;
  xscale = 1/inv_xscale;
  yscale = 1/inv_yscale;

  /* find the point in data space which will appear at the origin */
  xref = the_graph->min_x * xscale;
  yref = the_graph->min_y * yscale;

  /* determine the bounding box for this object */
  localmin.x = obj->bmin.x = origin.x;
  localmin.y = obj->bmin.y = origin.y - dim.y;
  localmax.x = obj->bmax.x = origin.x + dim.x;
  localmax.y = obj->bmax.y = origin.y;

  /* put in the tic marks now... */
  if( the_graph->do_x_tics && (!prim->prop_graph || !prim->prop_graph->integs_for_tics)){
    for(i=0;i<(int)rint(the_graph->num_tics_x);i++){
      xloc = origin.x + obj->scale.x * (the_graph->tic_start_x +
                                        i * the_graph->tic_sep_x - xref);
      g_line(xloc,origin.y+obj->scale.y*TIC_DIM,xloc,origin.y);

      localmin.y += obj->scale.y*TIC_DIM;

      /*****

        do the labels

      *****/
      xval = (the_graph->tic_start_x + i*the_graph->tic_sep_x)*inv_xscale;
      if( fabs(xval) < 1e-12 ) xval = 0.0;
      sprintf(numstring,"%lg",xval);
      yloc = origin.y+obj->scale.y*TIC_DIM*(1.1);

      g_center_text(xloc,yloc,numstring);
    }
  }

  /* Y tics */
  if( the_graph->do_y_tics ){
    for(i=0;i<(int)rint(the_graph->num_tics_y);i++){
      yloc = origin.y + obj->scale.y * (yref - the_graph->tic_start_y -
                                        i * the_graph->tic_sep_y);
      g_line(origin.x-obj->scale.x*TIC_DIM,yloc,origin.x,yloc);

      yval = (the_graph->tic_start_y + i*the_graph->tic_sep_y)*inv_yscale;
      if( fabs(yval) < 1e-12 ) yval = 0.0;
      sprintf(numstring,"%lg",yval);
      xloc = origin.x-obj->scale.x*TIC_DIM*1.1;

      g_right_text(xloc,yloc,numstring);
    }
  }

  /* put in legends if they are needed */
  if( the_graph->xlegend[0] != 0 && the_graph->do_x_tics ){
    xloc = origin.x + dim.x/2;
    yloc = origin.y+obj->scale.y*TIC_DIM*(1.1);

    g_xlegend(xloc,yloc,the_graph->xlegend);
    obj->bmax.y += 2.1*PS_options.fontsize;
  }

  if( the_graph->ylegend[0] != 0 && the_graph->do_y_tics ){
    yloc = origin.y - dim.y/2;
    xloc = origin.x-obj->scale.x*TIC_DIM*5.0;

    g_ylegend(xloc,yloc,the_graph->ylegend);
    obj->bmin.x -= 3.0*PS_options.fontsize;
  }

  /* Now do the title */
  if( the_graph->title[0] != 0 && the_graph->do_title){
    xloc = origin.x + dim.x/2;
    yloc = origin.y - dim.y;

    g_title(xloc,yloc,the_graph->title);
  }

  /* now do the plot itself */
  lineshown = 0;
  for(i=0;i<the_graph->num_curves;i++){
    if( the_graph->curves_to_display[i] ){
      /* adjust the line styles to get distinguishable graphs */
      g_change_linestyle(the_graph->styles[i]);

      for(j=0;j<the_graph->num_p;j++){
        points[j].x = fpoints[j].x = origin.x +
          (the_graph->data[j*the_graph->num_curves + i].x - xref)*obj->scale.x;

        points[j].y = fpoints[j].y = origin.y +
          (yref - the_graph->data[j*the_graph->num_curves + i].y)* obj->scale.y;
      }
      /*********

        Deal with the fact that DOS projections may be filled

      **********/
      if( prim->prop_graph && ((prim->prop_graph->type != COOP_PROP &&
         fill_projections && i != 0 ) || prim->prop_graph->the_data->fills[i])){

        /**********

          There are some complications in the filling if the
          end points of the graph are not at the same x level.

          deal with these potential problems by inserting 2 extra
          points into the curve.
        ************/
        if( *min_x == 0.0 || (*max_x >= 0 && *min_x < 0.0) ){
          points[the_graph->num_p].x = fpoints[the_graph->num_p].x = origin.x -
            xref*obj->scale.x;
          points[the_graph->num_p+1].x = fpoints[the_graph->num_p+1].x = origin.x -
            xref*obj->scale.x;
        }else if( *min_x > 0.0 ){
          points[the_graph->num_p].x = fpoints[the_graph->num_p].x = origin.x;
          points[the_graph->num_p+1].x = fpoints[the_graph->num_p+1].x = origin.x;
        }
        else{
          points[the_graph->num_p].x = fpoints[the_graph->num_p].x = origin.x +
            (*max_x - xref)*obj->scale.x;
          points[the_graph->num_p+1].x = fpoints[the_graph->num_p+1].x = origin.x +
            (*max_x - xref)*obj->scale.x;
        }

        points[the_graph->num_p].y = fpoints[the_graph->num_p].y = origin.y +
          (yref - the_graph->data[(the_graph->num_p-1)*the_graph->num_curves + i].y)
            * obj->scale.y;
        points[the_graph->num_p+1].y = fpoints[the_graph->num_p+1].y = origin.y +
          (yref - the_graph->data[i].y)* obj->scale.y;
        g_lines(points,fpoints,the_graph->num_p+2,1);
      }
      else{
        g_lines(points,fpoints,the_graph->num_p,0);
      }

      /* set the line style back to the default value */
      g_change_linestyle(0);
    }
  }

  /******

    put in the fermi level if this is a property graph and the user
    asked for it

  ******/
  if( prim->prop_graph && prim->prop_graph->show_fermi ){
    if( prim->prop_graph->Fermi_E > the_graph->min_y &&
       prim->prop_graph->Fermi_E < the_graph->max_y ){
      scaled_fermi = prim->prop_graph->Fermi_E * yscale;
      yloc = origin.y + (yref - scaled_fermi)*obj->scale.y;
      xloc = origin.x;
      /* use a dashed line */
      g_change_linestyle(1);
      /* draw a line */
      g_line(xloc,yloc,xloc+dim.x,yloc);
      /* set the line style back to the default */
      g_change_linestyle(0);
    }
  }

  /* check to see if we should draw a line through zero */
  if( the_graph->max_x > 0.0 && the_graph->min_x < 0.0 ){
    xloc = origin.x - xref * obj->scale.x;
    yloc = origin.y;
    g_line(xloc,yloc,xloc,yloc-dim.y);
  }


  /* check to see if we need to draw in an integration */
  if( prim->prop_graph && prim->prop_graph->the_integration ){
    the_graph = prim->prop_graph->the_integration;

    inv_xscale = (the_graph->max_x - the_graph->min_x) / DEF_GRAPH_X;
    inv_yscale = (the_graph->max_y - the_graph->min_y) / DEF_GRAPH_Y;
    xscale = 1/inv_xscale;
    yscale = 1/inv_yscale;
    /* find the point in data space which will appear at the origin */
    xref = the_graph->min_x * xscale;
    yref = the_graph->min_y * yscale;

    /*****

      if we are using the integration to provide the tic marks then
      show them now.

    *****/
    if( prim->prop_graph->the_data->do_x_tics && prim->prop_graph->integs_for_tics){
      for(i=0;i<(int)rint(the_graph->num_tics_x);i++){
        xloc = origin.x + obj->scale.x * (the_graph->tic_start_x +
                                          i * the_graph->tic_sep_x - xref);
        g_line(xloc,origin.y+obj->scale.y*TIC_DIM,xloc,origin.y);

        localmin.y += obj->scale.y*TIC_DIM;

        /*****

          do the labels

          *****/
        xval = (the_graph->tic_start_x + i*the_graph->tic_sep_x)*inv_xscale;
        if( fabs(xval) < 1e-12 ) xval = 0.0;
        sprintf(numstring,"%lg",xval);
        yloc = origin.y+obj->scale.y*TIC_DIM*(1.1);

        g_center_text(xloc,yloc,numstring);
      }
    }


    lineshown = 0;

    for(i=0;i<the_graph->num_curves;i++){
      if( the_graph->curves_to_display[i] ){
        /* adjust the line styles to get distinguishable graphs */
        g_change_linestyle(the_graph->styles[i]);

        for(j=0;j<the_graph->num_p;j++){
          points[j].x = fpoints[j].x = origin.x +
            (the_graph->data[j*the_graph->num_curves + i].x - xref)*obj->scale.x;
          points[j].y = fpoints[j].y = origin.y +
            (yref - the_graph->data[j*the_graph->num_curves + i].y)*obj->scale.y;
        }
        g_lines(points,fpoints,the_graph->num_p,0);

        g_change_linestyle(0);
      }
    }
    the_graph = prim->prop_graph->the_data;
  }

  /* draw in a box surrounding the plot */
  g_rectangle(origin.x,origin.y,dim.x,dim.y);

}