https://afsdzvcx123.tistory.com/entry/C-문법-C-콘솔창-텍스트-색상컬러-입히는-방법
//Stage.CS 부분
private int select; //선택지
public bool stageSelect;
public bool inFight = false; // 싸우는 도중인가?
do
{
Console.Write(">> ");
stageSelect = int.TryParse(Console.ReadLine(), out select);
if (!stageSelect)
{
Console.WriteLine("숫자를 입력해주세요.");
}
}
while (!stageSelect);
StageStart(select);
}
public void BattleStart()
{
int actNum; // 입력용
bool IsactNum;
Console.ForegroundColor = ConsoleColor.Yellow;
if (!inFight) // Battle!!
Console.WriteLine("\\r\\n######## ### ######## ######## ## ######## #### #### \\r\\n## ## ## ## ## ## ## ## #### #### \\r\\n## ## ## ## ## ## ## ## #### #### \\r\\n######## ## ## ## ## ## ###### ## ## \\r\\n## ## ######### ## ## ## ## \\r\\n## ## ## ## ## ## ## ## #### #### \\r\\n######## ## ## ## ## ######## ######## #### #### \\r\\n");
else // Your Turn!!
{
Console.WriteLine("\\r\\n## ## ####### ## ## ######## ######## ## ## ######## ## ## #### #### \\r\\n ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## #### #### \\r\\n #### ## ## ## ## ## ## ## ## ## ## ## #### ## #### #### \\r\\n ## ## ## ## ## ######## ## ## ## ######## ## ## ## ## ## \\r\\n ## ## ## ## ## ## ## ## ## ## ## ## ## #### \\r\\n ## ## ## ## ## ## ## ## ## ## ## ## ## ### #### #### \\r\\n ## ####### ####### ## ## ## ####### ## ## ## ## #### #### \\r\\n");
}
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
foreach (Monster monster in monsterInStage)
{
Console.ForegroundColor = ConsoleColor.Red;
if(monster.Health <= 0)
{
Console.ForegroundColor = ConsoleColor.DarkRed; // 몬스터가 죽은 상태면 검은 빨강으로 색상변경
}
monster.PrintMonster();
Console.ForegroundColor = ConsoleColor.White;
}
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("\\n[내 정보]");
Console.WriteLine($"Lv.{player1.stat.Level} {player1.Name} ({player1.stat.job}) ");
Console.WriteLine($"HP {player1.stat.Hp} / {player1.stat.MaxHp}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine("1. 공격");
Console.WriteLine();
do
{
Console.WriteLine("원하시는 행동을 입력해주세요.");
Console.Write(">> ");
IsactNum = int.TryParse(Console.ReadLine(), out actNum);
if (!IsactNum) // 숫자가 입력되지 않으면
{
Console.WriteLine("숫자를 입력해주세요.");
}
}
while (!IsactNum);
Console.Clear();
BattleTurn(actNum);
}
public void BattleTurn(int actNum) // 입력받은 값을 통해 플레이어와 몬스터의 턴이 진행됨 // 플레이어의 행동값 1.공격 2.스킬 3. 소모품 사용 등
{
inFight = true; // 전투중 (첫턴이아님)
PlayerTurn(actNum); // 플레이어 턴 진행
// 몬스터 턴 진행
MonsterTurn();
BattleStart();
}
public void MonsterTurn()
{
foreach (Monster monster in monsterInStage)
{
if (monster.Health <= 0) // 몬스터가 죽은상태면 공격을 안함
{
}
else
{
monster.HitDamage(player1, monster);
IsEnd();
}
}
}
public void PlayerTurn(int actNum)
{
bool IsRightEnemy; // 적을 알맞게 지정하였는가?
int EnemyNum; // 지정한 적 번호
int IntroNum = 0; // 적앞에 표시될 번호
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\\r\\n######## ### ######## ######## ## ######## #### #### \\r\\n## ## ## ## ## ## ## ## #### #### \\r\\n## ## ## ## ## ## ## ## #### #### \\r\\n######## ## ## ## ## ## ###### ## ## \\r\\n## ## ######### ## ## ## ## \\r\\n## ## ## ## ## ## ## ## #### #### \\r\\n######## ## ## ## ## ######## ######## #### #### \\r\\n");
Console.ForegroundColor = ConsoleColor.White;
switch (actNum) // 플레이어가 공격 혹은 스킬 혹은 소모품을 사용
{
case 1: // 플레이어의 일반 공격
foreach (Monster monster in monsterInStage)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(IntroNum + " ");
monster.PrintMonster();
IntroNum++;
Console.ForegroundColor = ConsoleColor.White;
}
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("\\n[내 정보]");
Console.WriteLine($"Lv.{player1.stat.Level} {player1.Name} ({player1.stat.job}) ");
Console.WriteLine($"HP {player1.stat.Hp} / {player1.stat.MaxHp}");
Console.ForegroundColor = ConsoleColor.White;
do
{
Console.WriteLine("\\n대상을 지정하세요");
Console.Write(">> ");
IsRightEnemy = int.TryParse(Console.ReadLine(), out EnemyNum);
if (!IsRightEnemy) // 숫자가 입력되지 않으면
{
Console.Clear();
Console.WriteLine("숫자를 제대로 입력해주세요.");
BattleTurn(actNum);
}
if (monsterInStage[EnemyNum].IsDead) // 지정한 몬스터가 죽었을 경우
{
Console.Clear();
Console.WriteLine("해당 몬스터는 이미 사망했습니다.");
BattleTurn(actNum); // 다시 원상복귀
}
Console.Clear(); // 지저분한 앞내용 지움
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write($"Lv.{player1.stat.Level} {player1.Name} 이(가) {monsterInStage[EnemyNum].Name} 을(를) 공격했습니다."); //
}
while (!IsRightEnemy);
monsterInStage[EnemyNum].TakeDamage(player1, player1.Critical()); // Player 가 몬스터에게 입힌 데미지 계산
break;
case 2: // 플레이어 스킬
break;
case 3: // 플레이어 소모품 사용
break;
default: // 잘못된 값 입력
BattleStart(); // 플레이어 입력턴으로 원상복귀
break;
}
IsEnd(); // 끝났는지 검사
// 플레이어 공격 적용
}
public void IsEnd() // 끝났는지 검사 단계
{
switch (IsBattleEnd())
{
case 1:
Console.WriteLine("플레이어 패배");
break;
case 2:
Console.WriteLine("\\r\\n## ## #### ###### ######## ####### ######## ## ## #### #### \\r\\n## ## ## ## ## ## ## ## ## ## ## ## #### #### \\r\\n## ## ## ## ## ## ## ## ## #### #### #### \\r\\n## ## ## ## ## ## ## ######## ## ## ## \\r\\n ## ## ## ## ## ## ## ## ## ## \\r\\n ## ## ## ## ## ## ## ## ## ## ## #### #### \\r\\n ### #### ###### ## ####### ## ## ## #### #### \\r\\n");
Console.WriteLine("플레이어 승리");
BattleResult();
Console.ReadLine(); // 출력확인용 입력대기
Start(player1);
break;
default: // 0
break;
}
}
public int IsBattleEnd() // 배틀이 끝났는지 여부 알아보기 및 승자가 누구인지 //1.플레이어 패배 2. 플레이어 승리 0. 전투가안끝남
{
if (player1.stat.Hp <= 0) // 플레이어가 죽었으면
{
return 1; // 1 return
}
foreach (Monster monster in monsterInStage)
{
if (!monster.IsDead) // 몬스터 중 한마리라도 살아있으면
{
return 0;
}
}
return 2; // 다죽었으면 2 return
}
Player.CS 부분
public void Wait() // 0번 입력대기용 함수
{
int input;
bool IsinputNum;
do
{
Console.WriteLine("0. 다음");
IsinputNum = int.TryParse(Console.ReadLine(), out input);
} while (IsinputNum);
switch (input)
{
case 1: // 상태보기
break;
default:
Console.WriteLine("올바른 입력을 해주세요.");
Wait();
break;
}
}
public int Attack => Critical(); // 신던전에서 사용할 공격력 적용 방법
// AttackPower = 임시공격력 상승, AttackInc = 플레이어 장비 총합, Attack.stat = 플레이어 기본 공격력
int atkinc = 0;
int definc = 0;// name, stat, market,
public void TakeDamage(Player player, int damage) // 회피기능 및 데미지 받음 (Damage 값)
{
int avoidProb;
avoidProb = new Random().Next(0, 100);
if (avoidProb < avoid + increaseAvoid) // 공격 회피
{
damage = 0;
Console.WriteLine($"{player.Name}이(가) 놀라운 반사신경으로 공격을 회피했습니다..\\n\\n");
}
else
{
Health -= damage;
if (IsDead) Console.WriteLine($"{Name}이(가) 죽었습니다.");
else Console.WriteLine($"{Name}이(가) {damage}의 데미지를 받았습니다. 남은 체력: {Health}");
}
Wait(); // 다음 버튼용 함수
}
public int Critical() // 크리티컬 계산식 및 데미지 계산식 (int 값 출력)
{
int dmgresult;
int criticalProb;
dmgresult = new Random().Next((int)((AttackPower + stat.Attack + stat.AttackInc)*0.9), (int)((AttackPower + stat.Attack + stat.AttackInc)*1.1));
criticalProb = new Random().Next(0, 100);
if (criticalProb < critical + increaseCritical)
{
// 크리티컬이 터진다.
dmgresult = (int)(dmgresult * (criticalDmg + increaseCriticalDmg / 100.0f)); // 크리티컬 확률 및 크리티컬 데미지 계산식
Console.ForegroundColor = ConsoleColor.Red;
Console.Write($"\\n{Name} 이 적의 급소를 노려 치명적인 일격이 적용!!");
}
return dmgresult; // 최종 데미지
}
public Player(string name)
{
Name = name;
stat = new Status(Name);
inven = new Inventory(name);
stage = new Stage();
market = new Market("초보자상점");
dungeon = new Dungeon();
camp = new Camp();
program = new Program();
//stat.Show_stat(); // 생성할 때, 캐릭터 정보를 출력 //현재 기능 비활성화
}