Esempio n. 1
0
 public bool Equals(PlayerState other)
 {
     if ((object)other == null) return false;
     return
         this.Number.Equals(other.Number)
         && this.Name.Equals(other.Name)
         && this.Color.Equals(other.Color)
         && this.Position.Equals(other.Position)
         && this.Direction.Equals(other.Direction)
         && this.Alive.Equals(other.Alive);
 }
Esempio n. 2
0
 private void stepMovePlayer(int playerNumber, Action action)
 {
     var player = State.Players[playerNumber];
     var dir = player.Direction.Value;
     if (player.Dead)
     {
         return;
     }
     if (action == Action.Right)
     {
         switch (dir)
         {
             case Direction.Right: dir = Direction.RightDown; break;
             case Direction.RightUp: dir = Direction.Right; break;
             case Direction.Up: dir = Direction.RightUp; break;
             case Direction.LeftUp: dir = Direction.Up; break;
             case Direction.Left: dir = Direction.LeftUp; break;
             case Direction.LeftDown: dir = Direction.Left; break;
             case Direction.Down: dir = Direction.LeftDown; break;
             case Direction.RightDown: dir = Direction.Down; break;
         }
     }
     else if (action == Action.Left)
     {
         switch (dir)
         {
             case Direction.Right: dir = Direction.RightUp; break;
             case Direction.RightUp: dir = Direction.Up; break;
             case Direction.Up: dir = Direction.LeftUp; break;
             case Direction.LeftUp: dir = Direction.Left; break;
             case Direction.Left: dir = Direction.LeftDown; break;
             case Direction.LeftDown: dir = Direction.Down; break;
             case Direction.Down: dir = Direction.RightDown; break;
             case Direction.RightDown: dir = Direction.Right; break;
         }
     }
     var pos = player.Position;
     switch (dir)
     {
         case Direction.Right: pos = new PositionState(pos.X + 1, pos.Y); break;
         case Direction.RightUp: pos = new PositionState(pos.X + 1, pos.Y - 1); break;
         case Direction.Up: pos = new PositionState(pos.X, pos.Y - 1); break;
         case Direction.LeftUp: pos = new PositionState(pos.X - 1, pos.Y - 1); break;
         case Direction.Left: pos = new PositionState(pos.X - 1, pos.Y); break;
         case Direction.LeftDown: pos = new PositionState(pos.X - 1, pos.Y + 1); break;
         case Direction.Down: pos = new PositionState(pos.X, pos.Y + 1); break;
         case Direction.RightDown: pos = new PositionState(pos.X + 1, pos.Y + 1); break;
     }
     var players = State.Players.ToList();
     players[playerNumber] = new PlayerState(
         player.Number, player.Name, player.Color,
         pos, new DirectionState(dir), player.Alive);
     State = new GameState(State.Field, players.AsReadOnly());
 }
Esempio n. 3
0
 private void stepJudge()
 {
     for (var i = 0; i < State.PlayersCount; ++i)
     {
         var player = State.Players[i];
         if (player.Dead)
         {
             continue;
         }
         if (stepJudgePlayer(i))
         {
             var players = State.Players.ToList();
             players[i] = new PlayerState(
                 player.Number, player.Name, player.Color,
                 player.Position, player.Direction, false);
             State = new GameState(State.Field, players.AsReadOnly());
         }
     }
 }