what is wrong with this?
Posted: Tue May 22, 2012 8:32 pm
something is wrong with this function, because sometimes when i run it, my game freezes and crashes. I cant figure out why. it only crashes in some situations where suddenDeath=0;
- Code: Select all
int checkWinners()
{
int firstPlayer;
int secondPlayer;
int thirdPlayer;
if(gamePlaying==1)
{
switch(suddenDeath)
{
case 0:
switch(amountChar)
{
case 2:
if(collide.playerNo==2)
{
winners[1]=1;
winners[2]=2;
return 1;
}
else
{
winners[1]=2;
winners[2]=1;
return 1;
}
case 3:
if(winners[3]==0)
{
winners[3]=collide.playerNo;
return 0;
}
else if(winners[2]==0)
{
winners[2]=collide.playerNo;
switch(winners[2])
{
case 1:
switch(winners[3])
{
case 2:
winners[1]=3;
break;
case 3:
winners[1]=2;
break;
}
break;
case 2:
switch(winners[3])
{
case 1:
winners[1]=3;
break;
case 3:
winners[1]=1;
break;
}
break;
case 3:
switch(winners[3])
{
case 1:
winners[1]=2;
break;
case 2:
winners[1]=1;
break;
}
break;
}
return 1;
}
break;
case 4:
if(winners[4]==0)
{
winners[4]=collide.playerNo;
return 0;
}
else if(winners[3]==0)
{
winners[3]=collide.playerNo;
return 0;
}
else if(winners[2]==0)
{
winners[2]=collide.playerNo;
switch(winners[2])
{
case 1:
switch(winners[3])
{
case 2:
switch(winners[4])
{
case 3:
winners[1]=4;
break;
case 4:
winners[1]=3;
break;
}
break;
case 3:
switch(winners[4])
{
case 2:
winners[1]=4;
break;
case 4:
winners[1]=2;
break;
}
break;
case 4:
switch(winners[4])
{
case 2:
winners[1]=3;
break;
case 3:
winners[1]=2;
break;
}
}
break;
case 2:
switch(winners[3])
{
case 1:
switch(winners[4])
{
case 3:
winners[1]=4;
break;
case 4:
winners[1]=3;
break;
}
break;
case 3:
switch(winners[4])
{
case 1:
winners[1]=4;
break;
case 4:
winners[1]=1;
break;
}
break;
case 4:
switch(winners[4])
{
case 1:
winners[1]=3;
break;
case 3:
winners[1]=1;
break;
}
break;
}
break;
case 3:
switch(winners[3])
{
case 1:
switch(winners[4])
{
case 2:
winners[1]=4;
break;
case 4:
winners[1]=2;
break;
}
break;
case 2:
switch(winners[4])
{
case 1:
winners[1]=4;
break;
case 4:
winners[1]=1;
break;
}
break;
case 4:
switch(winners[4])
{
case 1:
winners[1]=2;
break;
case 2:
winners[1]=1;
break;
}
break;
}
break;
case 4:
switch(winners[3])
{
case 1:
switch(winners[4])
{
case 2:
winners[1]=3;
break;
case 3:
winners[1]=2;
break;
}
break;
case 2:
switch(winners[4])
{
case 1:
winners[1]=3;
break;
case 3:
winners[1]=1;
break;
}
case 3:
switch(winners[4])
{
case 1:
winners[1]=2;
break;
case 2:
winners[1]=1;
break;
}
}
break;
}
return 1;
}
break;
}
break;
case 1:
firstPlayer=suddenDeathPlayers[4];
secondPlayer=suddenDeathPlayers[5];
thirdPlayer=suddenDeathPlayers[6];
switch(amountChar)
{
case 2:
if(collide.playerNo==secondPlayer)
{
winners[firstSlot]=firstPlayer;
winners[secondSlot]=secondPlayer;
return 1;
}
else if(collide.playerNo==firstPlayer)
{
winners[firstSlot]=secondPlayer;
winners[secondSlot]=firstPlayer;
return 1;
}
else
{
return 0;
}
case 3:
if(collide.playerNo==thirdPlayer)
{
if(winners[thirdSlot]==0)
{
winners[thirdSlot]=thirdPlayer;
return 0;
}
else if(winners[secondSlot]==0)
{
winners[secondSlot]=thirdPlayer;
if(winners[thirdSlot]==secondPlayer)
{
winners[firstSlot]=firstPlayer;
}
else if(winners[thirdSlot]==firstPlayer)
{
winners[firstSlot]=secondPlayer;
}
return 1;
}
}
else if(collide.playerNo==secondPlayer)
{
if(winners[thirdSlot]==0)
{
winners[thirdSlot]=secondPlayer;
return 0;
}
else if(winners[secondSlot]==0)
{
winners[secondSlot]=secondPlayer;
if(winners[thirdSlot]==thirdPlayer)
{
winners[firstSlot]=firstPlayer;
}
else if(winners[thirdSlot]==firstPlayer)
{
winners[firstSlot]=thirdPlayer;
}
return 1;
}
}
else if(collide.playerNo==firstPlayer)
{
if(winners[thirdSlot]==0)
{
winners[thirdSlot]=firstPlayer;
return 0;
}
else if(winners[secondSlot]==0)
{
winners[secondSlot]=firstPlayer;
if(winners[thirdSlot]==secondPlayer)
{
winners[firstSlot]=thirdPlayer;
}
else if(winners[thirdSlot]==thirdPlayer)
{
winners[firstSlot]=secondPlayer;
}
return 1;
}
}
}
break;
}
}
return 1;
}