Пример #1
0
bool MineDropper::drop_mine(Point drop_at)
{
  if ( num_of_mines > 0 && mine_handler->add_mine(Mine(drop_at, get_damage())) )
  {
    num_of_mines--;
    return true;
  }
  return false;
}
Пример #2
0
Mine* Init(const char* map)
{
	auto problem = std::make_shared<Problem>();
	if ( map )
	{
		std::ifstream is(map);
		problem = problem->read(is);
	}
	else
	{
		problem = problem->read(std::cin);
	}
  
  g_mine = Mine(problem);

	return &g_mine;
}
Пример #3
0
void Game::MakeMines()
{
   int minecount = max(level/2 + rand()%level - 1, 0);
   cout << "  Mines: " << minecount << endl;
   
   mines.clear();
   if (minecount > MAX_MINES)
      minecount = MAX_MINES;
   for (int i = 0; i < minecount; i++) {
      // Allocate space for mine
      int xpos, ypos;
      if (!objgrid.AllocFreeSpace(xpos, ypos, 2, 2)) {
         // Failed to allocate space
         minecount = i + 1;
         break;
      }
      mines.push_back(Mine(&objgrid, &viewport, xpos, ypos));
   }
}
Пример #4
0
	/************移动的函数*************/
	void move()                              /*一次移动一格 通过循环一直移动 无键盘响应的时候一直向前移动 */
	{
		void Poison();
		void add();
		void del();
		void gotoxy(int x, int y);
		int m, n;                                    /*将要移向的蛇头的坐标*/
        m = head->x;
		n = head->y;
		switch (direction)
		{
		case up:m--;
			break;
		case down:m++;
			break;
		case left:n--;
			break;
		case right:n++;
			break;
		}
		if (a[m][n] == 1||node<3)                     /*如果蛇头碰到墙或自己的蛇身或蛇身长度小于三 就清屏结束*/
		{
			system("cls");
			gotoxy(10, 9);
			printf("****************************************************");
			gotoxy(11, 9);
			printf("*                                                  *");
			gotoxy(12, 9);
			printf("*                                                  *");
			gotoxy(13, 9);
			printf("*              GAME OVER!!!!!!                     *");
			gotoxy(14, 9);
			printf("*                                                  *");
			gotoxy(15, 9);
			printf("*                                                  *");
			gotoxy(16, 9);
			printf("****************************************************");
			//exit(0);                        /*结束*/
			running = 0;
			return;
		}
		/*************出现食物**************/        /*food由0到1使屏幕上出现食物*/
		if (food.yes == 0)
		{
			srand((unsigned)time(NULL));
			do                                                     /*使食物被吃就再出现一个 否则不出现*/
			{
				food.x = rand() % 38 + 1;
				food.y = rand() % 38 + 1;
			} while (a[food.x][food.y] != 0);
			food.yes = 1;
		}
		if (food.yes == 1)
		{
			a[food.x][food.y] = 4;
			gotoxy(food.x, food.y);
			printf("%c", 5);
		}
		if (a[m][n] == 4)
		{
		add(m, n);
		food.yes = 0;
		node++;                                  /*若食物被吃则由0到1重新生成 否则一直不生成新的 一直是原来的*/
		num++;                                     /*且蛇头增加一个*/            
		sum++;                                        /*食物总数自增 直到20个时毒草消失*/
		return;
	    }
		if (num == 5)
		{
			Poison();
			Poison();
			Poison();
			Poison();
			Mine();
			Mine();
			num = 0;
			                                         /*num重新初始化为零 使每吃四个食物就出现一次*/
		}
		if (a[m][n] == 2)
		{
			add(m, n);
			node--;
			del();
			del();
			return;
		}
		if (a[m][n] == 3)
		{
			add(m, n);
			del();
			if (node % 2 == 0)
			{
				node = node / 2;
				for (i = 0; i < node; i++)
				{
					del();
				}

			}
			else
			{
				node = node / 2;
				for (i = 0; i <= node; i++)
				{
					del();
				}
				return;
			}
		}

		if (sum == 10)                                                /*毒草消失*/
        {
			int i = 0, j = 0;
			for (i = 0; i < N;i++)
			{
				for (j = 0; j < N;j++)
				{
					if (a[i][j] == 2)
					{
						a[i][j] = 0;
						gotoxy(i, j);
						printf(" ");
					}
			    };
			};
		}
			
			
			
	   add(m, n);                                   /*m,n是变化的???*/
		del();
   }
