using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace Shared
{
    /// <summary>
    /// Genere aleatoirement certaines valeurs
    /// </summary>
    public class Rand
    {
        private static Random random = new Random(DateTime.Now.Millisecond);
        static public float Float { get { return (float)random.NextDouble(); } }
        static public int Weapon { get { return random.Next(3) + 1; } }
        static public bool Crate { get { return random.Next(0, 9) < 3; } }
    }
    /// <summary>
    /// Annonce la deconnection
    /// </summary>
    [Serializable]
    public class Close { };
    /// <summary>
    /// Annonce le debut de la partie
    /// </summary>
    [Serializable]
    public class Start { };
    /// <summary>
    /// Represente l'angle d'une tourelle
    /// </summary>
    [Serializable]
    public class Angle : EventArgs
    {
        public float deg;
        public Angle(float f) { deg = f; }
    }
    /// <summary>
    /// Represente un round
    /// </summary>
    [Serializable]
    public class Round : EventArgs
    {
        public float windForce = Rand.Float;
        public float angle = Rand.Float;
        public int player;
        public float cratePos = (Rand.Crate)?Rand.Float:(float)-1.0;
        public int crateCont = Rand.Weapon;
        public Round(int player) { this.player = player; }
    }
    /// <summary>
    /// Represente les messages transmits entre utilisateurs
    /// </summary>
    [Serializable]
    public class Message : EventArgs
    {
        public string from;
        public string content;
        public Message(string f, string c) { from = f; content = c; }
        public override string ToString() { return from + ": " + content; }
    }
    /// <summary>
    /// Represente un tir
    /// </summary>
    [Serializable]
    public class Shoot : EventArgs
    {
        public float x, y;
        public int w;
        public float angle;
        public float strength;
        public Shoot(float x, float y, int w, float a, float s) { this.x = x; this.y = y; this.w = w; strength = s; angle = a; }
    }
    /// <summary>
    /// Represente une parte
    /// </summary>
    [Serializable]
    public class Game : EventArgs
    {
        public int map = new Random().Next(4); // La map
        public int[] pos;
        public Game(Users u)
        {
            const int NB_SPOT = 6;
            Random r = new Random(DateTime.Now.Millisecond);
            pos = new int[u.list.Count]; // Les positions des joueurs
            List<int> ids = new List<int>(NB_SPOT);
            for (int i = 0; i < NB_SPOT; i++) ids.Add(i);
            for (int i = 0; i < u.list.Count; i++)
            {
                int id = r.Next(ids.Count);
                pos[i] = ids[id];
                ids.RemoveAt(id);
            }
        }
    }
    /// <summary>
    /// Represente la liste des utilisateurs transmit au server
    /// </summary>
    [Serializable]
    public class Users : EventArgs
    {
        public List<User> list = new List<User>();
    }
    /// <summary>
    /// Represente un utilisateur
    /// </summary>
    [Serializable]
    public class User : EventArgs
    {
        public string name;
        public bool ready;
        public int id;
        public User(int i, string n, bool r) { id = i; name = n; ready = r; }
    }
}
