Java游戏:同时射击多名玩家

huangapple go评论59阅读模式
英文:

Java Game: Shooting multiple players at same time

问题

我正在开发一个游戏玩家可以射击子弹我正在遍历游戏中活跃玩家的列表并在玩家附近开枪射击它基本上是有效的除了一个情况当两名或更多玩家同时彼此射击时

**问题**

当两名玩家互相射击同时射出相同数量的子弹一名玩家死亡但另一名玩家仍然存活

**结果**

两名玩家应该同时死亡

在这种情况下我该如何实现两名玩家都应该死亡

我认为这与其中一个for循环有关因为列表中的第一个玩家会先射击所以第二名玩家将首先达到最大伤害然而我希盼他们能够同时达到最大伤害

游戏的运行方式

动画在单个回合内发生倒计时并执行放置的移动

每个回合有4个移动槽

```python

            对于玩家plistRegisteredPlayers()){
                如果(!p.isDamageMaxed()&&p.isSunk()){
	
	                // 如果他们与任何人发生碰撞则应用伤害
	                damagePlayersleftShootspDirection.LEFTslot;
	                damagePlayersrightShootspDirection.RIGHTslot;
                }

                如果p.isDamageMaxed()&&p.isSunk()){
                    p.setSunkslot;
                }
            }

        }

英文:

I'm working on a game where players can shoot bullets. I am iterating through list of active players in the game, and shooting at players if they are near. It works mostly except for a case when two or more players are shooting at each other at the same time.

Issue:

When two players shoot at each other (same amount of bullets at same time), one dies but other still stays alive.

Result:

Both players should die at the same time.

How would I implement this case where both players should die?

I think it has to deal with one of the for loop. Since the first player in the list will shoot first the second player will reach maxDamage first, however I want them to reach maxDamage at the same time.

How the game works:

The animations happen in a single turn which counts down and executes the moves placed.

There are 4 move slots for every turn

            
            for (Player p : listRegisteredPlayers()) {
                if (!p.isDamageMaxed() && !p.isSunk()) {
	
	                // Apply damages if they collided with anyone
	                damagePlayers(leftShoots, p, Direction.LEFT, slot);
	                damagePlayers(rightShoots, p, Direction.RIGHT, slot);
                }

                if (p.isDamageMaxed() && !p.isSunk()) {
                    p.setSunk(slot);
                }
            }

        }

答案1

得分: 3

你描述的行为明确表示,如果有人死亡,那么他就不能再射击。现在,玩家1向玩家2开火,玩家2向玩家1开火。现在,在您的情况下似乎发生了这种情况:

玩家1向玩家2开枪

玩家2死亡

玩家2因为已经死亡而无法进行射击

解决方案似乎是将射击与伤害分开。您需要实现一个循环,在这个循环中进行射击,但玩家还不会立即死亡。您只需计算他们的伤害,并从他们的生命值中减去,但在循环结束时,他们仍应该活着。然后,在下一个循环中评估玩家的健康状况,并确保应该死亡的玩家确实死亡。

如果您需要更多细节,您需要提供更多细节。

英文:

The behavior you describe clearly means that if someone is dead, then he no longer can shoot. Now, player1 shoots on player2 and player2 shoots on player1. Now, this seems to happen in your case:

> player1 shoots player2
>
> player2 dies
>
> player2 does not shoot because
> he's dead

The solution seems to be to separate shooting from damage. You need to implement a loop where the shooting happens, but the players do not die yet. You just compute their damage and reduce that from their life, but they should be still alive at the end of the loop. Then, in a next loop evaluate the health of players and ensure that whoever should die dies.

If you need more details, then you will need to provide more details.

huangapple
  • 本文由 发表于 2020年9月3日 03:17:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63712228.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定