Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Slot machine
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amarylis




PostPosted: Wed Nov 30, 2011 8:33 pm   Post subject: Slot machine

Well, er, hello everyone! I'm a new member to compsci.ca ^.^


For my school assignment, I have to create a slot machine program. That's really about the only requirement thus far, the teacher has yet to finish writting the assignment sheet, but I'm sort of already done a version that I could hand in (for a fairly good mark, might I add), and now I figured I would just try to add as many features as I could think of.


My only problem now is, I can't think of anything else that I could add, aside from better graphics (which I am working on. I made the background image on Paint, so it's really not that good at all. Problem with being horrible at art is, well, you're horrible at art). I've uploaded the latest version of it, and would love it if anyone could give me some feedback on it's current state, and/or (if people can find it in their hearts to help) give some advice as to what I could change/add to it



Oh, and if anyone would like an earlier version of it, I can upload that as well Smile



Slot Machine 1.2.rar
 Description:
Slot Machine version 1.2

Download
 Filename:  Slot Machine 1.2.rar
 Filesize:  563.56 KB
 Downloaded:  1117 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Wed Nov 30, 2011 11:20 pm   Post subject: Re: Slot machine

Okay, here are some things I noticed.

First and foremost, the slots should be spun all 3 at the same time (as apposed to one at a time). Like slot machines do. Also I would suggest making the white box take up only the space of the icons.

Secondly,

Turing:

procedure DrawWatermelon (x1 : int)
    Pic.Draw (watermelon, x1, 215, picMerge)
end DrawWatermelon

procedure DrawPear (x1 : int)
    Pic.Draw (pear, x1, 215, picMerge)
end DrawPear

procedure DrawCherry (x1 : int)
    Pic.Draw (cherry, x1, 215, picMerge)
end DrawCherry

procedure DrawClear (x1, x2 : int)
    Draw.FillBox (x1, 215, x2, 275, white)
end DrawClear


All of these procedures could be made into one, and you could just have the picture as a parameter. For instance

Turing:

procedure DrawPicture (x1, x2, picture : int)
    if picture = 0 then % Put in 0 if your looking to erase, also will bullet proof not having the a picture defined
        Draw.FillBox (x1, 215, x2, 275, white)
    else
    Pic.Draw (picture, x1, 215, picMerge)
    end if
end DrawPicture


Your read balance procedure, the if statements could be easier; It would be simpler to say

Turing:

if File.Exists (fileName) = true then
% stuff
else
% stuff
end if


instead of having one if for if it is true, and one for if it is false.


Your "Draw initial graphics" could be a procedure (Name Intro)

When they exit the program, you should delay a second and a half and then close the window. This can be done by instead of saying

Turing:

View.Set ("graphics:738;398,nobuttonbar")


to define your screen, you can use

Turing:

var window : int := Window.Open ("graphics:738;398,nobuttonbar")


that away you can close the window by saying

Turing:

Window.Close (window)




Generally, this program is pretty nice. The only thing that REALLY needs to be fixed is it reeling one at a time. The procedures are a bit redundant, but thats an easily change.

Might I recommend the icons 'spinning' instead of 'flashing'
Amarylis




PostPosted: Thu Dec 01, 2011 6:45 am   Post subject: Re: Slot machine

The procedures really are rather redundant, my teacher just likes seeing them in a program....