Пример #5
0
void Initialize(int argc, char *argv[])
{
	// Process command line arguments
	for (int i = 0; i < argc - 1; ++i)
	{
		if      (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--map-width"))
			gameWidth = atof(argv[++i]);
		else if (!strcmp(argv[i], "-y") || !strcmp(argv[i], "--map-height"))
			gameHeight = atof(argv[++i]);
		else if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--path"))
			path = argv[++i];
		else if (!strcmp(argv[i], "-w") || !strcmp(argv[i], "--screen-width"))
			windowWidth = atoi(argv[++i]);
		else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--screen-height"))
			windowHeight = atoi(argv[++i]);
	}
	
	// Process config file
	if (!file_exists(CONFIG_FILE))
	{
		ConfigFile newconfig;
		newconfig.add("playername", "Unnamed");
		newconfig.add("team", 'a');
		newconfig.save(CONFIG_FILE);
	}
	
	try { config = new ConfigFile(CONFIG_FILE); }
	catch (ConfigFile::file_not_found e)
	{
		delete config;
		config = NULL;
		puts("Unable to create config file: " CONFIG_FILE "!");
		exit(EXIT_FAILURE);
	}
	
	fullscreen = (config->read("fullscreen", '0')) == '1'? true : false;
	/* deprecated: for (int i = 0; i < argc; ++i)
	{
		if (!strcmp(argv[i], "--fullscreen"))
			fullscreen = true;
	}*/
	// Global subsystem initializations
	srand(time(NULL));
	
	// Create window and set up viewports
	game.window = new Video::Window(windowWidth, windowHeight,
	                                GAME_NAME, fullscreen);
	Video::Viewport *view = new Video::Viewport(1,1);
	game.window->viewports.push_back(view);
	
	// Show loading screen
	// Problem: we can't use the hud prior to asset loading
	
	// Load game assets
	Assets::Initialize(argc, argv);
	
	config->readInto(NetCode::MessageOfTheDay, "motd",
		string("No message of the day ;("));
	
	// Set up game world
	game.root = World(gameWidth, gameHeight);
	game.world = TO(World,game.root);
	game.topId = 1;
	
	game.teams.insert(make_pair('a', Team('a')));
	game.teams.insert(make_pair('b', Team('b')));
	
	string name;
	unsigned char team;
	config->readInto(name, "playername", string("Unnamed"));
	team = config->read("team", 'a');
	
	Player::Id pid = game.topId++;
	ObjectHandle player = Player(pid, team, name);
	game.player = TO(Player,player);
	game.player->weapon = weapLaser;
	game.player->origin = getSpawn(team);
	game.root->children.insert(player);
	game.players[pid] = player;
	
	game.world->terrain->placeStructure(GridPoint(2,2), Mine());
	game.world->terrain->placeStructure(GridPoint(2,48), Mine());
	game.world->terrain->placeStructure(GridPoint(48,2), Mine());
	game.world->terrain->placeStructure(GridPoint(48,48), Mine());
	game.world->terrain->placeStructure(GridPoint(25,25), RichMine());
	game.world->terrain->placeStructure(GridPoint(15,25), Mine());
	game.world->terrain->placeStructure(GridPoint(35,25), Mine());
	game.world->terrain->placeStructure(GridPoint(25,5), RichMine());
	game.world->terrain->placeStructure(GridPoint(25,45), RichMine());
	game.world->terrain->placeStructure(GridPoint(6,9), Mine());
	game.world->terrain->placeStructure(GridPoint(6,41), Mine());
	game.world->terrain->placeStructure(GridPoint(44,9), Mine());
	game.world->terrain->placeStructure(GridPoint(44,41), Mine());
	game.world->terrain->placeStructure(GridPoint(10,17), Mine());
	game.world->terrain->placeStructure(GridPoint(10,33), Mine());
	game.world->terrain->placeStructure(GridPoint(40,17), Mine());
	game.world->terrain->placeStructure(GridPoint(40,33), Mine());

	ObjectHandle RedBot = player;
	ObjectHandle BlueBot = player;
	
	if (team == 'b')
	{
		RedBot = Player(INT_MAX - 'a', 'a', "RedBot", Pd(-1000,-1000,-1000));
		//game.world->children.insert(RedBot);
		game.players[TO(Player, RedBot)->id] = RedBot;
	}
	else if (team == 'a')
	{
		BlueBot = Player(INT_MAX - 'b', 'b', "BlueBot", Pd(-1000,-1000,-1000));
		//game.world->children.insert(BlueBot);
		game.players[TO(Player, BlueBot)->id] = BlueBot;
	}

	game.world->terrain->placeStructure(GridPoint(3,25), HeadQuarters(TO(Player, BlueBot)->id));
	game.world->terrain->placeStructure(GridPoint(48,26), HeadQuarters(TO(Player, RedBot)->id));

	game.world->terrain->placeStructure(GridPoint(4,26), DefenseTower(TO(Player, BlueBot)->id));
	game.world->terrain->placeStructure(GridPoint(4,23), DefenseTower(TO(Player, BlueBot)->id));
	game.world->terrain->placeStructure(GridPoint(46,27), DefenseTower(TO(Player, RedBot)->id));
	game.world->terrain->placeStructure(GridPoint(46,24), DefenseTower(TO(Player, RedBot)->id));

	for(int i = 0; i <= 50; i++) {
		game.world->terrain->placeStructure(GridPoint(0,i), Wall());
		game.world->terrain->placeStructure(GridPoint(50,i), Wall());
		game.world->terrain->placeStructure(GridPoint(i,0), Wall());
		game.world->terrain->placeStructure(GridPoint(i,50), Wall());
	}

	for(int i = 8; i <= 42; i++) {
		if (i < 23 || i > 27) {
			game.world->terrain->placeStructure(GridPoint(25,i), Wall());
			game.world->terrain->placeStructure(GridPoint(i,5), Wall());
			game.world->terrain->placeStructure(GridPoint(i,45), Wall());
		}
		if (i < 22 || i > 28) {
			game.world->terrain->placeStructure(GridPoint(i,15), Wall());
			game.world->terrain->placeStructure(GridPoint(i,35), Wall());
		}
		if (i < 13 || i > 37) {
			game.world->terrain->placeStructure(GridPoint(i,25), Wall());
		}
	}

	for (int i = 5; i <=11; i++) {
		game.world->terrain->placeStructure(GridPoint(4,i), Wall());
		game.world->terrain->placeStructure(GridPoint(46,i), Wall());
		game.world->terrain->placeStructure(GridPoint(i,11), Wall());
		game.world->terrain->placeStructure(GridPoint(i,39), Wall());
	}

	for (int i = 39; i <=45; i++) {
		game.world->terrain->placeStructure(GridPoint(4,i), Wall());
		game.world->terrain->placeStructure(GridPoint(46,i), Wall());
		game.world->terrain->placeStructure(GridPoint(i,11), Wall());
		game.world->terrain->placeStructure(GridPoint(i,39), Wall());
	}

	for (int i = 15; i <= 35; i++) {
		game.world->terrain->placeStructure(GridPoint(8,i), Wall());
		game.world->terrain->placeStructure(GridPoint(42,i), Wall());
	}

	for (int i = 3; i <= 47; i++) {
		if (i < 12 || i > 38 || (i > 19 && i < 31)) {
			game.world->terrain->placeStructure(GridPoint(18,i), Wall());
			game.world->terrain->placeStructure(GridPoint(32,i), Wall());
		}
	}

	for (int i = 13; i <= 37; i++) {
		if (i < 18 || i > 32) {
			game.world->terrain->placeStructure(GridPoint(i,20), Wall());
			game.world->terrain->placeStructure(GridPoint(i,30), Wall());
		}
	}

	game.world->terrain->placeStructure(GridPoint(11,1), Wall());
	game.world->terrain->placeStructure(GridPoint(11,2), Wall());
	game.world->terrain->placeStructure(GridPoint(11,49), Wall());
	game.world->terrain->placeStructure(GridPoint(11,48), Wall());
	game.world->terrain->placeStructure(GridPoint(39,1), Wall());
	game.world->terrain->placeStructure(GridPoint(39,2), Wall());
	game.world->terrain->placeStructure(GridPoint(39,49), Wall());
	game.world->terrain->placeStructure(GridPoint(39,48), Wall());

	// Set up user interface
	view->world = game.root;
	game.controller = new Controller(view->camera, player);
	game.input = new Input(*game.window);
	game.input->onKeyUp = KeyUp;
	game.input->onKeyDown = KeyDown;
	//input->onMouseMove = MouseMove;
	
	Echo("Everything loaded!");
	Echo("Welcome to the game");
	Echo(NetCode::MessageOfTheDay);
}
Пример #6
0
void Anahori(void) {
	for (k = 0; k < WIDTH; k++) {
		for (l = 0; l < HIGHT; l++) {
			if (!(k == 0 || l == 0 || k == WIDTH - 1 || l == HIGHT - 1)) {
				mazepanel[k][l] = 1;
			}
		}
	}

	coordinate Mine(0, 0); //掘る場所
	
	//掘り始める初期位置決め
	do {
		Mine.x = rand() % (WIDTH - 1);
	} while (Mine.x % 2 == 0);
	do {
		Mine.y = rand() % (HIGHT - 1);
	} while (Mine.y % 2 == 0);

	bool canmine[4] = {true, true, true, true};//true:その方向は掘ることができるかもしれない

	while (MineLeaving()) {
		mazepanel[Mine.x][Mine.y] = 0;
		int c;
		switch (Direction()) {
		case 0:
			if (Mine.y - 2 > 0 && mazepanel[Mine.x][Mine.y - 2] != 0 && canmine[0] == true) {
				mazepanel[Mine.x][Mine.y - 1] = 0;
				Mine.y -= 2;
				for (c = 0; c < 4; c++) {
					canmine[c] = true;
				}
			}
			else {
				canmine[0] = false;
			}
			break;
		case 1:
			if (Mine.x - 2 > 0 && mazepanel[Mine.x - 2][Mine.y] != 0 && canmine[1] == true) {
				mazepanel[Mine.x - 1][Mine.y] = 0;
				Mine.x -= 2;
				for (c = 0; c < 4; c++) {
					canmine[c] = true;
				}
			}
			else {
				canmine[1] = false;
			}
			break;
		case 2:
			if (Mine.y + 2 < HIGHT - 1 && mazepanel[Mine.x][Mine.y + 2] != 0 && canmine[2] == true) {
				mazepanel[Mine.x][Mine.y + 1] = 0;
				Mine.y += 2;
				for (c = 0; c < 4; c++) {
					canmine[c] = true;
				}
			}
			else {
				canmine[2] = false;
			}
			break;
		case 3:
			if (Mine.x + 2 < WIDTH - 1 && mazepanel[Mine.x + 2][Mine.y] != 0 && canmine[3] == true) {
				mazepanel[Mine.x + 1][Mine.y] = 0;
				Mine.x += 2;
				for (c = 0; c < 4; c++) {
					canmine[c] = true;
				}
			}
			else {
				canmine[3] = false;
			}
			break;
		default:
			break;
		}
		if (!canmine[0] && !canmine[1] && !canmine[2] && !canmine[3]) {
			do {
				Mine.x = rand() % (WIDTH - 1);
				Mine.y = rand() % (HIGHT - 1);
			} while (Mine.x % 2 == 0 || Mine.y % 2 == 0 || mazepanel[Mine.x][Mine.y] == 1);
			for (c = 0; c < 4; c++) {
				canmine[c] = true;
			}
		}
	}

}