#pragma once
#include <windows.h>
#include <iostream>
using namespace std;
- Data Type
- char, short, int, __int64 ...
- unsigned char, unsigned short, unsinged int ...
- float, bool
int main()
{
int hp = 100;
unsigned int maxhp = 200; // unsigned - 음수 제거 후 양수 증가
char ch = 100; // ASCII CODE
bool bStart; // true, false
short BossHp = 10000;
BossHp += 40000; // overflow
}
- Branch
- if - 삼항연산자
- switch - enum
- 기존 enum 사용할 경우 이름이 중복이 되는 경우가 생김
- 이를 방지하기 위해 enum class(c++ 11) 사용
enum class WeaponType
{
NONE, COMMON, RARE, UNIQUE,
}; // pch.h
int main()
{
int level = 10;
int maxHp = 100;
bool bIsHighLevel = (level >= 50); // false
if (bIsHighLevel) maxHp += 10;
else maxHp -= 10;
maxHp = (bIsHighLevel) ? maxHp + 10 : maxHp - 10; // 삼항 연산자
cout << maxHp << endl; // 80
WeaponType weaponType = WeaponType::NONE; // enum class 사용
switch (weaponType)
{
case WeaponType::NONE:
break;
case WeaponType::COMMON:
break;
case WeaponType::RARE:
break;
case WeaponType::UNIQUE:
break;
default:
break;
}
}
- Loop
- for, while, do-while
- continue, break
- range-base for (c++ 11)
int main()
{
int count = 0;
for (int i = 0; i < 10; i++)
{
if (i == 9) continue; // i가 9일 때 실행하지 않고 넘김
count++;
}
cout << count << endl;
count = 0;
while (count < 10)
{
if (count == 5) break; // count가 5일 때 while 종료
count++;
}
cout << count << endl;
// TODO
vector<int> v{ 1,2,3,4,5,6 }; // range-base for 사용하기위한 벡터
for (int number : v)
cout << number << endl;
}
int Attack(int playerHp, int attackerHp, int attackerDamage) { return playerHp - attackerDamage; }
float Attack(int playerHp, int attackerHp, float attackerDamage) { return playerHp - attackerDamage; }
int main()
{
int playerHp = 100;
int attackerHp = 50;
int attackerDamage = 10;
float attackerDamagef = 5.f;
Attack(playerHp, attackerHp, attackerDamage);
Attack(playerHp, attackerHp, attackerDamagef);
}