Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package com.games;
  2.  
  3. /**
  4. * Created by 1 on 30.11.2015.
  5. */
  6. import java.util.Date;
  7. import java.util.Random;
  8.  
  9. /**
  10. * Created by archi on 25.10.2015.
  11. */
  12. interface Game {
  13. void turn();
  14. }
  15.  
  16. interface GameFactory {
  17. Game getGame();
  18. }
  19.  
  20. class Coin implements Game {
  21. public void turn () {
  22. Random rand = new Random();
  23. int side = rand.nextInt(2);
  24.  
  25. if (side == 0)
  26. System.out.println("Reshko");
  27. else
  28. System.out.println("Orel");
  29. }
  30.  
  31. public static GameFactory fact = new GameFactory(){
  32. public Game getGame(){
  33. return new Coin();
  34. }
  35. };
  36.  
  37. }
  38.  
  39.  
  40. class Bones implements Game {
  41. public void turn() {
  42. Random rand = new Random();
  43. int boneFirst = 1 + rand.nextInt(6);
  44. int boneSecond = 1 + rand.nextInt(6);
  45. int result = boneFirst + boneSecond;
  46.  
  47. System.out.println(boneFirst + " " + boneSecond + " = " + result);
  48. }
  49.  
  50. public static GameFactory fact = new GameFactory(){
  51. public Game getGame(){
  52. return new Bones();
  53. }
  54. };
  55. }
  56.  
  57.  
  58.  
  59. class Play {
  60. public static void letsPlay(GameFactory f){
  61. Game g = f.getGame();
  62. g.turn();
  63. }
  64.  
  65. public static void main(String[] args) {
  66. letsPlay(Coin.fact);
  67. letsPlay(Bones.fact);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement