1.다이아몬드와 소환권 구매
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static int gold;
static int diamondCount;
static int summonTicketCount;
static void Main(string[] args)
{
gold = 1000;
diamondCount = 0;
summonTicketCount = 0;
Purchase("다이아몬드");
Purchase("다이아몬드");
Purchase("다이아몬드");
Purchase("소환권");
}
/*기능
* 다이아몬드를 구매한다
* 소환권을 구매한다*/
static void Purchase(string goods)
{
if (goods == "다이아몬드")
{
gold -= 100;
diamondCount++;
Console.WriteLine("{0}를 구매했습니다.", goods);
Console.WriteLine("골드: {0}, 다이아: {1}, 소환권: {2}", gold, diamondCount, summonTicketCount);
}
else if (goods == "소환권")
{
gold -= 10;
summonTicketCount++;
Console.WriteLine("{0}을 구매했습니다.", goods);
Console.WriteLine("골드: {0}, 다이아: {1}, 소환권: {2}", gold, diamondCount, summonTicketCount);
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
2.저글링을 공격하는 마린
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
const int MAXHP = 8;
static int marineDamage = 5;
static int zerglingHp = 8;
static void Main(string[] args)
{
AttackZergling("마린", "저글링");
AttackZergling("마린", "저글링");
AttackZergling("마린", "저글링");
AttackZergling("마린", "저글링");
AttackZergling("마린", "저글링");
}
static void AttackZergling(string unitname1, string unitname2)
{
if (zerglingHp > 0 && zerglingHp > marineDamage)
{
zerglingHp -= marineDamage;
Console.WriteLine("{0}이(가) {1}을 공격했습니다.", unitname1, unitname2);
Console.WriteLine("ZerglingHp: {0}/{1}", zerglingHp, MAXHP);
}
else if (zerglingHp > 0 && zerglingHp <= marineDamage)
{
zerglingHp -= marineDamage;
Console.WriteLine("{0}이(가) {1}을 공격했습니다.", unitname1, unitname2);
Console.WriteLine("ZerglingHp: {0}/{1}", zerglingHp, MAXHP);
Console.WriteLine("저글링이 죽었습니다.");
}
else if (zerglingHp <= 0)
{
Console.WriteLine("잘못된 대상입니다.");
}
}
}
}
살았을때와 죽을때와 이미 죽었을때를 구분짓기 위해 논리연산을 떠올리는것에 시간이 많이 걸렸다.
'C# > 수업 내용' 카테고리의 다른 글
계산기 메서드 만들어보기 (0) | 2021.12.23 |
---|---|
반환값이 있는 메서드 연습 (벌쳐, 템플러, 홀짝 판단, 줄넘기) (0) | 2021.12.23 |
반환값은 없고 매개변수가 있는 메서드 연습 (0) | 2021.12.23 |
반환값이 없고 매개변수가 있는 메서드 정의 및 호출 (0) | 2021.12.23 |
메서드 정의하고 호출하기 5번연습 (0) | 2021.12.23 |