<lol바론과 애니비아의 사투>미완성(에러에러에러)
C#/과제 2019. 4. 9. 09:581 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class Annivia : Champion { public Annivia(CharacterInfo characterInfo, int id):base(characterInfo,id) { this.id = id; this.characterInfo = characterInfo; } public override void Move(Vector2 targetPos, float speed) { var distance = this.characterInfo.myPos.GetDistance(targetPos, this.characterInfo.myPos); Console.WriteLine("{0}({1},{2})이(가) ({3},{4})로 이동합니다.", this.dicCharacterData[this.id].name, this.characterInfo.myPos.x, this.characterInfo.myPos.y, targetPos.x, targetPos.y); while (true) { if (distance <= 0) { this.characterInfo.myPos = targetPos; break; } else//타겟좌표와 나의 거리가 0이 아닐때 { System.Threading.Thread.Sleep(1000); distance -= speed; Console.WriteLine("{0}이(가) 이동합니다.(거리:{1})", this.dicCharacterData[this.id].name, distance); } } Console.WriteLine("{0}이(가) ({1}, {2})에 도착했습니다.", this.dicCharacterData[this.characterInfo.id].name, this.characterInfo.myPos.x, this.characterInfo.myPos.y); } public override void Attack(Character target) { var distance = this.characterInfo.myPos.GetDistance(target.characterInfo.myPos, this.characterInfo.myPos); while(true) { System.Threading.Thread.Sleep(1000); if (distance > this.dicCharacterData[this.characterInfo.id].attackLength) { distance -= this.dicCharacterData[this.characterInfo.id].speed; Console.WriteLine("{0}이(가) 이동합니다.(거리:{1})", this.dicCharacterData[this.characterInfo.id].name, distance); } else { //Console.WriteLine("{0}이(가) {1}에게 기본공격을 합니다.", this.dicCharacterData[this.characterInfo.id].name, target.dicCharacterData[target.characterInfo.id].name); Console.WriteLine("{0}이(가) {1}에게 기본공격을 합니다.", this.dicCharacterData[this.id].name, target.dicCharacterData[target.id].name); target.TakeDamage(this.dicCharacterData[this.id].attackDamage); break; } } } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using Newtonsoft.Json; using System.Collections; namespace AttackTest { public class App { public Dictionary<int, Character> dicCharacters = new Dictionary<int, Character>(); public CharacterInfo characterInfo; public Dictionary<int, CharacterData> dicCharacterData = new Dictionary<int, CharacterData>(); public App() { this.DataLoad("./data/character_data.json"); } public void Start() { this.Infoload(); var gameLauncher = new GameLauncher(this.dicCharacterData, this.characterInfo, this.dicCharacters); var newCharacterInfo = gameLauncher.Start(); this.DataSave(newCharacterInfo); } public void DataLoad(string path)//데이터 불러오기 { var json = File.ReadAllText(path); var arrCharacterData = JsonConvert.DeserializeObject<CharacterData[]>(json); foreach (var data in arrCharacterData) { dicCharacterData.Add(data.id, data); } } public void Infoload() { if (Directory.Exists("./info")) { Console.WriteLine("기존 유저 입니다."); var json = File.ReadAllText("./info/character_info.json"); var characterInfo = JsonConvert.DeserializeObject<CharacterInfo>(json); this.characterInfo = characterInfo; this.dicCharacters[0] = new Character(characterInfo, 0); this.dicCharacters[1] = new Character(characterInfo, 1); } else { Console.WriteLine("신규 유저입니다."); Directory.CreateDirectory("./info"); this.dicCharacters[0] = new Character(new CharacterInfo(0,550), 0); this.dicCharacters[1] = new Character(new CharacterInfo(1,1000), 1); var json = JsonConvert.SerializeObject(this.dicCharacters); File.WriteAllText("./info/character_info.json", json, Encoding.UTF8); //파일읽기, 역직렬화, dic생성 json = File.ReadAllText("./info/character_info.json"); var characterInfo = JsonConvert.DeserializeObject<CharacterInfo>(json); this.characterInfo = characterInfo; } } public void DataSave(CharacterInfo newInfos) { this.characterInfo = newInfos; var json = JsonConvert.SerializeObject(this.characterInfo); File.WriteAllText("./info/character_info.json", json, Encoding.UTF8); } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class BaronNasser : Monster { public BaronNasser(CharacterInfo characterInfo, int id) : base(characterInfo, id) { this.id = id; this.characterInfo = characterInfo; } public override void Move(Vector2 targetPos,float speed) { Console.WriteLine("{0}은 움직일 수 없습니다.", this.dicCharacterData[this.characterInfo.id].name); } public override void Attack(Character target) { var distance = this.characterInfo.myPos.GetDistance(target.characterInfo.myPos, this.characterInfo.myPos); while (true) { System.Threading.Thread.Sleep(1000); if (distance > this.dicCharacterData[this.characterInfo.id].attackLength) { Console.WriteLine("사거리를 벗어나 공격 할 수 없습니다."); break; } else { Console.WriteLine("{0}이(가) {1}에게 기본공격을 합니다.", this.dicCharacterData[this.characterInfo.id].name, target.dicCharacterData[this.characterInfo.id].name); target.TakeDamage(this.dicCharacterData[this.characterInfo.id].attackDamage); break; } } } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class Champion : Character { public Champion(CharacterInfo characterInfo, int id) : base(characterInfo, id) { this.id = id; this.characterInfo = characterInfo; } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class Character { public int id; public CharacterInfo characterInfo; public Dictionary<int, CharacterData> dicCharacterData; public Character(CharacterInfo characterInfo,int id) { this.id = id; this.characterInfo = characterInfo; } public virtual void Move(Vector2 targetPos, float speed) { } public virtual void Attack(Character target) { } public virtual void TakeDamage(int damage) { this.characterInfo.hp -= damage; Console.WriteLine("{0}이(가) {1}의 피해를 받았습니다.", this.dicCharacterData[this.id].name, damage); Console.WriteLine("{0}의 남은 Hp : {1}", this.dicCharacterData[this.id].name, this.characterInfo.hp); } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class CharacterData { public int id; public string name; public int attackDamage; public float speed; public int attackLength; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class CharacterInfo { public int id; public int hp; public Vector2 myPos = new Vector2(0, 0); public List<Character> characters= new List<Character>(); public CharacterInfo() { } public CharacterInfo(List<Character> characters) { this.characters = characters; } public CharacterInfo(int id, int hp) { this.id = id; this.hp = hp; } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class GameLauncher { public Dictionary<int, Character> dicCharacters; public CharacterInfo characterInfo; public Dictionary<int, CharacterData> dicCharacterData; public GameLauncher(Dictionary<int, CharacterData> dicCharacterData, CharacterInfo characterInfo, Dictionary<int, Character> dicCharacters) { this.characterInfo = characterInfo; this.dicCharacterData = dicCharacterData; this.dicCharacters = dicCharacters; } public CharacterInfo Start() { var annivia = new Annivia(this.characterInfo, 0); annivia.dicCharacterData = this.dicCharacterData; var baron = new BaronNasser(this.characterInfo, 1); baron.dicCharacterData = this.dicCharacterData; Console.WriteLine("{0} : {1}", characterInfo.id, characterInfo.hp); //이동 //annivia.Move(new Vector2(10, 10), dicCharacterData[annivia.id].speed); //공격 //annivia.Attack(baron); return this.characterInfo;//수정하기 } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class Monster : Character { public Monster(CharacterInfo characterInfo, int id) : base(characterInfo, id) { this.id = id; this.characterInfo = characterInfo; } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { class Program { static void Main(string[] args) { App app = new App(); app.Start(); Console.ReadKey(); } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AttackTest { public class Vector2 { public float x, y; public Vector2(float x, float y) { this.x = x; this.y = y; } public static Vector2 operator +(Vector2 v1, Vector2 v2)//벡터합 { return new Vector2(v1.x + v2.x, v1.y + v2.y); } public static Vector2 operator -(Vector2 v1, Vector2 v2)//벡터차 { return new Vector2(v1.x - v2.x, v1.y - v2.y); } public float GetDistance(Vector2 targetPos, Vector2 myPos)//벡터간의 거리구하기(float반환) { return (float)Math.Sqrt(Math.Pow(targetPos.x - myPos.x, 2) + Math.Pow(targetPos.y - myPos.y, 2)); } } } | cs |
'C# > 과제' 카테고리의 다른 글
<바론과 애니비아 쌈박질> (0) | 2019.04.11 |
---|---|
<Overload, Override>, .json없이 .dat으로 (0) | 2019.04.10 |
<인벤토리> 저장, 불러오기 기능 (0) | 2019.04.08 |
<IEnumerable과 IEnumerator> 내일 다시 확인하여 예제 준비할 것 (0) | 2019.04.01 |
<인벤토리 1차>중첩방식 목록보기 (0) | 2019.03.31 |