Java Lab (1) People PK under the console

Source: Internet
Author: User

First, preface

There is such a thought for a long time, from the earliest interested in programming because you want to achieve a similar to the Street Fighter, boxing Emperor and other programs. Along the way, found that as a main business and programming has nothing to do with the people want to learn programming, is really very laborious, and in the application of the overflow of today, for a non-programming people, to myself, in the learning process also inevitably because one goal is difficult to achieve and turn to another goal, more deadly is to convert another method , another language to learn. The limited time, the limited energy, the growing age, all make oneself feel away from each goal more and more. I am aware of my shortcomings: lazy to insist. This is difficult to improve, it takes time to form a habit. In terms of goals, a more desirable goal is probably to set specific goals in conjunction with your own work. And no matter how much you can persist in learning, what kind of software you can make; no matter how many times I can spend in a week, my decision now is to spend all of my time in Java, not today in Java, and tomorrow in Python, as for the rest, and so I use Java to compile the target software. Learning to Java interface, inherit the time to find really difficult, but my advantage is that I do not need to hurry to understand, I can accept my slow, I adjust. For programming learning, the best thing to do is to set yourself a program topic that you can judge for yourself.

Second, the first version of

1, Program Overview: In the console to achieve the two characters PK program. 2, Characters: blood volume, damage value. 3, PK Description: Turn system PK, the two characters attack each other, until a certain side blood volume of 0 or less.

1 /*name:pk1.02 * Character parameters: Blood volume-blood; damage value-normalattack;3 * Function: Simple PK Under the console, text output PK process and results4 * For now I can achieve this program has been very fulfilling5 * Of course, this simple implementation of my code is also very cumbersome6 * and the function is very simple basic7 * But the important thing is, even if it's simple, I've achieved it:)8  */9 ImportJava.util.Scanner;Ten  One  Public classPK1 { A      Public Static voidMain (string[] args) { -         classrenwu{ - String name; the             DoubleBlood; -             DoubleNormalattack;  -         } -Scanner scan=NewScanner (system.in); +Renwu person1=NewRenwu (); -System.out.println ("------------Create character------------"); +System.out.println ("Please enter the character name you want to create (string):"); APerson1.name=scan.nextline (); atSystem.out.println ("Please enter the amount of blood (800~2000) you create the character:"); -Person1.blood=scan.nextdouble (); -System.out.println ("Please enter the damage value (80~120) of the person you created:"); -person1.normalattack=scan.nextdouble (); -System.out.println (person1.name+ "---blood:" +person1.blood+ "---damage value:" +person1.normalattack); -  inScanner scan1=NewScanner (system.in); -Renwu person2=NewRenwu (); toSystem.out.println ("------------Create character------------"); +System.out.println ("Please enter the character name you want to create (string):"); -Person2.name=scan1.nextline (); theSystem.out.println ("Please enter the amount of blood (800~2000) you create the character:"); *Person2.blood=scan1.nextdouble (); $System.out.println ("Please enter the damage value (80~120) of the person you created:");Panax Notoginsengperson2.normalattack=scan1.nextdouble (); -System.out.println (person2.name+ "---blood:" +person2.blood+ "---damage value:" +person2.normalattack); the  +         intI=1; A          while((person1.blood>0) && (person2.blood>0)){ theSystem.out.println ("+i+" round start:---------------"); +System.out.println (person1.name+ "Attack", "+person2.name+" caused "+person1.normalattack+" point damage); -System.out.println (person2.name+ "Attack", "+person1.name+" caused "+person2.normalattack+" point damage); $person1.blood=person1.blood-Person2.normalattack; $person2.blood=person2.blood-Person1.normalattack; -i++; -             if((person1.blood>0) && (person2.blood>0)){ theSystem.out.println (person1.name+ "and" +person1.blood+ "point Health"); -System.out.println (person2.name+ "and" +person2.blood+ "point Health");Wuyi}Else if(person1.blood<=0){ theSystem.out.println (person1.name+ "Defeated!! "); -System.out.println (person2.name+ "and" +person2.blood+ "point Health"); Wu                      Break; -}Else if(person2.blood<=0){ AboutSystem.out.println (person2.name+ "Defeated!! "); $System.out.println (person1.name+ "and" +person1.blood+ "point Health"); -                      Break; -             } -         }    A     } +}

Third, according to the progress of learning to update ~

Java Lab (1) People PK under the console

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.