示例#1
0
 public CardMove( TwoClient twoClient, Card card, int startX, int startY, int endX, int endY, int duration )
 {
     _twoClient = twoClient;
     _startX = startX;
     _startY = startY;
     _card = card;
     _xDist = startX - endX;
     _yDist = startY - endY;
     _duration = duration*10000000;
     _startTime = System.DateTime.Now.Ticks;
 }
示例#2
0
文件: Card.cs 项目: Twistie/TwoClient
 /// <summary>
 /// Checks whether the card can be played on top of a given card
 /// </summary>
 /// <param name="c">Card to be compared to</param>
 /// <returns>Boolean value of whether a card can be played</returns>
 public Boolean CanBePlayed(Card c)
 {
     foreach (string s in Types)
     {
         foreach (string vType in c.ValidTypes)
         {
             if (s == vType)
                 return true;
         }
     }
     return false;
 }
示例#3
0
 /// <summary>
 /// Sends a card to the server to be played
 /// </summary>
 /// <param name="c">Card to be played</param>
 public void SendCard(Card c)
 {
     int n = PlayerCards.Count;
     for (int i = 0; i < n; i++)
     {
         if (PlayerCards[i] == c)
         {
             string toSend = ("CARD " + i);
             SendMessage(toSend);
             return;
         }
     }
 }
示例#4
0
        /// <summary>
        /// Parses a message recieved by udp and executes instructions contained within
        /// </summary>
        /// <param name="inMessage">Message to be passed</param>
        /// <param name="inAddr">Address message originated</param>
        public void MessageParser(string inMessage, IPEndPoint inAddr)
        {
            AddTextFromThread(inMessage);
            string[] messageArray = inMessage.Split(' ');
            if (GameState == 0)
                if (messageArray[0] == "GAME" && ServDialog != null)
                {

                    ServDialog.AddServer("Game",inAddr);
                    return;
                }
                else
                    return;

            if (messageArray[0] == "GAME")
                return;

            switch (messageArray[0])
            {
                case "PLAYERNUMBER":
                    PlayerNumber = int.Parse(messageArray[1]);
                    SetAnnouncement("Player Number: " + messageArray[1]);
                    AddTextFromThread("Our player number: " + messageArray[1]);
                    break;
                case "CARDLIST":
                    SetPlayerCards(messageArray);
                    break;

                case "TURN":
                    Turn = int.Parse(messageArray[1]);
                    if (TimedDialog != null)
                        if (TimedDialog.IsActive)
                            return;
                    if (int.Parse(messageArray[1]) == PlayerNumber)
                        if (PlayerList[PlayerNumber].NumberOfDrinks < 5)
                        {
                            SetGameState(2);
                            GameState = 2;
                        }
                        else
                        {
                            TimedDialog = new TimedDrinkDialog(this, PlayerList[PlayerNumber].NumberOfDrinks * .75f, "NOT SO FAST. Too many drinks backed up.");
                            SendMessage("DRINKSFORM " + PlayerList[PlayerNumber].NumberOfDrinks * .75f);
                            GameState = 4;
                        }
                    else
                        GameState = 1;

                    break;
                case "TOPCARD":
                    TopCard = _cardList[double.Parse(messageArray[1])];
                    break;
                case "PLAYERLIST":
                    SetPlayerList(messageArray);
                    DrawOtherPlayers();
                    break;
                case "ANIMATION":
                    switch( messageArray[1])
                    {
                        case "CARDSTO":
                                Animation_CardToPlayer(int.Parse(messageArray[2]), int.Parse(messageArray[3]), TopDown);

                            break;
                        case "CARDSFROM":
                            Animation_CardFromPlayer(int.Parse(messageArray[2]), int.Parse(messageArray[3]), TopDown);
                            break;
                        default:
                            break;
                    }
                    break;
                case "NUMBERCARDS":
                    PlayerList[int.Parse(messageArray[1])].NumberOfCards = int.Parse(messageArray[2]);
                    break;
                case "TARGETPLAYER":
                    DoTargetPlayer();
                    break;
                case "ANNOUNCE":
                    SetAnnouncement(inMessage.Remove(0,8));
                    break;
                case "GAMEANNOUNCE":
                    SetGameAnnouncement(inMessage.Remove(0, 12));
                    break;
                case "LIGHTON":
                    PlayerList[int.Parse(messageArray[1])].LightOn = true;
                    SoundDict["BEEP"].Play(.15f, 0f, 0f);
                    break;
                case "LIGHTOFF":
                    PlayerList[int.Parse(messageArray[1])].LightOn = false;
                    break;
                case "TIMEDFORM":

                        if (int.Parse(messageArray[2]) == PlayerNumber)
                        {
                            if( TimedDialog == null || !TimedDialog.IsActive )
                                TimedDialog = new TimedDrinkDialog(this, float.Parse(messageArray[1]), inMessage.Remove(0, 14));
                            else
                            {
                                TimedDrinkDialog d = (TimedDrinkDialog) TimedDialog;
                                d.AddDrink(float.Parse(messageArray[2]));
                            }
                        }
                        else
                        {
                            PlayerList[int.Parse(messageArray[2])].Drink(float.Parse(messageArray[1]));
                        }

                    break;
                case "STARTDRINK":
                    int playerStarted = int.Parse(messageArray[1]);
                    if( playerStarted != PlayerNumber )
                    {
                        PlayerList[playerStarted].StartDrink();
                    }

                    //TimedDialog.Start();
                    break;
                case "MOOSE":
                    TimedDialog = new MooseForm(this, WindowWidth/2 - 250, WindowHeight/2 - 250, 500, 500);
                    break;
                case "NAME":
                    PlayerList[int.Parse(messageArray[1])].Name = inMessage.Remove(0,7);
                    break;
                case "COLOUR":
                    DoColour(int.Parse(messageArray[1]),int.Parse(messageArray[2]));
                    break;
                case "LOBBY":
                    GameState = -2;
                    break;
                case "DRINK":
                    PlayerList[int.Parse(messageArray[1])].NumberOfDrinks += int.Parse(messageArray[2]);
                    break;
                case "SETDRINK":
                    PlayerList[int.Parse(messageArray[1])].NumberOfDrinks = int.Parse(messageArray[2]);
                    break;
                case "STARTGAME":
                    StartGame sg = new StartGame(this);
                    break;
            }
        }
