Пример #1
0
CharString NounStructure::status() const
{
	CharString info;
	info += "\n";

	if ( damage() > 0 )
		info += CharString().format("<color;0000ff>DAMAGE: %d%%</color>\n", (damage() * 100) / maxDamage() );
	if ( workers() != 0 )
		info += CharString().format( "Workers: %s\n", FormatNumber<char,int>( -workers() ).cstr() );
	if ( power() != 0 )
		info += CharString().format( "Power: %s\n", FormatNumber<char,int>( power() ).cstr() );
	if ( technology() != 0 )
		info += CharString().format( "Technology: %d\n", technology() );
	if ( upkeep() != 0 )
		info += CharString().format( "Upkeep: %d\n", upkeep() );

	if ( active() )
	{
		if ( food() != 0 )
			info += CharString().format( "Food: %s\n", FormatNumber<char,int>( food() ).cstr() );
		if ( habitat() != 0 )
			info += CharString().format( "Habitat: %s\n", FormatNumber<char,int>( habitat() ).cstr() );
		if ( mining() != 0 )
			info += CharString().format( "Mining: %s\n", FormatNumber<char,int>( mining() ).cstr() );
		if ( research() != 0 )
			info += CharString().format( "Research: %s\n", FormatNumber<char,int>( research() ).cstr() );
		if ( production() != 0 )
			info += CharString().format( "Production: %s\n", FormatNumber<char,int>( production() ).cstr() );
		if ( protection() != 0.0f )
			info += CharString().format( "PD: %d%%\n", (int)(protection() * 100) );
	}
	else if ( flags() & FLAG_ACTIVE )
	{
		if ( flags() & FLAG_WORKER_SHORT )
			info += "<color;0000ff>WORKER SHORTAGE!</color>\n";
		if ( flags() & FLAG_POWER_SHORT )
			info += "<color;0000ff>POWER SHORTAGE!</color>\n";
		if ( flags() & FLAG_TECH_SHORT )
			info += "<color;0000ff>TECHNOLOGY SHORTAGE!</color>\n";
	}
	else
	{
		info += "\n<color;ffffff>INACTIVE</color>\n";
	}

	if ( isBuilding() )
		info += CharString().format("\nBuilding...%d%% complete\n", buildComplete() );

	return info;
}
Пример #2
0
void		Core::begin(const IGui *gui)
{
  Food		food(_pos, _width, _height);

  if (gui)
    loopBegin(gui, food, SPACE_KEY);
}
Пример #3
0
void eat(Snake* head)
{
	Snake* vernier = head;
	if(foodx == 0 || foody == 0)
	{
		food(head);
	}
	if(head->x == foodx && head->y == foody)
	{
		foodx = 0;
		foody = 0;
		food(head);
		scoring++;
		add(head);
	}
}
Пример #4
0
int			expose_hook(t_env *env)
{
	move(env);
	if (env->bouffe == 0)
		food(env);
	creator(env);
	mlx_put_image_to_window (env->mlx, env->win, env->image, 0, 0);
	return (0);
}
Пример #5
0
void eat()
{
	if(s == g && x == h)
	{
		food();
		SCORE++;
		k++;
		add_length();
	}
}
Пример #6
0
void GamePainter::drawFoodCell(QPoint _pos)
{
    QBrush food( Qt::red );
    m_painter.setBrush( food );

    m_painter.drawEllipse( _pos.x() * m_cellSize.width() + 5
                           , _pos.y() * m_cellSize.height() + 37
                           , m_cellSize.width()/2
                           , m_cellSize.height()/2
                           );
}
Пример #7
0
int main()
{
	void control();
	void print();
	void seed();
	void map();
	void find();
	void judge_1();
	void follow();
	void food();
	void go_on();
	void add();
loop1:
	tail = NULL;
	head = &b[0];
	for (i = 0; i <= N; i++)
	{
		b[i].next = &b[i + 1];
		b[i + 1].previous = &b[i];
	}
	b[N].next = tail;
	b[0].x = 10;
	b[0].y = 11;
	b[1].x = 10;
	b[1].y = 10;
	b[2].x = 10;
	b[2].y = 9;
	for (i = 0; i <= N; i++)
		a[b[i].x][b[i].y] = 'O';
loop2: seed();
	while (1)
	{
		map();
		food();
		find();
		system("cls");
		print();
		Sleep(300);
		if (_kbhit())
		{
			control();
			follow();
		}
		else go_on();
		judge_1();
	}
	return 0;
}
Пример #8
0
int main()
{
    int i, j;
    long long flag;
    clrscr();
    printf("Enter the size of the matrix : ");
    scanf("%d", &n);
    for(i = 1; i < n-1; i++)
    {
	for(j = 1; j < n-1; j++)
	{
	    c[i][j] = ' ';
	}
    }
    food();
    c[s][x] = '>';
    while(1)
    {
	clrscr();
	c[g][h] = '$';
	prints();
	if(kbhit())
	{
		hits();
		if(checks())
		{
			printf("\nGAME OVER.\n");
			getch();
			return 0;
		}
		delay(500);
		continue;
	}
	blank();
	c[g][h] = ' ';
	pressed_key();
	eat();
	if(checks())
	{
		printf("\nGAME OVER.\n");
		getch();
		return 0;
	}
	add_length();
	delay(500);
    }
}
void bar() {

  float c = 1.7;
  bool b = c;

  double e = 1.7;
  b = e;

  b = foof(4.0);

  b = foof(c < 1); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}}

  b = food(e < 2); // expected-warning {{implicit conversion turns floating-point number into bool: 'double' to 'bool'}}

  foo(c, b);    // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}}
  foo(c, c);

}
Пример #10
0
int main()
{
	hOut = GetStdHandle(STD_OUTPUT_HANDLE);  //标准输出句柄获得
	SetConsoleCursorInfo(hOut, &cur_info);  //隐藏光标
	while(1)
	{
		system("cls");/*清屏*/
		Snake* head = (Snake*)malloc(sizeof(Snake));
		initialization(head);
		background();
		while(1)
		{
			Sleep(500);
			refresh();
			getkeys();
			run(head);
			eat(head);
			if(door(head)) break;
			food(head);
		}
		release_list(head);
		SetConsoleCursorPosition(hOut, pos);
		SetConsoleTextAttribute(hOut, 0x07);
		system("cls");/*清屏*/
		printf("得分:%d\n空格重新开始\n",scoring);
		while(1)
		{
			int w = getch();
			if(w == ' ')
			{
				break;
			}
			else
			{
				continue;
			}
		}
	}
	return 0;
}
Пример #11
0
void Game::run() {
	float GameTime;
	Gui gui(window);
	Player player(gui.view, START_WIDTH_HEIGHT, START_WIDTH_HEIGHT, &gui);
	Food food(gui, &player);
	AI ai(&gui, &player);
	int exitPressed = 0;
	while (gui.window->isOpen())
	{
		GameTime = clock.getElapsedTime().asMicroseconds();
		GameTime /= (float)GAME_SPEED;
		clock.restart();
		Event event;
		
		while (gui.window->pollEvent(event)){
			if (event.type == Event::Closed) {
				gui.window->close();
			}
		}
		if (Keyboard::isKeyPressed(Keyboard::Escape) || player.gameOver) {
			if (!player.gameOver) gameOver(window, player.score);
			return;
		}
		gui.proceedKeyboardInput(player, GameTime);
		gui.moveOnMouse(player, GameTime);
		player.update(gui.view, gui.scoreText, gui.massText);
		gui.window->clear();
		gui.drawBgAroundPlayer(player);
		food.draw(gui);
		gui.performFoodRenderQueue();
		gui.window->setView(gui.view);
		ai.move(GameTime);
		ai.draw();
		player.draw(*(gui.window));
		gui.window->draw(gui.scoreText);
		gui.window->draw(gui.massText);
		gui.window->display();
	}
}
Пример #12
0
void CPlayState::Update(CGameEngine* game)
{
  sf::Vector2u window_size = game->window.getSize();

	//System Constants
  unsigned WINDOW_WIDTH = window_size.x;
  unsigned WINDOW_HEIGHT = window_size.y;
  unsigned FPS = 60;
  double PI = 3.14159265;

  //Window Settings
  /*
  sf::ContextSettings settings;
  settings.antialiasingLevel = 8;
  sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Runner", sf::Style::Default, settings);
  window.setVerticalSyncEnabled(true);
  */

  sf::RenderWindow& window = game->window;

  double lastFrameTimeStamp = GetTickCount(); // GetTickCount is for Windows only
  double frame_length = 1000/FPS;

  //random generator
  std::default_random_engine rand_generator;
  rand_generator.seed(time(0)); // seed will only change once per second
  std::uniform_int_distribution<unsigned> random_x(25,WINDOW_WIDTH-25);
  std::uniform_int_distribution<unsigned> random_y(25,WINDOW_HEIGHT-25);


//-----------------------------------
  //LOAD SOUND FILES

  sf::SoundBuffer buffer;
  if (!buffer.loadFromFile("eat.wav")) {
    //error loading file
  }
  sf::Sound eatsound;
  eatsound.setBuffer(buffer);
  eatsound.setVolume(30);

  sf::SoundBuffer buffer2;
  if (!buffer2.loadFromFile("gameover.wav")) {
    //error loading file
  }
  sf::Sound gameoversound;
  gameoversound.setBuffer(buffer2);
  gameoversound.setVolume(30);


//-----------------------------------
  //LOAD FONT AND TEXT

  //Set Default font and text settings
  sf::Font font;
  font.loadFromFile("arial.ttf");
  sf::Text default_text_settings;
  default_text_settings.setFont(font);
  default_text_settings.setColor(sf::Color(254,255,221,100));
  default_text_settings.setStyle(sf::Text::Bold);
  default_text_settings.setCharacterSize(24);

  sf::Text displayscore = default_text_settings;
  displayscore.setPosition(500,50);

//--------------------------------------
  //INITIALIZE GAME OBJECTS

  //game variables
  bool collision = false;
  bool game_running = true;
  double snake_speed = game->m_GameMode.getGameSpeed();
  std::string gamespeed = "normal";
  unsigned directional_speed = 10;
  double hitbox = 2.2;
  unsigned score = 0;
  if(game->m_GameMode.getGameSpeed() == .30) {
      gamespeed = "fast";
      directional_speed = 15;
      hitbox = 3.3;
  }

  //snake
  unsigned snake_width = 10;
  unsigned snake_height = 10;
  int snake_length = 0;
  float snake_direction = 0;
  sf::Vector2f snake_coord;

  //snake head
  sf::RectangleShape snake(sf::Vector2f(snake_width*2, snake_height*2));
  snake.setPosition(WINDOW_WIDTH/2, WINDOW_HEIGHT/2);
  snake.setOrigin(snake_width, snake_height);

  //snake head
  sf::Texture snakehead;
  if (!snakehead.loadFromFile("snake_head.gif")) {
                // error...
  }
  snakehead.setSmooth(true);
  snake.setTexture(&snakehead);

  //snake skin
  sf::Texture snaketexture;
  if (!snaketexture.loadFromFile("snake_skin.gif")) {
                // error...
  }
  snaketexture.setSmooth(true);
  //snake.setTexture(&snaketexture);

  //snake body
  std::deque<sf::RectangleShape> snake_body{};
  sf::Vector2f snake_body_coord;

  //store past snake coordinates
  std::queue<sf::Vector2f> snake_history;

  //food
  sf::RectangleShape food(sf::Vector2f(6, 6));
  food.setFillColor(sf::Color(255,153,0));
  food.setPosition(random_x(rand_generator), random_y(rand_generator));
  sf::Vector2f food_coord;

  //background
  sf::Texture bgtexture;
  if (!bgtexture.loadFromFile("grassbackground2.jpg",sf::IntRect(0,0,640,480))) {
  //error
  }
  sf::Sprite bgsprite;
  bgsprite.setTexture(bgtexture);


//---------------------------------------



  //GAME LOOP

    while(game_running)
    {
      double currentTimeStamp = GetTickCount();
      if(currentTimeStamp - lastFrameTimeStamp >= frame_length)
      {

        //EVENT HANDLER
        sf::Event event;
        while (window.pollEvent(event))
        {
          switch (event.type)
          {
            case sf::Event::Closed:
              window.close();
              game->Quit();
              break;
          }
        }

        //USER INPUT HANDLER
        if(game->m_ControlMode.getControlType() == "keyboard") {
          if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
            snake_direction -= directional_speed;// move left
          }
          if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
            snake_direction += directional_speed; // move right
          }
        }

        if(game->m_ControlMode.getControlType() == "mouse") {
          if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
            snake_direction -= directional_speed; // move left
          }
          if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
            snake_direction += directional_speed;// move right
          }
        }


        //GAME LOGIC

        //store past coordinates
        snake_coord = snake.getPosition();
        snake_history.push(snake_coord);

        //limit size of history queue so it doesn't grow too large
        if (snake_history.size() > snake_length + 10)
        {
          snake_history.pop();
        }

        //Create new snake shape
        sf::RectangleShape snake_temp(sf::Vector2f(snake_width, snake_height));
        //snake_temp.setFillColor(sf::Color(128,128,0));
        snake_temp.setPosition(snake_history.back());
        snake_temp.setOrigin(snake_width/2, snake_height/2);
        snake_temp.setTexture(&snaketexture);

        //Add new temporary snake shape to vector
        snake_body.push_back(snake_temp);

        //remove oldest snake shape from snake body if snake did not grow
        if(snake_body.size() > snake_length)
        {
          snake_body.pop_front();
        }

        //change snake head angle
        snake.setRotation(snake_direction);

        //move snake head forward
        snake.move((snake_speed * frame_length)*sin(snake_direction * PI / 180),
                   (snake_speed * frame_length)*-cos(snake_direction * PI / 180));


        //check if snake hit edge of window
        snake_coord = snake.getPosition();
        if(snake_coord.x - snake_width < 0)
        {
          std::cout<< "Game Over: left edge hit" << std::endl;
          collision = true;
        }
        if(snake_coord.y - snake_height < 0)
        {
          std::cout<< "Game Over: top edge hit" << std::endl;
          collision = true;
        }
        if(snake_coord.x + snake_width > WINDOW_WIDTH)
        {
          std::cout<< "Game Over: right edge hit" << std::endl;
          collision = true;
        }
        if(snake_coord.y + snake_height> WINDOW_HEIGHT)
        {
          std::cout<< "Game Over: bottom edge hit" << std::endl;
          collision = true;
        }

        //SURVIVAL GAME MODE
        if(game->m_GameMode.getGameType() == "survival") {
          snake_length++;
        }

        //check if snake ate food
        snake_coord = snake.getPosition();
        food_coord = food.getPosition();

        if ((snake_coord.x <= food_coord.x + snake_width) &&
            (snake_coord.x >= food_coord.x - snake_width) &&
            (snake_coord.y <= food_coord.y + snake_height) &&
            (snake_coord.y >= food_coord.y - snake_height))
        {
          food.setPosition(random_x(rand_generator), random_y(rand_generator));
          snake_length += 5;
          eatsound.play();
          score++;
        }

        //check for snake head and snake body collision
        for(std::deque<sf::RectangleShape>::size_type i = 0; i != snake_body.size(); i++) {
          snake_body_coord = snake_body[i].getPosition();


          if ((snake_coord.x <= snake_body_coord.x + hitbox) &&
              (snake_coord.x >= snake_body_coord.x - hitbox) &&
              (snake_coord.y <= snake_body_coord.y + hitbox) &&
              (snake_coord.y >= snake_body_coord.y - hitbox))   {
                  std::cout << "Game Over: Collision with body piece: #" << i << std::endl;
                  collision = true;
                  break;
          }
        }

        //GAME OVER CONDITION
        if (collision) {
          gameoversound.play();

          //Store the score in the file
          std::ofstream file;
          file.open ("highscores.txt", std::ios_base::app | std::ios_base::out);
          file << game->m_GameMode.getGameType() << "," << gamespeed << "," << score << "\r";
          file.close();

          Sleep(1000);
          game_running = false;
          game->PopState();
          game->PopState();
          break;
        }

        std::ostringstream ss;
        ss << score;
        displayscore.setString( std::string( "Score: "+ss.str() ) );

        //RENDER
        window.clear();

        window.draw(bgsprite);

        for(std::deque<sf::RectangleShape>::size_type i = snake_body.size(); i != 0; --i) {
          window.draw(snake_body[i-1]); //i != vector.size
        }
        window.draw(snake); //head drawn after body so it is on top
        window.draw(food);
        window.draw(displayscore);
        window.display();

        lastFrameTimeStamp = currentTimeStamp;

        //DEBUG
        //std::cout << snake_body.size();

      }

      Sleep(1); // saves some cpu

    } //end core game loop

}
Пример #13
0
void main()
{
	int sss,q,ll,gd=DETECT,p,gm,area,a=(450-(50*5)),d,cat=77,ch,dh,eh,t1,t2,t12,t22,len,cc,hh;
	char *str,*str1,*tim;
	initgraph(&gd,&gm,"");
	p=1;
	front();
	dr:
	viewport();
	q=menu();
	if(q==3)
	{
	     arun:	hh=help();
		if(hh==1)
		{
			how();
			goto arun;
		}
		if(hh==2)
		{
			select();
			goto arun;
		}
		if(hh==3)
		{
			credit();
			goto arun;
		}
		if(hh==4)
		{
			design();
			goto arun;
		}
		if(hh==5)
			goto dr;
	}
	if(q==2)
	{
	 rr:
		ll=sivakumar();
	       if(ll==1)
	       {
			p=m2();

			goto rr;
	       }
	       if(ll==2)
	       {
			a=speed();
			viewport();
			goto rr;
	       }
	       if(ll==3)
	       {
			topscore();
			goto rr;
		}
	       if(ll==4)
		    goto dr;
	}
	if(q==4)
		exit(0);
      if(q==1)
      {
	names();
	hide();
	viewport();
	x[0]=85;
	x[1]=70;
	x[2]=55;
	x[3]=40;
	y[0]=y[1]=y[2]=y[3]=35;
	setcolor(4);
	rectangle(24,19,626,396);
	ra();
	setcolor(15);
	setfillstyle(1,10);
	bar(32,32,43,43);
	area=imagesize(30,30,45,45);
	buff=malloc(area);
	getimage(30,30,45,45,buff);
	putimage(30,30,buff,XOR_PUT);
	setpos(0,0);
	setfillstyle(1,0);
	bar(100,100,500,350);
	prakash(p);
	level=p;
	putimage(40,35,buff,XOR_PUT);
	putimage(55,35,buff,XOR_PUT);
	putimage(70,35,buff,XOR_PUT);
	putimage(85,35,buff,XOR_PUT);
	textcolor(GREEN+BLINK);
	len=0;
	status("Game Play: Arrow keys       Menu: Esc         Pause (or) Play: Others key");
	while(1)
	{

	sss=getpixel(5,5);
	if(sss!=0);
	{
		setfillstyle(SOLID_FILL,0);
		bar(0,0,15,15);
	}
		if(((i-4)%11==0)&&(bon==0)&&(len!=(i-4)))
		{
			len=(i-4);
			gettime(&t);
			bonous();
				bon=1;
			t1=t.ti_sec;
			cc=10;
		}
		gettime(&t);
		if((t1!=t.ti_sec)&&(bon==1))
		{
			cc--;
			t1=t.ti_sec;
			itoa(cc,tim,10);
			setfillstyle(SOLID_FILL,0);
			bar(470,0,530,18);
			outtextxy(500,0,tim);

		}
		if((cc==0)&&(bon==1))
		{
			putimage(xc1,yc1,f2,XOR_PUT);
			bar(470,0,530,18);
			bon=0;
		}
		gotoxy(68,1);
		setcolor(6);
	       itoa(score,str,10);
	       setfillstyle(1,0);
	       settextstyle(3,0,1);
	       if(strcmp(str,str1)!=0)
	       {    bar(80,400,350,450);
		    outtextxy(100,420,"Score : ");
		    outtextxy(180,420,str);
		    strcpy(str1,str);
	       }
		if(kbhit())
		{
		       //	ch=getch();
			dh=getch();
			cat=dh;
		}
		else
		{
			arrange(x,y,i);
			if(set==0)
				food();
			if(cat!=dupli)
				cat=lock(cat,dupli);
			switch(cat)
			{
				case 72:
					     if(y[1]==20)
						  y[0]=380;
					     else
						  y[0]=y[1]-15;
					     x[0]=x[1];
					     d=getpixel(x[0]+8,y[0]+8);
					     if((d==10)||(d==14))
						doctor();
					     if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
					     else if(d==15)
					     {
						i++;
						set=0;
						sound(800);
						delay(40);
						score+=bb;
						nosound();
						putimage(x[0],y[0],buff,XOR_PUT);
					     }
					     else
					     {
						 putimage(x[0],y[0],buff,XOR_PUT);
						 putimage(x[i-1],y[i-1],buff,XOR_PUT);
					     }
						delay(a);
				     break;
				case 80:
				     if(y[1]==380)
					  y[0]=20;
				     else
					  y[0]=y[1]+15;
				     x[0]=x[1];
				      d=getpixel(x[0]+8,y[0]+8);
				      if((d==10)||(d==14))
					doctor();
					     if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
				      else if(d==15)
					     {
						i++;
						score+=bb;
						sound(800);
						delay(40);
						set=0;
						nosound();
						putimage(x[0],y[0],buff,XOR_PUT);
					     }
				       else
				      {
					     putimage(x[0],y[0],buff,XOR_PUT);
					     putimage(x[i-1],y[i-1],buff,XOR_PUT);
				      }
				     delay(a);
				     break;
				case 75:
				     if(x[1]==25)
					  x[0]=610;
				     else
					  x[0]=x[1]-15;
				     y[0]=y[1];
				     d=getpixel(x[0]+8,y[0]+8);
					if((d==10)||(d==14))
						doctor();
					     if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
					else if(d==15)
					  {
						i++;
						sound(800);
						delay(40);
						set=0;
						nosound();
						score+=bb;
						putimage(x[0],y[0],buff,XOR_PUT);
					  }
					  else
					  {
					     putimage(x[0],y[0],buff,XOR_PUT);
					     putimage(x[i-1],y[i-1],buff,XOR_PUT);
					  }
				      delay(a);
				 break;
				case 77:
				     if(x[1]==610)
					  x[0]=25;
				     else
					  x[0]=x[1]+15;
				     y[0]=y[1];
				     d=getpixel(x[0]+8,y[0]+8);
				      if((d==10)||(d==14))
					doctor();
					    if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
					else if(d==15)
					    {
						i++;
						set=0;
						sound(800);
						delay(40);
						score+=bb;
						nosound();
						putimage(x[0],y[0],buff,XOR_PUT);
					     }
					     else
					     {
						     putimage(x[0],y[0],buff,XOR_PUT);
						     putimage(x[i-1],y[i-1],buff,XOR_PUT);
					     }
				       delay(a);
					break;
				case 27:
					goto dx;
				//	break;
			}
			dupli=cat;
		}
    }
     }
     dx:
     call();
}
Пример #14
0
void CSnakeView::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	KillTimer(1); //停掉OnCreate中的定时器
	CString score;
	score.Format(_T("分数: %d"), snakeLength-4); //游戏分数为蛇的节点数-蛇出生时的节点数
	AliveOrDie();	
	
	//创建设备描述表
	CDC *pDC, hDC;
	pDC = GetDC();	
	hDC.CreateCompatibleDC(NULL);
	CBitmap hBitmap, *pOldBitmap ;
	hBitmap.CreateCompatibleBitmap(pDC, 1000, 1000);
	pOldBitmap = hDC.SelectObject(&hBitmap);

	hDC.FillSolidRect(0, 0, 1000, 1000, RGB(255, 255, 255)); //设定白色区域范围
	hDC.TextOut(550, 200, score);  //在坐标(500,200)处输出游戏分数
	hDC.Rectangle(CRect(90, 90, 520, 520)); //设定外矩形框
	hDC.Rectangle(CRect(100, 100, 510, 510)); 

	if(gameStart == 1)  //游戏处于运行状态
	{
		b.x = a[0].x;
		b.y = a[0].y;

		//第0个节点的变化
		if (move == right)		//向右移动
		{
			a[0].x = a[0].x + 10;
		}
		else if (move == up)	//向上移动
		{
			a[0].y = a[0].y - 10;
		}
		else if (move == left)	//向左移动
		{
			a[0].x = a[0].x - 10;
		}
		else if (move == down)	//向下移动
		{
			a[0].y = a[0].y + 10;
		}

				//除第0、1个节点之外其它所有节点的变化
		for (int i = 1; i < snakeLength - 1; i++)
		{
			a[snakeLength - i].x = a[snakeLength - 1 - i ].x;
			a[snakeLength - i].y = a[snakeLength - 1 - i ].y;
		}

		//第1个节点的变化
		a[1].x = b.x;
		a[1].y = b.y;

		CBrush head(RGB(255, 0, 0));  //将蛇的头节点设置成红色
		hDC.SelectObject(head);
		rect = new CRect(a[0].x, a[0].y, a[0].x+10, a[0].y+10); //头节点的边框
		hDC.Rectangle(rect);
		for(int i = 1; i < snakeLength; i++)
		{
			CBrush body(RGB(255, 255, 0)); //将蛇的身体节点设置成黄色
			hDC.SelectObject(body);
			rect = new CRect(a[i].x, a[i].y, a[i].x+10, a[i].y+10); //身体各节点的边框
			hDC.Rectangle(rect);
		}

		if(a[0].x == xfood && a[0].y == yfood) //蛇吃了食物
		{
			snakeLength++; //蛇的长度加1
			foodOrNot = 1; //产生新食物
			//蛇新增加的尾节点与原先的尾节点(现在的倒数第二个节点)的位置重合
			//再移动一下才能看到蛇的节点加1
			a[snakeLength-1].x = a[snakeLength-2].x;
			a[snakeLength-1].y = a[snakeLength-2].y;
		}

		if(foodOrNot == 1)
		{
			int x1 = int(Random(10,50));  // 产生的随机值在11~51之间
			int y1 = int(Random(10,50));
			xfood = x1*10;
			yfood = y1*10;
			for(int i=0; i<snakeLength; i++)
			{
				if(xfood==a[i].x && yfood==a[i].y)
				{
					//如果食物的位置恰好在蛇的某个节点的位置,重新设置食物的位置
					int x2 = int(Random(10,50));
					int y2 = int(Random(10,50));
					xfood = x2*10;
					yfood = y2*10;
				}
			}
			foodOrNot = 0;
		}
		CBrush food(RGB(0,255,0)); //食物的颜色设置为绿色
		hDC.SelectObject(food);
		hDC.Rectangle(xfood, yfood, xfood+10, yfood+10);  //设置食物的边框
	}

	pDC->BitBlt(0, 0, 1000, 1000, &hDC, 0, 0, SRCCOPY);
	hBitmap.DeleteObject();
	hDC.DeleteDC();
	OnDraw(pDC);

	SetTimer(1, difficulty*30, NULL); //将游戏难度与移动时间相关

	CView::OnTimer(nIDEvent);
}
Пример #15
0
bool game::dump_stats( const std::string &what, dump_mode mode,
                       const std::vector<std::string> &opts )
{
    try {
        loading_ui ui( false );
        load_core_data( ui );
        load_packs( _( "Loading content packs" ), { mod_id( "dda" ) }, ui );
        DynamicDataLoader::get_instance().finalize_loaded_data( ui );
    } catch( const std::exception &err ) {
        std::cerr << "Error loading data from json: " << err.what() << std::endl;
        return false;
    }

    std::vector<std::string> header;
    std::vector<std::vector<std::string>> rows;

    int scol = 0; // sorting column

    std::map<std::string, standard_npc> test_npcs;
    test_npcs[ "S1" ] = standard_npc( "S1", { "gloves_survivor", "mask_lsurvivor" }, 4, 8, 10, 8,
                                      10 /* DEX 10, PER 10 */ );
    test_npcs[ "S2" ] = standard_npc( "S2", { "gloves_fingerless", "sunglasses" }, 4, 8, 8, 8,
                                      10 /* PER 10 */ );
    test_npcs[ "S3" ] = standard_npc( "S3", { "gloves_plate", "helmet_plate" },  4, 10, 8, 8,
                                      8 /* STAT 10 */ );
    test_npcs[ "S4" ] = standard_npc( "S4", {}, 0, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
    test_npcs[ "S5" ] = standard_npc( "S5", {}, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
    test_npcs[ "S6" ] = standard_npc( "S6", { "gloves_hsurvivor", "mask_hsurvivor" }, 4, 8, 10, 8,
                                      10 /* DEX 10, PER 10 */ );

    std::map<std::string, item> test_items;
    test_items[ "G1" ] = item( "glock_19" ).ammo_set( "9mm" );
    test_items[ "G2" ] = item( "hk_mp5" ).ammo_set( "9mm" );
    test_items[ "G3" ] = item( "ar15" ).ammo_set( "223" );
    test_items[ "G4" ] = item( "remington_700" ).ammo_set( "270" );
    test_items[ "G4" ].emplace_back( "rifle_scope" );

    if( what == "AMMO" ) {
        header = {
            "Name", "Ammo", "Volume", "Weight", "Stack",
            "Range", "Dispersion", "Recoil", "Damage", "Pierce"
        };
        auto dump = [&rows]( const item & obj ) {
            // a common task is comparing ammo by type so ammo has multiple repeat the entry
            for( const auto &e : obj.type->ammo->type ) {
                std::vector<std::string> r;
                r.push_back( obj.tname( 1, false ) );
                r.push_back( e.str() );
                r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) );
                r.push_back( to_string( to_gram( obj.weight() ) ) );
                r.push_back( to_string( obj.type->stack_size ) );
                r.push_back( to_string( obj.type->ammo->range ) );
                r.push_back( to_string( obj.type->ammo->dispersion ) );
                r.push_back( to_string( obj.type->ammo->recoil ) );
                damage_instance damage = obj.type->ammo->damage;
                r.push_back( to_string( damage.total_damage() ) );
                r.push_back( to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );
                rows.push_back( r );
            }
        };
        for( const itype *e : item_controller->all() ) {
            if( e->ammo ) {
                dump( item( e, calendar::turn, item::solitary_tag {} ) );
            }
        }

    } else if( what == "ARMOR" ) {
        header = {
            "Name", "Encumber (fit)", "Warmth", "Weight", "Storage", "Coverage", "Bash", "Cut", "Acid", "Fire"
        };
        auto dump = [&rows]( const item & obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( 1, false ) );
            r.push_back( to_string( obj.get_encumber() ) );
            r.push_back( to_string( obj.get_warmth() ) );
            r.push_back( to_string( to_gram( obj.weight() ) ) );
            r.push_back( to_string( obj.get_storage() / units::legacy_volume_factor ) );
            r.push_back( to_string( obj.get_coverage() ) );
            r.push_back( to_string( obj.bash_resist() ) );
            r.push_back( to_string( obj.cut_resist() ) );
            r.push_back( to_string( obj.acid_resist() ) );
            r.push_back( to_string( obj.fire_resist() ) );
            rows.push_back( r );
        };

        body_part bp = opts.empty() ? num_bp : get_body_part_token( opts.front() );

        for( const itype *e : item_controller->all() ) {
            if( e->armor ) {
                item obj( e );
                if( bp == num_bp || obj.covers( bp ) ) {
                    if( obj.has_flag( "VARSIZE" ) ) {
                        obj.item_tags.insert( "FIT" );
                    }
                    dump( obj );
                }
            }
        }

    } else if( what == "EDIBLE" ) {
        header = {
            "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy"
        };
        for( const auto &v : vitamin::all() ) {
            header.push_back( v.second.name() );
        }
        auto dump = [&rows]( const item & obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( false ) );
            r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) );
            r.push_back( to_string( to_gram( obj.weight() ) ) );
            r.push_back( to_string( obj.type->stack_size ) );
            r.push_back( to_string( obj.type->comestible->get_calories() ) );
            r.push_back( to_string( obj.type->comestible->quench ) );
            r.push_back( to_string( obj.type->comestible->healthy ) );
            auto vits = g->u.vitamins_from( obj );
            for( const auto &v : vitamin::all() ) {
                r.push_back( to_string( vits[ v.first ] ) );
            }
            rows.push_back( r );
        };

        for( const itype *e : item_controller->all() ) {
            item food( e, calendar::turn, item::solitary_tag {} );

            if( food.is_food() && g->u.can_eat( food ).success() ) {
                dump( food );
            }
        }

    } else if( what == "GUN" ) {
        header = {
            "Name", "Ammo", "Volume", "Weight", "Capacity",
            "Range", "Dispersion", "Effective recoil", "Damage", "Pierce",
            "Aim time", "Effective range", "Snapshot range", "Max range"
        };

        std::set<std::string> locations;
        for( const itype *e : item_controller->all() ) {
            if( e->gun ) {
                std::transform( e->gun->valid_mod_locations.begin(),
                                e->gun->valid_mod_locations.end(),
                                std::inserter( locations, locations.begin() ),
                []( const std::pair<gunmod_location, int> &q ) {
                    return q.first.name();
                } );
            }
        }
        for( const auto &e : locations ) {
            header.push_back( e );
        }

        auto dump = [&rows, &locations]( const standard_npc & who, const item & obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( 1, false ) );
            r.push_back( obj.ammo_type() ? obj.ammo_type().str() : "" );
            r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) );
            r.push_back( to_string( to_gram( obj.weight() ) ) );
            r.push_back( to_string( obj.ammo_capacity() ) );
            r.push_back( to_string( obj.gun_range() ) );
            r.push_back( to_string( obj.gun_dispersion() ) );
            r.push_back( to_string( obj.gun_recoil( who ) ) );
            damage_instance damage = obj.gun_damage();
            r.push_back( to_string( damage.total_damage() ) );
            r.push_back( to_string( damage.empty() ? 0 : ( *damage.begin() ).res_pen ) );

            r.push_back( to_string( who.gun_engagement_moves( obj ) ) );

            for( const auto &e : locations ) {
                const auto &vml = obj.type->gun->valid_mod_locations;
                const auto iter = vml.find( e );
                r.push_back( to_string( iter != vml.end() ? iter->second : 0 ) );
            }
            rows.push_back( r );
        };
        for( const itype *e : item_controller->all() ) {
            if( e->gun ) {
                item gun( e );
                if( !gun.magazine_integral() ) {
                    gun.emplace_back( gun.magazine_default() );
                }
                gun.ammo_set( gun.ammo_type()->default_ammotype(), gun.ammo_capacity() );

                dump( test_npcs[ "S1" ], gun );

                if( gun.type->gun->barrel_length > 0 ) {
                    gun.emplace_back( "barrel_small" );
                    dump( test_npcs[ "S1" ], gun );
                }
            }
        }

    } else if( what == "RECIPE" ) {

        // optionally filter recipes to include only those using specified skills
        recipe_subset dict;
        for( const auto &r : recipe_dict ) {
            if( opts.empty() || std::any_of( opts.begin(), opts.end(), [&r]( const std::string & s ) {
            if( r.second.skill_used == skill_id( s ) && r.second.difficulty > 0 ) {
                    return true;
                }
                auto iter = r.second.required_skills.find( skill_id( s ) );
                return iter != r.second.required_skills.end() && iter->second > 0;
            } ) ) {
                dict.include( &r.second );
            }
        }

        // only consider skills that are required by at least one recipe
        std::vector<Skill> sk;
        std::copy_if( Skill::skills.begin(), Skill::skills.end(),
        std::back_inserter( sk ), [&dict]( const Skill & s ) {
            return std::any_of( dict.begin(), dict.end(), [&s]( const recipe * r ) {
                return r->skill_used == s.ident() ||
                       r->required_skills.find( s.ident() ) != r->required_skills.end();
            } );
        } );

        header = { "Result" };

        for( const auto &e : sk ) {
            header.push_back( e.ident().str() );
        }

        for( const recipe *e : dict ) {
            std::vector<std::string> r;
            r.push_back( e->result_name() );
            for( const auto &s : sk ) {
                if( e->skill_used == s.ident() ) {
                    r.push_back( to_string( e->difficulty ) );
                } else {
                    auto iter = e->required_skills.find( s.ident() );
                    r.push_back( to_string( iter != e->required_skills.end() ? iter->second : 0 ) );
                }
            }
            rows.push_back( r );
        }

    } else if( what == "VEHICLE" ) {
        header = {
            "Name", "Weight (empty)", "Weight (fueled)",
            "Max velocity (mph)", "Safe velocity (mph)", "Acceleration (mph/turn)",
            "Mass coeff %", "Aerodynamics coeff %", "Friction coeff %",
            "Traction coeff % (grass)"
        };
        auto dump = [&rows]( const vproto_id & obj ) {
            auto veh_empty = vehicle( obj, 0, 0 );
            auto veh_fueled = vehicle( obj, 100, 0 );

            std::vector<std::string> r;
            r.push_back( veh_empty.name );
            r.push_back( to_string( to_kilogram( veh_empty.total_mass() ) ) );
            r.push_back( to_string( to_kilogram( veh_fueled.total_mass() ) ) );
            r.push_back( to_string( veh_fueled.max_velocity() / 100 ) );
            r.push_back( to_string( veh_fueled.safe_velocity() / 100 ) );
            r.push_back( to_string( veh_fueled.acceleration() / 100 ) );
            r.push_back( to_string( ( int )( 100 * veh_fueled.k_mass() ) ) );
            r.push_back( to_string( ( int )( 100 * veh_fueled.k_aerodynamics() ) ) );
            r.push_back( to_string( ( int )( 100 * veh_fueled.k_friction() ) ) );
            r.push_back( to_string( ( int )( 100 * veh_fueled.k_traction( veh_fueled.wheel_area(
                                                 false ) / 2.0f ) ) ) );
            rows.push_back( r );
        };
        for( auto &e : vehicle_prototype::get_all() ) {
            dump( e );
        }

    } else if( what == "VPART" ) {
        header = {
            "Name", "Location", "Weight", "Size"
        };
        auto dump = [&rows]( const vpart_info & obj ) {
            std::vector<std::string> r;
            r.push_back( obj.name() );
            r.push_back( obj.location );
            r.push_back( to_string( int( ceil( to_gram( item( obj.item ).weight() ) / 1000.0 ) ) ) );
            r.push_back( to_string( obj.size / units::legacy_volume_factor ) );
            rows.push_back( r );
        };
        for( const auto &e : vpart_info::all() ) {
            dump( e.second );
        }

    } else {
        std::cerr << "unknown argument: " << what << std::endl;
        return false;
    }

    rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string> &e ) {
        return e.empty();
    } ), rows.end() );

    if( scol >= 0 ) {
        std::sort( rows.begin(), rows.end(), [&scol]( const std::vector<std::string> &lhs,
        const std::vector<std::string> &rhs ) {
            return lhs[ scol ] < rhs[ scol ];
        } );
    }

    rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() );

    switch( mode ) {
        case dump_mode::TSV:
            rows.insert( rows.begin(), header );
            for( const auto &r : rows ) {
                std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) );
                std::cout << r.back() << "\n";
            }
            break;

        case dump_mode::HTML:
            std::cout << "<table>";

            std::cout << "<thead>";
            std::cout << "<tr>";
            for( const auto &col : header ) {
                std::cout << "<th>" << col << "</th>";
            }
            std::cout << "</tr>";
            std::cout << "</thead>";

            std::cout << "<tdata>";
            for( const auto &r : rows ) {
                std::cout << "<tr>";
                for( const auto &col : r ) {
                    std::cout << "<td>" << col << "</td>";
                }
                std::cout << "</tr>";
            }
            std::cout << "</tdata>";

            std::cout << "</table>";
            break;
    }

    return true;
}
Пример #16
0
Файл: q.c Проект: ishaj/snake
void display2()
{
  if((xa>=inx+50) ||(xa<=iny-50)||(ya>=inx) ||(ya<=iny))
  	{	
		glClear(GL_COLOR_BUFFER_BIT);
		pointsz(1.0);
		glBegin(GL_POINTS);
		//show();
		glColor3f(0.0,0.0,0.0);
		view();
		//call3();
		glutSwapBuffers();
		glEnd();
       	        glFlush();	
	}
  else
 {
  glColor3f(0.0,0.0,1.0);
  pointsz(1.0);
  view();
  pointsz(4.0);
  glBegin(GL_POINTS);
  dda(xa,ya,xb,yb);//snake
	  if(start == 0) 
	  {
		   glColor3f(1.0,1.0,1.0);
		   food();
		   start++;
	  }
	if((((xf-20) <= xa) && ((xf +20) >= xa) && ((yf-20) <= ya) && ((yf +20) >= ya)))
		 {
	score++;
		printf("%d\n",score);
	tailgrow(xf,yf,xa,ya,xb,yb);
	} 
  glutSpecialFunc(specialKeys);
  //sleep(1);
  pointsz(4.0);
	if(xa==xb)
	{
 		if(ya>yb)
 		{
 			 ya=ya+i;
 			 yb=yb+i;
 		}
 		else
 		{
 			 ya=ya-i;
 			 yb=yb-i;
 		}
	}
	else if(ya==yb)
	{
		 if(xa>xb)
		 {
			  xa=xa+i;
			  xb=xb+i;
		 }
		 else
		 {
  			xa=xa-i;
  			xb=xb-i;
 		}	
	}	
  	glBegin(GL_POINTS);
  	dda(xa,ya,xb,yb);
  	glEnd();
  	glFlush();
  	glutPostRedisplay();
  	pointsz(6.0);
	glColor3f(1.0,1.0,1.0);
  	glBegin(GL_POINTS);
  	SetPixel(xf,yf);
	pointsz(1.0);
  	glFlush();
	}
}
Пример #17
0
bool game::dump_stats( const std::string& what, dump_mode mode, const std::vector<std::string> &opts )
{
    try {
        load_core_data();
    } catch( const std::exception &err ) {
        std::cerr << "Error loading data from json: " << err.what() << std::endl;
        return false;
    }
    DynamicDataLoader::get_instance().finalize_loaded_data();

    std::vector<std::string> header;
    std::vector<std::vector<std::string>> rows;

    int scol = 0; // sorting column

    std::map<std::string, standard_npc> test_npcs;
    test_npcs[ "S1" ] = standard_npc( "S1", { "gloves_survivor", "mask_lsurvivor" }, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
    test_npcs[ "S2" ] = standard_npc( "S2", { "gloves_fingerless", "sunglasses" }, 4, 8, 8, 8, 10 /* PER 10 */ );
    test_npcs[ "S3" ] = standard_npc( "S3", { "gloves_plate", "helmet_plate" },  4, 10, 8, 8, 8 /* STAT 10 */ );
    test_npcs[ "S4" ] = standard_npc( "S4", {}, 0, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
    test_npcs[ "S5" ] = standard_npc( "S5", {}, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );
    test_npcs[ "S6" ] = standard_npc( "S6", { "gloves_hsurvivor", "mask_hsurvivor" }, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ );

    std::map<std::string, item> test_items;
    test_items[ "G1" ] = item( "glock_19" ).ammo_set( "9mm" );
    test_items[ "G2" ] = item( "hk_mp5" ).ammo_set( "9mm" );
    test_items[ "G3" ] = item( "ar15" ).ammo_set( "223" );
    test_items[ "G4" ] = item( "remington_700" ).ammo_set( "270" );
    test_items[ "G4" ].emplace_back( "rifle_scope" );

    if( what == "AMMO" ) {
        header = {
            "Name", "Ammo", "Volume", "Weight", "Stack",
            "Range", "Dispersion", "Recoil", "Damage", "Pierce"
        };
        auto dump = [&rows]( const item& obj ) {
            // a common task is comparing ammo by type so ammo has multiple repeat the entry
            for( const auto &e : obj.type->ammo->type ) {
                std::vector<std::string> r;
                r.push_back( obj.tname( 1, false ) );
                r.push_back( e.str() );
                r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) );
                r.push_back( to_string( obj.weight() ) );
                r.push_back( to_string( obj.type->stack_size ) );
                r.push_back( to_string( obj.type->ammo->range ) );
                r.push_back( to_string( obj.type->ammo->dispersion ) );
                r.push_back( to_string( obj.type->ammo->recoil ) );
                r.push_back( to_string( obj.type->ammo->damage ) );
                r.push_back( to_string( obj.type->ammo->pierce ) );
                rows.push_back( r );
            }
        };
        for( auto& e : item_controller->get_all_itypes() ) {
            if( e.second.ammo ) {
                dump( item( e.first, calendar::turn, item::solitary_tag {} ) );
            }
        }

    } else if( what == "ARMOR" ) {
        header = {
            "Name", "Encumber (fit)", "Warmth", "Weight", "Storage", "Coverage", "Bash", "Cut", "Acid", "Fire"
        };
        auto dump = [&rows]( const item& obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( 1, false ) );
            r.push_back( to_string( obj.get_encumber() ) );
            r.push_back( to_string( obj.get_warmth() ) );
            r.push_back( to_string( obj.weight() ) );
            r.push_back( to_string( obj.get_storage() / units::legacy_volume_factor ) );
            r.push_back( to_string( obj.get_coverage() ) );
            r.push_back( to_string( obj.bash_resist() ) );
            r.push_back( to_string( obj.cut_resist() ) );
            r.push_back( to_string( obj.acid_resist() ) );
            r.push_back( to_string( obj.fire_resist() ) );
            rows.push_back( r );
        };

        body_part bp = opts.empty() ? num_bp : get_body_part_token( opts.front() );

        for( auto& e : item_controller->get_all_itypes() ) {
            if( e.second.armor ) {
                item obj( e.first );
                if( bp == num_bp || obj.covers( bp ) ) {
                    if( obj.has_flag( "VARSIZE" ) ) {
                        obj.item_tags.insert( "FIT" );
                    }
                    dump( obj );
                }
            }
        }

    } else if( what == "EDIBLE" ) {
        header = {
            "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy"
        };
        for( const auto& v : vitamin::all() ) {
             header.push_back( v.second.name() );
        }
        auto dump = [&rows,&test_npcs]( const item& obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( false ) );
            r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) );
            r.push_back( to_string( obj.weight() ) );
            r.push_back( to_string( obj.type->stack_size ) );
            r.push_back( to_string( obj.type->comestible->get_calories() ) );
            r.push_back( to_string( obj.type->comestible->quench ) );
            r.push_back( to_string( obj.type->comestible->healthy ) );
            auto vits = g->u.vitamins_from( obj );
            for( const auto& v : vitamin::all() ) {
                 r.push_back( to_string( vits[ v.first ] ) );
            }
            rows.push_back( r );
        };
        for( auto& e : item_controller->get_all_itypes() ) {
            if( e.second.comestible &&
                ( e.second.comestible->comesttype == "FOOD" ||
                  e.second.comestible->comesttype == "DRINK" ) ) {

                item food( e.first, calendar::turn, item::solitary_tag {} );
                if( g->u.can_eat( food, false, true ) == EDIBLE ) {
                    dump( food );
                }
            }
        }

    } else if( what == "GUN" ) {
        header = {
            "Name", "Ammo", "Volume", "Weight", "Capacity",
            "Range", "Dispersion", "Effective recoil", "Damage", "Pierce",
            "Aim time", "Effective range", "Snapshot range", "Max range"
        };

        std::set<std::string> locations;
        for( const auto& e : item_controller->get_all_itypes() ) {
            if( e.second.gun ) {
                std::transform( e.second.gun->valid_mod_locations.begin(),
                                e.second.gun->valid_mod_locations.end(),
                                std::inserter( locations, locations.begin() ),
                                []( const std::pair<std::string, int>& e ) { return e.first; } );
            }
        }
        for( const auto &e : locations ) {
            header.push_back( e );
        }

        auto dump = [&rows,&locations]( const standard_npc &who, const item& obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( 1, false ) );
            r.push_back( obj.ammo_type() ? obj.ammo_type().str() : "" );
            r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) );
            r.push_back( to_string( obj.weight() ) );
            r.push_back( to_string( obj.ammo_capacity() ) );
            r.push_back( to_string( obj.gun_range() ) );
            r.push_back( to_string( obj.gun_dispersion() ) );
            r.push_back( to_string( obj.gun_recoil( who ) ) );
            r.push_back( to_string( obj.gun_damage() ) );
            r.push_back( to_string( obj.gun_pierce() ) );

            r.push_back( to_string( who.gun_engagement_moves( obj ) ) );

            r.push_back( string_format( "%.1f", who.gun_engagement_range( obj, player::engagement::effective ) ) );
            r.push_back( string_format( "%.1f", who.gun_engagement_range( obj, player::engagement::snapshot ) ) );
            r.push_back( string_format( "%.1f", who.gun_engagement_range( obj, player::engagement::maximum ) ) );

            for( const auto &e : locations ) {
                r.push_back( to_string( obj.type->gun->valid_mod_locations[ e ] ) );
            }
            rows.push_back( r );
        };
        for( const auto& e : item_controller->get_all_itypes() ) {
            if( e.second.gun ) {
                item gun( e.first );
                if( !gun.magazine_integral() ) {
                    gun.emplace_back( gun.magazine_default() );
                }
                gun.ammo_set( default_ammo( gun.ammo_type() ), gun.ammo_capacity() );

                dump( test_npcs[ "S1" ], gun );

                if( gun.type->gun->barrel_length > 0 ) {
                    gun.emplace_back( "barrel_small" );
                    dump( test_npcs[ "S1" ], gun );
                }
            }
        }

    } else if( what == "VEHICLE" ) {
        header = {
            "Name", "Weight (empty)", "Weight (fueled)",
            "Max velocity (mph)", "Safe velocity (mph)", "Acceleration (mph/turn)",
            "Mass coeff %", "Aerodynamics coeff %", "Friction coeff %",
            "Traction coeff % (grass)"
        };
        auto dump = [&rows]( const vproto_id& obj ) {
            auto veh_empty = vehicle( obj, 0, 0 );
            auto veh_fueled = vehicle( obj, 100, 0 );

            std::vector<std::string> r;
            r.push_back( veh_empty.name );
            r.push_back( to_string( veh_empty.total_mass() ) );
            r.push_back( to_string( veh_fueled.total_mass() ) );
            r.push_back( to_string( veh_fueled.max_velocity() / 100 ) );
            r.push_back( to_string( veh_fueled.safe_velocity() / 100 ) );
            r.push_back( to_string( veh_fueled.acceleration() / 100 ) );
            r.push_back( to_string( (int)( 100 * veh_fueled.k_mass() ) ) );
            r.push_back( to_string( (int)( 100 * veh_fueled.k_aerodynamics() ) ) );
            r.push_back( to_string( (int)( 100 * veh_fueled.k_friction() ) ) );
            r.push_back( to_string( (int)( 100 * veh_fueled.k_traction( veh_fueled.wheel_area( false ) / 2.0f ) ) ) );
            rows.push_back( r );
        };
        for( auto& e : vehicle_prototype::get_all() ) {
            dump( e );
        }

    } else if( what == "VPART" ) {
        header = {
            "Name", "Location", "Weight", "Size"
        };
        auto dump = [&rows]( const vpart_info &obj ) {
            std::vector<std::string> r;
            r.push_back( obj.name() );
            r.push_back( obj.location );
            r.push_back( to_string( int( ceil( item( obj.item ).weight() / 1000.0 ) ) ) );
            r.push_back( to_string( obj.size / units::legacy_volume_factor ) );
            rows.push_back( r );
        };
        for( const auto &e : vpart_info::all() ) {
            dump( e.second );
        }

    } else if( what == "AIMING" ) {
        scol = -1; // unsorted output so graph columns have predictable ordering

        const int cycles = 1400;

        header = { "Name" };
        for( int i = 0; i <= cycles; ++i ) {
            header.push_back( to_string( i ) );
        }

        auto dump = [&rows]( const standard_npc &who, const item &gun) {
            std::vector<std::string> r( 1, string_format( "%s %s", who.get_name().c_str(), gun.tname().c_str() ) );
            double penalty = MIN_RECOIL;
            for( int i = 0; i <= cycles; ++i ) {
                penalty -= who.aim_per_move( gun, penalty );
                r.push_back( string_format( "%.2f", who.gun_current_range( gun, penalty ) ) );
            }
            rows.push_back( r );
        };

        if( opts.empty() ) {
            dump( test_npcs[ "S1" ], test_items[ "G1" ] );
            dump( test_npcs[ "S1" ], test_items[ "G2" ] );
            dump( test_npcs[ "S1" ], test_items[ "G3" ] );
            dump( test_npcs[ "S1" ], test_items[ "G4" ] );

        } else {
            for( const auto &str : opts ) {
                auto idx = str.find( ':' );
                if( idx == std::string::npos ) {
                    std::cerr << "cannot parse test case: " << str << std::endl;
                    return false;
                }
                auto test = std::make_pair( test_npcs.find( str.substr( 0, idx ) ),
                                            test_items.find( str.substr( idx + 1 ) ) );

                if( test.first == test_npcs.end() || test.second == test_items.end() ) {
                    std::cerr << "invalid test case: " << str << std::endl;
                    return false;
                }

                dump( test.first->second, test.second->second );
            }
        }

    } else if( what == "EXPLOSIVE" ) {
        header = {
            // @todo Should display more useful data: shrapnel damage, safe range
            "Name", "Power", "Power at 5 tiles", "Power halves at", "Shrapnel count", "Shrapnel mass"
        };

        auto dump = [&rows]( const std::string &name, const explosion_data &ex ) {
            std::vector<std::string> r;
            r.push_back( name );
            r.push_back( to_string( ex.power ) );
            r.push_back( string_format( "%.1f", ex.power_at_range( 5.0f ) ) );
            r.push_back( string_format( "%.1f", ex.expected_range( 0.5f ) ) );
            r.push_back( to_string( ex.shrapnel.count ) );
            r.push_back( to_string( ex.shrapnel.mass ) );
            rows.push_back( r );
        };
        for( const auto& e : item_controller->get_all_itypes() ) {
            const auto &itt = e.second;
            const auto use = itt.get_use( "explosion" );
            if( use != nullptr && use->get_actor_ptr() != nullptr ) {
                const auto actor = dynamic_cast<const explosion_iuse *>( use->get_actor_ptr() );
                if( actor != nullptr ) {
                    dump( itt.nname( 1 ), actor->explosion );
                }
            }

            auto c_ex = dynamic_cast<const explosion_iuse *>( itt.countdown_action.get_actor_ptr() );
            if( c_ex != nullptr ) {
                dump( itt.nname( 1 ), c_ex->explosion );
            }
        }

    } else {
        std::cerr << "unknown argument: " << what << std::endl;
        return false;
    }

    rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string>& e ) {
        return e.empty();
    } ), rows.end() );

    if( scol >= 0 ) {
        std::sort( rows.begin(), rows.end(), [&scol]( const std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
            return lhs[ scol ] < rhs[ scol ];
        } );
    }

    rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() );

    switch( mode ) {
        case dump_mode::TSV:
            rows.insert( rows.begin(), header );
            for( const auto& r : rows ) {
                std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) );
                std::cout << r.back() << "\n";
            }
            break;

        case dump_mode::HTML:
            std::cout << "<table>";

            std::cout << "<thead>";
            std::cout << "<tr>";
            for( const auto& col : header ) {
                std::cout << "<th>" << col << "</th>";
            }
            std::cout << "</tr>";
            std::cout << "</thead>";

            std::cout << "<tdata>";
            for( const auto& r : rows ) {
                std::cout << "<tr>";
                for( const auto& col : r ) {
                    std::cout << "<td>" << col << "</td>";
                }
                std::cout << "</tr>";
            }
            std::cout << "</tdata>";

            std::cout << "</table>";
            break;
    }

    return true;
}
Пример #18
0
void game::dump_stats( const std::string& what, dump_mode mode )
{
    load_core_data();
    DynamicDataLoader::get_instance().finalize_loaded_data();

    std::vector<std::string> header;
    std::vector<std::vector<std::string>> rows;

    if( what == "AMMO" ) {
        header = {
            "Name", "Ammo", "Volume", "Weight", "Stack",
            "Range", "Dispersion", "Recoil", "Damage", "Pierce"
        };
        auto dump = [&rows]( const item& obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( false ) );
            r.push_back( obj.type->ammo->type );
            r.push_back( std::to_string( obj.volume() ) );
            r.push_back( std::to_string( obj.weight() ) );
            r.push_back( std::to_string( obj.type->stack_size ) );
            r.push_back( std::to_string( obj.type->ammo->range ) );
            r.push_back( std::to_string( obj.type->ammo->dispersion ) );
            r.push_back( std::to_string( obj.type->ammo->recoil ) );
            r.push_back( std::to_string( obj.type->ammo->damage ) );
            r.push_back( std::to_string( obj.type->ammo->pierce ) );
            rows.push_back( r );
        };
        for( auto& e : item_controller->get_all_itypes() ) {
            if( e.second->ammo ) {
                dump( item( e.first, calendar::turn, item::solitary_tag {} ) );
            }
        }

    } else if( what == "EDIBLE" ) {
        header = {
            "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy"
        };
        for( const auto& v : vitamin::all() ) {
             header.push_back( v.second.name() );
        }
        auto dump = [&rows]( const item& obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( false ) );
            r.push_back( std::to_string( obj.volume() ) );
            r.push_back( std::to_string( obj.weight() ) );
            r.push_back( std::to_string( obj.type->stack_size ) );
            r.push_back( std::to_string( obj.type->comestible->get_calories() ) );
            r.push_back( std::to_string( obj.type->comestible->quench ) );
            r.push_back( std::to_string( obj.type->comestible->healthy ) );
            auto vits = g->u.vitamins_from( obj );
            for( const auto& v : vitamin::all() ) {
                 r.push_back( std::to_string( vits[ v.first ] ) );
            }
            rows.push_back( r );
        };
        for( auto& e : item_controller->get_all_itypes() ) {
            if( e.second->comestible &&
                ( e.second->comestible->comesttype == "FOOD" ||
                  e.second->comestible->comesttype == "DRINK" ) ) {

                item food( e.first, calendar::turn, item::solitary_tag {} );
                if( g->u.can_eat( food, false, true ) == EDIBLE ) {
                    dump( food );
                }
            }
        }

    } else if( what == "GUN" ) {
        header = {
            "Name", "Ammo", "Volume", "Weight", "Capacity",
            "Range", "Dispersion", "Recoil", "Damage", "Pierce"
        };
        std::set<std::string> locations;
        for( const auto& e : item_controller->get_all_itypes() ) {
            if( e.second->gun ) {
                std::transform( e.second->gun->valid_mod_locations.begin(),
                                e.second->gun->valid_mod_locations.end(),
                                std::inserter( locations, locations.begin() ),
                                []( const std::pair<std::string, int>& e ) { return e.first; } );
            }
        }
        for( const auto &e : locations ) {
            header.push_back( e );
        }

        auto dump = [&rows,&locations]( const item& obj ) {
            std::vector<std::string> r;
            r.push_back( obj.tname( false ) );
            r.push_back( obj.ammo_type() != "NULL" ? obj.ammo_type() : "" );
            r.push_back( std::to_string( obj.volume() ) );
            r.push_back( std::to_string( obj.weight() ) );
            r.push_back( std::to_string( obj.ammo_capacity() ) );
            r.push_back( std::to_string( obj.gun_range() ) );
            r.push_back( std::to_string( obj.gun_dispersion() ) );
            r.push_back( std::to_string( obj.gun_recoil() ) );
            r.push_back( std::to_string( obj.gun_damage() ) );
            r.push_back( std::to_string( obj.gun_pierce() ) );
            for( const auto &e : locations ) {
                r.push_back( std::to_string( obj.type->gun->valid_mod_locations[ e ] ) );
            }
            rows.push_back( r );
        };
        for( const auto& e : item_controller->get_all_itypes() ) {
            if( e.second->gun ) {
                item gun( e.first );
                if( gun.is_reloadable() ) {
                    gun.ammo_set( default_ammo( gun.ammo_type() ), gun.ammo_capacity() );
                }
                dump( gun );

                if( gun.type->gun->barrel_length > 0 ) {
                    gun.emplace_back( "barrel_small" );
                    dump( gun );
                }
            }
        }

    } else if( what == "VEHICLE" ) {
        header = {
            "Name", "Weight (empty)", "Weight (fueled)"
        };
        auto dump = [&rows]( const vproto_id& obj ) {
            auto veh_empty = vehicle( obj, 0, 0 );
            auto veh_fueled = vehicle( obj, 100, 0 );

            std::vector<std::string> r;
            r.push_back( veh_empty.name );
            r.push_back( std::to_string( veh_empty.total_mass() ) );
            r.push_back( std::to_string( veh_fueled.total_mass() ) );
            rows.push_back( r );
        };
        for( auto& e : vehicle_prototype::get_all() ) {
            dump( e );
        }

    } else if( what == "VPART" ) {
        header = {
            "Name", "Location", "Weight", "Size"
        };
        auto dump = [&rows]( const vpart_info *obj ) {
            std::vector<std::string> r;
            r.push_back( obj->name() );
            r.push_back( obj->location );
            r.push_back( std::to_string( int( ceil( item( obj->item ).weight() / 1000.0 ) ) ) );
            r.push_back( std::to_string( obj->size ) );
            rows.push_back( r );
        };
        for( const auto e : vpart_info::get_all() ) {
            dump( e );
        }
    }

    rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string>& e ) {
        return e.empty();
    } ), rows.end() );

    std::sort( rows.begin(), rows.end(), []( const std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
        return lhs[ 0 ] < rhs[ 0 ];
    } );

    rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() );

    switch( mode ) {
        case dump_mode::TSV:
            rows.insert( rows.begin(), header );
            for( const auto& r : rows ) {
                std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) );
                std::cout << r.back() << "\n";
            }
            break;

        case dump_mode::HTML:
            std::cout << "<table>";

            std::cout << "<thead>";
            std::cout << "<tr>";
            for( const auto& col : header ) {
                std::cout << "<th>" << col << "</th>";
            }
            std::cout << "</tr>";
            std::cout << "</thead>";

            std::cout << "<tdata>";
            for( const auto& r : rows ) {
                std::cout << "<tr>";
                for( const auto& col : r ) {
                    std::cout << "<td>" << col << "</td>";
                }
                std::cout << "</tr>";
            }
            std::cout << "</tdata>";

            std::cout << "</table>";
            break;
    }
}
int main(int argc, char** argv)
{
	
	
	Settings settings=Settings();	
	std::vector<Snake> players;
	sf::Text scores;
	
	Flag flags[2]={Flag(sf::Color::Blue,sf::Vector2f(XRES-50,YRES/2)),Flag(sf::Color::Red,sf::Vector2f(50,YRES/2))};
	
	flags[0].setFillColor(sf::Color::Blue);
	flags[1].setFillColor(sf::Color::Red);
	
	
	scores.setPosition(0,0);
	scores.setColor(sf::Color::White);
	players.push_back(Snake(5,0,sf::Vector2f(15,15),new Turner(settings.controlls[0])));
	players.push_back(Snake(5,-3.1428,sf::Vector2f(XRES-15,YRES-45),new Turner(settings.controlls[1])));

	
	std::srand(time(NULL));
	
	sf::RectangleShape food(sf::Vector2f(20,20));
	food.setPosition(sf::Vector2f(15*(std::rand()%(XRES/15)),15*(std::rand()%(YRES/15))));
	food.setFillColor(sf::Color::Green);
	
	int difficulty=40;
	
	
	
	sf::RenderWindow win(sf::VideoMode(XRES,YRES,32),"Snake");
	win.setFramerateLimit(difficulty);
	sf::Event mainloop;
	
	while (win.isOpen()) {
		win.clear();
		
		
		for (int i=0;i<players.size();i++)
		{
			bool eaten=false;
			players[i].turn();
			eaten= eaten || players[i].try_eat(food);
		
			if (eaten) {
				food.setPosition(sf::Vector2f(15*(std::rand()%(XRES/15))+5,15*(std::rand()%(YRES/15))+5));
			};
		}
		win.draw(food);
		std::string scorestr="";
		
		
		for (int i=0;i<players.size();i++) {
			win.draw(players[i]);
			for (int y=0;y<2;y++) {
				if (players[i].collide(flags[y])) {
					if (i!=y) {
						if (players[i].isCarrying()) {
							  flags[y].reset();
							  players[i].drop();
							  players[i].score++;
							  
						};
					
				}
				else players[i].carry(flags[y]);
				};
				win.draw(flags[y]);
			};
			
			
			//scorestr+="P"+std::to_string(players[i].id+1)+": "+std::to_string(players[i].score)+"\n";
		};
		scores.setString(scorestr);
		win.draw(scores);
		
		
		while (win.pollEvent(mainloop)) {
			
			if (mainloop.type==sf::Event::Closed) win.close();
			
			if (mainloop.type==sf::Event::KeyPressed) {
				
				
				switch (mainloop.key.code) {
					case sf::Keyboard::Key::Add  : {TURN_SPEED+=0.05;break;}
					case sf::Keyboard::Key::Subtract   : {TURN_SPEED-=0.05;break;}
					default: break;
				};
				
				
			};
		};
		
		win.display();
		for (int i=0;i<players.size();i++) players[i].move(players);
		
	};
		
	return 0;
}
Пример #20
0
void move( int matrix[][50], int v[][2], int f[]) // move the vector v in a direction
// OBS: building
// portal1 = 1
// portal2 = 2
{
    int k; // counter to the vector v
    int save[2];
    save[0] = v[length-1][0];
    save[1] = v[length-1][1]; // saving the position of last element of snake
    for(k=(length-1); k>=1; k-=1) {
        v[k][0] = v [k-1][0];    // positions will "delay"
        v[k][1] = v[k-1][1];
    }

    if (dir==u) look = 'u';
    else if (dir==d) look = 'd';
    else if (dir==l) look = 'l';
    else if (dir==r) look = 'r';
    // first, check of portal1
    if((dir==u)&&(v[0][0]-1==portal1[0])&&(v[0][1]==portal1[1])) {
        v[0][0] = portal2[0]-1;
        v[0][1] = portal2[1];
        if(t>20) {
            t -= 1;
            sp++;
        }
    }
    else if((dir==d)&&(v[0][0]+1==portal1[0])&&(v[0][1]==portal1[1])) {
        v[0][0] = portal2[0]+1;
        v[0][1] = portal2[1];
        if(t>20) {
            t -= 1;
            sp++;
        }
    }
    else if((dir==l)&&(v[0][1]-1==portal1[1])&&(v[0][0]==portal1[0])) {
        v[0][0] = portal2[0];
        v[0][1] = portal2[1]-1;
        if(t>20) {
            t -= 1;
            sp++;
        }
    }
    else if((dir==r)&&(v[0][1]+1==portal1[1])&&(v[0][0]==portal1[0])) {
        v[0][0] = portal2[0];
        v[0][1] = portal2[1]+1;
        if(t>20) {
            t -= 1;
            sp++;
        }
    }

    // now, check of portal2
    else if((dir==u)&&(v[0][0]-1==portal2[0])&&(v[0][1]==portal2[1])) {
        v[0][0] = portal1[0]-1;
        v[0][1] = portal1[1];
        if(t>20) {
            t -= 1;
        }
    }
    else if((dir==d)&&(v[0][0]+1==portal2[0])&&(v[0][1]==portal2[1])) {
        v[0][0] = portal1[0]+1;
        v[0][1] = portal1[1];
        if(t>20) {
            t -= 1;
        }
    }
    else if((dir==l)&&(v[0][1]-1==portal2[1])&&(v[0][0]==portal2[0])) {
        v[0][0] = portal1[0];
        v[0][1] = portal1[1]-1;
        if(t>20) {
            t -= 1;
        }
    }
    else if((dir==r)&&(v[0][1]+1==portal2[1])&&(v[0][0]==portal2[0])) {
        v[0][0] = portal1[0];
        v[0][1] = portal1[1]+1;
        if(t>20) {
            t -= 1;
        }
    }

    else if ((dir==u)&&(v[0][0]-1 == v[1][0])) {
        v[0][0] +=1;
    }
    else if((dir==u)&&(v[0][0]==0)) {
        v[0][0]=24;
    }
    else if(dir==u) {
        v[0][0]-=1;
    }

    else if ((dir==d)&&(v[0][0]+1 == v[1][0])) {
        v[0][0] -=1;
    }
    else if((dir==d)&&(v[0][0]==24)) {
        v[0][0]=0;
    }
    else if(dir==d) {
        v[0][0]+=1;
    }

    else if ((dir==r)&&(v[0][1]+1 == v[1][1])) {
        v[0][1] -=1;
    }
    else if((dir==r)&&(v[0][1]==49)) {
        v[0][1]=0;
    }
    else if(dir==r) {
        v[0][1]+=1;
    }

    else if ((dir==d)&&(v[0][0]-1 == v[1][0])) {
        v[0][0] +=1;
    }
    else if((dir==l)&&(v[0][1]==0)) {
        v[0][1]=49;
    }
    else if(dir==l) {
        v[0][1]-=1;
    }

    if((v[0][0]==f[0])&&(v[0][1]==f[1])) // if the snake eat the food
    {
        score = score + 10;
        length = length + 1;
        sp = sp + 1;
        v[length-1][0] = save[0];
        v[length-1][1] = save[1];
        food(matrix,f);
    }

}
Пример #21
0
int main()
{
    int field[25][50];
    int python[1000][2];
    int fd[2];
    int k,i,j,n=1,counter=0, over,t2;
    char directory[] = "Music/x.mid";

    allegro_init();
    install_keyboard();
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 600, 272, 0, 0);
    install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);

    BITMAP *buffer = create_bitmap(600,272);
    MIDI *music;
    while(n>0)
    {
        dir = r;
        length = 4;
        score = 0;
        t = 100;
        sp = 1;
        over = 0;
        look = 'r';
        t2 = 1;
        python[0][0] = 15;
        python[0][1] = 10;
        python[1][0] = 15;
        python[1][1] = 9;
        python[2][0] = 15;
        python[2][1] = 8;
        python[3][0] = 15;
        python[3][1] = 7;

        srand(time(NULL));
        directory[6] = intchar(rand()%9 + 1);

        music = load_midi(directory);
        play_midi(music,0);

        clear_to_color(screen,0x000000);
        opening();
        menu_mode(field);
        init(field);

        position(field,python);  // position the snake
        food(field,fd);
        guardi = python[length-1][0];
        guardj = python[length-1][1];
        display(field,python,fd,t2);

        while(over!=1)
        {
            if(t2<10) {
                t2++;
            }
            guardi = python[length-1][0];
            guardj = python[length-1][1];
            save = dir;
            python[length][0] = i;
            python[length][1] = j;
            rest(10);
            if(keypressed()) {
                dir = readkey();
            }
            else if ((dir & 0xff) == 'w') dir =u;
            else if ((dir & 0xff) == 's') dir =d;
            else if ((dir & 0xff) == 'a') dir =l;
            else if ((dir & 0xff) == 'd') dir =r;

            if((dir==u)||(dir==d)||(dir==l)||(dir==r)) {
                over = analysis(field,python,fd);
                rest(t-10);
            }
            else if(dir==esc) {
                over=1;
                n=0;
            }
            else {
                dir = save;
                over = analysis(field,python,fd);
                rest(t-10);
            };
            display(field,python,fd,t2);



        }
        portal1[0] = 50;
        portal1[1] = 50;
        portal2[0] = 50;
        portal2[1] = 50;
        clear_to_color(screen,0xFFFFFF);
        textout_ex(screen,font,"Score: ",225,160,0x02094A,0xF7FF0B);
        outnumber(265,160,score);
        saverec(field,python,fd);
        destroy_midi(music);
        rest(100);
        if(readkey()==esc) {
            n=0;
        }

    }

    destroy_bitmap(buffer);
    return 0;
}