[CODE]def problem_type()
puts "What kind of math problem would you like to do?
Addition: +
Subtraction: -
Multiplication: *"
choice = STDIN.gets.chomp
if choice.eql?("+") or choice.eql?("-") or choice.eql?("*")
return choice
else
puts "#{choice} is not a valid option"
return problem_type()
end
end
def number_of_problems()
puts "How many problems would you like to do?"
numOfProblems = Integer(STDIN.gets.chomp)
if numOfProblems.is_a?(Integer)
return numOfProblems
else
puts "#{numOfProblems} is not a valid choice"
number_of_problems()
end
end
def num_of_digits()
puts "How many digits would you like each problem to be?"
digits = Integer(STDIN.gets.chomp)
if digits.is_a?(Integer)
if digits == 1 or digits == 2
return digits
else
return num_of_digits()
end
else
puts "#{digits} is not a valid choice"
num_of_digits()
end
end
def solve_problems(choice, problems, digit)
correct = 0
incorrect = 0
rand = Random.new
for i in 1..problems do
answer = nil
a = nil
b = nil
if digit == 1
a = rand(1..9)
b = rand(1..9)
elsif digit == 2
a = rand(10..99)
b = rand(10..99)
end
if choice.eql?("+")
answer = a + b
elsif choice.eql?("-")
if a > b
answer = a - b
else
answer = b - a
end
elsif choice.eql?("*")
answer = a * b
end
if a > b
puts "#{a} #{choice} #{b}"
else
puts "#{b} #{choice} #{a}"
end
userAnswer = Integer(STDIN.gets.chomp)
if userAnswer.eql?(answer)
puts "Correct!"
correct+=1
else
puts "Incorrect!"
incorrect+=1
end
end
puts "Total answers correct: #{correct}\nTotal answers incorrect: #{incorrect}"
end
def run_math_project()
choice = problem_type()
puts "\t#{choice} was chosen."
problems = number_of_problems()
puts "\t#{problems} problems will be done."
digit = num_of_digits()
puts "\t#{digit} problems will be done."
solve_problems(choice, problems, digit)
puts "Would you like to practice more? Y/N"
practice = STDIN.gets.chomp
practice.capitalize!
while !practice.eql?("Y") or !practice.eql?("N")
if practice.eql?("Y")
return run_math_project()
elsif practice.eql?("N")
puts "Smell ya later"
return
else
puts "#{practice} was an invalid choice. Just answer the question..."
puts "Would you like to practice more? Y/N"
practice = STDIN.gets.chomp
practice.capitalize!
end
end
end
run_math_project()
[/CODE]
I am currently learning Ruby for fun. It's a really simple math quiz program. Obviously not as cool as some of the projects here, but none the less here it is.
I really enjoy it! I would love for a Ruby expert to tell me I screwed up please because right now I am using Learn Ruby the Hard Way.
I come from a Java background.
I recently got a job teaching/helping cs college kids figure out where their bugs are in their programs at my university. I am not allowed to show them my Java code or write their code for them. So I figured it was a good idea to do one of the first year projects ahead of time so when kids come to me for help, I can explain it while picking up the syntax sugar that is Ruby.
They aren't supposed to be doing recursion as loop control, but I wanted to try out some recursion/test some Ruby features.
Now that the semester has finally started, I am currently enrolled in Computer Organization, apparently we touch on C and primarily work in x86 assembly, as well as Operating Systems and Concepts. Which is described as," Introduction to Linux and Windows systems. GUI and Windowing Systems. Files and Directories. Ownership and Sharing. Programs and Processes. System calls, Libraries. Loading. Dynamic linking. Command Line Shells. Scripting languages. Regular expressions. Clients and Servers. Web browser clients and servers. Secure shell, sftp. SSL/TSL. HTTPS. System Administration. "
I am extremely happy. I have a job, I'm learning cool shit, and all my professors are excellent.
[QUOTE=KillaMaaki;45797950]We'll never get to "the" answer, because there is none.[/QUOTE]
I guess my wording was wrong. My point is that there is no answer, but people who say "you shouldn't use components because X" think they have "the" answer.
Holyshit, one person bought my game !
My quest to becoming a millionaire has now begun.
[QUOTE=Map in a box;45797659]Because you mine as well use inheritance with those dependencies[/QUOTE]
Let's say you have a "Component" container in each entity and each component inherits from Component as well as its dependencies. So you have a super common component such as Position, which Graphics, Collision, etc all inherit from. Now you have two separate Positions in your container.
And now you've essentially recreated C++'s Diamond problem.
Inheritance should [I]only[/I] be used for an "is a" relationship. "Collision" is not a Position, it "has a" Position.
Making a component system without using inheritance is probably going to be awkward, likewise, an entity hierarchy that uses only inheritance and no modular concepts such as components is also likely to become a clusterfuck. Restricting your use of programming paradigms is just going to lead to awkward and badly written code. Be flexible, use whatever concepts or styles you need to fulfil a given task.
[editline]a[/editline]
Arguing strict inheritance heirarchies vs aggregate entities is pointless, a good program draws from both to ensure issues such as the 'diamond problem' don't arise.
[editline]25th August 2014[/editline]
[QUOTE=ECrownofFire;45798600]Inheritance should [I]only[/I] be used for an "is a" relationship. "Collision" is not a Position, it "has a" Position.[/QUOTE]
Also this. Inheritance for "is a" relationships, aggregation/components/modules/whatever for "has a" relationships.
[QUOTE=ECrownofFire;45798600]Let's say you have a "Component" container in each entity and each component inherits from Component as well as its dependencies. So you have a super common component such as Position, which Graphics, Collision, etc all inherit from. Now you have two separate Positions in your container.
And now you've essentially recreated C++'s Diamond problem.
Inheritance should [I]only[/I] be used for an "is a" relationship. "Collision" is not a Position, it "has a" Position.[/QUOTE]
Using inheritance from the getgo instead of components, not extending components like that. Mixins are still the best idea IMO; use components only for things that have uncommon uses
Finally got all of my settings panes done, the View Model is pretty much complete. Just gotta write a few context menus and the processing backend now! Planning on using the ThreadPool to help speed things up. Anyhow, [url=http://a.pomf.se/glkroe.zip]click here[/url] if you wanna try to break it for me :)
[url=http://th03.deviantart.net/fs70/PRE/f/2010/092/1/7/Deadpool_with_a_Web_Shooter_by_Merides.jpg]ThreadPool?[/url] I'm so sorry... I'll leave now.
[B]Working on a new Pig Game.[/B]
[img_thumb]http://i.imgur.com/arGjvI1.jpg[/img_thumb]
[video=youtube;8cCgNy8GJOw]http://www.youtube.com/watch?v=8cCgNy8GJOw[/video]
[img]http://puu.sh/b81PK/4cb3ce0c7b.png[/img]
Dear god.
If only I had taken a class in binary codes.
Maybe then he would donate a whole $5 to me.
If I only understood more about binary coding like this man, maybe I would find a way to improve our meager 90% success rate, and finally find a way to fix Valve's API downtime/rate limiting!
Curse my lack of ambition!
[QUOTE=blacksam;45798440]I am currently learning Ruby for fun. It's a really simple math quiz program. Obviously not as cool as some of the projects here, but none the less here it is.
I really enjoy it! I would love for a Ruby expert to tell me I screwed up please because right now I am using Learn Ruby the Hard Way.
[/QUOTE]
I only see minor things. You're off to a good start!
1. variables should be snake_case, class names are CamelCase.
2. strip is more permissive than chomp
3. `problems.times do` is more idiomatic than `for i in 1..probelms do`
4. eql? is really only for use with hash keys. Usually == is what you want.
5. Integer() throws an exception on failure, so your error check needs to be a begin ... rescue block.
6. The convention is 2 spaces per tab, no hard tabs. I spent years resisting, but life is easier going with the flow.
[QUOTE=Larikang;45801551]6. The convention is 2 spaces per tab, no hard tabs. I spent years resisting, but life is easier going with the flow.[/QUOTE]
Here we go again..
Hard tabs are the best but don't make them quite as large. I usually have my tab size at 2 or 4.
[QUOTE=dvondrake;45801334]
[b]Edit:[/b] Okay, gonna try and make my own UI. No idea where to start for loading and displaying fonts. I swear 3D math is easier than this font shit..[/QUOTE]
If you're using C/C++, you can go for SDL2. If you're using just C++, SFML is another decent go I think. C# has bindings for both SFML and SDL2 I think.
[URL="http://www.ludumdare.com/compo/ludum-dare-30/?action=preview&uid=7173"]ludum dre game[/URL]
[IMG]http://puu.sh/b8d3T/c4d3c48b21.gif[/IMG]
[QUOTE=adnzzzzZ;45801844][URL="http://www.ludumdare.com/compo/ludum-dare-30/?action=preview&uid=7173"]ludum dre game[/URL]
[IMG]http://puu.sh/b8d3T/c4d3c48b21.gif[/IMG][/QUOTE]
Milky Rain.zip is malicious, and Chrome has blocked it. Shame.
[QUOTE=dvondrake;45801949]Thanks, but I'd rather not include such big libraries just to use fonts. I already have a (somewhat) functional engine using GLFW for context, just looking for the font bit on it's own if I can.
Currently looking at QuesoGLC and FTGL, but they seem to output their text to the active framebuffer whereas I'd greatly prefer it if they outputted to textures. Seems kind of overkill/inefficient to make a buffer of my own just for text that goes to a texture anyway, so I may have to figure out kerning and stuff on my own. Boo.
Also, [url=http://quesoglc.sourceforge.net/group__render.php]is this not the most rage-inducing site ever[/url]? Try and get to one of the reference manuals on the left. It's one of those stupid hover menus that keeps disappearing when you try to move the cursor over to one of its links. Fonts, confirmed most difficult thing you can do in OpenGL.[/QUOTE]
[URL="http://gltext.sourceforge.net/"]You can use GLText[/URL].
[QUOTE=Map in a box;45797625]Components often depend on eachother so often its pointless to not use inheritance. At most one could use mixins[/QUOTE]
The whole idea is to make everything loosely coupled. Using inheritance for coupling things is as rigid as it gets.
If a component depends on another one, you need to express that in the context of the component system. Not in the structure of your code.
[QUOTE=Darwin226;45802942]The whole idea is to make everything loosely coupled. Using inheritance for coupling things is as rigid as it gets.
If a component depends on another one, you need to express that in the context of the component system. Not in the structure of your code.[/QUOTE]
Yeah.
Lets have abstract class Tank and abstract class Turret.
Tank requires Turret component with [RequireComponent(typeof(Turret))].
Now you inherit from Tank a class called PanzerTank and you inherit from turret called PanzerGun.
They are loosely coupled.
Too bad I never did this, I always just inherit.. because it is easier and game will be one time only I think :)
[QUOTE=Fourier;45803839]Yeah.
Lets have abstract class Tank and abstract class Turret.
Tank requires Turret component with [RequireComponent(typeof(Turret))].
Now you inherit from Tank a class called PanzerTank and you inherit from turret called PanzerGun.
They are loosely coupled.
Too bad I never did this, I always just inherit.. because it is easier and game will be one time only I think :)[/QUOTE]
If you're more precise about what your dependencies are you can use interfaces instead of concrete types or even just function signatures if you don't need a full blown object.
Ideally, you'd have a more powerful type system than what .NET offers so you could use typeclasses but you can do just fine without them.
That way you just define the what your components inputs are and what it outputs and register it to some dependency resolver that handles the wiring.
[QUOTE=Fourier;45803839]Yeah.
Lets have abstract class Tank and abstract class Turret.
Tank requires Turret component with [RequireComponent(typeof(Turret))].
Now you inherit from Tank a class called PanzerTank and you inherit from turret called PanzerGun.
They are loosely coupled.
Too bad I never did this, I always just inherit.. because it is easier and game will be one time only I think :)[/QUOTE]
Vehicle (require IWheel)
- Tank (require IWeapon)
IWheel
- TankTreads
IWeapon
- TankTurret
PanzerTank and PanzerGun may not even need to exist in this context. They could just be variations of properties exposed on Tank and TankTurret
[QUOTE=dvondrake;45801949]Thanks, but I'd rather not include such big libraries just to use fonts. I already have a (somewhat) functional engine using GLFW for context, just looking for the font bit on it's own if I can.
Currently looking at QuesoGLC and FTGL, but they seem to output their text to the active framebuffer whereas I'd greatly prefer it if they outputted to textures. Seems kind of overkill/inefficient to make a buffer of my own just for text that goes to a texture anyway, so I may have to figure out kerning and stuff on my own. Boo.
Also, [url=http://quesoglc.sourceforge.net/group__render.php]is this not the most rage-inducing site ever[/url]? Try and get to one of the reference manuals on the left. It's one of those stupid hover menus that keeps disappearing when you try to move the cursor over to one of its links. Fonts, confirmed most difficult thing you can do in OpenGL.[/QUOTE]
Any reason against just using a bitmapped font? It's a terribly unoptimal way to go, but it DOES work.
[QUOTE=Dr. Evilcop;45806577]Any reason against just using a bitmapped font? It's a terribly unoptimal way to go, but it DOES work.[/QUOTE]
It's next to impossible to localize into many languages.
Freetype wasn't that hard after I found out I was doing something stupid. Try it
"Write a paragraph summarizing how you used clicking and dragging to make your screen look like Figure A-25."
This is a real assignment I must do for a class I must take in pursuit of a computer science degree.
I'm attempting to take one of my old Unity games I made as a hobby project and turn it into a full fledged mobile game at the moment, I am currently taking my old project files and turning them into a unity 4.6 beta compatible android build version. This mostly right now means reconnecting broken assets :/
[QUOTE=KillaMaaki;45804533]Vehicle (require IWheel)
- Tank (require IWeapon)
IWheel
- TankTreads
IWeapon
- TankTurret
PanzerTank and PanzerGun may not even need to exist in this context. They could just be variations of properties exposed on Tank and TankTurret[/QUOTE]
I am personally an absolutely huge fan of component-centric systems, using interfaces to abstract away coupling.
I won't lie when I say I probably abuse interfaces a bit, but I just absolutely love the idea of having two objects with obscenely different internal functionality (with the same exposed functions) be able to be swapped out without any hassle.
I also try to compartmentalize behavior into sub-objects as well. For example, if I had a Skeleton NPC, rather than having his target-acquisition, moving, and attacking hardcoded, I would delegate these to what I refer to as "packages": TargetPackage, MotionPackage, CombatPackage.
All of these elements implement interfaces (INPC, ITargetPackage,, IMotionPackage, ICombatPackage) that expose their core functionality. Then when I create a realization of them, I can do something like
NPCSkeleton implements INPC
Requires TargetPackageUndead, MotionPackageSimple, CombatPackageMelee
However, if I wanted to change the skeleton's behavior - perhaps make it so rather than just charging straight at a target, it does its best to flank its target - then all I have to do is make it instead use MotionPackageFlank. Likewise, if I want the skeleton to behave as if its part of a pack, where some members of the pack charge head-first and others flank, then I can change to MotionPackagePack and CombatPackagePack.
Similarly, abstracting away behavior like this allows me to create various NPCs that share similar traits while not being clones of one another - for example, I could have my NPCSkeleton as the "Require" described above, and then I could have an NPCPaladin that requires TargetPackageAdventurer, MotionPackageSimple, CombatPackageMelee. My Paladin moves and attacks the same as the skeleton, but instead of targeting the player and living things, he now targets monsters and the undead!
However, my personal favorite use of this sort of component system is to abstract NPCs out even further, and stick with a simple NPCGeneric class. I then use a file format like INI or XML to externally describe NPCs - their display names, health and such variables, and then their packages. For example, the skeleton and Paladin wouldn't be separate classes, but would instead be described as such
[code][NPC]
name=Skeleton
health=5
targetPackage=TargetPackageUndead
motionPackage=MotionPackageSimple
combatPackage=CombatPackageMelee
[NPC]
name=Paladin
health=7
targetPackage=TargetPackageAdventurer
motionPackage=MotionPackageSimple
combatPackage=CombatPackageMelee[/code]
And then I use either reflection, or a static HashMap of String->IPackage (which the packages all implement) to assign the components accordingly.
Doing things like this with just inheritance would be a right pain. I prefer to keep my inheritance trees flat, rather than deep. Components allow me to do that with ease.
Heh, if I were doing that I'd probably go really extreme with it:
[code]
[NPC]
name=Skeleton
level=10
health=5
mesh=Res/Meshes/NPC/Skeleton.fbx // what does this NPC look like
animset=Res/Anims/NPC/Skeleton.animset // what animations does this NPC have
physics=CharacterPhysicsSimple // how does this NPC move
controller=AIController // could be PlayerController too ;)
behaviorClass=UndeadBehavior // behavior class used by AIController
inventory=CharacterInventory // could also be ContainerInventory or whatever
defaultInventory=Res/Misc/InvSet/SkeletonInventory.cfg // maybe this defines what inventory this NPC might have
[/code]
Just as a purely hypothetical example. Want your skeleton to move like a horse instead of a character? That's fine. Have the inventory of an adventurer? Sure. Act like a mudcrab? No problem. Be controlled by the player? Okey dokey.
Damn it who here wrote the VM with the pretty colour bars and how did you handle a framebuffer that was greater than a 16 bit integer assuming it wasn't a 32 bit VM... Sprites or some sort of paging?
Christ, after god knows how many years of searching I finally found this link: [url]http://www.phreedom.org/research/tinype/[/url]
I think someone posted it in waywo ages ago, it's a guy making the smallest possible portable executable that downloads/runs a file from the internet
[QUOTE=ben1066;45808100]Damn it who here wrote the VM with the pretty colour bars and how did you handle a framebuffer that was greater than a 16 bit integer assuming it wasn't a 32 bit VM... Sprites or some sort of paging?[/QUOTE]
I think that was natrox
[QUOTE=ben1066;45808100]Damn it who here wrote the VM with the pretty colour bars and how did you handle a framebuffer that was greater than a 16 bit integer assuming it wasn't a 32 bit VM... Sprites or some sort of paging?[/QUOTE]
My VM was 32-bit.
If you wish to output colors to a frame buffer using 16-bit integers, you could opt for a 16-bit color format like R5G6B5 or a 16-bit palette.
I am not aware of the design of your virtual machine, but you can also split up a 32-bit (A)RGB color into (A)R in the first 2 bytes and GB in the second 2 bytes. You can store these colors in an array of W*H*4b and then use an external function to copy them to a frame buffer.
If I am misunderstanding your issue, you may contact me on Steam so I can help you take a look at it (though I will go to sleep pretty soon).
Sorry, you need to Log In to post a reply to this thread.