示例#5
0
        public void DrawCard(int x, int y, Card c, Color colour, float rotation, float scale)
        {
            Vector2 zeroVect = new Vector2(0, 0);

            SpriteBatch.Draw(_cardTexture, new Vector2(x, y), c.CardRect, colour, rotation, zeroVect, scale/2.6f,
                              new SpriteEffects(), 0);
        }
示例#6
0
        /// <summary>
        /// Draws a card
        /// </summary>
        /// <param name="x">y</param>
        /// <param name="y">x</param>
        /// <param name="c">card</param>
        /// <param name="colour">colour</param>
        public void DrawCard(int x, int y, Card c, Color colour)
        {
            Vector2 zeroVect = new Vector2(0, 0);

            SpriteBatch.Draw(_cardTexture, new Vector2(x, y), c.CardRect, colour, 0, zeroVect, .75f, new SpriteEffects(),
                              0);
        }
示例#7
0
        /// <summary>
        /// Creates the card list and stores it in the _cardList variable, includes information on when a card
        /// can be played and the graphics to be drawn for it
        /// </summary>
        public void CardList()
        {
            _cardList = new Dictionary<double, Card>();
            for (int i = 0; i < 4; i++)
            {
                string colour = "";
                switch (i)
                {
                    case 0:
                        colour = "Red";
                        break;
                    case 1:
                        colour = "Blue";
                        break;
                    case 2:
                        colour = "Yellow";
                        break;
                    case 3:
                        colour = "Green";
                        break;
                }
                Card c;
                for (int n = 0; n < 10; n++)
                {
                    c = new Card(colour + " " + n, double.Parse(i + ".0" + n), i, n);
                    c.Name = colour + " " + n;
                    c.SortValue = double.Parse(i + ".0" + n);
                    c.Types.Add(colour);
                    c.Types.Add(n.ToString());
                    c.ValidTypes.Add(colour);
                    c.ValidTypes.Add(n.ToString());
                    _cardList.Add(c.SortValue, c);
                }
                for (int n = 0; n < 2; n++)
                {
                    int draw = n + 2;

                    c = new Card(colour + " Draw " + draw, double.Parse(i + ".1" + draw), i, 10 + n);
                    c.Types.Add(colour);
                    c.Types.Add("DRAW " + draw);
                    c.ValidTypes.Add("TARGET " + draw);
                    c.ValidTypes.Add("DRAW " + draw);
                    _cardList.Add(c.SortValue, c);

                    c = new Card(colour + " Draw " + draw, double.Parse(i + ".1" + draw + "1"), i, 10 + n);
                    c.Types.Add(colour);
                    c.Types.Add("DRAW " + draw);
                    c.ValidTypes.Add("DRAW " + draw);
                    c.ValidTypes.Add(colour);
                    _cardList.Add(c.SortValue, c);
                }
                c = new Card("Targetted Draw 2", i+ .22,i,12);
                c.Types.Add(colour);
                c.Types.Add("TARGET 2");
                c.ValidTypes.Add("TARGET 2");
                _cardList.Add(c.SortValue,c);

                c = new Card("Targetted Draw 2", i + .221, i, 12);
                c.Types.Add(colour);
                c.Types.Add("TARGET 2");
                c.ValidTypes.Add(colour);
                c.ValidTypes.Add("TARGET 2");
                _cardList.Add(c.SortValue, c);

                c = new Card("Light Master", double.Parse(i + ".3"),i,13);
                c.Types.Add(colour);
                c.Types.Add("LIGHTMASTER");
                c.ValidTypes.Add(colour);
                c.ValidTypes.Add("LIGHTMASTER");
                _cardList.Add(c.SortValue, c);

                c = new Card("Double Down", double.Parse(i + ".4"),i,15);
                c.Types.Add(colour);
                c.Types.Add("DOUBLEDOWN");
                c.ValidTypes.Add(colour);
                c.ValidTypes.Add("DOUBLEDOWN");
                _cardList.Add(c.SortValue,c);

                c = new Card("Skip", double.Parse(i + ".5"),i,14);
                c.Types.Add(colour);
                c.Types.Add("SKIP");
                c.ValidTypes.Add(colour);
                c.ValidTypes.Add("SKIP");
                _cardList.Add(c.SortValue,c);

            }
            Card pf = new Card("Princess Fufu", 5.01, 4, 1);
            pf.Types.Add("Red");
            pf.Types.Add("Blue");
            pf.Types.Add("Green");
            pf.Types.Add("Yellow");
            pf.ValidTypes.Add("Red");
            pf.ValidTypes.Add("Blue");
            pf.ValidTypes.Add("Green");
            pf.ValidTypes.Add("Yellow");
            _cardList.Add(5.01,pf);

            Card bc = new Card("BoomCard", 5.02, 4, 2);
            bc.Types.Add("Red");
            bc.Types.Add("Blue");
            bc.Types.Add("Green");
            bc.Types.Add("Yellow");
            bc.ValidTypes.Add("Red");
            bc.ValidTypes.Add("Blue");
            bc.ValidTypes.Add("Green");
            bc.ValidTypes.Add("Yellow");
            _cardList.Add(5.02, bc);

            bc = new Card("Grey", 5.03, 4, 3);
            bc.Types.Add("Red");
            bc.Types.Add("Blue");
            bc.Types.Add("Green");
            bc.Types.Add("Yellow");
            bc.ValidTypes.Add("Red");
            bc.ValidTypes.Add("Blue");
            bc.ValidTypes.Add("Green");
            bc.ValidTypes.Add("Yellow");
            _cardList.Add(5.03, bc);
        }
