示例#1
0
        public bool PlaceFree_X(int dir)
        {
            int width = isHorizontal == true ? size : 0;

            // Check that the wanted position is within the boundaries of the map
            if ((dir > 0 && (posX + width) < map.Width) || (dir < 0 && posX > (map.PosX + dir)))
            {
                // Check that none of tiles are occupied
                for (int i = 0; i < size; i++)
                {
                    if (map.CheckTile(posX + dir + i, posY))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
示例#2
0
        public void TurnMaster(IPEndPoint endPoint, string targetTile)
        {
            #region bogstavertiltal
            string letter = targetTile.Remove(1);
            string number = targetTile.Substring(1);
            int    posY   = 123;
            switch (letter)
            {
            case "a":
                posY = 0;
                break;

            case "b":
                posY = 1;
                break;

            case "c":
                posY = 2;
                break;

            case "d":
                posY = 3;
                break;

            case "e":
                posY = 4;
                break;

            case "f":
                posY = 5;
                break;

            case "g":
                posY = 6;
                break;

            case "h":
                posY = 7;
                break;

            case "i":
                posY = 8;
                break;

            case "j":
                posY = 9;
                break;
            }
            #endregion
            if (endPoint == playerOneEP)
            {
                if (!playerTwoMap.CheckTile(int.Parse(number), posY))
                {
                    string sData = CipherUtility.Encrypt <AesManaged>(Program.Usernames[playerOneEP] + " missed at position: " + letter + number, "password", "salt");
                    lock (Program.MsgsLock)
                    {
                        Program.Msgs.Add(Program.InfoSender[playerOneEP], sData);
                        Program.Msgs.Add(Program.InfoSender[playerTwoEP], sData);
                    }
                    playerOneTurn = false;
                }
                else
                {
                    string sData = CipherUtility.Encrypt <AesManaged>(Program.Usernames[playerOneEP] + " hit at position: " + letter + number, "password", "salt");
                    lock (Program.MsgsLock)
                    {
                        Program.Msgs.Add(Program.InfoSender[playerOneEP], sData);
                        Program.Msgs.Add(Program.InfoSender[playerTwoEP], sData);
                    }
                    playerTwoMap.UnOccupyTile(int.Parse(number), posY);
                    if (playerTwoMap.Win())
                    {
                        sData = CipherUtility.Encrypt <AesManaged>(Program.Usernames[playerOneEP] + " won!", "password", "salt");
                        lock (Program.MsgsLock)
                        {
                            Program.Msgs.Add(Program.InfoSender[playerOneEP], sData);
                            Program.Msgs.Add(Program.InfoSender[playerTwoEP], sData);
                        }
                        lock (Program.ConnectedUsersLock)
                        {
                            Program.MatchedUsers.Remove(playerTwoEP);
                            Program.MatchedUsers.Remove(playerOneEP);
                            Program.ConnectedUsers.Add(playerTwoEP);
                            Program.ConnectedUsers.Add(playerOneEP);
                        }
                    }
                }
            }
            else if (endPoint == playerTwoEP)
            {
                if (!playerOneMap.CheckTile(int.Parse(number), posY))
                {
                    string sData = CipherUtility.Encrypt <AesManaged>(Program.Usernames[playerTwoEP] + " missed at position: " + letter + number, "password", "salt");
                    lock (Program.MsgsLock)
                    {
                        Program.Msgs.Add(Program.InfoSender[playerOneEP], sData);
                        Program.Msgs.Add(Program.InfoSender[playerTwoEP], sData);
                    }
                    playerOneTurn = true;
                }
                else
                {
                    string sData = CipherUtility.Encrypt <AesManaged>(Program.Usernames[playerTwoEP] + " hit at position: " + letter + number, "password", "salt");
                    lock (Program.MsgsLock)
                    {
                        Program.Msgs.Add(Program.InfoSender[playerOneEP], sData);
                        Program.Msgs.Add(Program.InfoSender[playerTwoEP], sData);
                    }
                    playerOneMap.UnOccupyTile(int.Parse(number), posY);
                    if (playerOneMap.Win())
                    {
                        sData = CipherUtility.Encrypt <AesManaged>(Program.Usernames[playerTwoEP] + " won!", "password", "salt");
                        lock (Program.MsgsLock)
                        {
                            Program.Msgs.Add(Program.InfoSender[playerOneEP], sData);
                            Program.Msgs.Add(Program.InfoSender[playerTwoEP], sData);
                        }
                        lock (Program.ConnectedUsersLock)
                        {
                            Program.MatchedUsers.Remove(playerTwoEP);
                            Program.MatchedUsers.Remove(playerOneEP);
                            Program.ConnectedUsers.Add(playerTwoEP);
                            Program.ConnectedUsers.Add(playerOneEP);
                        }
                    }
                }
            }
        }