好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

拳皇(Java简单的小程序)代码实例

刚开始学习java,看完老九君的视频根据他的内容敲的代码,感觉还挺有成就感的,毕竟刚学习java。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

package helloasd; import java.util.*;

public class hellojava {

         public static void main(string[] args) {

             scanner input = new scanner(system.in);

             system.out.print( "输入名称: " );

             //用户自己输入名字

             string username = input.next();

             string comname = "阿杰" ;

             system.out.println(username + "vs" + comname);

             //初始化双方数据

             int hp1 = 100 , hp2 = 100 ;       //双方的hp 

             int attack1 = 0 , attack2 = 0 ;

            

             //使用循环模拟对战过程

             while (hp1 > 0 && hp2 > 0 ) {

                 attack1 = ( int )(math.random() * 1000 ) % 11 + 5 ; //双方随机的攻击力(10~15)

                 attack2 = ( int )(math.random() * 1000 ) % 11 + 5 ;

                

                 //玩家先攻击

                 hp2 -= attack1; //玩家攻击,电脑掉血

                 system.out.println(comname + ": " + hp2);

                 if (attack1 > 0 && attack1 <= 5 ) {

                     system.out.println( "阿杰被命中攻击!" );

                 }

                 else if (attack1 > 5 && attack1 <= 10 ) {

                     system.out.println( "阿杰被重重的攻击!" );

                 }

                 else {

                     system.out.println( "阿杰被致命一击!" );

                 }

                    

                 //显示电脑血量

                

                 hp1 -= attack2; //电脑攻击,玩家掉血

                 system.out.println(username + ": " + hp2);

                 //显示玩家血量

                 if (attack1 > 0 && attack1 <= 5 ) {

                     system.out.println(username + "被" + comname + "侥幸攻击了一下!" );

                 }

                 else if (attack1 > 5 && attack1 <= 10 ) {

                     system.out.println(username + "遇到了强烈进攻!" );

                 }

                 else {

                     system.out.println(username + "被沉重打击!" );

                 }

                

                 system.out.println( "\n" );

             }

             //打印结果

             system.out.println( "\n" );

             system.out.println( "ko!" );

             system.out.println( "玩家姓名\t血量" );

             system.out.println(username + "\t" + hp1);

             system.out.println(comname + "\t" + hp2);

             if (hp1 < 0 ) {

                 system.out.println( "阿杰获胜!" );

             }

             else {

                 system.out.println(username + "获胜!" );

             }

     }

}

以上所述是小编给大家介绍的拳皇java简单小程序详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

原文链接:https://blog.csdn.net/qq_43535204/article/details/88559527

查看更多关于拳皇(Java简单的小程序)代码实例的详细内容...

  阅读:22次