1.game.h:類宣告
#ifndef game_h_included
#define game_h_included
#include using namespace std;
class point //point類宣告
;class weapon
;class role
;#endif // game_h_included
2.point.cpp,定義點類,表示位置
#include "game.h"
#include point::point(int x, int y): x(x), y(y)
int point::getx()
int point::gety()
//移到另外一點
void point::moveto(int x, int y)
//從當前位置移動
void point::move(int dx, int dy)
double point::distance(const point& p)
3.weapon.cpp,定義**類
#include "game.h"
weapon::weapon(string wnam, int f, double k):wname(wnam),force(f),killrange(k) {}
weapon::weapon(const weapon &w):wname(w.wname),force(w.force),killrange(w.killrange) {}
string weapon::getwname()
//返回殺傷力
int weapon::getforce()
//返回殺傷距離
double weapon::getkillrange()
4.role.cpp,定義角色類,表示參與遊戲的角色
#include #include "game.h"
using namespace std;
role::role(string nam, int b, point l, weapon w):name(nam),blood(b),location(l),weapon(w)
role::~role()
//攻擊別人,自己漲血,同時對方被攻擊失血,血量取決於當前用的**
//在**的攻擊範圍內才可以攻擊
void role::attack(role &r) //攻擊別人,漲1血
}//被別人攻擊,引數f是承受的攻擊力
void role::beattack(int f)
//返回與另一角色的距離
double role::distance(role &r)
//是否活著
bool role::isalived()
//移到另外一點
void role::moveto(int x, int y)
//從當前位置移動
void role::move(int dx, int dy)
//顯示
第八周上機實踐
01.02.程式的版權和版本宣告部分 05.檔名稱 test.cpp 06.作 者 初瑞 07.完成日期 2013 年 10 月 15 日 08.版 本 號 v1.0 09.對任務及求解方法的描述部分 10.輸入描述 8 7 1 0 3 12.程式輸出 7 6 0 1 2 13.問題分析 輸入x,按...
第八周上機實踐 專案3 順序串演算法
檔名稱 test.cpp 完成日期 2015年10月23日 版本 v1.0 問題描述 採用順序儲存方式儲存串,實現下列演算法並測試。輸入描述 各個演算法 程式輸出 所得結果 標頭檔案sqstring.h見順序串演算法庫 1 試編寫演算法實現將字串s中所有值為c1的字元換成值為c2的字元 void t...
第八周上機實踐專案 專案1 陣列作資料成員
檔名稱 main.cpp 作 者 郭永恆 完成日期 2016年4月18日 版 本 號 v1.0 問題描述 設計乙個工資類 1 實現類的成員函式,並且給每個漲工資500元 2 從檔案讀入工資,增加兩個函式,分別從檔案讀入資料和將資料寫入檔案 3 多檔案組織程式 1 include include us...