Kenthris

Starting Player Positions

Apr 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. //beginning
  2. int sp, counter, player;
  3. //i want to keep i and j for the array, so let's use counter for the sake of consistency
  4. int userflag = 1;
  5. //userflag becomes 0 when the first random user is found, you'll get it later
  6. int direction;
  7. //direction becomes 0 (up), 1 (left) or 2 (right) through the use of rand(). Keep this comment in the code
  8. //it is later used to check a direction's corresponding starting point for availability to put a player on
  9.  
  10. //once dimensions have been decided
  11. sp = (dimensions/2) - 1;
  12.  
  13. //malloc an array the size of players called wincon. it will save the characters u, l, r and d
  14. //which will be the opposite of the player's direction when he is being given a starting point
  15. //malloc an array named pcoord which will be players x 2, where player coordinates will be saved
  16. //initialize all of pcoord to be dimensions + 1
  17.  
  18.  
  19. do{
  20. //select a random number from 0 to 3 and set this number to player
  21. if(pcoord[player][0] == (dimensions + 1)){ //this if checks if the player has already had his starting point set
  22. if((type[player] == 0) && (userflag == 1){ //this if checks for the first randomly chosen player
  23. pcoord[player][0] = sumi;
  24. pcoord[player][1] = sp;
  25. wincon[player] = 'u';
  26. array[sumi][sp] = symbol[player];
  27. userflag = 0;
  28. }
  29. else{//this takes care of every player other than the first randomly selected user
  30. //randomly check a direction
  31. //check for direction's availability. we could potentially use a small array, but i did it the hard way
  32. //make the check in a loop. might need a new variable
  33. if (direction == 0){ //0 is for starting position up (array[2][sp])
  34. pcoord[player][0] = 2;
  35. pcoord[player][1] = sp;
  36. wincon[player] = 'd';
  37. array[2][sp] = symbol[player];
  38. }
  39. else if(direction == 1){ //1 is for starting position left (array[sp][3])
  40. pcoord[player][0] = sp;
  41. pcoord[player] = 3;
  42. wincon[player] = 'r';
  43. array[sp][3] = symbol[player];
  44. }
  45. else if(direction == 2){ //2 is for starting position right (array[sp][sumj])
  46. //could have gone for a simple else, but put the check in as a precaution
  47. pcoord[player][0] = sp;
  48. pcoord[player][1] = sumj;
  49. wincon[player] = 'l';
  50. array[sp][sumj] = symbol[player];
  51. }
  52. }
  53. counter++; //now that a new player has had his starting point set, the counter can increment
  54. }
  55. }while (counter < 4);
Add Comment
Please, Sign In to add comment