Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/controller/
/view/
/model/
Binary file added bin/Database.accdb
Binary file not shown.
Binary file modified bin/controller/EnemyAI.class
Binary file not shown.
Binary file modified bin/model/Enemy.class
Binary file not shown.
Binary file modified bin/model/Event.class
Binary file not shown.
Binary file modified bin/model/Player.class
Binary file not shown.
Binary file modified bin/view/MBattleView.class
Binary file not shown.
Binary file modified bin/view/MChooseView.class
Binary file not shown.
Binary file modified bin/view/MStartView$1.class
Binary file not shown.
Binary file modified bin/view/MStartView.class
Binary file not shown.
Binary file modified src/Database.accdb
Binary file not shown.
51 changes: 51 additions & 0 deletions src/controller/ChoiceListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import model.Player;
import view.ContentPane;

public class ChoiceListener implements ActionListener{

private int choice;
private ContentPane cp;

public ChoiceListener(int choice,ContentPane cp) {
this.setChoice(choice);
this.setCp(cp);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
StartGame.curEvent.getChoices()[this.choice].changeAttribute();
try {
StartGame.curEvent=StartGame.curEvent.getChoices()[this.choice].newEvent(StartGame.curEvent.getChoices()[this.choice].getNextID());
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ContentPane.textLabel.setText(StartGame.curEvent.getDescription());
ContentPane.tattr[0].setText(""+Player.hp);
ContentPane.tattr[1].setText(""+Player.money);
ContentPane.tattr[2].setText(""+Player.food);
ContentPane.tattr[3].setText(""+Player.water);
if(StartGame.gameOver()) {
// TODO
}
}
public int getChoice() {
return choice;
}
public void setChoice(int choice) {
this.choice = choice;
}
public ContentPane getCp() {
return cp;
}
public void setCp(ContentPane cp) {
this.cp = cp;
}

}
20 changes: 10 additions & 10 deletions src/controller/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import model.Player;

public class Game {
/** �ܾ���*/
/** 总距离*/
public static final int DISTANCE=100;

public static Random eRand=new Random();
Expand All @@ -25,7 +25,7 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
if(aEvent==null) {
aEvent=Event.find(eventId);
}
System.out.println(aEvent.getDescription()+":\nA."+aEvent.getChoices()[0].getDescription()+"\nB."+aEvent.getChoices()[1].getDescription()+"\nC."+aEvent.getChoices()[2].getDescription()+"\nD."+aEvent.getChoices()[3].getDescription()+"\n��ѡ��");
System.out.println(aEvent.getDescription()+":\nA."+aEvent.getChoices()[0].getDescription()+"\nB."+aEvent.getChoices()[1].getDescription()+"\nC."+aEvent.getChoices()[2].getDescription()+"\nD."+aEvent.getChoices()[3].getDescription()+"\n请选择:");
Scanner sc=new Scanner(System.in);
String pChoice=sc.nextLine();
Choice curChoice=chooseEvent(pChoice,aEvent);
Expand All @@ -36,10 +36,10 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
}

/**
* ѡ��
* @param pChoice ѡ��
* @param aEvent �¼�
* @return ѡ��
* 选择
* @param pChoice 选项
* @param aEvent 事件
* @return 选项
*/
public static Choice chooseEvent(String pChoice, Event aEvent) {
if(pChoice.equals("A")||pChoice.equals("a")) {
Expand All @@ -56,8 +56,8 @@ public static Choice chooseEvent(String pChoice, Event aEvent) {
}

/**
* ��Ϸ�Ƿ����
* @return �Ƿ�
* 游戏是否结束
* @return 是否
*/
public static boolean gameOver() {
if(Player.food<=0||Player.hp<=0||Player.water<=0||Player.distance>=DISTANCE) {
Expand All @@ -68,7 +68,7 @@ public static boolean gameOver() {
}

/**
* չʾ��Ϸ���
* 展示游戏结果
*/
public static void showResult() {
if((Player.food<=0||Player.hp<=0||Player.water<=0)&&Player.distance<DISTANCE) {
Expand All @@ -77,4 +77,4 @@ public static void showResult() {
System.out.println("you win");
}
}
}
}
50 changes: 47 additions & 3 deletions src/controller/StartGame.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,60 @@
package controller;
import view.MStartView;
import view.MChooseView;

import java.sql.SQLException;
import java.util.Random;
import model.Event;
import model.Player;
import view.MBattleView;

public class StartGame {
public static MStartView sv;
public static MChooseView cv;
public static MBattleView bv;

public static void main(String[] args) {

//wzw edit-add
/** 总距离*/
public static final int DISTANCE=100;
public static Random eRand=new Random();
public static int curEventId;
public static Event curEvent=null;
//wzw

public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
StartGame.sv=new MStartView("Neptune");

//wzw edit-add
new Player();
Player.showDetails();
Event.initialize();
curEventId=Game.eRand.nextInt(4)+1;
curEvent=Event.find(curEventId);
//wzw
}

//wzw edit-add
/**
* 游戏是否结束
* @return 是否
*/
public static boolean gameOver() {
if(Player.food<=0||Player.hp<=0||Player.water<=0||Player.distance>=DISTANCE) {
showResult();
return true;
}
return false;
}

/**
* 展示游戏结果
*/
public static void showResult() {
if((Player.food<=0||Player.hp<=0||Player.water<=0)&&Player.distance<DISTANCE) {
System.out.println("you lose");
}else if(Player.food>=0 && Player.hp>=0 && Player.water>=0 && Player.distance>=DISTANCE) {
System.out.println("you win");
}
}
//wzw
}
50 changes: 27 additions & 23 deletions src/model/Choice.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,41 @@

import java.sql.SQLException;

import controller.StartGame;

/**
* ѡ����
* @author ��֮��
* 选项类
* @author 王之威
*
*/
public class Choice {
/** ����*/
/** 描述*/
private String description;
/** ��Ǯ*/
/** 金钱*/
private int money;
/** ʳ��*/
/** 食物*/
private int food;
/** Ѫ��*/
/** 血量*/
private int HP;
/** ˮ*/
/** */
private int water;
/** �������*/
/** 触发的函数*/
private int whichFun;
/** ��һ���¼���ID*/
/** 下一个事件的ID*/
private int nextID;
/** �ƶ�����*/
/** 移动距离*/
private int diatance;

/**
* ѡ��캯��
* @param des ѡ������
* @param money ��Ǯ
* @param food ʳ��
* @param HP Ѫ��
* @param water ˮ
* @param whichFun ѡ�к�����ĸ�����
* @param nextID ��һ�������¼�ID
* 选项构造函数
* @param des 选项描述
* @param money 金钱
* @param food 食物
* @param HP 血量
* @param water 水
* @param nextID 下一个关联事件ID
*/
public Choice(String des, int diatance,int money ,int food, int HP,int water, int whichFun,int nextID) {
public Choice(String des, int diatance,int money ,int food, int HP,int water,int nextID) {
this.setDescription(des);
this.setDiatance(diatance);
this.setMoney(money);
Expand All @@ -46,27 +47,30 @@ public Choice(String des, int diatance,int money ,int food, int HP,int water, in
}

/**
* �����ض�����һ���¼�
* 产生特定的下一个事件
* @return
* @throws SQLException
*/
public Event newEvent(int nextID) throws SQLException {
if(nextID!=0) {
return Event.find(nextID);
}else {
int eventId;
eventId=StartGame.eRand.nextInt(4)+1;
return Event.find(eventId);
}
return null;
}

/**
* ����򶷽���
* 进入打斗界面
*/
public void fight() {
new Fight(100,200);

}

/**
* �ı��������
* 改变玩家属性
*/
public void changeAttribute() {
Player.hp+=this.getHP();
Expand Down
11 changes: 6 additions & 5 deletions src/model/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
import java.sql.SQLException;

/**
* �¼���
* @author ��֮��
* 事件类
* @author 王之威
*
*/
public class Event {
/** �¼�ID*/
/** 事件ID*/
private int ID;
/** �¼�����*/
/** 事件描述*/
private String description;
/** ѡ������*/
/** 选项数组*/
private Choice[] choices;

public Event(int id,String description,Choice[] choices) {
this.setID(id);
this.setDescription(description);
this.setChoices(choices);
System.out.println("eeee");
}

public static void initialize() throws ClassNotFoundException, SQLException {
Expand Down
Loading