Thank you for the input! I think I figured out how to make them flash all three at once (though I'm not entirely sure how I could make them spin... Graphics stuff is not my strong point)
Aange10




PostPosted: Thu Dec 01, 2011 6:16 pm   Post subject: RE:Slot machine

Would you post it?

and

Quote:

The procedures really are rather redundant, my teacher just likes seeing them in a program


Having anything redundant is terrible. It slows down the program, makes it harder to read, and more code generally adds unnecessary complexity.


Your teacher would be much more impressed to see you having a procedure with a parameter that also doubles to bullet proof it.
Amarylis




PostPosted: Thu Dec 01, 2011 7:03 pm   Post subject: Re: Slot machine

I'm not entirely sure how much my teacher actually knows about programming, I sometimes get the feeling she just looks to see if there are procedures (not for the content of them), and if the program runs. Aside from that, and the visual components to the projects (she likes to have "pretty pictures" in the programs), everything is pretty much fair game for what the actual code is, no matter how redundant or unnecessary it is.


The general consensus seems to be, the more complex the program, the higher the mark, irrelevant of how needed the complexity actually is.


As for the program itself, I'm uploading it now (it should be attached to this post, right? Sorry, new to this forum and not quite sure how these things work in this one Razz)



Slot Machine v1.2.5.rar
 Description:

Download
 Filename:  Slot Machine v1.2.5.rar
 Filesize:  564.44 KB
 Downloaded:  117 Time(s)

Aange10




PostPosted: Thu Dec 01, 2011 7:08 pm   Post subject: RE:Slot machine

Sounds to me like your teacher is terrible.
Aange10




PostPosted: Thu Dec 01, 2011 7:19 pm   Post subject: RE:Slot machine

It wouldn't be terribly difficult to have the flash at different times, it makes it seem less like your being juked.

Also

Turing:

    for i : 1 .. 5
        DrawPictures (133, 193, 0)
        DrawPictures (263, 323, 0)
        DrawPictures (393, 453, 0)
        DrawPictures (133, 193, watermelon)
        DrawPictures (263, 323, watermelon)
        DrawPictures (393, 453, watermelon)
        delay (75)
        DrawPictures (133, 193, 0)
        DrawPictures (263, 323, 0)
        DrawPictures (393, 453, 0)
        DrawPictures (133, 193, pear)
        DrawPictures (263, 323, pear)
        DrawPictures (393, 453, pear)
        delay (75)
        DrawPictures (133, 193, 0)
        DrawPictures (263, 323, 0)
        DrawPictures (393, 453, 0)
        DrawPictures (133, 193, cherry)
        DrawPictures (263, 323, cherry)
        DrawPictures (393, 453, cherry)
        delay (75)
    end for

    choice (1) := Rand.Int (1, 3)
    if choice (1) = 1 then
        DrawPictures (133, 193, 0)
        DrawPictures (133, 193, watermelon)
    elsif choice (1) = 2 then
        DrawPictures (133, 193, 0)
        DrawPictures (133, 193, pear)
    elsif choice (1) = 3 then
        DrawPictures (133, 193, 0)
        DrawPictures (133, 193, cherry)
    end if

    for i : 1 .. 5
        DrawPictures (263, 323, 0)
        DrawPictures (393, 453, 0)
        DrawPictures (263, 323, watermelon)
        DrawPictures (393, 453, watermelon)
        delay (75)
        DrawPictures (263, 323, 0)
        DrawPictures (393, 453, 0)
        DrawPictures (263, 323, pear)
        DrawPictures (393, 453, pear)
        delay (75)
        DrawPictures (263, 323, 0)
        DrawPictures (393, 453, 0)
        DrawPictures (263, 323, cherry)
        DrawPictures (393, 453, cherry)
        delay (75)
    end for

    choice (2) := Rand.Int (1, 3)
    if choice (2) = 1 then
        DrawPictures (263, 323, 0)
        DrawPictures (263, 323, watermelon)
    elsif choice (2) = 2 then
        DrawPictures (263, 323, 0)
        DrawPictures (263, 323, pear)
    elsif choice (2) = 3 then
        DrawPictures (263, 323, 0)
        DrawPictures (263, 323, cherry)
    end if

    for i : 1 .. 5
        DrawPictures (393, 453, 0)
        DrawPictures (393, 453, watermelon)
        delay (75)
        DrawPictures (393, 453, 0)
        DrawPictures (393, 453, pear)
        delay (75)
        DrawPictures (393, 453, 0)
        DrawPictures (393, 453, cherry)
        delay (75)
    end for


    choice (3) := Rand.Int (1, 3)
    if choice (3) = 1 then
        DrawPictures (393, 453, 0)
        DrawPictures (393, 453, watermelon)
    elsif choice (3) = 2 then
        DrawPictures (393, 453, 0)
        DrawPictures (393, 453, pear)
    elsif choice (3) = 3 then
        DrawPictures (393, 453, 0)
        DrawPictures (393, 453, cherry)
    end if


If you ever find yourself with code that is so repetitive, then you should consider for loops, or another means.

Think about what your i for loop does... It shows us how many times we drew the item to the screen.

So why can't our j : for (for example) keep track of what we're assigning values for?

To put it to test

Turing:

for j : 1 .. 3
for i : 1 .. 5
    % Draw stuff
    % Delay
    % Draw stuff
    % Delay
    % Draw stuff
    % Delay
    % SomeVariable := Rand.Int (1,3)
   if i = 5 then % Top of the for
         if choice (j) = SomeVariable then
             %Assign
        end if
    end if
end for
end for



* One with ingenuity would realize the redundancy within the i for (Drawing three times, delaying). If said person had said ingenuity, they could think of an efficient way to fix it.
Amarylis




PostPosted: Thu Dec 01, 2011 8:21 pm   Post subject: Re: Slot machine

Okay, so I'm fairly sure I have it now. If anything, it's at least more programmer-friendly, not quite sure about efficency... I made a process for drawing everything with parameters that set it so my first for loop will define how many of the icons will be flashing. Here it is~


Slot Machine v1.2.6.rar
 Description:

Download
 Filename:  Slot Machine v1.2.6.rar
 Filesize:  17.44 KB
 Downloaded:  105 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Thu Dec 01, 2011 9:06 pm   Post subject: RE:Slot machine

Congradulations! Its a lot less redundant!

Do remember repetitive thigns often can be fixed with a procedure or a for, in this case

Turing:

        DrawPictures (133, 193, watermelon)
        DrawPictures (263, 323, watermelon)
        DrawPictures (393, 453, watermelon)
% Could be simplified as
        for i : 1 .. 3
             DrawPictures (i * 133, (i * 133) + 60, watermelon)
        end for


But ingenuity is a big part of this. In my opinion you are doing really well. So don't let a lot of criticism bring you down.

Sometimes the criticism turns out to be just suggestions.


...
Changing the drawpic to clear everytime seems a bit unneccasary. Keeping it at 0 would be better, it's less the computer has to do; you call it every time you draw something, which is unneccasary.

Try adding the 0 parameter back in, and doing it only after delays.

You made a whole new procedure that just has an x parameter, and then some if statements telling it how many times to repeat. Instead of the if statements, why don't you use it as it's end result; how many times it repeats.

Turing:

for i : 1 .. x


See how our procedure just went from 37 lines to 5 lines?

....
I also suggest you fix your comments going off the screen in windowed mode. It's a more or less general way of commenting, see Turing Walkthrough for a 'how to comment' tutorial.

I personally find

Turing:

% ____________ Dividers ___________

% Describers
if I do this then
that happens
end if % Specific Describers


to be a nice style of commenting.


Line 76, you probably have a typo. If I'm correct your looking for strintok not strrealok.


Also I noticed you have a lot of variable declarations and what not towards the bottom of the screen. Can't most of that go at the top, with the other declarations?
Amarylis




PostPosted: Thu Dec 01, 2011 9:57 pm   Post subject: Re: Slot machine

Okay, I've simplified the code even further, and don't worry, I take criticism not as a "put down" of sorts, but more of a challange :3 I know that I wont be able to learn anything more through my school, so I decided to post things in here where others who have a much broader knowledge on the subject than I can give their input on my code.


As for my clearing the area where I'll draw a new picture every time, it seems necessary thus far, but I think changing the Pic.Draw's picMerge parameter to a picCopy should fix that right up


I've fixed the things you've mentioned, and yes, line 76 was a typo that I had forgotten to fix when I changed the balance into an integer as opposed to a real


Uploaded 1.2.6.1



Slot Machine v1.2.6.1.rar
 Description:

Download
 Filename:  Slot Machine v1.2.6.1.rar
 Filesize:  17.49 KB
 Downloaded:  101 Time(s)

Aange10




PostPosted: Thu Dec 01, 2011 11:22 pm   Post subject: RE:Slot machine

Quote:
As for my clearing the area where I'll draw a new picture every time, it seems necessary thus far, but I think changing the Pic.Draw's picMerge parameter to a picCopy should fix that right up


Definitely necessary.. If your drawing the picture back on top of another picture. picMerge isn't the problem.

Say If I have a 5x5 grid, and I color a square at 1,1 and another at 2,2 and another at 3,3, I don't need to erase each box before i color it. I only need to erase them if there's something already there.

The biggest problem here, is that if there came a time you needed another picture into the procedure, it might make things not work so well.

Think about when you need it to clear, and do it there. Instead of hard coding the procedure to do it every time.


Other than that, theres a tiny flaw in your program. (And no, I'm not talking about the syntax errors in the procedures(: )

Whats the point of your for i in drawEverything procedure?

Toy with that, and see why you don't want it.

Also your if choice (z) = 1 then statements are being ran 5 times in the *spin*. Don't you want it to do it once; at the end?
Amarylis




PostPosted: Fri Dec 02, 2011 5:23 am   Post subject: RE:Slot machine

oh, crap, I thought I took the choice(z) out of the second for loop Razz
evildaddy911




PostPosted: Fri Dec 02, 2011 8:37 am   Post subject: Re: Slot machine

Quote:
I'm not entirely sure how much my teacher actually knows about programming, I sometimes get the feeling she just looks to see if there are procedures (not for the content of them), and if the program runs. Aside from that, and the visual components to the projects (she likes to have "pretty pictures" in the programs), everything is pretty much fair game for what the actual code is, no matter how redundant or unnecessary it is.

yeah, same with my teacher, i asked him how to use numbers with Input.KeyDown, and he said, "I dont know, ive never used it before
Amarylis




PostPosted: Fri Dec 02, 2011 12:53 pm   Post subject: Re: Slot machine

Okay, so I'm fairly sure this should hold the script, almost void of all useless crap.


Slot Machine v1.2.6.2.rar
 Description:

Download
 Filename:  Slot Machine v1.2.6.2.rar
 Filesize:  17.43 KB
 Downloaded:  134 Time(s)

Aange10




PostPosted: Sat Dec 03, 2011 7:56 pm   Post subject: RE:Slot machine

Seems better. Now just time to add features! Yay!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: