设为首页 加入收藏

TOP

Java猜拳游戏
2014-11-24 02:43:28 来源: 作者: 【 】 浏览:0
Tags:Java 猜拳 游戏

  //Computer


  import java.util.Scanner;


  public class Computer {


  String name;


  int score;


  //方法


  public int showFist(){


  int fist=1;


  fist=(int)(Math.random()*10)%3+1;


  return fist;


  }


  }


  ------------------------------------------------------------------------------------------------------------------------------------


  //Person


  import java.util.*;


  public class Person {


  //属性


  String name;


  int score;


  //方法


  public int showFist(){


  int fist;


  Scanner input=new Scanner(System.in);


  System.out.println("请您出拳 1:剪刀 2 石头 3 布");


  fist=input.nextInt();


  return fist;


  }


  }


  ------------------------------------------------------------------------------------------------------------------------------------


  //Game


  public class Game {


  Person role1;


  Computer role2;


  int count;


  public void beginGame(){


  role1=new Person();


  role2=new Computer();


  int fist1=0,fist2=0;


  fist1=role1.showFist();


  System.out.println("您出了"+fist1);


  fist2=role2.showFist();


  System.out.println("电脑出了"+fist2);


  if(fist1==1&&fist2==3 || fist1==2&&fist2==1 ||fist1==3&&fist2==2){


  System.out.println("恭喜,你赢了");


  }


  else if(fist1==1&&fist2==2|| fist1==2&&fist2==3 ||fist1==3&&fist2==1 ){


  System.out.println("恭喜,你输了");


  }


  else{


  System.out.println("平了");


  }


  }


  }


  ------------------------------------------------------------------------------------------------------------------------------------


  //TestGame


  public class TestGame {


  /**


  * @param args


  */


  public static void main(String[] args) {


  // TODO 自动生成方法存根


  Game game=new Game();


  game.beginGame();


  }


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java代码调用存储过程(JDBC) 下一篇Java入门教程:Hello world程序

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: