Browse Source

style: 🎨 format fix

tags/0.1.0
shangfengh 2 years ago
parent
commit
ba1cf34d3c
3 changed files with 327 additions and 361 deletions
  1. +109
    -107
      logic/Gaming/AttackManager.cs
  2. +168
    -205
      logic/Gaming/Game.cs
  3. +50
    -49
      logic/Gaming/PropManager.cs

+ 109
- 107
logic/Gaming/AttackManager.cs View File

@@ -22,15 +22,17 @@ namespace Gaming
gameMap: gameMap, gameMap: gameMap,
OnCollision: (obj, collisionObj, moveVec) => OnCollision: (obj, collisionObj, moveVec) =>
{ {
//BulletBomb((Bullet)obj, (GameObj)collisionObj);
return MoveEngine.AfterCollision.Destroyed; },
//BulletBomb((Bullet)obj, (GameObj)collisionObj);
return MoveEngine.AfterCollision.Destroyed;
},
EndMove: obj => EndMove: obj =>
{ {
#if DEBUG #if DEBUG
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);


#endif #endif
BulletBomb((Bullet)obj, null); }
BulletBomb((Bullet)obj, null);
}
); );
} }
private void BombOnePlayer(Bullet bullet, Character playerBeingShot) private void BombOnePlayer(Bullet bullet, Character playerBeingShot)
@@ -75,136 +77,136 @@ namespace Gaming


Thread.Sleep(GameData.reviveTime); Thread.Sleep(GameData.reviveTime);


playerBeingShot.AddShield(GameData.shieldTimeAtBirth); // 复活加个盾
playerBeingShot.AddShield(GameData.shieldTimeAtBirth); // 复活加个盾


// gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
// try
//{
// gameMap.GameObjDict[GameObjIdx.Player].Add(playerBeingShot);
// }
// finally { gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock(); }
// gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
// try
//{
// gameMap.GameObjDict[GameObjIdx.Player].Add(playerBeingShot);
// }
// finally { gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock(); }


if (gameMap.Timer.IsGaming)
{
playerBeingShot.CanMove = true;
}
playerBeingShot.IsResetting = false;
}
if (gameMap.Timer.IsGaming)
{
playerBeingShot.CanMove = true;
}
playerBeingShot.IsResetting = false;
}
) )
{ IsBackground = true }.Start(); { IsBackground = true }.Start();
}
} }
}
private void BulletBomb(Bullet bullet, GameObj? objBeingShot)
{
private void BulletBomb(Bullet bullet, GameObj? objBeingShot)
{
#if DEBUG #if DEBUG
Debugger.Output(bullet, "bombed!");
Debugger.Output(bullet, "bombed!");
#endif #endif
bullet.CanMove = false;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
foreach (ObjOfCharacter _bullet in gameMap.GameObjDict[GameObjIdx.Bullet])
{
if (_bullet.ID == bullet.ID)
bullet.CanMove = false;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
foreach (ObjOfCharacter _bullet in gameMap.GameObjDict[GameObjIdx.Bullet])
{ {
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.BombedBullet].Add(new BombedBullet(bullet));
}
finally
if (_bullet.ID == bullet.ID)
{ {
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].ExitWriteLock();
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.BombedBullet].Add(new BombedBullet(bullet));
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.BombedBullet].ExitWriteLock();
}
gameMap.GameObjDict[GameObjIdx.Bullet].Remove(_bullet);
break;
} }
gameMap.GameObjDict[GameObjIdx.Bullet].Remove(_bullet);
break;
} }
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
}

/*if (objBeingShot != null)
{
else if (objBeingShot is Bullet) //子弹不能相互引爆,若要更改这一设定,取消注释即可。
}
finally
{ {
new Thread(() => { BulletBomb((Bullet)objBeingShot, null); }) { IsBackground = true }.Start();
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
} }
}*/


// 子弹爆炸会发生的事↓↓↓
var beAttackedList = new List<Character>();
gameMap.GameObjLockDict[GameObjIdx.Player].EnterReadLock();
try
{
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
if (bullet.CanAttack(player))
/*if (objBeingShot != null)
{
else if (objBeingShot is Bullet) //子弹不能相互引爆,若要更改这一设定,取消注释即可。
{ {
beAttackedList.Add(player);
if (player.ID != bullet.Parent.ID)
bullet.Parent.HP = (int)(bullet.Parent.HP + (bullet.Parent.Vampire * bullet.AP));
new Thread(() => { BulletBomb((Bullet)objBeingShot, null); }) { IsBackground = true }.Start();
} }
}*/

// 子弹爆炸会发生的事↓↓↓
var beAttackedList = new List<Character>();
gameMap.GameObjLockDict[GameObjIdx.Player].EnterReadLock();
try
{
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
if (bullet.CanAttack(player))
{
beAttackedList.Add(player);
if (player.ID != bullet.Parent.ID)
bullet.Parent.HP = (int)(bullet.Parent.HP + (bullet.Parent.Vampire * bullet.AP));
} }
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Player].ExitReadLock();
}
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Player].ExitReadLock();
}


foreach (Character beAttackedPlayer in beAttackedList)
{
BombOnePlayer(bullet, beAttackedPlayer);
foreach (Character beAttackedPlayer in beAttackedList)
{
BombOnePlayer(bullet, beAttackedPlayer);
}
beAttackedList.Clear();
} }
beAttackedList.Clear();
}
public bool Attack(Character? player, double angle) // 射出去的子弹泼出去的水(狗头)
{ // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange
if (player == null)
{
public bool Attack(Character? player, double angle) // 射出去的子弹泼出去的水(狗头)
{ // 子弹如果没有和其他物体碰撞,将会一直向前直到超出人物的attackRange
if (player == null)
{
#if DEBUG #if DEBUG
Console.WriteLine("the player who will attack is NULL!");
Console.WriteLine("the player who will attack is NULL!");
#endif #endif
return false;
}
return false;
}


if (player.IsResetting)
return false;
Bullet? bullet = player.RemoteAttack(
new XY // 子弹紧贴人物生成。
(
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Cos(angle)),
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Sin(angle))
)
);
if (bullet != null)
{
bullet.CanMove = true;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.Bullet].Add(bullet);
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
}
moveEngine.MoveObj(bullet, (int)((player.AttackRange - player.Radius - BulletFactory.BulletRadius(player.BulletOfPlayer)) * 1000 / bullet.MoveSpeed), angle); // 这里时间参数除出来的单位要是ms
if (player.IsResetting)
return false;
Bullet? bullet = player.RemoteAttack(
new XY // 子弹紧贴人物生成。
(
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Cos(angle)),
(int)((player.Radius + BulletFactory.BulletRadius(player.BulletOfPlayer)) * Math.Sin(angle))
)
);
if (bullet != null)
{
bullet.CanMove = true;
gameMap.GameObjLockDict[GameObjIdx.Bullet].EnterWriteLock();
try
{
gameMap.GameObjDict[GameObjIdx.Bullet].Add(bullet);
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Bullet].ExitWriteLock();
}
moveEngine.MoveObj(bullet, (int)((player.AttackRange - player.Radius - BulletFactory.BulletRadius(player.BulletOfPlayer)) * 1000 / bullet.MoveSpeed), angle); // 这里时间参数除出来的单位要是ms
#if DEBUG #if DEBUG
Console.WriteLine($"playerID:{player.ID} successfully attacked!");
Console.WriteLine($"playerID:{player.ID} successfully attacked!");
#endif #endif
return true;
}
else
{
return true;
}
else
{
#if DEBUG #if DEBUG
Console.WriteLine($"playerID:{player.ID} has no bullets so that he can't attack!");
Console.WriteLine($"playerID:{player.ID} has no bullets so that he can't attack!");
#endif #endif
return false;
return false;
}
} }
} }
} }
} }
}

+ 168
- 205
logic/Gaming/Game.cs View File

@@ -16,13 +16,13 @@ namespace Gaming
public uint birthPointIndex; public uint birthPointIndex;
public long teamID; public long teamID;
public long playerID; public long playerID;
public PassiveSkillType passiveSkill;
public CharacterType characterType;
public ActiveSkillType commonSkill; public ActiveSkillType commonSkill;
public PlayerInitInfo(uint birthPointIndex, long teamID, long playerID, PassiveSkillType passiveSkill, ActiveSkillType commonSkill)
public PlayerInitInfo(uint birthPointIndex, long teamID, long playerID, CharacterType characterType, ActiveSkillType commonSkill)
{ {
this.birthPointIndex = birthPointIndex; this.birthPointIndex = birthPointIndex;
this.teamID = teamID; this.teamID = teamID;
this.passiveSkill = passiveSkill;
this.characterType = characterType;
this.commonSkill = commonSkill; this.commonSkill = commonSkill;
this.playerID = playerID; this.playerID = playerID;
} }
@@ -40,9 +40,9 @@ namespace Gaming
|| gameMap.BirthPointList[playerInitInfo.birthPointIdx].Parent != null)*/ || gameMap.BirthPointList[playerInitInfo.birthPointIdx].Parent != null)*/
return GameObj.invalidID; return GameObj.invalidID;


XYPosition pos = gameMap.BirthPointList[playerInitInfo.birthPointIndex].Position;
XY pos = gameMap.BirthPointList[playerInitInfo.birthPointIndex].Position;
// Console.WriteLine($"x,y: {pos.x},{pos.y}"); // Console.WriteLine($"x,y: {pos.x},{pos.y}");
Character newPlayer = new(pos, GameData.characterRadius, gameMap.GetPlaceType(pos), playerInitInfo.passiveSkill, playerInitInfo.commonSkill);
Character newPlayer = new(pos, GameData.characterRadius, gameMap.GetPlaceType(pos), playerInitInfo.characterType, playerInitInfo.commonSkill);
gameMap.BirthPointList[playerInitInfo.birthPointIndex].Parent = newPlayer; gameMap.BirthPointList[playerInitInfo.birthPointIndex].Parent = newPlayer;
gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock(); gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
try try
@@ -64,62 +64,62 @@ namespace Gaming
{ {
while (!gameMap.Timer.IsGaming) while (!gameMap.Timer.IsGaming)
Thread.Sleep(newPlayer.CD); Thread.Sleep(newPlayer.CD);
long lastTime = Environment.TickCount64;
new FrameRateTaskExecutor<int>(
loopCondition: () => gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (!newPlayer.IsResetting)
long lastTime = Environment.TickCount64;
new FrameRateTaskExecutor<int>(
loopCondition: () => gameMap.Timer.IsGaming,
loopToDo: () =>
{
if (!newPlayer.IsResetting)
{
long nowTime = Environment.TickCount64;
if (newPlayer.BulletNum == newPlayer.MaxBulletNum)
lastTime = nowTime;
if (nowTime - lastTime >= newPlayer.CD)
{
_ = newPlayer.TryAddBulletNum();
lastTime = nowTime;
}
}
},
timeInterval: GameData.checkInterval,
finallyReturn: () => 0
)
{ {
long nowTime = Environment.TickCount64;
if (newPlayer.BulletNum == newPlayer.MaxBulletNum)
lastTime = nowTime;
if (nowTime - lastTime >= newPlayer.CD)
AllowTimeExceed = true
/*MaxTolerantTimeExceedCount = 5,
TimeExceedAction = exceedTooMuch =>
{ {
_ = newPlayer.TryAddBulletNum();
lastTime = nowTime;
}
if (exceedTooMuch) Console.WriteLine("The computer runs too slow that it cannot check the color below the player in time!");
}*/
} }
},
timeInterval: GameData.checkInterval,
finallyReturn: () => 0
) {
AllowTimeExceed = true
/*MaxTolerantTimeExceedCount = 5,
TimeExceedAction = exceedTooMuch =>
{
if (exceedTooMuch) Console.WriteLine("The computer runs too slow that it cannot check the color below the player in time!");
}*/
}
.Start();
}
.Start();
}
) )
{ IsBackground = true }.Start(); { IsBackground = true }.Start();


