14 changed files with 470 additions and 36 deletions
@ -0,0 +1,27 @@ |
|||
fileFormatVersion: 2 |
|||
guid: a94cf6fef2879da4c91e5ef768aadf4e |
|||
PluginImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
iconMap: {} |
|||
executionOrder: {} |
|||
defineConstraints: [] |
|||
isPreloaded: 0 |
|||
isOverridable: 0 |
|||
isExplicitlyReferenced: 0 |
|||
validateReferences: 1 |
|||
platformData: |
|||
- first: |
|||
Any: |
|||
second: |
|||
enabled: 1 |
|||
settings: {} |
|||
- first: |
|||
Editor: Editor |
|||
second: |
|||
enabled: 0 |
|||
settings: |
|||
DefaultValueInitialized: true |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,99 @@ |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class Enemy |
|||
{ |
|||
public List<EnemyCard> deck = new List<EnemyCard>(); // 卡组
|
|||
public List<EnemyCard> hand = new List<EnemyCard>(); // 手牌
|
|||
public List<EnemyCard> discardPile = new List<EnemyCard>();// 弃牌堆
|
|||
public List<EnemyCard> inPlay = new List<EnemyCard>(); // 战场上的牌
|
|||
|
|||
|
|||
public void EnemyTurnSettle(int num) |
|||
{ |
|||
for (int i = 0; i < num; i++) |
|||
{ |
|||
DrawOneCard(); |
|||
} |
|||
} |
|||
public void PlayCard(int num) |
|||
{ |
|||
// 处理无效输入
|
|||
if (deck == null || deck.Count == 0) return ; |
|||
|
|||
// 如果n超过列表长度,则删除全部元素
|
|||
if (num >= deck.Count) |
|||
{ |
|||
deck.Clear(); |
|||
ReshuffleDiscardIntoDeck(); |
|||
return; |
|||
} |
|||
|
|||
// 存储被选中的元素
|
|||
var selectedElements = new List<EnemyCard>(num); |
|||
|
|||
// 随机选择并删除元素
|
|||
for (int i = 0; i < num; i++) |
|||
{ |
|||
int randomIndex = new System.Random().Next(deck.Count); |
|||
selectedElements.Add(deck[randomIndex]); |
|||
deck.RemoveAt(randomIndex); |
|||
} |
|||
} |
|||
|
|||
// 洗牌(将弃牌堆洗入卡组)
|
|||
public void ReshuffleDiscardIntoDeck() |
|||
{ |
|||
if (discardPile.Count == 0) |
|||
{ |
|||
Debug.Log("弃牌堆为空,无法洗牌"); |
|||
return; |
|||
} |
|||
|
|||
// 将弃牌堆加入卡组
|
|||
deck.AddRange(discardPile); |
|||
discardPile.Clear(); |
|||
|
|||
// 洗牌算法
|
|||
ShuffleDeck(); |
|||
|
|||
Debug.Log($"已将弃牌堆洗入卡组,当前卡组有 {deck.Count} 张牌"); |
|||
} |
|||
|
|||
// 洗牌算法
|
|||
void ShuffleDeck() |
|||
{ |
|||
// Fisher-Yates 洗牌算法
|
|||
for (int i = deck.Count - 1; i > 0; i--) |
|||
{ |
|||
int j = Random.Range(0, i + 1); |
|||
EnemyCard temp = deck[i]; |
|||
deck[i] = deck[j]; |
|||
deck[j] = temp; |
|||
} |
|||
} |
|||
public void DrawOneCard() |
|||
{ |
|||
if (deck.Count == 0) |
|||
{ |
|||
Debug.Log("卡组空了,无法抽牌!"); |
|||
ReshuffleDiscardIntoDeck(); |
|||
if (deck.Count == 0) |
|||
{ |
|||
Debug.Log("洗牌后卡组仍然为空!"); |
|||
return; |
|||
} |
|||
} |
|||
EnemyCard drawnCard = deck[0]; |
|||
deck.RemoveAt(0); |
|||
settleCard(drawnCard); |
|||
discardPile.Add(drawnCard); |
|||
} |
|||
|
|||
public void settleCard(EnemyCard card) |
|||
{ |
|||
MapUnity target = getNodeTools.getBestTargetNodeForEnemyCard(card.nodesMark, card.nodesColor); |
|||
card.CardSettle(target); |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: a8bcecd86a4bbbd42b662c5ee02ea8d2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class EnemyCard |
|||
{ |
|||
public string[] nodesMark; |
|||
public string[] nodesColor; |
|||
|
|||
public void CardSettle(MapUnity targetNode) |
|||
{ |
|||
Debug.Log("打出一张"); |
|||
float euler = 90.0f; |
|||
//Debug.Log("currentNode的X是" + targetNode.locationX + "currentNode的Y是" + targetNode.locationY);
|
|||
//Debug.Log("currentNode的Q是" + currentNode.cubeQ + "currentNode的S是" + currentNode.cubeS + "currentNode的R是" + currentNode.cubeR);
|
|||
List<(int, int, int)> cubeList = new List<(int, int, int)>(); |
|||
int intEuler = (int)euler; |
|||
//Debug.Log("euler是" + intEuler);
|
|||
for (int i = 0; i < nodesMark.Length; i++) |
|||
{ |
|||
|
|||
try |
|||
{ |
|||
string[] marks = nodesMark[i].Split("_"); |
|||
//Debug.Log("AxialToCube的X是" + int.Parse(marks[0]) + "AxialToCube的Y是" + int.Parse(marks[1]));
|
|||
(int q, int s, int y) = MathTool.AxialToCube(int.Parse(marks[0]), int.Parse(marks[1])); |
|||
cubeList.Add((q, s, y)); |
|||
} |
|||
catch (Exception e) |
|||
{ } |
|||
} |
|||
List<(int, int, int)> rotatedCubeList = new List<(int, int, int)>(); |
|||
rotatedCubeList = MathTool.RotateCoordinates(cubeList, intEuler); |
|||
foreach (var tuple in rotatedCubeList) |
|||
{ |
|||
MapUnity endNode = null; |
|||
endNode = getNodeTools.getNodeWithCube(tuple.Item1, tuple.Item2, tuple.Item3); |
|||
// Debug.Log("rotatedNode的X是" + endNode.locationX + "rotatedNode的Y是" + endNode.locationY);
|
|||
//Debug.Log("rotatedNode的Q是" + tuple.Item1 + "rotatedNode的S是" + tuple.Item2 + "rotatedNode的R是" + tuple.Item3);
|
|||
} |
|||
|
|||
|
|||
List<(int, int, int)> trueCubeList = new List<(int, int, int)>(); |
|||
trueCubeList = MathTool.TranslateHexesToNewOrigin(rotatedCubeList, (targetNode.cubeQ, targetNode.cubeS, targetNode.cubeR)); |
|||
for (int i = 0; i < trueCubeList.Count; i++) |
|||
{ |
|||
MapUnity endNode = null; |
|||
endNode = getNodeTools.getNodeWithCube(trueCubeList[i].Item1, trueCubeList[i].Item2, trueCubeList[i].Item3); |
|||
// Debug.Log("endNode的X是" + endNode.locationX + "endNode的Y是" + endNode.locationY);
|
|||
//Debug.Log("endNode的Q是"+endNode.cubeQ+ "endNode的S是" + endNode.cubeS+ "endNode的R是" + endNode.cubeR);
|
|||
if (endNode != null) |
|||
{ |
|||
endNode.switchColor(Name.stringColorToint(nodesColor[i])); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: d8c2b264584fca34c94ae347efe2655b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
Loading…
Reference in new issue