So right now I have two big problems. I am trying to create a slot machine. There are 4 images I can have. Obviously if all 3 images are the same, I win, if they aren't I lose. For my bool return function, I have:
And for my Image return function, I have:
Image out_image(Point pt, int w, int h, int symbol)
{
Image img = out_image(pt, w, h, symbol);
return (img);
}
I'm not sure if either of these are right, but what confuses me is what to write in "instint_main()". I have the math correct, but I can't seem to get a "winning" output when all 3 reels are equal, I'm guessing my bool statements are wrong. And also, for each random number (this is my last function):
int rand_pic(int min, int max)
{
int random_number = rand()%(max-min+1)+min;
return (random_number);
}
i do something like this in instinct_main() (not sure if correct though):
int reel1 = rand_pic(0,3);
int reel2 = rand_pic(0,3);
int reel3 = rand_pic(0,3);
and this goes right before the bool statement. the range is 0-3 because I have a total of 4 images, and each number (chosen randomly per reel) corresponds to that certain image, and I have NO clue whatsoever how to code that. ive tried everything, it just does not work. Please help, please!
This is my entire code
------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "instinct.h"
using namespace std;
int rand_pic(int min, int max)
{
int random_number = rand()%(max-min+1)+min;
return (random_number);
}
Image out_image(Point pt, int w, int h, int symbol)
{
Image img = out_image(pt, w, h, symbol);
return (img);
}
int instinct_main()
{
srand(time(NULL));
win.set_background_color(WHITE);
// Starting Credits, with a min and a max.
int starting_credits;
const int MIN = 1;
const int MAX = 99;
// Getting the starting credits.
starting_credits = win.get_int("Please enter your "
"starting credits (1-99): \n");
// Must be between min and max
// If not, it re-asks until you put in a valid number.
while (!(starting_credits >= MIN && starting_credits <= MAX))
{
starting_credits = win.get_int("Please enter another number "
"(1-99)\n");
}
win.output_buffer();
// second part
// Constant position for "CREDITS"
// Underneath "CREDITS" will go the current credits count
//first output
int tot_creds;
const string CREDITS = "CREDITS";
const double creds_name_pos_x = 4.5;
const double creds_num_pos_x = 4.8;
const double creds_name_pos_y = 4;
const double creds_num_pos_y = 3.5;
// Constant position for current/total credits, right under "CREDITS"
// first output (show number that you inputed)
// part three
int width = 1;
double height = 0.75;
const double OUTCOME_TXT_WIDTH = 4.375;
const int OUTCOME_TXT_HEIGHT = 7;
Point outcome_pos = Point(OUTCOME_TXT_WIDTH, OUTCOME_TXT_HEIGHT);
// strings for images to be randomly selected
const string LEMON = "image0.jpg";
const string CHERRY = "image1.jpg";
const string MELON = "image2.jpg";
const string BANANA = "image3.jpg";
// Messages for win or loss
Message WINNER = Message(outcome_pos,"WINNER: You won 5 credits!");
Message LOSER = Message(outcome_pos,"LOSER: You lost 1 credit!");
// Function from the beginning
bool win_or_lose;
// part four
// Outputting pictures.
int choice;
int win_num = 5;
const int SENTINEl = 0;
Point p1 = Point(2.75,5);
Point p2 = Point(4.5,5);
Point p3 = Point(6.25,5);
choice = win.get_int("Please enter your choice "
"(0 to quit, 1 to bet 1).");
while (choice != 0)
{
while (choice == 1)
{
int reel1 = rand_pic(0,3);
int reel2 = rand_pic(0,3);
int reel3 = rand_pic(0,3);
if (win_or_lose == true)
{
win.clear_buffer();
WINNER = Message(outcome_pos,"WINNER\n+ 5 Credits!!");
tot_creds = tot_creds - choice + win_num;
creds_num = Message(creds_num_loc, tot_creds);
win << creds_name << WINNER << creds_num;
win.output_buffer();
choice = win.get_int("Please enter your choice "
"(0 to quit, 1 to bet 1).");
}
else
{
win.clear_buffer();
LOSER = Message(outcome_pos,"LOSER\n-1 Credit!");
tot_creds = tot_creds - choice;
creds_num = Message(creds_num_loc, tot_creds);
win << creds_name << creds_num << LOSER;
win.output_buffer();
choice = win.get_int("Please enter your choice "
"(0 to quit, 1 to bet 1).");
}
}
while (choice != 0 && choice != 1)
{
win.clear_buffer();
Message creds_name = Message(cred_name_loc, CREDITS);
Message creds_num = Message(creds_num_loc, tot_creds);
win << creds_name << creds_num;
win.output_buffer();
choice = win.get_int("Please re-enter your choice "
"0 to quit, 1 to bet 1:");
if (choice == 1)
{
if (win_or_lose == true)
{
win.clear_buffer();
WINNER = Message(outcome_pos,"WINNER\n"
"+5 Credits!!");
tot_creds = tot_creds - choice + win_num;
creds_num = Message(creds_num_loc, tot_creds);
win << creds_name << WINNER << creds_num;
win.output_buffer();
choice = win.get_int("Please enter your choice "
"(0 to quit, 1 to bet 1).");
}
else
{
win.clear_buffer();
LOSER = Message(outcome_pos,"LOSER\n-1 Credit!");
tot_creds = tot_creds - choice;
creds_num = Message(creds_num_loc, tot_creds);
win << creds_name << creds_num << LOSER;
win.output_buffer();
choice = win.get_int("Please enter your choice "
"(0 to quit, 1 to bet 1).");
}
}
}
}