Ejemplo n.º 1
0
 private void SendFacing(Facing f)
 {
     Pack p = new Pack(packNames.Facing, f);
     Network.send(p);
 }
Ejemplo n.º 2
0
        private void Refresher_Tick(object o, EventArgs e)
        {
            if (Controller.IsEnded())
            {
                MessageBoxResult result = MessageBoxResult.No;
                if (Controller.IsLost() && Controller.IsWin())
                {
                    result = MessageBox.Show("Draw! Wanna play again?", "Game over", MessageBoxButton.YesNo);
                }
                else if (Controller.IsLost())
                {
                    result = MessageBox.Show("You lost! Wanna play again?", "Game over", MessageBoxButton.YesNo);
                }
                else if (Controller.IsWin())
                {
                    result = MessageBox.Show("You win! Wanna play again?", "Game over", MessageBoxButton.YesNo);
                }
                Refresher.Stop();
                //this.Hide();
                if (result == MessageBoxResult.Yes)
                {
                    Pack p = new Pack(packNames.Replay, "Yes");
                    Network.send(p);

                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        if (replay == "Yes")
                        {
                            initialize(Network, MyProfile);
                            run();
                        }
                        else if(replay == "No")
                        {
                            this.Hide();
                        }
                    }));
                }
                else
                {
                    Pack p = new Pack(packNames.Replay, "No");
                    Network.send(p);
                    this.Hide();
                }
            }
        }
Ejemplo n.º 3
0
 public void Mover_Tick(object o, EventArgs e)
 {
     Point newPosition = Position;
     switch (Facing)
     {
         case Facing.Down:
             {
                 newPosition.Y++;
                 break;
             }
         case Facing.Left:
             {
                 newPosition.X--;
                 break;
             }
         case Facing.Up:
             {
                 newPosition.Y--;
                 break;
             }
         case Facing.Right:
             {
                 newPosition.X++;
                 break;
             }
     }
     Point newOpPosition = OpponentPosition;
     switch (OpponentFacing)
     {
         case Facing.Down:
             {
                 newOpPosition.Y++;
                 break;
             }
         case Facing.Left:
             {
                 newOpPosition.X--;
                 break;
             }
         case Facing.Up:
             {
                 newOpPosition.Y--;
                 break;
             }
         case Facing.Right:
             {
                 newOpPosition.X++;
                 break;
             }
     }
     bool felt1 = newPosition.X >= 0.0 && newPosition.Y >= 0.0 && newPosition.X <= 500 && newPosition.Y <= 500 && Arena.GetPixel(Convert.ToInt32(newPosition.X), Convert.ToInt32(newPosition.Y)) == Colors.Black;
     bool felt2 = newOpPosition.X >= 0.0 && newOpPosition.Y >= 0.0 && newOpPosition.X <= 500 && newOpPosition.Y <= 500 && Arena.GetPixel(Convert.ToInt32(newOpPosition.X), Convert.ToInt32(newOpPosition.Y)) == Colors.Black;
     if (!felt1 && !felt2)
     {
         Mover.Stop();
         Lost = true;
         Win = true;
         Pack p = new Pack(packNames.End, "Draw");
         Network.send(p);
     }
     else
     {
         if (felt1)
         {
             Arena.DrawLine(Convert.ToInt32(Position.X.ToString()), Convert.ToInt32(Position.Y.ToString()), Convert.ToInt32(newPosition.X.ToString()), Convert.ToInt32(newPosition.Y.ToString()), MyColor);
             Position = newPosition;
         }
         else
         {
             Mover.Stop();
             Lost = true;
             Pack p = new Pack(packNames.End, "Lost");
             Network.send(p);
         }
         if (felt2)
         {
             Arena.DrawLine(Convert.ToInt32(OpponentPosition.X.ToString()), Convert.ToInt32(OpponentPosition.Y.ToString()), Convert.ToInt32(newOpPosition.X.ToString()), Convert.ToInt32(newOpPosition.Y.ToString()), OpponentColor);
             OpponentPosition = newOpPosition;
         }
         else
         {
             Mover.Stop();
             Win = true;
             Pack p = new Pack(packNames.End, "Win");
             Network.send(p);
         }
     }
 }