return newPlayer.ID; return newPlayer.ID;
}
public bool StartGame(int milliSeconds)
{
}
public bool StartGame(int milliSeconds)
{
if (gameMap.Timer.IsGaming) if (gameMap.Timer.IsGaming)
return false;
return false;
gameMap.GameObjLockDict[GameObjIdx.Player].EnterReadLock(); gameMap.GameObjLockDict[GameObjIdx.Player].EnterReadLock();
try try
{ {
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
player.CanMove = true;
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
player.CanMove = true;


player.AddShield(GameData.shieldTimeAtBirth);
}
player.AddShield(GameData.shieldTimeAtBirth);
}
} }
finally finally
{ {
gameMap.GameObjLockDict[GameObjIdx.Player].ExitReadLock();
gameMap.GameObjLockDict[GameObjIdx.Player].ExitReadLock();
} }


propManager.StartProducing(); propManager.StartProducing();
gemManager.StartProducingGem();
new Thread
new Thread
( (
() => () =>
{ {
@@ -128,24 +128,24 @@ namespace Gaming
loopCondition: () => gameMap.Timer.IsGaming, loopCondition: () => gameMap.Timer.IsGaming,
loopToDo: () => loopToDo: () =>
{ {
foreach (var kvp in gameMap.GameObjDict) // 检查物体位置
{
if (kvp.Key == GameObjIdx.Bullet || kvp.Key == GameObjIdx.Player || kvp.Key == GameObjIdx.Prop || kvp.Key == GameObjIdx.Gem)
{
gameMap.GameObjLockDict[kvp.Key].EnterWriteLock();
try
{
foreach (var item in gameMap.GameObjDict[kvp.Key])
{
item.Place = gameMap.GetPlaceType(item.Position);
}
}
finally
{
gameMap.GameObjLockDict[kvp.Key].ExitWriteLock();
}
}
}
foreach (var kvp in gameMap.GameObjDict) // 检查物体位置
{
if (kvp.Key == GameObjIdx.Bullet || kvp.Key == GameObjIdx.Player || kvp.Key == GameObjIdx.Prop)
{
gameMap.GameObjLockDict[kvp.Key].EnterWriteLock();
try
{
foreach (var item in gameMap.GameObjDict[kvp.Key])
{
item.Place = gameMap.GetPlaceType(item.Position);
}
}
finally
{
gameMap.GameObjLockDict[kvp.Key].ExitWriteLock();
}
}
}
}, },
timeInterval: GameData.checkInterval, timeInterval: GameData.checkInterval,
finallyReturn: () => 0 finallyReturn: () => 0
@@ -153,228 +153,192 @@ namespace Gaming
{ {
AllowTimeExceed = true AllowTimeExceed = true
}.Start(); }.Start();
}
}
) )
{ IsBackground = true }.Start(); { IsBackground = true }.Start();
// 开始游戏 // 开始游戏
if (!gameMap.Timer.StartGame(milliSeconds)) if (!gameMap.Timer.StartGame(milliSeconds))
return false;
return false;


EndGame(); // 游戏结束时要做的事 EndGame(); // 游戏结束时要做的事


return true; return true;
}
}


public void EndGame()
{
public void EndGame()
{
gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock(); gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
try
/*try
{ {
foreach (var player in gameMap.GameObjDict[GameObjIdx.Player])
{
gemManager.UseAllGem((Character)player);
}
} }
finally finally
{ {
}*/
gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock(); gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock();
}
}
public void MovePlayer(long playerID, int moveTimeInMilliseconds, double angle)
{
}
public void MovePlayer(long playerID, int moveTimeInMilliseconds, double angle)
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return;
return;
Character? player = gameMap.FindPlayer(playerID); Character? player = gameMap.FindPlayer(playerID);
if (player != null) if (player != null)
{ {
moveManager.MovePlayer(player, moveTimeInMilliseconds, angle);
moveManager.MovePlayer(player, moveTimeInMilliseconds, angle);
#if DEBUG #if DEBUG
Console.WriteLine($"PlayerID:{playerID} move to ({player.Position.x},{player.Position.y})!");
Console.WriteLine($"PlayerID:{playerID} move to ({player.Position.x},{player.Position.y})!");
#endif #endif
} }
else else
{ {
#if DEBUG #if DEBUG
Console.WriteLine($"PlayerID:{playerID} player does not exists!");
Console.WriteLine($"PlayerID:{playerID} player does not exists!");
#endif #endif
} }
}
public void Attack(long playerID, double angle)
{
if (!gameMap.Timer.IsGaming)
return;
Character? player = gameMap.FindPlayer(playerID);
if (player != null)
{
_ = attackManager.Attack(player, angle);
}
}
public void UseGem(long playerID, int num = int.MaxValue)
{
if (!gameMap.Timer.IsGaming)
return;
Character? player = gameMap.FindPlayer(playerID);
if (player != null)
{
gemManager.UseGem(player, num);
return;
}
}
public void ThrowGem(long playerID, int moveMilliTime, double angle, int size = 1)
{
if (!gameMap.Timer.IsGaming)
return;
Character? player = gameMap.FindPlayer(playerID);
if (player != null)
{
gemManager.ThrowGem(player, moveMilliTime, angle, size);
return;
}
}
public bool PickGem(long playerID)
{
}
public void Attack(long playerID, double angle)
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return false;
return;
Character? player = gameMap.FindPlayer(playerID); Character? player = gameMap.FindPlayer(playerID);
if (player != null) if (player != null)
{ {
return gemManager.PickGem(player);
_ = attackManager.Attack(player, angle);
} }
return false;
}
public void UseProp(long playerID)
{
}
public void UseProp(long playerID)
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return;
return;
Character? player = gameMap.FindPlayer(playerID); Character? player = gameMap.FindPlayer(playerID);
if (player != null) if (player != null)
{ {
propManager.UseProp(player);
propManager.UseProp(player);
} }
}
public void ThrowProp(long playerID, int timeInmillionSeconds, double angle)
{
}
public void ThrowProp(long playerID, int timeInmillionSeconds, double angle)
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return;
return;
Character? player = gameMap.FindPlayer(playerID); Character? player = gameMap.FindPlayer(playerID);
if (player != null) if (player != null)
{ {
propManager.ThrowProp(player, timeInmillionSeconds, angle);
propManager.ThrowProp(player, timeInmillionSeconds, angle);
} }
}
public bool PickProp(long playerID, PropType propType = PropType.Null)
{
}
public bool PickProp(long playerID, PropType propType = PropType.Null)
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return false;
return false;
Character? player = gameMap.FindPlayer(playerID); Character? player = gameMap.FindPlayer(playerID);
if (player != null) if (player != null)
{ {
return propManager.PickProp(player, propType);
return propManager.PickProp(player, propType);
} }
return false; return false;
}
}


public bool UseCommonSkill(long playerID)
{
public bool UseCommonSkill(long playerID)
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return false;
return false;
Character? player = gameMap.FindPlayer(playerID); Character? player = gameMap.FindPlayer(playerID);
if (player != null) if (player != null)
{ {
return skillManager.UseCommonSkill(player);
return skillManager.UseCommonSkill(player);
} }
else else
return false;
}
return false;
}


public void AllPlayerUsePassiveSkill()
{
public void AllPlayerUsePassiveSkill()
{
if (!gameMap.Timer.IsGaming) if (!gameMap.Timer.IsGaming)
return;
return;
gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock(); gameMap.GameObjLockDict[GameObjIdx.Player].EnterWriteLock();
try try
{ {
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
skillManager.UsePassiveSkill(player);
}
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
skillManager.UsePassiveSkill(player);
}
} }
finally finally
{ {
gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock();
gameMap.GameObjLockDict[GameObjIdx.Player].ExitWriteLock();
} }
}
}


