HELP! How to make slot machine columns rotate separately

Dec 8, 2019 at 3:29pm
Hi guys, I'm building a slot machine console program, and I need to make the columns stop rotating one by one. I have manage to make the whole array visually 'rotate', so the whole array spins and stops at the same time, but I don't know how to separate the columns (each wheel).
I'm really stucked on how to do this. Any help will be kindly appreciated


This is the section for randomising and printing the slots from the array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
while (spin == true)
		{

			Set_Color(rand() % 15, 0);

			Draw_String(0, 0, "");


			for (int i = 0; i < rows; i++) { //prints rows

				for (int j = 0; j < cols; j++) { //prints columns

					int random = rand() % 5;

					int temp = slots[i][j];
					slots[i][j] = slots[random][j];
					slots[random][j] = temp;
					cout << "|   " << slots[i][j] << "   |";
				}
				cout << "\n";

			}

			// SECTION: synchronize to a constant frame rate 

			Sleep(100);

			if (GetKeyState('S') & 0x8000)
			{
				// if S is pressed, stop spinning
				spin = false;
			}

			cout << "\n";

			cout << "Press 'S' to stop spinning       ";

		}

		Draw_String(0, 0, "");

		//loop to print randomised slot result
		for (int i = 0; i < 5; i++) {

			for (int j = 0; j < 5; j++) {

				cout << "|   " << slots[i][j] << "   |";
			}
			cout << "\n";

		}


If you need the entire code let me know
Many thanks in advance!
Last edited on Dec 9, 2019 at 2:10pm
Dec 8, 2019 at 4:09pm
Real slot machines spin each wheel at a different rate, and stop each one at a different time.

Your main is way too long.
Move blocks of code out into functions for clarity of purpose, not to mention ease of reading.
1
2
3
4
5
6
7
8
9
10
  while (input != 'n')
  {
    //take 1 coin for each game
    coins--;

    //loop for randomising the slots (array elements)
    animateSlots(slots);
    coins += winnings(slots);
    input = playAgain();
  }
Dec 9, 2019 at 1:05am
Thanks, I've done that now on my main code. How would I go to stop each column one by one? I've managed to make them spin and stop, but all at the same time.
Dec 9, 2019 at 4:38am
Well since you deleted most of the interesting code, it's harder to say.

But what I would suggest would be another function called rotateSlot, which does the actual work of moving one slot around a number of positions.

1
2
3
4
5
for ( col = 0 ; col < 5 ; col++ ) {
    rotate = rand() % 5;
    rotateSlot(slots,col,rotate);
}
printSlots(slots);

Dec 9, 2019 at 8:27pm
Topic archived. No new replies allowed.