Esempio n. 1
0
//KONSTRUKTOR klasy ClassicSTR
Block_Q :: Block_Q(sf::RenderWindow& oknoAplikacji): okno(oknoAplikacji)
{
	position=1;
	opoznienie=0;
//	srand(unsigned(time(NULL)));
	Reset();
	for(int i=1; i<10; i++)
		generateSpecial(special);
		generateMess(special);
}
Esempio n. 2
0
//KONSTRUKTOR klasy ClassicSTR
Block_Z :: Block_Z(sf::RenderWindow& oknoAplikacji): okno(oknoAplikacji)
{
	position=1;
	opoznienie=0;
	srand(unsigned(time(NULL)));
	int pozycja;
	for(int i=0; i<10; i++)
	pozycja=rand()%100+1;
	type=pozycja;
	//Reset();
	for(int i=1; i<10; i++)
		generateSpecial(special);
		generateMess(special);
}
Esempio n. 3
0
void Snake::moveDown()
{
	if(direction!=upDir)
	{
		if(countDown==0) //i.e. time over in getting the special seed
		{
			counter=0;
			generateSpecial();
		}

		direction= downDir;
		if((head->yVal> 0 && grid[head->xVal][head->yVal-1]== 1) || (head->yVal== 0 && grid[head->xVal][edge-1]==1))
		{
			gameStatus= OVER;
		}

		else if(head->yVal> 0 && head->xVal== seed[0] && head->yVal-1==seed[1])
		{
			score= score+ 10;
			head->next= new node(head->xVal, head->yVal-1);
			head= head->next;
			grid[head->xVal][head->yVal]=1;
			generateSeed();
			if(counter!=5)
			{
				counter++;
				if(counter==5)
				{
					generateSpecial();
				}
			}
		}

		else if(head->yVal== 0 && seed[0]== head->xVal && seed[1]==edge-1)
		{
			score= score+ 10;
			head->next= new node(head->xVal, edge-1);
			head= head->next;
			grid[head->xVal][head->yVal]=1;
			generateSeed();
			if(counter!=5)
			{
				counter++;
				if(counter==5)
				{
					generateSpecial();
				}
			}
		}

		else if(head->yVal> 0)
		{
			if(counter==5 && special[0]== head->xVal && special[1]== head->yVal-1)
			{
				counter=0;
				score= score+ 10*countDown;
				generateSpecial();
				
			}

			if(head==tail)
			{
				head->yVal= head->yVal-1;
			}
			else
			{
				node* ptr= tail;
				tail= tail->next;
				grid[ptr->xVal][ptr->yVal]=0;
				ptr->xVal= head->xVal;
				ptr->yVal= head->yVal- 1;
				ptr->next= NULL;
				head->next= ptr;
				head= head->next;
				grid[head->xVal][head->yVal]=1;
			}
		}

		else//when head->yVal==0
		{
			if(counter==5 && special[0]== head->xVal && special[1]== edge-1)
			{
				counter=0;
				score= score+ 10*countDown;
				generateSpecial();
				
			}

			if(head==tail)
			{
				head->yVal= edge-1;
			}
			else
			{
				node* ptr= tail;
				tail= tail->next;
				grid[ptr->xVal][ptr->yVal]= 0;
				ptr->xVal= head->xVal;
				ptr->yVal= edge-1;
				ptr->next= NULL;
				head->next= ptr;
				head= head->next;
				grid[head->xVal][head->yVal]=1;
			}
		}

		if(counter==5)
		{
			countDown--;
		}

		storeTime= clock();
	}
}
Esempio n. 4
0
void Snake::moveRight()
{
	if(direction!=leftDir)
	{
		if(countDown==0) //i.e. time over in getting the special seed
		{
			counter=0;
			generateSpecial();
		}

		direction= rightDir;
		if((head->xVal<edge-1 && grid[head->xVal+ 1][head->yVal]== 1) || (head->xVal== edge-1 && grid[0][head->yVal]==1))
		{
			gameStatus= OVER;
		}

		else if(head->xVal<edge-1 && head->xVal+1== seed[0] && head->yVal==seed[1])
		{
			score= score+ 10;
			head->next= new node(head->xVal+ 1, head->yVal);
			head= head->next;
			grid[head->xVal][head->yVal]=1;
			generateSeed();
			if(counter!=5)
			{
				counter++;
				if(counter==5)
				{
					generateSpecial();
				}
			}
		}

		else if(head->xVal== edge-1 && seed[0]==0 && head->yVal==seed[1])
		{
			score= score+ 10;
			head->next= new node(0, head->yVal);
			head= head->next;
			grid[head->xVal][head->yVal]=1;
			generateSeed();
			if(counter!=5)
			{
				counter++;
				if(counter==5)
				{
					generateSpecial();
				}
			}
		}


		else if(head->xVal< edge-1)
		{
			if(counter==5 && countDown>0 && head->xVal+ 1==special[0] && head->yVal==special[1])//i.e. it stikies special seed
			{
				counter=0;
				score= score+ 10*countDown;
				generateSpecial();
				
			}

			if(tail==head)//i.e. one node
			{
				head->xVal= head->xVal+1;
			}
			else
			{
				node* ptr= tail;
				tail= tail->next;
				grid[ptr->xVal][ptr->yVal]=0;
				ptr->xVal= head->xVal+ 1;
				ptr->yVal= head->yVal;
				ptr->next= NULL;
				head->next= ptr;
				head= head->next;
				grid[head->xVal][head->yVal]=1;
			}
		}

		else//when head->xVal==edge-1
		{
			if(counter==5 && special[0]==0 && special[1]==head->yVal)
			{
				counter=0;
				score= score+ 10*countDown;
				generateSpecial();
				
			}

			if(tail==head)
			{
				head->xVal= 0;
			}
			else
			{
				node* ptr= tail;
				tail= tail->next;
				grid[ptr->xVal][ptr->yVal]= 0;
				ptr->xVal= 0;
				ptr->yVal= head->yVal;
				ptr->next= NULL;
				head->next= ptr;
				head= head->next;
				grid[head->xVal][head->yVal]=1;
			}
		}

		if(counter==5)
		{
			countDown--;
		}

		storeTime= clock();
	}
}