• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Joshua D Farrow

Code Review - Dice Game (No graphics)

13 posts in this topic

This is my first code review post. This is a text-based java game that was very simple to make. I am trying to keep my focus on learning the basics of programming, rather than messing with graphics. Please let me know what I can do better.

 

Here is the PasteBin link:

http://pastebin.com/6ABunV4H

 

0

Share this post


Link to post
Share on other sites

Indifferent,

 

Thank you so much for your review. Just by looking at my code, I knew that there were a ton of things that could have been done better. Most of the things you pointed out were the issues that I knew needed to be fixed, but wasn't sure how. I highly appreciate you taking the time to review it, and more importantly, that you were nice about it and offered me some solutions. The biggest thing that I would like to learn is coding etiquette and formatting. Do you happen to know of any websites or articles that offer any insight into this? 

0

Share this post


Link to post
Share on other sites

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. ;)

 

Thank you for this 

0

Share this post


Link to post
Share on other sites

Indifferent,

 

Thank you so much for your review. Just by looking at my code, I knew that there were a ton of things that could have been done better. Most of the things you pointed out were the issues that I knew needed to be fixed, but wasn't sure how. I highly appreciate you taking the time to review it, and more importantly, that you were nice about it and offered me some solutions. The biggest thing that I would like to learn is coding etiquette and formatting. Do you happen to know of any websites or articles that offer any insight into this? 

 

There are quite a few books that you'll see recommended time and time again. Code Complete seems to be a seminal book that might interest you, although I haven't read it myself so I can't vouch for it.

 

I personally just tend to read articles that I stumble across, search for recommendations when I'm unsure whether I'm going about something in the right way (almost every question has been asked and answered a dozen times already) or browse forums like this one.

1

Share this post


Link to post
Share on other sites

I agree with most of the things Indifferent says, but I want to add a few small things.

 

All methods are static. Basically this means there is no Object Oriented programming, which makes it harder to break things apart. I think it would be a good idea to try and find a book that discusses Java and OO.

Logic and UI are not separated. This is along the lines with Indifferents "Class length", but with a different angle.. When you separate the logic from the actual UI output it will be easier later on to try and add a Graphical layer, besides that it will be easier to test your logic using unit tests.

In the rules() method you have multiple calls to System.out.println(), and although it is probably a matter of taste, I would combine the complete string and print it all in one println().

 

Btw. for method lengths a good rule of thumb is methods between 3 and 7 lines, especially when the logic is complex, you want less lines.

1

Share this post


Link to post
Share on other sites

Thanks, both of you, for the advice on using classes. I'm currently reading through a book titled "Java Programming: From the Ground Up", and have just gotten to the basics of OOP. In fact, I think the chapter I'm about to start is about making classes and implementing them correctly.

 

 

Btw. for method lengths a good rule of thumb is methods between 3 and 7 lines, especially when the logic is complex, you want less lines.

I'm always afraid that I'm going to have too many methods in my program, so would I clear this up by making custom classes, and then just creating an object that can reference them?

 

 

Code Complete seems to be a seminal book that might interest you, although I haven't read it myself so I can't vouch for it.

Thanks for this! I'll look it up on Amazon and give it a whirl.

Edited by litta_gator
0

Share this post


Link to post
Share on other sites

Btw. for method lengths a good rule of thumb is methods between 3 and 7 lines, especially when the logic is complex, you want less lines.

I'm always afraid that I'm going to have too many methods in my program, so would I clear this up by making custom classes, and then just creating an object that can reference them?

I don't think you can have too many methods in a program. As is said before, your class should have one responsibility, but your methods shoud also have just one responsibility. Besides that, not all methods have to be public.

That being said, sometimes there are reasons to make a method larger than usually. This could be for readability or performance.

I can recommend the articles, videos and book of Robert C. Martin about "Clean Code". It is a relative old book, but still very usefull to read.

1

Share this post


Link to post
Share on other sites

I can recommend the articles, videos and book of Robert C. Martin about "Clean Code". It is a relative old book, but still very usefull to read.

 

Thank you so much for this. I know that this code isn't very elaborate, nor is the game. But, I really appreciate the objectiveness you have shown me. I know that sometimes, newbies (like me) are easy to tear apart, since their code is messy and wrong. You guys have really helped me to feel welcome to GameDevs. Thank you for all of your advice.

0

Share this post


Link to post
Share on other sites

 

Btw. for method lengths a good rule of thumb is methods between 3 and 7 lines, especially when the logic is complex, you want less lines.

I'm always afraid that I'm going to have too many methods in my program, so would I clear this up by making custom classes, and then just creating an object that can reference them?

I don't think you can have too many methods in a program. As is said before, your class should have one responsibility, but your methods shoud also have just one responsibility. Besides that, not all methods have to be public.

That being said, sometimes there are reasons to make a method larger than usually. This could be for readability or performance.

I can recommend the articles, videos and book of Robert C. Martin about "Clean Code". It is a relative old book, but still very usefull to read.

 

This might help... you don't always have to think of methods as performing some vital function... sometimes you can have a private method whose sole purpose is to simplify the code in a more complicated public method.  I often write little private methods that do various bits of non-trivial math operations, just to simplify the code.

1

Share this post


Link to post
Share on other sites

This might help... you don't always have to think of methods as performing some vital function... sometimes you can have a private method whose sole purpose is to simplify the code in a more complicated public method. I often write little private methods that do various bits of non-trivial math operations, just to simplify the code.

Agreed, sometimes I make a method just for the condition of an if statement, especially when it is more complex or used multiple times.

1

Share this post


Link to post
Share on other sites

Agreed, sometimes I make a method just for the condition of an if statement, especially when it is more complex or used multiple times.

 

I'm starting to realize this. I'm big about "clearing" the screen whenever changing player turns. I realized that it was a lot simpler to write a small method named clearScreen(), rather than type out:

 

for(int i=0;i<10;i++)
{
  System.out.println();
}

 

every single time that I wanted to clear the screen.

0

Share this post


Link to post
Share on other sites

I know that using global variables is usually frowned upon, but is it okay to use them if I believe that I can do so efficiently?

Edited by litta_gator
0

Share this post


Link to post
Share on other sites

I know that using global variables is usually frowned upon, but is it okay to use them if I believe that I can do so efficiently?

 

There are no hard and fast rules in programming, even when it comes to some of the more controversial constructs. Although a global or two likely won't hurt, you should get into the habit of doing what you can to avoid needing them.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0