public class Application {
public static void main(String args[]){
User user=new User();
for(int i=0;i<3;i++){
user.setAccount(i);
user.select();
user.playGame();
NPC npc =new NPC();
npc.talk(user);
System.out.println();
}
}
}
interface Task
public interface Task {
public void post();
default void getPrize() {
System.out.println("得到奖励");
}
default void getTask() {
System.out.println("接受任务");
}
}
NPC.java
public class NPC {
Task task;
boolean flag=false;
void talk(User user){
int account1=user.account;
System.out.println("与NPC交谈");
switch (account1){
case 0:task=new Arrest();
task.post();
task.getTask();
flag=true;break;
case 1:task=new Kill();
task.post();
task.getTask();
flag=true;break;
case 2:task=new Plant();
task.post();
task.getTask();
flag=true;break;
}
}
}
Kill.java
public class Kill implements Task{
public void post(){
System.out.println("发布杀人任务");
}
}
HuntTreasure.java
public class HuntTreasure implements Task{
public void post(){
System.out.println("发布寻宝任务");
}
}
Arrest.java
public class Arrest implements Task{
public void post(){
System.out.println("发布抓捕任务");
}
}
Plant.java
public class Plant implements Task{
public void post(){
System.out.println("发布种地任务");
}
}
User.java
public class User {
Character role;
int account;
void setRole(Character role) {
this.role = role;
}
void select(){
int account1=account%6;
switch (account1){
case 0:Swordsman swordsman=new Swordsman("帅气的服装","帅气的头发","帅气的外表","Swordsman");
setRole(swordsman);
break;
case 1:Thief thief=new Thief("黑色的服装","黑色的头发","伪装的外表","Thief");
setRole(thief);
break;
case 3:Constable constable=new Constable("官府的服装","官方的发型","官方权威的外表","Constable");
setRole(constable);
break;
case 2:Civilian civilian=new Civilian("普通的服装","普通的头发","普通的外表","Civilian");
setRole(civilian);
break;
default:OfficerZhiFu zhiFu=new OfficerZhiFu("官方的服装","官方的头发","官方的外表","ZhiFu");
setRole(zhiFu);
break;
}
}
void setAccount(int account1){
account=account1;
}
void playGame(){
role.playGame();
}
}
Character.java
abstract public class Character {
String clothes;
String hairColor;
String appearance;
String name;
abstract void walk();
abstract void run();
abstract void show();
abstract void speak();
abstract void playGame();
public Character(String clothes,String hairColor,String appearance,String name){
this.clothes=clothes;
this.hairColor=hairColor;
this.appearance=appearance;
this.name=name;
}
}
Civilian.java
class Civilian extends Character{
public Civilian(String clothes,String hairColor,String appearance,String name){
super(clothes,hairColor,appearance,name);
}
void walk() {
System.out.println("普通地走");
}
void run() {
System.out.println("普通地跑:时速10Km/h");
}
void show() {
System.out.println("普通地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
}
void speak() {
System.out.println("普通地说话:我赢了");
}
void playGame(){
walk();
run();
show();
speak();
}
}
Thief.java
class Thief extends Character{
public Thief(String clothes,String hairColor,String appearance,String name){
super(clothes,hairColor,appearance,name);
}
void walk() {
System.out.println("偷偷摸摸地走");
}
void run() {
System.out.println("偷偷摸摸地跑:时速40Km/h");
}
void show() {
System.out.println("偷偷摸摸地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
}
void speak() {
System.out.println("偷偷摸摸地说话:我赢了");
}
void playGame(){
walk();
run();
show();
speak();
}
}
Swordsman.java
class Swordsman extends Character{
public Swordsman(String clothes,String hairColor,String appearance,String name){
super(clothes,hairColor,appearance,name);
}
void walk() {
System.out.println("帅气地走");
}
void run() {
System.out.println("帅气地跑:时速50Km/h");
}
void show() {
System.out.println("帅气地展示:"+this.clothes+" "+this.hairColor+" "+this.appearance+" "+this.name);
}
void speak() {
System.out.println("依本大侠看……"); }
void playGame(){
walk();
run();
show();
speak();
}
}