public void ClearLists(GameObjIdx[] objIdxes)
{
public void ClearLists(GameObjIdx[] objIdxes)
{
foreach (var idx in objIdxes) foreach (var idx in objIdxes)
{ {
if (idx != GameObjIdx.None)
{
gameMap.GameObjLockDict[idx].EnterWriteLock();
try
{
gameMap.GameObjDict[idx].Clear();
}
finally
{
gameMap.GameObjLockDict[idx].ExitWriteLock();
}
}
if (idx != GameObjIdx.None)
{
gameMap.GameObjLockDict[idx].EnterWriteLock();
try
{
gameMap.GameObjDict[idx].Clear();
}
finally
{
gameMap.GameObjLockDict[idx].ExitWriteLock();
}
}
} }
}
public void ClearAllLists()
{
}
public void ClearAllLists()
{
foreach (var keyValuePair in gameMap.GameObjDict) foreach (var keyValuePair in gameMap.GameObjDict)
{ {
if (keyValuePair.Key != GameObjIdx.Map)
{
gameMap.GameObjLockDict[keyValuePair.Key].EnterWriteLock();
try
{
if (keyValuePair.Key == GameObjIdx.Player)
if (keyValuePair.Key != GameObjIdx.Map)
{ {
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
gameMap.GameObjLockDict[keyValuePair.Key].EnterWriteLock();
try
{ {
player.CanMove = false;
if (keyValuePair.Key == GameObjIdx.Player)
{
foreach (Character player in gameMap.GameObjDict[GameObjIdx.Player])
{
player.CanMove = false;
}
}
gameMap.GameObjDict[keyValuePair.Key].Clear();
}
finally
{
gameMap.GameObjLockDict[keyValuePair.Key].ExitWriteLock();
} }
} }
gameMap.GameObjDict[keyValuePair.Key].Clear();
}
finally
{
gameMap.GameObjLockDict[keyValuePair.Key].ExitWriteLock();
}
} }
}
}
}


public int GetTeamScore(long teamID)
{
public int GetTeamScore(long teamID)
{
return teamList[(int)teamID].Score; return teamList[(int)teamID].Score;
}
public List<IGameObj> GetGameObj()
{
}
public List<IGameObj> GetGameObj()
{
var gameObjList = new List<IGameObj>(); var gameObjList = new List<IGameObj>();
foreach (var keyValuePair in gameMap.GameObjDict) foreach (var keyValuePair in gameMap.GameObjDict)
{ {
if (keyValuePair.Key != GameObjIdx.Map)
{
gameMap.GameObjLockDict[keyValuePair.Key].EnterReadLock();
try
{
gameObjList.AddRange(gameMap.GameObjDict[keyValuePair.Key]);
}
finally
{
gameMap.GameObjLockDict[keyValuePair.Key].ExitReadLock();
}
}
if (keyValuePair.Key != GameObjIdx.Map)
{
gameMap.GameObjLockDict[keyValuePair.Key].EnterReadLock();
try
{
gameObjList.AddRange(gameMap.GameObjDict[keyValuePair.Key]);
}
finally
{
gameMap.GameObjLockDict[keyValuePair.Key].ExitReadLock();
}
}
} }
return gameObjList; return gameObjList;
}
public Game(uint[,] mapResource, int numOfTeam)
{
}
public Game(uint[,] mapResource, int numOfTeam)
{
// if (numOfTeam > maxTeamNum) throw new TeamNumOverFlowException(); // if (numOfTeam > maxTeamNum) throw new TeamNumOverFlowException();


gameMap = new Map(mapResource); gameMap = new Map(mapResource);
@@ -384,14 +348,13 @@ public Game(uint[,] mapResource, int numOfTeam)
teamList = new List<Team>(); teamList = new List<Team>();
for (int i = 0; i < numOfTeam; ++i) for (int i = 0; i < numOfTeam; ++i)
{ {
teamList.Add(new Team());
teamList.Add(new Team());
} }


skillManager = new SkillManager(); skillManager = new SkillManager();
attackManager = new AttackManager(gameMap); attackManager = new AttackManager(gameMap);
moveManager = new MoveManager(gameMap); moveManager = new MoveManager(gameMap);
propManager = new PropManager(gameMap); propManager = new PropManager(gameMap);
gemManager = new GemManager(gameMap);
}
}
}
}
} }

