Beispiel #1
0
void GameMapRecrusive::setCoin(int r, int c)
{
    ValueMap val;
    val["type"] = "Coin";

    if(rand()%100<50)
    {
        val["coin"] = 10;
    }
    else if(rand()%100<60)
    {
        val["coin"] = 50;
    }
    else if(rand()%100<65)
    {
        val["coin"] = 100;
    }
    else
    {
        m_coinCount--;
        return;
    }

    m_objects[r][c]->clear();
    m_objects[r][c]->pushObjBy(val);

    if(rand()%100<80)
    {
        setSoil(r, c, false);
    }

    m_coinCount--;
}
Beispiel #2
0
void GameMapRecrusive::setTrap(int r, int c)
{
    ValueMap data;
    data["type"] = rand()%2?"TrapFire":"TrapBomb";
    m_objects[r][c]->clear();
    m_objects[r][c]->pushObjBy(data);
	if (rand()%100<80)
	{
		setSoil(r, c, false);
	}
    m_mineCount--;
}
Beispiel #3
0
void GameMapRecrusive::setProp(int r, int c)
{
    string candy[] =
    {
        "heart.png", "shield.png", "key.png", "arrow.png", "hoe.png", "bomb.png", "map.png"
    };
    ValueMap val;
    val["type"] = "Prop";
    val["texture"] = candy[ rand()%7 ];
    m_objects[r][c]->clear();
    m_objects[r][c]->pushObjBy(val);
    m_propCount--;

    if(rand()%100<95)
    {
        setSoil(r, c, false);
    }

    m_propCount--;
}
Beispiel #4
0
void Meadow::randomize(){
    std::string soilKind = Soil::randomizeSoilKind();
    if(soilKind != "")
        setSoil(soilKind);
}
Beispiel #5
0
void GameMapRecrusive::makeMap(int mLevel, int vLevel)
{
    m_mLevel = mLevel;
    m_vLevel = vLevel;

    //10*20 -> 20*20 -> 20*30 -> 30*30
    m_mapRows = 10* (vLevel/2+1);
    m_mapCols = 20+10*vLevel/2;
    m_mapCols = min(50, m_mapCols);

    m_roomSize = 5;//5-vLevel/3;//3 + vLevel/2;
    m_roomSize = max(3, m_roomSize);

    m_mineCount = 5 + 20*vLevel;
    m_coinCount = 5+vLevel;// + 10*vLevel;
    m_propCount = 5+vLevel;// + 10*vLevel;
// 	m_hallMin = max(2, 5 - vLevel/2);
    //
    m_objects.resize(m_mapRows);

    for(int r=0; r<m_mapRows; ++r)
    {
        m_objects[r].resize(m_mapCols);

        for(int c=0; c<m_mapCols; ++c)
        {
            MapCell* cell = MapCell::create();
            cell->setPosition(Point(c*m_tw, r*m_th) + Point(0, m_th) /*+ m_border*/);
            cell->setLocalZOrder((m_mapRows-r-1)*m_mapCols + c);
            addChild(cell);
            m_objects[r][c] = cell;
        }
    }

    //
    this->setContentSize(Size(m_mapCols*m_tw/*+m_border.width*2*/, m_mapRows*m_th/*+m_border.height*2*/));
    generate(0, 0, m_mapRows, m_mapCols);

    while(m_mineCount>0)
    {
        int r = rand()% (m_mapRows-2)+1;
        int c = rand()% (m_mapCols-2)+1;
        setTrap(r, c);
    }

    while(m_coinCount>0)
    {
        int r = rand()% (m_mapRows-2)+1;
        int c = rand()% (m_mapCols-2)+1;
        setCoin(r, c);
    }

    while(m_propCount > 0)
    {
        int r = rand()% (m_mapRows-2)+1;
        int c = rand()% (m_mapCols-2)+1;
        setProp(r, c);
    }

	for (int r = 0; r < m_mapRows; ++r)
	{
		for (int j=0; j < m_mapCols; ++j)
		{
			if (m_objects[r][j]->empty())
			{
				if (rand()%100<70)
				{
					setSoil(r, j, false);
				}
			}
		}
	}
    //
    const Index2 pos(rand()%m_mapRows,0);
    m_pPlayer = Player::create();
    m_pPlayer->setPosition(index2ToPoint(pos)+Point(m_tw/2, m_th/2));
    addChild(m_pPlayer, m_mapRows*m_mapCols+1);
    m_objects[pos.first][pos.second]->clear();

    for(auto x : getSurrounding(pos))
    {
        m_objects[x.first][x.second]->clear();
    }

    //
    ValueMap val;
    val["type"] = "LevelStair";
    const Index2 win(rand()%m_mapRows, m_mapCols-1);
    m_objects[win.first][win.second]->clear();
    m_objects[win.first][win.second]->pushObjBy(val);
}