package wed.poke; import wed.Clear; import java.awt.*; import java.awt.event.InputEvent; import java.util.*; import java.util.ArrayList; import java.util.Scanner; import java.util.Random; import java.util.HashMap; public class 牌库 { private char[] hs={'♤' ,'♧' ,'♡' ,'♢'}; private String[] sum={"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; private ArrayList用到的清屏 *** 作:ay=new ArrayList(); private ArrayList rk=new ArrayList(); public ArrayList p1=new ArrayList(); public ArrayList p2=new ArrayList(); public ArrayList p3=new ArrayList(); private Random r=new Random(); Scanner sc=new Scanner(System.in); HashMap pz = new HashMap(); public static void clear() { try { Robot r = new Robot(); r.mouseMove(500, 750); r.mousePress(InputEvent.BUTTON3_DOWN_MASK); r.mouseRelease(InputEvent.BUTTON3_DOWN_MASK); r.mouseMove(510, 810); r.mousePress(InputEvent.BUTTON1_DOWN_MASK); r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } catch (AWTException e) { e.printStackTrace(); } } public void setup(){ int t; for(int i=0;i<4;i++) { for(int x=0;x<13;x++) { ay.add(hs[i]+sum[x]); pz.put(hs[i]+sum[x],x+1); } } ay.add("Queen"); pz.put("Queen",14); ay.add("King"); pz.put("King",15); pz.put("0",0); } public void re(){ int i=54; String a,b; while(i!=0){ a=ay.remove(r.nextInt(53)); b=ay.remove(r.nextInt(53)); ay.add(a); ay.add(b); i--; } } public void see(){ for(int i=0;i<54;i++){ System.out.printf("%s ",ay.get(i)); } } public void setplay(){ int i=54; String s; while(i!=0){ s=ay.remove(r.nextInt(i)); p1.add(s); i--; s=ay.remove(r.nextInt(i)); p2.add(s); i--; s=ay.remove(r.nextInt(i)); p3.add(s); i--; } } public void start(){ int i=2; String[] s={"0","0"}; String[] pl={"p1","p2"}; while(true){ Clear.cls(); System.out.println("np1: "+p1); System.out.printf("np1: "); s[i%2]=sc.next(); pl[i%2]="p1"; if(s[i%2].equals("过")){ System.out.printf("n请重新出牌: "); continue; } if(pl[i%2].equals(pl[(i-1)%2])){ i++; break; } else{ if(p1.contains(s[i%2])){ if(pz.get(s[i%2])>pz.get(s[(i-1)%2])){ p1.remove(s[i%2]); i++; break; } else{ System.out.printf("n请重新出牌: "); } } else{ System.out.printf("n请重新出牌: "); } } } while(!p1.isEmpty()||!p2.isEmpty()&&!p3.isEmpty()){ while(true&&!p2.isEmpty()){ Clear.cls(); System.out.println("np2: "+p2); System.out.println("n"+pl[(i-1)%2]+": "+s[(i-1)%2]); System.out.printf("np2: "); s[i%2]=sc.next(); pl[i%2]="p2"; if(s[i%2].equals("过")){ if(pl[i%2].equals(pl[(i-1)%2])){ System.out.printf("n请重新出牌: "); continue; } break; } if(pl[i%2].equals(pl[(i-1)%2])){ if(!p2.remove(s[i%2])){ System.out.printf("n请重新出牌: "); continue; } if(p2.isEmpty()) { rk.add("p2"); if(p1.isEmpty()){ rk.add("p3"); p3.clear(); } if(p3.isEmpty()){ rk.add("p1"); p1.clear(); } pl[i%2]="p3"; } i++; break; } else{ if(p2.contains(s[i%2])){ if(pz.get(s[i%2])>pz.get(s[(i-1)%2])){ p2.remove(s[i%2]); if(p2.isEmpty()) { rk.add("p2"); if(p1.isEmpty()){ rk.add("p3"); p3.clear(); } if(p3.isEmpty()){ rk.add("p1"); p1.clear(); } pl[i%2]="p3"; } i++; break; } else{ System.out.printf("n请重新出牌: "); } } else{ System.out.printf("n请重新出牌: "); } } } while(true&&!p3.isEmpty()){ Clear.cls(); System.out.println("np3: "+p3); System.out.println("n"+pl[(i-1)%2]+": "+s[(i-1)%2]); System.out.printf("np3: "); s[i%2]=sc.next(); pl[i%2]="p3"; if(s[i%2].equals("过")){ if(pl[i%2].equals(pl[(i-1)%2])){ System.out.printf("n请重新出牌: "); continue; } break; } if(pl[i%2].equals(pl[(i-1)%2])){ if(!p3.remove(s[i%2])){ System.out.printf("n请重新出牌: "); continue; } if(p3.isEmpty()) { rk.add("p3"); if(p1.isEmpty()){ rk.add("p2"); p2.clear(); } if(p2.isEmpty()){ rk.add("p1"); p1.clear(); } pl[i%2]="p1"; } i++; break; } else{ if(p3.contains(s[i%2])){ if(pz.get(s[i%2])>pz.get(s[(i-1)%2])){ p3.remove(s[i%2]); if(p3.isEmpty()) { rk.add("p3"); if(p1.isEmpty()){ rk.add("p2"); p2.clear(); } if(p2.isEmpty()){ rk.add("p1"); p1.clear(); } pl[i%2]="p1"; } i++; break; } else{ System.out.printf("n请重新出牌: "); } } else{ System.out.printf("n请重新出牌: "); } } } while(true&&!p1.isEmpty()){ Clear.cls(); System.out.println("np1: "+p1); System.out.println("n"+pl[(i-1)%2]+": "+s[(i-1)%2]); System.out.printf("np1: "); s[i%2]=sc.next(); pl[i%2]="p1"; if(s[i%2].equals("过")){ if(pl[i%2].equals(pl[(i-1)%2])){ System.out.printf("n请重新出牌: "); continue; } break; } if(pl[i%2].equals(pl[(i-1)%2])){ if(!p1.remove(s[i%2])){ System.out.printf("n请重新出牌: "); continue; } if(p1.isEmpty()) { rk.add("p1"); if(p2.isEmpty()){ rk.add("p3"); p3.clear(); } if(p3.isEmpty()){ rk.add("p2"); p2.clear(); } pl[i%2]="p2"; } i++; break; } else{ if(p1.contains(s[i%2])){ if(pz.get(s[i%2])>pz.get(s[(i-1)%2])){ p1.remove(s[i%2]); if(p1.isEmpty()) { rk.add("p1"); if(p2.isEmpty()){ rk.add("p3"); p3.clear(); } if(p3.isEmpty()){ rk.add("p2"); p2.clear(); } pl[i%2]="p2"; } i++; break; } else{ System.out.printf("n请重新出牌: "); } } else{ System.out.printf("n请重新出牌: "); } } } } } public void end(){ Clear.cls(); System.out.println("nFirst: "+rk.get(0)); System.out.println("nSecond: "+rk.get(1)); System.out.println("nThird: "+rk.get(2)); } }
编译器idea 控制台清空快捷键 ctrl+alt+backspace
package wed; import java.awt.*; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; public class Clear { public static void cls(){ try{ Robot r=new Robot(); r.setAutoDelay(100); r.mouseMove(500,700); r.mousePress(KeyEvent.BUTTON1_DOWN_MASK); r.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); r.setAutoDelay(50); r.keyPress(KeyEvent.VK_CONTROL); r.keyPress(KeyEvent.VK_ALT); r.keyPress(KeyEvent.VK_BACK_SPACE); r.keyRelease(KeyEvent.VK_CONTROL); r.keyRelease(KeyEvent.VK_ALT); r.keyRelease(KeyEvent.VK_BACK_SPACE); }catch(AWTException e){ e.printStackTrace(); } } }主体程序:
package wed.poke; import wed.Clear; import java.util.Scanner; public class 发牌员 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); 牌库 pk=new 牌库(); pk.setup(); pk.re(); pk.setplay(); System.out.printf("np1: "); for(int i=0;i<18;i++){ System.out.printf("%s ",pk.p1.get(i)); } System.out.printf("np2: "); for(int i=0;i<18;i++){ System.out.printf("%s ",pk.p2.get(i)); } System.out.printf("np3: "); for(int i=0;i<18;i++){ System.out.printf("%s ",pk.p3.get(i)); } Clear.cls(); pk.start(); pk.end(); try { Thread.sleep( 10000 ); } catch (Exception e){ System.exit( 0 ); //退出程序 } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)