+ 50
- 49
logic/Gaming/PropManager.cs View File

@@ -20,7 +20,7 @@ namespace Gaming


private bool isProducingProp = false; private bool isProducingProp = false;


private readonly List<XYPosition> availableCellForGenerateProp;
private readonly List<XY> availableCellForGenerateProp;
public void StartProducing() public void StartProducing()
{ {
if (isProducingProp) if (isProducingProp)
@@ -175,49 +175,49 @@ namespace Gaming
{ {
while (!gameMap.Timer.IsGaming) while (!gameMap.Timer.IsGaming)
Thread.Sleep(1000); Thread.Sleep(1000);
new FrameRateTaskExecutor<int>(
() => gameMap.Timer.IsGaming,
() =>
{
int rand = r.Next(0, len);
XYPosition randPos = availableCellForGenerateProp[rand];

gameMap.GameObjLockDict[GameObjIdx.Prop].EnterWriteLock();
try
{
switch (r.Next(0, 4))
new FrameRateTaskExecutor<int>(
() => gameMap.Timer.IsGaming,
() =>
{ {
case 0:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new AddLIFE(randPos));
break;
case 1:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new AddSpeed(randPos));
break;
case 2:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new Shield(randPos));
break;
case 3:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new Spear(randPos));
break;
default:
break;
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Prop].ExitWriteLock();
}
},
GameData.PropProduceTime,
() => 0
)
.Start();
}
int rand = r.Next(0, len);
XY randPos = availableCellForGenerateProp[rand];

gameMap.GameObjLockDict[GameObjIdx.Prop].EnterWriteLock();
try
{
switch (r.Next(0, 4))
{
case 0:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new AddLIFE(randPos));
break;
case 1:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new AddSpeed(randPos));
break;
case 2:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new Shield(randPos));
break;
case 3:
gameMap.GameObjDict[GameObjIdx.Prop].Add(new Spear(randPos));
break;
default:
break;
}
}
finally
{
gameMap.GameObjLockDict[GameObjIdx.Prop].ExitWriteLock();
}
},
GameData.PropProduceTime,
() => 0
)
.Start();
}
) )
{ IsBackground = true }.Start(); { IsBackground = true }.Start();
}
public PropManager(Map gameMap) // 道具不能扔过墙
{
}
public PropManager(Map gameMap) // 道具不能扔过墙
{
this.gameMap = gameMap; this.gameMap = gameMap;
this.moveEngine = new MoveEngine( this.moveEngine = new MoveEngine(
gameMap: gameMap, gameMap: gameMap,
@@ -227,20 +227,21 @@ namespace Gaming
{ {
// obj.Place = gameMap.GetPlaceType((GameObj)obj); // obj.Place = gameMap.GetPlaceType((GameObj)obj);
obj.CanMove = false; obj.CanMove = false;
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64); }
Debugger.Output(obj, " end move at " + obj.Position.ToString() + " At time: " + Environment.TickCount64);
}
); );
availableCellForGenerateProp = new List<XYPosition>();
availableCellForGenerateProp = new List<XY>();
for (int i = 0; i < gameMap.ProtoGameMap.GetLength(0); i++) for (int i = 0; i < gameMap.ProtoGameMap.GetLength(0); i++)
{ {
for (int j = 0; j < gameMap.ProtoGameMap.GetLength(1); j++)
{
if (gameMap.ProtoGameMap[i, j] == (int)MapInfo.MapInfoObjType.Null)
for (int j = 0; j < gameMap.ProtoGameMap.GetLength(1); j++)
{ {
availableCellForGenerateProp.Add(GameData.GetCellCenterPos(i, j));
if (gameMap.ProtoGameMap[i, j] == (int)MapInfo.MapInfoObjType.Null)
{
availableCellForGenerateProp.Add(GameData.GetCellCenterPos(i, j));
}
} }
} }
}
}
} }
} }
} }
}

Loading…
Cancel
Save