티스토리 뷰
package javaapplication23;
import java.util.Random;
public class JavaApplication23 {
public static class WarSim
{
public static void main (String[] args)
{
Unit[] team1=new Unit[10];
Unit[] team2=new Unit[10];
//=======================================================
team1[0]=new Warrior();
team1[1]=new Magicion();
team1[2]=new DarkM();
team1[3]=new Warrior();
team1[4]=new Magicion();
team1[5]=new DarkM();
team1[6]=new Warrior();
team1[7]=new Magicion();
team1[8]=new Warrior();
team1[9]=new DarkM();
//=======================================================
team2[0]=new Warrior();
team2[1]=new Magicion();
team2[2]=new DarkM();
team2[3]=new Warrior();
team2[4]=new Magicion();
team2[5]=new DarkM();
team2[6]=new Warrior();
team2[7]=new Magicion();
team2[8]=new DarkM();
team2[9]=new DarkM();
boolean bWarring=true;
int tick=0;
Unit attacker;
Unit target;
while(bWarring)
{
// …… 공격 유닛 선정, 대상 유닛 선정
attacker=team1[6];
target=team2[3];
if(attacker.IsAction(tick))
{attacker.Attack(target);}
tick++;
}
}
}
}
abstract class Unit
{
int m_hp;
boolean m_bAlive;
int m_type=0;
int m_stat;
int m_actionTick=0;
private Unit () {}
public Unit (int hp, int type,int tick)
{
m_bAlive=true;
m_hp=hp;
m_type=type;
m_actionTick=tick;
}
abstract public void Attack(Unit p);
public void Damaged(int damage)
{
m_hp -= damage;
if(m_hp <= 0)
m_bAlive=false;
}
public boolean IsAction(int tick)
{
if(m_bAlive &&
(tick % m_actionTick == 0 || tick ==0)&&m_stat==0)
return true;
else{
m_stat--;
return false;
}
}
}
class Warrior extends Unit
{
public Warrior()
{
super(300,1,2);
m_type=1;
}
public void Attack(Unit p)
{
if(p.m_type==1)
p.Damaged(10);
else if(p.m_type==2)
p.Damaged(20);
else if(p.m_type==3)
p.Damaged(15);
}
}
class Magicion extends Unit
{
public Magicion()
{
super(200,2,4);
m_type=2;
}
public void Attack(Unit p)
{
Random At_st = new Random();
int At=At_st.nextInt(4);
if(At<=2)
p.Damaged(30);
else
{
p.m_stat=4;
}
}
}
class DarkM extends Unit
{
public DarkM()
{
super(150,3,5);
m_type=3;
}
public void Attack(Unit p)
{
Random At_st = new Random();
int At=At_st.nextInt(4);
if(At<=2)
{
p.Damaged(30);
m_hp+=30;
}
else
{
p.m_stat=10;
}
}
}
'IT Skills > Programming' 카테고리의 다른 글
[C#] 텍스트박스에 숫자만 입력받도록 하기. (4) | 2015.09.04 |
---|---|
C# 인터페이스 (0) | 2013.05.06 |
C# -- 동물농장 (0) | 2013.04.29 |
C# - 동물농장 참고자료#2 (0) | 2013.04.22 |
C# - 시험참고자료#` (0) | 2013.04.22 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 안산
- Windows 10
- 프로그래밍
- 디지바이스
- 일본여행
- Asus
- m5a97
- 듀얼쇼크4
- 건담
- 이어폰
- javascript
- 카카오프렌즈
- 고양이
- 구글
- 애드센스
- 피규어
- 마우스
- 일본
- 보스
- 노트북
- 아이폰X
- razer
- 라이언
- 디지몬
- PS2
- 플스2
- AMD
- 윈도우즈 10
- ps4
- 프라모델
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함