放开那三国战斗规则出手顺序实现
Posted Alixc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了放开那三国战斗规则出手顺序实现相关的知识,希望对你有一定的参考价值。
package com.wcc.game.fight;
import java.util.ArrayList;
import java.util.List;
class TestPlayer {
private int index;
private String name;
public TestPlayer() {
}
public TestPlayer(int index, String name) {
this.index = index;
this.name = name;
}
@Override
public String toString() {
return "TestPlayer [index=" + index + ", name=" + name + "]";
}
}
public class MainTest {
public static void printArray(List<TestPlayer> players) {
for (TestPlayer testPlayer : players) {
System.out.println(testPlayer.toString());
}
}
public static void main(String[] args) {
TestPlayer testPlayerA1 = new TestPlayer(1, "A1");
TestPlayer testPlayerA2 = new TestPlayer(2, "A2");
TestPlayer testPlayerA3 = new TestPlayer(3, "A3");
TestPlayer testPlayerA4 = new TestPlayer(4, "A4");
TestPlayer testPlayerA5 = new TestPlayer(5, "A5");
TestPlayer testPlayerA6 = new TestPlayer(6, "A6");
TestPlayer testPlayerB1 = new TestPlayer(1, "B1");
TestPlayer testPlayerB2 = new TestPlayer(2, "B2");
TestPlayer testPlayerB3 = new TestPlayer(3, "B3");
TestPlayer testPlayerB4 = new TestPlayer(4, "B4");
TestPlayer testPlayerB5 = new TestPlayer(5, "B5");
TestPlayer testPlayerB6 = new TestPlayer(6, "B6");
List<TestPlayer> playersA = new ArrayList<TestPlayer>();
// playersA.add(testPlayerA1);
playersA.add(testPlayerA2);
playersA.add(testPlayerA3);
// playersA.add(testPlayerA4);
playersA.add(testPlayerA5);
playersA.add(testPlayerA6);
List<TestPlayer> playersB = new ArrayList<TestPlayer>();
playersB.add(testPlayerB1);
playersB.add(testPlayerB2);
playersB.add(testPlayerB3);
playersB.add(testPlayerB4);
playersB.add(testPlayerB5);
playersB.add(testPlayerB6);
// printArray(playersB);
List<TestPlayer> endPlayers = new ArrayList<TestPlayer>();
// A1 A2 A3 A4 A5 A6
// B1 B2 B3 B4 B5 B6
// 合并两个数组 实现方式 隔位插入就可以实现效果
int maxSideSize = playersA.size() >= playersB.size() ? playersA.size() : playersB.size();
boolean aFirst = true;
for (int i = 0; i < maxSideSize; i++) {
if (aFirst) {
if (i < playersA.size()) {
endPlayers.add(playersA.get(i));
}
if (i < playersB.size()) {
endPlayers.add(playersB.get(i));
}
} else {
if (i < playersB.size()) {
endPlayers.add(playersB.get(i));
}
if (i < playersA.size()) {
endPlayers.add(playersA.get(i));
}
}
}
printArray(endPlayers);
}
}
以上是关于放开那三国战斗规则出手顺序实现的主要内容,如果未能解决你的问题,请参考以下文章
cocos2dx游戏--三国关羽传角色扮演类Demo的制作及实现