テキストベースの RPG ゲームの一種の 2D マップとして多次元配列を作成しようとしています。たとえば、5x5 の多次元配列を作成したいと考えています。配列は、オブジェクトの空白を表すために 0 で埋められます。他の数字はplayer
、マップ上の 、enemy
、npc
、skill-object
(エンチャント テーブルなどのように)、doors
マップにリンクする 、およびを表しchests
ます。それらはすべて、そこにあるオブジェクトを表すために異なる値を持ちます。player
がに足を踏み入れようとすると、chest
代わりに を略奪しchest
ます。次に、chest
を 0 にリセットして空のスペースを表し、player
そこを歩かせて、チェストがないことを表します。がplayer
上を歩こうとするとenemy
、代わりに戦闘に参加します(別のクラスと関数によって処理されます)。を表す数値の上を歩くと、door
別のマップを表す別の多次元配列にリンクします。
player
彼がマップ上のどこにいるかを処理するために、クラス内に配置する必要があるプロパティの種類を知りたいです。次に、関数がその値を変更して、マップ内で彼を移動させます。マップのクラスを作成するのは良い考えでしょうか? オブジェクトの値をそこに保存するか、それらのオブジェクトの個々のクラスに保存しますか? これについてどうすればいいですか?ご協力ありがとうございました。参考までに、これが私のプレーヤークラスです(注意してください、長いです...):
public class Player
{
public string name { get; set; } //Name of Player
public int level { get; set; } //Player's combat level (average of combat-related skills' levels)
public int health { get; set; } //Player's health (player dies when this value reaches 0)
public int health_max { get; set; } //Player's maximum health
public int stamina { get; set; } //Player's stamina (used for power attacks, slowly recharges on own)
public int stamina_max { get; set; } //Player's maxiumum stamina
public int fatigue { get; set; } //Player's fatigue rate (player cannot fight or run while fatigue is 100)
public int hunger { get; set; } //Player's hunger level (player becomes weaker as hunger increases)
public int style { get; set; } //Player's fighting style (refer to styles.txt)
//THIEVERY SKILLS - LOCKPICKING / LOCK_P, LUCK / LUCK, PICKPOCKETING / PICK_P, SNEAKING / SNEAK
skill LOCK_P = new skill(); //Ability to pick locks to open locked doors or chests. Trained by unlocking locks successfully. Higher level, better locks.
skill LUCK = new skill(); //The higher the level, the more lucky. Loot from enemies, dungeons, and chests are better. Higher level, higher crit chance. Leveled up 3 times every time your overall thievery levels up.
skill PICK_P = new skill(); //Ability to steal from NPCs' pockets without turning them against you. Trained by sucessfully stealing items.
skill SNEAK = new skill(); //Ability to move unseen. 25% of your sneak level boosts your pickpocketing level. 100% crit chance with an attack from sneaking. Trained by sneaking / escaping combat.
//COMBAT SKILLS - MELEE / MELEE, SORCERY / SOR, MAGICKA / MAGICKA, ARCHERY / ARCHERY, HEAVY ARMOR / H_ARM, LIGHT ARMOR / L_ARM
skill MELEE = new skill(); //Ability to fight better with melee weapons in combat. Trained by dealing damage with melee weapons.
skill SOR = new skill(); //Ability to fight better with sorcerey and spells in combat. Trained by dealing damage with spells.
skill MAGICKA = new skill(); //Affects how many spells you can cast before you must regenerate your magicka pool. Trained by casting spells.
skill ARCHERY = new skill(); //Ability to fight better with ranged weapons, like bows, in combat. Trained by dealing damage with ranged weapons.
skill H_ARM = new skill(); //Affects how effective wearing heavy armor, like metal armor, is. Trained by taking damage while wearing heavy armor.
skill L_ARM = new skill(); //Affects how effective wearing light armor, like leather armor, is. Trained by taking damage while wearing light armor.
//CRAFTSHIP SKILLS - SMITHING / SMITH, CRAFTING / CRAFT, ENCHANTMENT / ENCH, HERBLORE / HERB, FLETCHING / FLETCH
skill SMITH = new skill(); //Ability to create heavy armor and forge melee weapons. Trained by creating mentioned items.
skill CRAFT = new skill(); //Ability to create jewlery to be enchanted. Trained by creating jewlery.
skill ENCH = new skill(); //Ability to enchant items so that they give stat boosts to the wearer. Trained by enchanting items.
skill HERB = new skill(); //Ability to create potions from collected materials and plants. Trained by creating potions.
skill FLETCH = new skill(); //Ability to create bows, arrows, and crossbow stocks. Trained by creating mentioned items.
//MISC. SKILLS - AGILITY / AGILITY, MINING / MINING, WOODCUTTING / WOOD_C, COOKING / COOK, SLAYER / SLAY
skill AGILITY = new skill(); //Ability to pass obstacles. Trained by passing obstacles.
skill MINING = new skill(); //Ability to mine ore from ore veins to be used in smithing. Trained by mining ore.
skill WOOD_C = new skill(); //Ability to cut wood from trees and vines to be used in fletching. Trained by cutting wood.
skill COOK = new skill(); //Ability to cook food to feed hunger / heal health.
skill SLAY = new skill(); //The knowledge of how to slay advanced monsters using special equipment. Trained by completeing tasks.
public void set_all_skills() //Function to set values for all skills. Called once at beginning of game.
{
string[] names = { "Thievery", "Combat", "Craftship", "Misc" }; //Group names for skills
skill[] skills = { LOCK_P, LUCK, PICK_P, SNEAK, MELEE, SOR, MAGICKA, ARCHERY, H_ARM, L_ARM, SMITH, CRAFT, ENCH, HERB, FLETCH, AGILITY, MINING, WOOD_C, COOK, SLAY }; //Array of all the player's skills
for (int i = 0; i < 20; i++) { skills[i].set_level(1); } //For loop to set each level at 1 (for base values).
int counter = 0, name = 0; //Creates variables for the while loop to set tag names.
while (counter < 20) //While loop to set tag names of each skill.
{
if (counter < 4) { skills[counter].set_tag(names[0]); } //First 4 skills are given the first tag
if (counter > 4 && counter < 11) { skills[counter].set_tag(names[1]); } //Next 6 skills are given the second tag
if (counter > 11 && counter < 16) { skills[counter].set_tag(names[2]); } //Next 5 skills are given the third tag
if (counter > 16 && counter < 21) { skills[counter].set_tag(names[3]); } //Last 5 skills are given the last tag
counter++; //Increment the counter by 1.
}
}
//Health / Stamina Alteration Functions
public void take_blunt_damage(int dmg) { this.health -= dmg; } //Decrement player's health by the value of `dmg`
public void take_weak_damage(int dmg, int weak) { this.health -= dmg + weak; } //Take this dmg if the player is weak to the enemy's type of attack
public void take_strong_damage(int dmg, int str) { this.health -= dmg - str; } //Take this dmg if the player is strong to the enemy's type of attack
public void heal(int x) { this.health += x; } //Increment player's health by `x` amount
public void heal() { this.health = health_max; } //Fully heal the player
public void die() { this.health = 0; } //Kill the player by setting health to 0
public void dec_stamina(int x) { this.stamina -= x; } //Decrement player's stamina by `x` amount
public void fill_stamina(int x) { this.stamina += x; } //Increment player's stamina by `x` amount
public void fill_stamina() { this.stamina = stamina_max; } //Fully fill the player's stamina
//Stat Alteration
public void lvl_stat(int x, skill s) { s.level_up_x(x); } //Level up skill `s` by `x` levels
public void lvl_stat(skill s) { s.level_up(); } //Level up skill `s` once
}
参照用にそれが必要な人のために、ここに私のskill
クラスがあります:
public class skill
{
public string tag { get; set; } //Tags a sub-skill to a major-skill
public int level { get; set; } //Level of the skill (average of sub-skills' levels)
public int XP { get; set; } //XP towards leveling up
public int[] XP_to_level_up = { 50, 120, 200, 350, 420, 500, 650, 720, 800, 950, 1020, 2000, 3500, 4200, 5000, 6500, 7200, 8000, 9500, 10200, 11000, 12500, 13200, 14000, 15500 }; //XP needed to level up
public void set_tag(string tag) { this.tag = tag; } //Sets the tag of the skill
public void set_level(int x) { this.level = x; } //Set this level to int x
public bool level_up() { this.level++; return true; } //Increment this level by 1
public bool level_up_x(int x) { this.level += x; return true; } //Increment this level by int x
public void add_XP(int x) { this.XP += x; } //Add XP towards the next level
public int calc_where_on_array(int level, int[] XP_to_level_up) //Calculate what int on the array based on your level
{
return XP_to_level_up[level];
}
public bool check_XP(int XP, int where_on_array, int[] XP_to_level_up) //Check if the current XP you have can level you up
{
if (XP >= XP_to_level_up[where_on_array]) //If current XP is greater than what is needed to level up...
{
this.level_up(); //... level this skill up.
return true; //Return true, to show that you successfully leveled up.
}
else { return false; } //If you cannot level up, return false.
}
}