剪刀石头布游戏
来源:互联网 发布:sql 多列union 用法 编辑:程序博客网 时间:2024/05/16 20:28
1. 游戏结果
package cn.yjq.game;public enum Outcome {//赢,输,平WIN, LOSE, DRAW;}
2. 游戏Item
package cn.yjq.game;import static cn.yjq.game.Outcome.*;public interface Item {Outcome compete(Item it);Outcome eval(Paper p);Outcome eval(Scissors s);Outcome eval(Rock r);}class Paper implements Item { //布public Outcome compete(Item it) { return it.eval(this); }public Outcome eval(Paper p) { return DRAW; }public Outcome eval(Scissors s) { return WIN; }public Outcome eval(Rock r) { return LOSE; }public String toString() { return "Paper"; }}class Scissors implements Item { //剪刀public Outcome compete(Item it) { return it.eval(this); }public Outcome eval(Paper p) { return LOSE; }public Outcome eval(Scissors s) { return DRAW; }public Outcome eval(Rock r) { return WIN; }public String toString() { return "Scissors"; }}class Rock implements Item { //石头public Outcome compete(Item it) { return it.eval(this); }public Outcome eval(Paper p) { return WIN; }public Outcome eval(Scissors s) { return LOSE; }public Outcome eval(Rock r) { return DRAW; }public String toString() { return "Rock"; }}
3. 游戏机
package cn.yjq.game;import java.util.Random;public class Game {static final int SIZE = 10;static final Random random = new Random(47);public static Item newItem() {switch(random.nextInt(3)) {default :case 1 : return new Paper();case 2 : return new Scissors();case 3 : return new Rock();}}public static void match(Item a, Item b) {System.out.println(a + " VS " + b + " : " + a.compete(b));}public static void main(String[] args) {for(int i=0; i<SIZE; i++) {match(newItem(), newItem());}}}
//outputScissors VS Scissors : DRAWPaper VS Scissors : LOSEPaper VS Scissors : LOSEPaper VS Scissors : LOSEPaper VS Paper : DRAWPaper VS Paper : DRAWPaper VS Paper : DRAWScissors VS Paper : WINPaper VS Paper : DRAWScissors VS Paper : WIN
1 0
- 剪刀、石头、布游戏
- 剪刀石头布游戏
- 剪刀石头布游戏
- 石头剪刀布游戏
- 剪刀石头布游戏
- 石头剪刀布游戏
- 石头,剪刀,布游戏
- 石头-剪刀-布游戏
- 石头剪刀布游戏
- 石头剪刀布游戏
- 石头、剪刀布游戏
- 游戏_石头,剪刀,布
- python 石头剪刀布游戏
- 石头、剪刀、布猜拳游戏
- 8.5 剪刀石头布游戏
- ***4.34-游戏:剪刀石头布
- 剪刀石头布《静态游戏》
- [AHK]石头剪刀布游戏
- C++基础知识总结
- POJ训练计划1611_The Suspects(并查集)
- java 安全 防盗链 post
- Python字典方法注意点
- KMP算法
- 剪刀石头布游戏
- 在Windows命令行里编译C++程序
- Anroid 应用程序目录架构
- 割裂的中国互联网
- 新手建站完美教程
- UIButton
- JavaScript的那些书
- 云计算(三十)-hbase shell基础和常用命令详解
- Chrome带有自带移动设备模拟器