コード例 #1
0
        internal void FromString(string[] splitMessage)
        {
            List<OWScreen> tmpQ = new List<OWScreen>();
            for (int i = 2; i < splitMessage.Length - 1; i++)
            {
                tmpQ.Add(new OWScreen(splitMessage[i]));
            }

            // which screen we are on
            for (int i = 0; i < tmpQ.Count; i++)
            {
                // give that screen a row of the adjacency matrix
                string row = splitMessage[1].Substring(i * tmpQ.Count, tmpQ.Count);
                // step through the matrix row
                for (int j = 0; j < tmpQ.Count; j++)
                {
                    if (row[j] == 'n')
                    {
                        tmpQ[i].North = tmpQ[j];
                    }
                    else if (row[j] == 's')
                    {
                        tmpQ[i].South = tmpQ[j];
                    }
                    else if (row[j] == 'e')
                    {
                        tmpQ[i].East = tmpQ[j];
                    }
                    else if (row[j] == 'w')
                    {
                        tmpQ[i].West = tmpQ[j];
                    }
                }
            }
            screen = tmpQ[0];
            Draw();
        }
コード例 #2
0
 internal bool MoveAvatar(int player, char keyPressed)
 {
     switch (keyPressed)
     {
         case 'w':
             if (avatars[player].PosY != 0)
             {
                 if (screen.Tiles[avatars[player].PosX, avatars[player].PosY - 1] != 'u')
                 {
                     return true;
                 }
             }
             else
             {
                 screen = screen.North;
                 return true;
             }
             break;
         case 's':
             if (avatars[player].PosY != 7)
             {
                 if (screen.Tiles[avatars[player].PosX, avatars[player].PosY + 1] != 'u')
                 {
                     return true;
                 }
             }
             else
             {
                 screen = screen.South;
                 return true;
             }
             break;
         case 'a':
             if (avatars[player].PosX != 0)
             {
                 if (screen.Tiles[avatars[player].PosX - 1, avatars[player].PosY] != 'u')
                 {
                     return true;
                 }
             }
             else
             {
                 screen = screen.West;
                 return true;
             }
             break;
         case 'd':
             if (avatars[player].PosX != 13)
             {
                 if (screen.Tiles[avatars[player].PosX + 1, avatars[player].PosY] != 'u')
                 {
                     return true;
                 }
             }
             else
             {
                 screen = screen.East;
                 return true;
             }
             break;
         default:
             break;
     }
     return false;
 }