⭐ 대략적인 코딩
class 포켓몬{
// 멤버 변수
String type; // 타입 (강제)
String name; // 이름 (강제)
int level; // 레벨
int exp; // 경험치
int attackExp; // 공격시 추가되는 경험치
// 클래스 변수
static Random rand = new Random();
static final int maxLevel =30;
// 생성자
포켓몬(String 타입,String 이름) { //초기화
this.type = type;
this.name = name;
this.level = rand.nextInt(5)+1; // 1에서 5까지 레벨
this.exp = 0;
this.attackExp = 0;
}
// 함수
void attack(){ // attack 메서드
// 공격 50% 확률로 성공
attackVoice(); // 기술명 외침 ex ) 전기공격!
hello(); // 울음소리 ex) 삐까삐까!
int attackChance = rand.nextInt(2);
if(성공시){
// 경험 랜덤 50~500
int attackExp = rand.nextInt(451)+50;
"공격에 성공했습니다." 출력
levelUp();
}
else{ // 실패시
"공격에 실패했습니다." 출력
}
}
void hello(){ // hello 메서드, 울음소리
"울음소리" 출력
}
void levelUp(){ // levelUp 메서드
// 기존에 있던 경험치 + 새로 추가된 경험치
this.exp += attackExp;
if(최대레벨이 되면){
최대레벨 = 레벨;
syso("만렙달성!");
}
// 경험치가 100 미만이 될 때까지 반복
while(true){
if(100이상이면){
level++; //레벨업 +1
exp-=100; // 경험치 -100
}
else{ // 100미만이면 반복문 나감
break;
}
}
}
void attackVoice(){ // 공격할 때 기술명
"받아라~!" 출력
}
@오버라이딩
void toString(){ // 오버라이딩
포켓몬 정보 출력
}
} // 포켓몬 클래스 닫기
class 메타몽 extends 포켓몬{
// 생성자
// 타입, 이름 고정
// 함수
// hello, attackVoice 오버라이딩
// 어라??
}
class 조로아 extends 포켓몬{
// 생성자
// 타입, 이름 고정
// 함수
// hello, attackVoice 오버라이딩
// 조로조로
}
class 탕구리 extends 포켓몬{
// 생성자
// 타입, 이름 고정
// 함수
// hello, attackVoice 오버라이딩
// 구리구리?
}
class 뚜벅쵸 extends 포켓몬{
// 생성자
// 타입, 이름 고정
// 함수
// hello, attackVoice 오버라이딩
// 뚜벅뚜벅
}
public class PokemonGame{
void menu(){
메뉴판 println
}
int printMenu() { // 메뉴판 출력, 값받는 메서드
System.out.println("포켓몬 게임입니다.");
"메뉴" 출력
Scanner sc = new Scanner(System.in);
// 유효성 검사 추가
// 메뉴 입력
System.out.println("메뉴를 선택해주세요. >> ");
int menu = sc.nextInt();
return menu;
}
// 샘플 데이터
public static void sampleData(){
datas[0] = new Ditto(); // 메타몽 생성
}
public static boolean isNull(int cnt){
if(cnt<=0) { // 아직 저장된 포켓몬 데이터가 전혀 없을때
System.out.println("저장된 포켓몬이 없습니다!");
return true;
}
return false;
}
public static boolean isFull(int cnt,포켓몬[] datas) {
if(cnt>=datas.length) { // 더 이상 포켓몬 데이터를 저장할 수 없을때
System.out.println("저장가능한 공간이 없습니다!");
return true;
}
return false;
}
public static int selectOne(){
// 정수를 입력받음
// 범위 안의 정수인지 확인
}
public static int pokemonMenu(){
// 소지 포켓몬 출력
selectOne();
}
}
public static void main(String[] args) {
포켓몬[] datas=new 포켓몬[3]; // 포켓몬도감 객체 생성?
sampleData();
int cnt = 1;
if(menu==0) { // 0. 게임종료
break;
}
else if(menu==1) { // 1. 게임하기 (공격)
if(보유한 포켓몬이 있는지 유효성 검사(isNull?)){
continue;
}
// syso ("공격을 실행합니다. 게임할 포켓몬을 선택해주세요"); 출력
// 소지한 포켓몬 목록 출력 (게임할 포켓몬 선택)
int num;
while(true){ // 유효성 검사
// 입력(num)받는 sc.nextInt();
// if(만약에 범위 내에 선택했다면){
break;
}
// "올바른 번호를 선택해주세요" 출력
}
//
datas[num].attack();
}
else if(menu==2) { // 2. 전체 상태 출력
// 보유한 포켓몬이 있는지 유효성 검사(isNull?)
}
else if(menu==3) { // 3. 울음소리 듣기
// 보유한 포켓몬이 있는지 유효성 검사(isNull?)
//포켓몬 선택
// 울음소리 출력
}
else if(menu==4) { // 4. 포켓몬 잡기 (포획)
// 기존에 보유한 포켓몬이 4마리인 경우>> 유효성 검사(isFull?)
// 새로 잡은 포켓몬의 레벨을 1~5 랜덤, 경험치는 0
}
else {
System.out.println("잘못된 입력입니다!");
}
}
}
⭐ 주요 함수 목록
package pokemongame;
class 포켓몬{
/*변수선언 */
/*클래스변수 선언*/
포켓몬 생성자(타입,이름){
/* 초기화 */
}
void attack(){
}
void hello(){
}
void levelUp(){
}
void attackVoice(){
}
@Override
void toString(){
}
}
//자식클래스들//
class 메타몽 extends 포켓몬{
}
class 조로아 extends 포켓몬{
}
class 탕구리 extends 포켓몬{
}
class 뚜벅쵸 extends 포켓몬{
}
////////////////
public class PokemonGame{
void menu(){
보이는 메뉴판 0~3 println
}
public static boolean isNull(int cnt){
/*보유포켓몬 없으면*/
}
public static boolean isFull(int cnt, Pokemon[] datas){
/*포켓몬 가득차면*/
}
public static int selectOne(){
/*포켓몬 선택, 유효성 검사*/
}
public static int pokemonMenu(){
/*소지 포켓몬 출력, 포켓몬 선택*/
}
public static void main(String[] args) {
/*포켓몬도감 객체생성?*/
메뉴(0) 끝내기
메뉴(1) 게임시작하기
메뉴(2) 전체상태 출력
메뉴(3) 울음소리 듣기
메뉴(4) 포켓몬 잡기
나머지 잘못입력
}
}