Esempio n. 1
0
 protected bool IsAtDelay(SnakePlayer Player)
 {
     foreach (Point D in Delay)
     {
         if (D.X == Player.Head.X && D.Y == Player.Head.Y)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 2
0
 protected bool IsAtTurbo(SnakePlayer Player)
 {
     foreach (Point T in Turbo)
     {
         if (T.X == Player.Head.X && T.Y == Player.Head.Y)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
 protected bool IsAtFood(SnakePlayer Player)
 {
     foreach (Point F in Food)
     {
         if (F.X == Player.Head.X && F.Y == Player.Head.Y)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 4
0
 public void AddPlayer(SnakePlayer Player)
 {
     if (Players.Count > 1) { throw new InvalidOperationException(); }
     int Which = Players.Count + 1;
     Players.Add(Player);
     Player.Game = this;
     Player.Closed += new Client.CloseDelegate(AbortGame);
     Player.Send("#Player " + Which.ToString());
     MessageLogged(this, new LogEventArgs((Which == 1 ? "First" : "Second") + " player connected"));
     if (Players.Count == 2)
     {
         StartGame();
     }
 }
Esempio n. 5
0
 protected void FinishGame(SnakePlayer Winner)
 {
     if (Winner == null)
     {
         Send("#Draw");
         MessageLogged(this, new LogEventArgs("Game over: Draw"));
     }
     else
     {
         int Won = Winner == Players.First() ? 1 : 2;
         Send("#Winner " + Won.ToString());
         MessageLogged(this, new LogEventArgs("Game over: Player " + Won.ToString() + " won"));
     }
     AbortGame();
 }
Esempio n. 6
0
        public void AddPlayer(SnakePlayer Player)
        {
            if (Players.Count > 1)
            {
                throw new InvalidOperationException();
            }
            int Which = Players.Count + 1;

            Players.Add(Player);
            Player.Game    = this;
            Player.Closed += new Client.CloseDelegate(AbortGame);
            Player.Send("#Player " + Which.ToString());
            MessageLogged(this, new LogEventArgs((Which == 1 ? "First" : "Second") + " player connected"));
            if (Players.Count == 2)
            {
                StartGame();
            }
        }
Esempio n. 7
0
 protected void FinishGame(SnakePlayer Winner)
 {
     if (Winner == null)
     {
         Send("#Draw");
         MessageLogged(this, new LogEventArgs("Game over: Draw"));
     }
     else
     {
         int Won = Winner == Players.First() ? 1 : 2;
         Send("#Winner " + Won.ToString());
         MessageLogged(this, new LogEventArgs("Game over: Player " + Won.ToString() + " won"));
     }
     AbortGame();
 }
Esempio n. 8
0
 protected bool IsAtDelay(SnakePlayer Player)
 {
     foreach (Point D in Delay) { if (D.X == Player.Head.X && D.Y == Player.Head.Y) { return true; } }
     return false;
 }
Esempio n. 9
0
 protected bool IsAtTurbo(SnakePlayer Player)
 {
     foreach (Point T in Turbo) { if (T.X == Player.Head.X && T.Y == Player.Head.Y) { return true; } }
     return false;
 }
Esempio n. 10
0
 protected bool IsAtFood(SnakePlayer Player)
 {
     foreach (Point F in Food) { if (F.X == Player.Head.X && F.Y == Player.Head.Y) { return true; } }
     return false;
 }
Esempio n. 11
0
        protected void NextMove(SnakePlayer Player)
        {
            if (TurboRound && !Player.TurboEnabled) { return; }
            if (Player.Delay > 0) { return; }

            Point Head = Player.Head;
            Point NewHead = new Point(0, 0);

            Direction NextDirection = Player.CurrentDirection;
            if (Player.DirectionQueue.Count > 0)
            {
                NextDirection = Player.DirectionQueue.First();
                Player.DirectionQueue.RemoveAt(0);
            }

            if (Player.CurrentDirection != NextDirection)
            {
                switch (NextDirection)
                {
                    case Direction.Up: if (Player.CurrentDirection != Direction.Down) { Player.CurrentDirection = Direction.Up; } break;
                    case Direction.Down: if (Player.CurrentDirection != Direction.Up) { Player.CurrentDirection = Direction.Down; } break;
                    case Direction.Left: if (Player.CurrentDirection != Direction.Right) { Player.CurrentDirection = Direction.Left; } break;
                    case Direction.Right: if (Player.CurrentDirection != Direction.Left) { Player.CurrentDirection = Direction.Right; } break;
                }
            }
            switch (Player.CurrentDirection)
            {
                case Direction.Right: NewHead.X = Head.X + 1; NewHead.Y = Head.Y; break;
                case Direction.Left: NewHead.X = Head.X - 1; NewHead.Y = Head.Y; break;
                case Direction.Up: NewHead.X = Head.X; NewHead.Y = Head.Y - 1; break;
                case Direction.Down: NewHead.X = Head.X; NewHead.Y = Head.Y + 1; break;
            }

            NewHead = ModPoint(NewHead);

            bool Fail = false;
            for (int i = 0; i < Player.Snake.Count - 1; i++)
            {
                if ((Player.Snake[i].X == NewHead.X) && (Player.Snake[i].Y == NewHead.Y)) { Fail = true; }
            }
            for (int i = 0; i < Map.Walls.Count; i++)
            {
                if ((Map.Walls[i].X == NewHead.X) && (Map.Walls[i].Y == NewHead.Y)) { Fail = true; }
            }
            if (Fail) { throw new InvalidOperationException(); }

            Player.Snake.Add(NewHead);
        }
Esempio n. 12
0
        protected void NextMove(SnakePlayer Player)
        {
            if (TurboRound && !Player.TurboEnabled)
            {
                return;
            }
            if (Player.Delay > 0)
            {
                return;
            }

            Point Head    = Player.Head;
            Point NewHead = new Point(0, 0);

            Direction NextDirection = Player.CurrentDirection;

            if (Player.DirectionQueue.Count > 0)
            {
                NextDirection = Player.DirectionQueue.First();
                Player.DirectionQueue.RemoveAt(0);
            }

            if (Player.CurrentDirection != NextDirection)
            {
                switch (NextDirection)
                {
                case Direction.Up: if (Player.CurrentDirection != Direction.Down)
                    {
                        Player.CurrentDirection = Direction.Up;
                    }
                    break;

                case Direction.Down: if (Player.CurrentDirection != Direction.Up)
                    {
                        Player.CurrentDirection = Direction.Down;
                    }
                    break;

                case Direction.Left: if (Player.CurrentDirection != Direction.Right)
                    {
                        Player.CurrentDirection = Direction.Left;
                    }
                    break;

                case Direction.Right: if (Player.CurrentDirection != Direction.Left)
                    {
                        Player.CurrentDirection = Direction.Right;
                    }
                    break;
                }
            }
            switch (Player.CurrentDirection)
            {
            case Direction.Right: NewHead.X = Head.X + 1; NewHead.Y = Head.Y; break;

            case Direction.Left: NewHead.X = Head.X - 1; NewHead.Y = Head.Y; break;

            case Direction.Up: NewHead.X = Head.X; NewHead.Y = Head.Y - 1; break;

            case Direction.Down: NewHead.X = Head.X; NewHead.Y = Head.Y + 1; break;
            }

            NewHead = ModPoint(NewHead);

            bool Fail = false;

            for (int i = 0; i < Player.Snake.Count - 1; i++)
            {
                if ((Player.Snake[i].X == NewHead.X) && (Player.Snake[i].Y == NewHead.Y))
                {
                    Fail = true;
                }
            }
            for (int i = 0; i < Map.Walls.Count; i++)
            {
                if ((Map.Walls[i].X == NewHead.X) && (Map.Walls[i].Y == NewHead.Y))
                {
                    Fail = true;
                }
            }
            if (Fail)
            {
                throw new InvalidOperationException();
            }

            Player.Snake.Add(NewHead);
        }