Ejemplo n.º 1
0
    /// <summary>
    /// Initialisation.
    /// </summary>
    public static void initGameManager()
    {
        endOfGame          = false; // Pour une nouvelle séquence
        currentPlayerIndex = 0;     //Pour une nouvelle séquence

        captureBench1 = _init.cb1;
        captureBench2 = _init.cb2;

        captureBench1.player = players[0];
        captureBench2.player = players[1];

        players[0].captureBench = captureBench1;
        players[1].captureBench = captureBench2;
        board = new Board(tokens, boxes);
        // Première update des moves disponibles pour tous les tokens
        updateAllTokenMoves();

        allTokens = new List <Token> ();

        updateAllTokens();

        lastRewardPlayer = new double[2] {
            0, 0
        };

        players [0].score = 0;
        players [1].score = 0;

        turnCount = 0;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Permet de cloner un objet sérializable.
    /// </summary>
    /// <param name="cb">Un banc de capture.</param>
    /// <returns>Une copie de l'objet donné.</returns>
    public static List <CaptureBox> CloneCaptureBoxesInitial(CaptureBench cb)
    {
        List <CaptureBox> listBoxes = new List <CaptureBox> ();

        if (!cb.boxBishop.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms1 = new MemoryStream();
        BinaryFormatter bf1 = new BinaryFormatter();

        bf1.Serialize(ms1, cb.boxBishop);
        ms1.Position = 0;
        listBoxes.Add((CaptureBox)bf1.Deserialize(ms1));
        ms1.Close();

        if (!cb.boxGold.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms2 = new MemoryStream();
        BinaryFormatter bf2 = new BinaryFormatter();

        bf2.Serialize(ms2, cb.boxGold);
        ms2.Position = 0;
        listBoxes.Add((CaptureBox)bf2.Deserialize(ms2));
        ms2.Close();

        if (!cb.boxKnight.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms3 = new MemoryStream();
        BinaryFormatter bf3 = new BinaryFormatter();

        bf3.Serialize(ms3, cb.boxKnight);
        ms3.Position = 0;
        listBoxes.Add((CaptureBox)bf3.Deserialize(ms3));
        ms3.Close();

        if (!cb.boxLance.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms4 = new MemoryStream();
        BinaryFormatter bf4 = new BinaryFormatter();

        bf4.Serialize(ms4, cb.boxLance);
        ms4.Position = 0;
        listBoxes.Add((CaptureBox)bf4.Deserialize(ms4));
        ms4.Close();

        if (!cb.boxPawn.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms5 = new MemoryStream();
        BinaryFormatter bf5 = new BinaryFormatter();

        bf5.Serialize(ms5, cb.boxPawn);
        ms5.Position = 0;
        listBoxes.Add((CaptureBox)bf5.Deserialize(ms5));
        ms5.Close();

        if (!cb.boxRook.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms6 = new MemoryStream();
        BinaryFormatter bf6 = new BinaryFormatter();

        bf6.Serialize(ms6, cb.boxRook);
        ms6.Position = 0;
        listBoxes.Add((CaptureBox)bf6.Deserialize(ms6));
        ms6.Close();

        if (!cb.boxSilver.GetType().IsSerializable)
        {
            throw new Exception("Object must be serializable");
        }
        MemoryStream    ms7 = new MemoryStream();
        BinaryFormatter bf7 = new BinaryFormatter();

        bf7.Serialize(ms7, cb.boxSilver);
        ms7.Position = 0;
        listBoxes.Add((CaptureBox)bf7.Deserialize(ms7));
        ms7.Close();

        return(listBoxes);
    }