Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.games;
- /**
- * Created by 1 on 30.11.2015.
- */
- import java.util.Date;
- import java.util.Random;
- /**
- * Created by archi on 25.10.2015.
- */
- interface Game {
- void turn();
- }
- interface GameFactory {
- Game getGame();
- }
- class Coin implements Game {
- public void turn () {
- Random rand = new Random();
- int side = rand.nextInt(2);
- if (side == 0)
- System.out.println("Reshko");
- else
- System.out.println("Orel");
- }
- public static GameFactory fact = new GameFactory(){
- public Game getGame(){
- return new Coin();
- }
- };
- }
- class Bones implements Game {
- public void turn() {
- Random rand = new Random();
- int boneFirst = 1 + rand.nextInt(6);
- int boneSecond = 1 + rand.nextInt(6);
- int result = boneFirst + boneSecond;
- System.out.println(boneFirst + " " + boneSecond + " = " + result);
- }
- public static GameFactory fact = new GameFactory(){
- public Game getGame(){
- return new Bones();
- }
- };
- }
- class Play {
- public static void letsPlay(GameFactory f){
- Game g = f.getGame();
- g.turn();
- }
- public static void main(String[] args) {
- letsPlay(Coin.fact);
- letsPlay(Bones.fact);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement