Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Scoring machine help.

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Scoring machine help.

    Hi guys! right now I'm programming a simple zombie survival game and I want to keep adding the score with the use of an object. Whenever the player makes a decision there will be a certain points to be given to him or her. What's a simple way of making a scoring machine?

    Here is a sample of what the code looks like:

    System.out.println("\tYou have been hiding inside your house for a long time.");
    		System.out.println("\tOutside there are plenty of zombies. What will you do?");
    		System.out.println("");
    		System.out.println("\t\t==================================================");
    		System.out.println("\t\t|| [1] Barricade the house                      ||");
    		System.out.println("\t\t|| [2] Go outside and fight the zombies         ||");
    		System.out.println("\t\t|| [3] Search for supply                        ||");
    		System.out.println("\t\t|| [4] Escape through the back                  ||");
    		System.out.println("\t\t==================================================");
    		System.out.println("\t\tWhat would it be?:");
    		int ans1 = keyIn.nextInt();
     
    		if(ans1 == 1)
    			HomeGame.home1a(); //add score
     
    		if(ans1 == 2)
    			HomeGame.home1b(); //add score
     
    		if(ans1 == 3)
    			HomeGame.home1c(); //add score
     
    		if(ans1 == 4)
    			HomeGame.home1d(); //add score

    I would really appreciate the help guys. Thanks!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Scoring machine help.

    I might have used a switch statement where the code switches on ans1 and each case decides what score amount to add, and what to do next all in one go.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Scoring machine help.

    Sorry I didn't quite understand that

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Scoring machine help.

    Quote Originally Posted by hawkeye10 View Post
    Sorry I didn't quite understand that
    Did you click on the link and read about switch case? If not, do so. If so, what is your question? You asked for a simple way of making a scoring machine. Looking at your code design, I suggest using a switch in place of the if/else. Maybe you did not get to this in class yet? (maybe you do not take classes?) There are samples available with minimal searching, and people are here to answer questions if you have any.

Similar Threads

  1. ATM machine
    By MostinCredible21 in forum Java Theory & Questions
    Replies: 2
    Last Post: December 6th, 2011, 04:09 PM
  2. JMS same machine JBoss
    By IDH123123 in forum Web Frameworks
    Replies: 0
    Last Post: June 21st, 2011, 04:30 AM
  3. [SOLVED] Using Arrays to make a scoring program
    By woodcutterni in forum What's Wrong With My Code?
    Replies: 13
    Last Post: January 7th, 2011, 06:02 PM
  4. Moving MySql Database from one machine to another machine
    By vaishali in forum JDBC & Databases
    Replies: 5
    Last Post: July 21st, 2010, 01:21 AM
  5. Replies: 6
    Last Post: November 14th, 2008, 02:09 PM