Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //beginning
- int sp, counter, player;
- //i want to keep i and j for the array, so let's use counter for the sake of consistency
- int userflag = 1;
- //userflag becomes 0 when the first random user is found, you'll get it later
- int direction;
- //direction becomes 0 (up), 1 (left) or 2 (right) through the use of rand(). Keep this comment in the code
- //it is later used to check a direction's corresponding starting point for availability to put a player on
- //once dimensions have been decided
- sp = (dimensions/2) - 1;
- //malloc an array the size of players called wincon. it will save the characters u, l, r and d
- //which will be the opposite of the player's direction when he is being given a starting point
- //malloc an array named pcoord which will be players x 2, where player coordinates will be saved
- //initialize all of pcoord to be dimensions + 1
- do{
- //select a random number from 0 to 3 and set this number to player
- if(pcoord[player][0] == (dimensions + 1)){ //this if checks if the player has already had his starting point set
- if((type[player] == 0) && (userflag == 1){ //this if checks for the first randomly chosen player
- pcoord[player][0] = sumi;
- pcoord[player][1] = sp;
- wincon[player] = 'u';
- array[sumi][sp] = symbol[player];
- userflag = 0;
- }
- else{//this takes care of every player other than the first randomly selected user
- //randomly check a direction
- //check for direction's availability. we could potentially use a small array, but i did it the hard way
- //make the check in a loop. might need a new variable
- if (direction == 0){ //0 is for starting position up (array[2][sp])
- pcoord[player][0] = 2;
- pcoord[player][1] = sp;
- wincon[player] = 'd';
- array[2][sp] = symbol[player];
- }
- else if(direction == 1){ //1 is for starting position left (array[sp][3])
- pcoord[player][0] = sp;
- pcoord[player] = 3;
- wincon[player] = 'r';
- array[sp][3] = symbol[player];
- }
- else if(direction == 2){ //2 is for starting position right (array[sp][sumj])
- //could have gone for a simple else, but put the check in as a precaution
- pcoord[player][0] = sp;
- pcoord[player][1] = sumj;
- wincon[player] = 'l';
- array[sp][sumj] = symbol[player];
- }
- }
- counter++; //now that a new player has had his starting point set, the counter can increment
- }
- }while (counter < 4);
Add Comment
Please, Sign In to add comment