Java案例斗地主游戏
目录
一案例要求:
二具体代码:
一案例要求:
(由于暂时没有学到通信知识,所以只会发牌,不会设计打牌游戏)
二具体代码:
Ⅰ:主函数
package three; public class test { public static void main(String[] args) { Room room=new Room(); room.start(); } }
Ⅱ:实体类:
package three; public class card { private String number; private String color; private int size; public card() { } public card(String number, String color, int size) { this.number = number; this.color = color; this.size = size; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } @Override public String toString() { return color+number; } }
Ⅲ操作类:
package three; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Room { private List allcards=new ArrayList(); public Room(){ String []numbers={"3","4","5","6","7","8","9","10","J","Q","K","A","2"}; String []color={"♠","♣","■","♥"}; int size=0; for (String number : numbers) { size++; for (String s : color) { card a=new card(number,s,size); allcards.add(a); } } card a1=new card("","🃏",++size); card a2=new card("","🃏",++size); Collections.addAll(allcards,a1,a2); System.out.println("新牌"+allcards); } public void start() { Collections.shuffle(allcards); System.out.println("洗牌后"+allcards); Listxiaozhang=new ArrayList(); Listxiaowang=new ArrayList(); Listxiaochong=new ArrayList(); for (int i = 0; i
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。