Help with Game

Hi there, i have recently been trying to build a slot machine that emulates the wheel actually spinning. For example i would like the characters A B C D E to repeatedly prints at the same position to give the illusion of it rotating. I tried using the "/r" feature which would work but it would only return one character instead of the line. Any help on where i am going wrong would be appreciated. Thanks.

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
#include <cstdlib>    // random numbers header file//
#include <ctime>	// used to get date and time information
#include <conio.h>//used to read and validate input
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int money = 10;//global variable used to keep track of money
int main()
{


	char First[5][3] =  // initialise array to grid
	{
	{ 'A','A','A' },	// row 0
	{ 'B','B','B' },	// row 1
	{ 'C','C','C' },	// row 2
	{ 'D','D','D' },	// row 3
	{ 'E','E','E' },	// row 4
	};

	cout << "Welcome to the Machine              Money Count:"<<money << endl;
	cout << "                Press 1 to spin"<<endl;
	int answer = 0;
	

	//1.0 Display Contents of 2d array
	for (int i = 0; i < 5; i++)
	{
		cout << First[i][1] <<First[i][2]<< First[i][3]<<"\r"; 
		//outputs slot machine board using 2d array contents
	}
My advice is that this is a waste of effort to try to do in the console. The console isn't meant for complicated manipulation like this. I would use a graphical window using SFML or a similar library.
https://www.sfml-dev.org/

That being said, if you still want to try to do something, and you're on windows, look through Microsoft's examples on the Console API.

https://docs.microsoft.com/en-us/windows/console/console-reference
https://docs.microsoft.com/en-us/windows/console/using-the-console
https://docs.microsoft.com/en-us/windows/console/using-the-high-level-input-and-output-functions

If you're on Linux, I'm not sure but perhaps try something like ncurses library would work. But really I just suggest not doing this with a console, and using a GUI window instead.
Last edited on
Thanks for the reply. I'll have a look at those links.
That code probably runs too fast for you to notice. Try this:
1
2
3
4
5
       for (int i = 0; i < 2000000; i++)
        {
            int idx = i % 5;
            cout << First[idx][1] <<First[idx][2]<< First[idx][3]<<'\r';
        }
Oh, that makes more sense. Guess that's a lot easier than using windows api.
@dhayden - That works perfect for one line, i will just need to figure out how to do it for the other lines. Thanks.
If you need to do multiple lines then you should take Guando's advice. At a minimum, you need a curses app.
Topic archived. No new replies allowed.