Posted: 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
Posted: 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
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 =0then% 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) endif end DrawPicture
Your read balance procedure, the if statements could be easier; It would be simpler to say
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
Posted: 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
Posted: 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
Posted: 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 )
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 =5then% Top of the for if choice (j)= SomeVariable then %Assign endif endif endfor endfor
* 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
Posted: 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~
Posted: 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) endfor
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
endif% 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
Posted: 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
Posted: 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 fori 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
Posted: 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
evildaddy911
Posted: 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
Posted: 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.