我尝试这用记事本完成《Java入门第三季》的最终作业,调试了一下午才编译通过,又显示“找不到或无法加载主类”,求帮忙看一下,多谢了!package game;
public class Main{
public static void main (String [] args){
new Game();
}
}package game;
import java.util.Scanner;
import java.util.Random;
import java.util.List;
import java.util.ArrayList;
public class Game {
List<Card> cards;
Player playerA,playerB;
short a;
Card temporary;
Random random;
public Game(){
this.random = new Random();
this.cards = new ArrayList<Card>();
Scanner scanner = new Scanner(System.in);
System.out.println("please input first player's name");
this.playerA = new Player(scanner.next());
System.out.println("please input second player's name");
this.playerB = new Player(scanner.next());
System.out.println("loading");
//开始洗牌
for(short times = 0;times < 52;times ++){
do{
this.temporary = new Card((short)(random.nextInt(13)+1),(short)(random.nextInt(4)+1));
}while(this.cards.contains(temporary));
}
System.out.println("please waite a minute");
//开始发牌
a = (short)random.nextInt(this.cards.size());
this.playerA.take(this.cards.get(a));
this.cards.remove(a);
a = (short)random.nextInt(this.cards.size());
this.playerB.take(this.cards.get(a));
this.cards.remove(a);
a = (short)random.nextInt(this.cards.size());
this.playerA.take(this.cards.get(a));
this.cards.remove(a);
a = (short)random.nextInt(this.cards.size());
this.playerB.take(this.cards.get(a));
this.cards.remove(a);
//开始比较
System.out.println("fight");
if(this.playerA.show().compareTo(this.playerB.show()) > 0){
System.out.println("Player:A Wins !");
}else {
System.out.println("Player:B Wins !");
}
//游戏结束
System.out.println("Game Over !");
}
}package game;
public class Card implements Comparable <Card>{
short number;
short shape;
public Card(short number,short shape){
this.number = number;
this.shape = shape;
}
public int compareTo(Card card){
if(this.number == card.number){
return (new Integer(this.shape)).compareTo(new Integer(card.shape));
}else {
return (new Integer(this.number)).compareTo(new Integer(card.number));
}
}
public boolean equals(Card card){
if (this.number == card.number & this.shape == card.shape){
return true;
}else{
return false;
}
}
}package game;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Player {
String name;
List<Card> cards;
public Player(String name){
this.name = name;
this.cards = new ArrayList<Card>();
}
public Card show (){
Collections.sort(this.cards);
return this.cards.get(1);
}
public void take (Card card){
this.cards.add(card);
}
}
添加回答
举报
0/150
提交
取消