Beispiel #1
0
        public NetHackController()
		{
		    encoding = new ASCIIEncoding();

            termCells = new TerminalCell[TelnetHelper.TERMINAL_COLS, TelnetHelper.TERMINAL_ROWS];

            for (int r = 0; r < TelnetHelper.TERMINAL_ROWS; ++r)
                for (int c = 0; c < TelnetHelper.TERMINAL_COLS; ++c)
				  termCells[c,r] = new TerminalCell(c,r);
		}
Beispiel #2
0
        public NetHackController()
        {
            encoding = new ASCIIEncoding();

            termCells = new TerminalCell[TelnetHelper.TERMINAL_COLS, TelnetHelper.TERMINAL_ROWS];

            for (int r = 0; r < TelnetHelper.TERMINAL_ROWS; ++r)
            {
                for (int c = 0; c < TelnetHelper.TERMINAL_COLS; ++c)
                {
                    termCells[c, r] = new TerminalCell(c, r);
                }
            }
        }
Beispiel #3
0
        // will be private but for testing it will be public
        public List<TerminalCell> ProcessTerminalCommand(NetHackController nhControl, byte[] command, byte[] data)
        {
            List<TerminalCell> updateList = new List<TerminalCell>();
            TerminalCell[,] termCells = nhControl.getTermCells();
            TerminalCell termCell;
            
            // [##d
            // Move to row
            if (command[command.Length - 1] == 'd')
            {
                // (byte[]) [16d => (int) 16
                int row = int.Parse(encoder.GetString(command, 1, command.Length - 2));
                int col = 0;

                // Copy data over
                for (int i = col; i < data.Length; ++i)
                {
                    termCell = new TerminalCell(i, row, (char)data[i]);

                    updateList.Add(termCell);
                    termCells[i,row] = termCell;
                }
            }

            // [##;##H
            // Move to row, col
            else if (command[command.Length - 1] == 'H')
            {
                int col, row;

                if (command.Length != 2)
                {
                    string commandStr = encoder.GetString(command);
                    int locationOfSemicolon = commandStr.IndexOf(';') - 1;
                    int locationOfEnd = (commandStr.Length - 2) - (locationOfSemicolon + 1);

                    col = int.Parse(commandStr.Substring(1, locationOfSemicolon));
                    row = int.Parse(commandStr.Substring(locationOfSemicolon + 2, locationOfEnd));
                }

                else
                {
                    col = 0;
                    row = 0;
                }

                //Console.WriteLine("(" + row + "," + col + ")");

                // Copy data over
                for (int i = 0; i < data.Length; ++i)
                {
                    termCell = new TerminalCell(col+i, row, (char)data[i]);

                    updateList.Add(termCell);
                    termCells[col+i, row] = termCell;
                }
            }

            // THREAD UNSAFE
            nhControl.setTermCells(termCells);

            return updateList;
        }
Beispiel #4
0
        // will be private but for testing it will be public
        public List <TerminalCell> ProcessTerminalCommand(NetHackController nhControl, byte[] command, byte[] data)
        {
            List <TerminalCell> updateList = new List <TerminalCell>();

            TerminalCell[,] termCells = nhControl.getTermCells();
            TerminalCell termCell;

            // [##d
            // Move to row
            if (command[command.Length - 1] == 'd')
            {
                // (byte[]) [16d => (int) 16
                int row = int.Parse(encoder.GetString(command, 1, command.Length - 2));
                int col = 0;

                // Copy data over
                for (int i = col; i < data.Length; ++i)
                {
                    termCell = new TerminalCell(i, row, (char)data[i]);

                    updateList.Add(termCell);
                    termCells[i, row] = termCell;
                }
            }

            // [##;##H
            // Move to row, col
            else if (command[command.Length - 1] == 'H')
            {
                int col, row;

                if (command.Length != 2)
                {
                    string commandStr          = encoder.GetString(command);
                    int    locationOfSemicolon = commandStr.IndexOf(';') - 1;
                    int    locationOfEnd       = (commandStr.Length - 2) - (locationOfSemicolon + 1);

                    col = int.Parse(commandStr.Substring(1, locationOfSemicolon));
                    row = int.Parse(commandStr.Substring(locationOfSemicolon + 2, locationOfEnd));
                }

                else
                {
                    col = 0;
                    row = 0;
                }

                //Console.WriteLine("(" + row + "," + col + ")");

                // Copy data over
                for (int i = 0; i < data.Length; ++i)
                {
                    termCell = new TerminalCell(col + i, row, (char)data[i]);

                    updateList.Add(termCell);
                    termCells[col + i, row] = termCell;
                }
            }

            // THREAD UNSAFE
            nhControl.setTermCells(termCells);

            return(updateList);
        }
Beispiel #5
0
 public void setTermCells(TerminalCell[,] termCells)
 {
     this.termCells = termCells;
 }