示例#8
0
 /// <summary>
 /// Creates an animation in which n cards are moving from the middle of the deck to a player and adds it to
 /// the animation list
 /// </summary>
 /// <param name="player">int of player that is to recieve the card</param>
 /// <param name="noCards">number of cards to pass</param>
 /// <param name="card">what card graphic to use</param>
 public void Animation_CardToPlayer(int player, int noCards, Card card)
 {
     switch( PlayerList[player].PlayerPos )
     {
         case 0:
             for (int i = 0; i < noCards; i++)
             {
                 AnimationList.Add(new DelayedCardMove(this, TopDown, WindowWidth / 2 + 30, WindowHeight / 2 - 40,
                                                WindowWidth / 2, WindowHeight - 220, .2f,.07f*i));
             }
             break;
         case 2:
             for (int i = 0; i < noCards; i++)
             {
                 AnimationList.Add(new DelayedCardMove(this, TopDown, WindowWidth / 2 + 30, WindowHeight / 2 - 90,
                                                WindowWidth / 2 - 100, 120, .2f, .07f * i));
             }
             break;
         case -1:
             for (int i = 0; i < noCards; i++)
             {
                 AnimationList.Add(new DelayedCardMove(this, TopDown, WindowWidth / 2 - 30, WindowHeight / 2 - 40,
                                                100, WindowHeight / 2 - 40, .2f, .07f * i));
             }
             break;
         case 1:
             for (int i = 0; i < noCards; i++)
             {
                 AnimationList.Add(new DelayedCardMove(this, TopDown, WindowWidth / 2 + 60, WindowHeight / 2 - 40,
                                                WindowWidth - 100, WindowHeight / 2 - 40, .2f, .07f * i));
             }
             break;
         default:
             return;
     }
 }
示例#9
0
 public DelayedCardMove(TwoClient twoClient, Card card, int startX, int startY, int endX, int endY, float duration, float delay)
 {
     _twoClient = twoClient;
     _startX = startX;
     _startY = startY;
     _card = card;
     _xDist = startX - endX;
     _yDist = startY - endY;
     _duration = (int)(duration * 10000000);
     _startTime = System.DateTime.Now.Ticks + (int)(delay * 10000000);
 }