如何从一个数组字符串添加int作为我的纸牌游戏的攻击伤害

时间:2017-08-17 17:46:48

标签: java

我正在与我的学校项目合作制作2人纸牌游戏。我正在尝试开始制作英雄阵列,但我不知道在哪里可以存储攻击/伤害的int。我即将制作100个英雄并随机交给用户,每个玩家将有5张牌。

import java.util.Scanner;

public class AngelsAndMinions {

    public static void main(String[]args) {

        Scanner in = new Scanner(System.in);
        System.out.println("Enter Player 1 Name : ");
        String Player1 = in.next();
        System.out.println("Enter Player 2 Name : ");
        String Player2 = in.next();

        String [] Heroes =  new String[5];

        Heroes[0] = "Winter Wyvern - Like many great poets, Auroth just wants time to write, but the Winter Wyvern's life is full of interruptions.";
        Heroes[1] = "Visage - Perched atop the entrance to the Narrow Maze sit the looming shapes of sneering gargoyles, the paths into the hereafter forever in their gaze.";
        Heroes[2] = "Skywrath Mage - A highly placed mage in the court of the Ghastly Eyrie, Dragonus lives a troubled existence. "; 
        Heroes[3] = "Jakiro - Even among magical beasts, a twin-headed dragon is a freak.";     
        Heroes[4] = "Puck - While Puck seems at first glance a mischievous, childish character, this quality masks an alien personality.";
}

1 个答案:

答案 0 :(得分:5)

为你的英雄创建一个类:

public class Hero {

    public String name;
    public String description;
    public int damage;

    public Hero(String name, String description, int damage) {
        this.name = name;
        this.description = description;
        this.damage = damage;
    }   
}

在你的main()方法中创建一个英雄数组并创建Hero对象:

Hero[] heroes =  new Hero[5];
heroes[0] = new Hero("Example Hero", "Example description", 50);