Node Js Blackjack Server
- Node JS, Javascript, and AJAX. Is there any code for this? Search a lot on google as newbie, but no luck.
- How to set up your very own repository of Node.js modules with Blackjack and version control. ISPmanager for web-server management, VMmanager for virtualization, and BILLmanager for hosting.
Designing websites was always the next big step for me after graduating art school and I am finally making that dream a reality. I love the entire creative process, from concept to creation, and I especially enjoy working with people who share the same passions for code and design as I do. How to set up your very own repository of Node.js modules with Blackjack and version control ISPsystem currently has 3 front-end teams developing three large projects: ISPmanager for web-server management, VMmanager for virtualization, and BILLmanager for hosting business automation. My first repl share - a Blackjack program with some degree of UI. Didn't know how I managed to make a simple program contain 600 lines of code, but please try it out regardless.
- 1
Welcome to the Ranch!
When posting code, please UseCodeTags (←click that link to learn how). They make code so much easier to read and reference in replies because they provide line numbers to the listing. As a courtesy to a newcomer such as yourself, we will add those for you this time.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
1. You put everything in your main() method. We have a wiki page that explains why Main Is A Pain. You might want to read that if you want to avoid feeling that pain over and over again.
2. Because you have put all your code into the same method, you have amassed a huge amount of it. Lots of code in one method is BAD. Lots of code that does lots of things in one method is WORSE. Lots of code that does lots of things in loops that have been nested lots of times is the WORST. Wait for it...
3. Code that is not aligned properly to clearly show the different levels of logical structures of your code is the WORST of the WORST.
Ok, so there's a lot of bad stuff going on in that code and I've even barely scratched the surface.
So you don't feel too bad, let me just say that it's a pleasant surprise to see someone use something like 'n'.equals(anotherCard). There are a couple things right about that little gem in the muck around it but just look at it for a little bit if you want to feel better.
Next reply, we'll talk about what you can do to get out of that corner.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
1. Hack your way out.
2. Clean your way out.
One way may get you out eventually but it's likely to leave your code in a bigger mess than it's in now.
The other way, of course, will get you out with your code in much better shape than what it's in now.
You choose. The right way is not always the easiest way though.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
In Eclipse or NetBeans, the keyboard command to autoformat your code is CTRL+SHIFT+F. That will give you something like the listing below; I added some blank lines to get separation between a few logical parts of the code (another favor... you owe us TWO now):
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
mike laww wrote:Such a simple command to format my entire code, gee that would've been nice to know... professor. Ya think she would've taught us such a simple trick!
Yeah, you'd think that would be one of the first things they teach but no. It's one of the first things I taught my son when he enrolled in his first programming course in college last year.
Have you made your choice on which way you want to go? Hack your way out or Clean your way out? Choose wisely... there is only one path down which I will be willing to go with you. Choose poorly and you're on your own.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
methods should be broken out by actions as described in English (or whatever language you speak). Imagine you were telling a story of what happens:
Deal a card to the player
Deal a card to the dealer
Deal a card to the player
Deal a card to the dealer
ask the player what they want to do
get their answer
etc..
you do this, then look for 'actions'. So, 'deal a card' is something you DO. Note that it doesn't matter who you are dealing to, the process is the same - select a card from what's left in the deck. once you know what it is, you add it to the correct player's hand...
Methods for getting and setting variables are OK - they're sometimes called 'getters' and 'setters', or 'accessors' and 'mutators' (I think), but they are part of a class (like a Player class). I'm not sure if you're going to start defining your own classes yet...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
- 1
mike laww wrote:So, would it be organized by different data types? Like a method for loops, method for if statements, method for setting and getting variables, etc?
As Fred said, your program is broken out by actions. I like to call them 'behaviors' because I find that helps shift your mindset to a place where it's more natural to think of the programs as living, sentient 'things', i.e. Objects. You heard that Java is an object-oriented programming language, right?
Let's not get ahead of ourselves yet though. Just think of it for now as something called 'functional decomposition' - breaking down your huge problem into smaller, more manageable problems that focus on one small part of the larger whole.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
This gradual breaking down of the problem from high-level to more details, then to even more details as you drill down and finally arrive at the smallest task, like 'Mom, how do I peel the potatoes?' and Mom will say, 'Go to the drawer next to the sink, pull it out, dig around for the peeler, make sure you wash the potatoes first, then get a trash bag ready, walk over to the island, set the potatoes down, then start peeling those taters!' That level of detail would not have been appropriate during that first time that she asked you to prepare Thanksgiving dinner, right?
Mom held off giving you those details until just the right moment when you were ready to follow that many detailed instructions to a Tee. Giving you all of those detailed instructions up front would have been like the mess that you find right now in your main() method, right? All jumbled up and confusing as heck. How would you ever get dinner ready that way?!
That's kind of like how you want to layer your program instructions. Start with the large one-liner command in the main() method. Ideally, it would look something like this:
That's it! And then, the play method would look something like this:
And then you just keep drilling down into more details of each of the initPlayer(), initGame(), playUntilSomebodyWins(), and other methods you see there.
It's not that complicated. It just takes a little bit of organization and logical thinking.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
Welcome to the Ranch!
When posting code, please UseCodeTags (←click that link to learn how). They make code so much easier to read and reference in replies because they provide line numbers to the listing. As a courtesy to a newcomer such as yourself, we will add those for you this time.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
1. You put everything in your main() method. We have a wiki page that explains why Main Is A Pain. You might want to read that if you want to avoid feeling that pain over and over again.
2. Because you have put all your code into the same method, you have amassed a huge amount of it. Lots of code in one method is BAD. Lots of code that does lots of things in one method is WORSE. Lots of code that does lots of things in loops that have been nested lots of times is the WORST. Wait for it...
3. Code that is not aligned properly to clearly show the different levels of logical structures of your code is the WORST of the WORST.
Ok, so there's a lot of bad stuff going on in that code and I've even barely scratched the surface.
So you don't feel too bad, let me just say that it's a pleasant surprise to see someone use something like 'n'.equals(anotherCard). There are a couple things right about that little gem in the muck around it but just look at it for a little bit if you want to feel better.
Next reply, we'll talk about what you can do to get out of that corner.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
1. Hack your way out.
2. Clean your way out.
One way may get you out eventually but it's likely to leave your code in a bigger mess than it's in now.
The other way, of course, will get you out with your code in much better shape than what it's in now.
You choose. The right way is not always the easiest way though.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
In Eclipse or NetBeans, the keyboard command to autoformat your code is CTRL+SHIFT+F. That will give you something like the listing below; I added some blank lines to get separation between a few logical parts of the code (another favor... you owe us TWO now):
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
mike laww wrote:Such a simple command to format my entire code, gee that would've been nice to know... professor. Ya think she would've taught us such a simple trick!
Yeah, you'd think that would be one of the first things they teach but no. It's one of the first things I taught my son when he enrolled in his first programming course in college last year.
Have you made your choice on which way you want to go? Hack your way out or Clean your way out? Choose wisely... there is only one path down which I will be willing to go with you. Choose poorly and you're on your own.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
- 1
methods should be broken out by actions as described in English (or whatever language you speak). Imagine you were telling a story of what happens:
Deal a card to the player
Deal a card to the dealer
Deal a card to the player
Deal a card to the dealer
ask the player what they want to do
get their answer
etc..
you do this, then look for 'actions'. So, 'deal a card' is something you DO. Note that it doesn't matter who you are dealing to, the process is the same - select a card from what's left in the deck. once you know what it is, you add it to the correct player's hand...
Methods for getting and setting variables are OK - they're sometimes called 'getters' and 'setters', or 'accessors' and 'mutators' (I think), but they are part of a class (like a Player class). I'm not sure if you're going to start defining your own classes yet...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
- 1
mike laww wrote:So, would it be organized by different data types? Like a method for loops, method for if statements, method for setting and getting variables, etc?
As Fred said, your program is broken out by actions. I like to call them 'behaviors' because I find that helps shift your mindset to a place where it's more natural to think of the programs as living, sentient 'things', i.e. Objects. You heard that Java is an object-oriented programming language, right?
Let's not get ahead of ourselves yet though. Just think of it for now as something called 'functional decomposition' - breaking down your huge problem into smaller, more manageable problems that focus on one small part of the larger whole.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code
Node Js Blackjack Server Cs 1.6
- 1
This gradual breaking down of the problem from high-level to more details, then to even more details as you drill down and finally arrive at the smallest task, like 'Mom, how do I peel the potatoes?' and Mom will say, 'Go to the drawer next to the sink, pull it out, dig around for the peeler, make sure you wash the potatoes first, then get a trash bag ready, walk over to the island, set the potatoes down, then start peeling those taters!' That level of detail would not have been appropriate during that first time that she asked you to prepare Thanksgiving dinner, right?
Mom held off giving you those details until just the right moment when you were ready to follow that many detailed instructions to a Tee. Giving you all of those detailed instructions up front would have been like the mess that you find right now in your main() method, right? All jumbled up and confusing as heck. How would you ever get dinner ready that way?!
That's kind of like how you want to layer your program instructions. Start with the large one-liner command in the main() method. Ideally, it would look something like this:
That's it! And then, the play method would look something like this:
And then you just keep drilling down into more details of each of the initPlayer(), initGame(), playUntilSomebodyWins(), and other methods you see there.
It's not that complicated. It just takes a little bit of organization and logical thinking.
Node Js Blackjack Server Commands
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions How to Answer Questions Format Your Code