Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            nc = new NetHackController();

            tc = new TelnetController();

            wc = new WindowController(nc);

            encoder = new ASCIIEncoding();
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            nc = new NetHackController();

            tc = new TelnetController();

            wc = new WindowController(nc);

            encoder = new ASCIIEncoding();
        }
Exemplo n.º 3
0
        public WindowController(NetHackController nc)
        {
            font = new Font(FontFamily.GenericMonospace, 16, GraphicsUnit.Pixel);

            tilesRaw = new Bitmap(@"..\..\nhtiles.bmp"); // Hard coded for now

            tileSize = tilesRaw.Width / NUM_TILES_ACROSS;

            render = new Bitmap(tilesRaw.Width, tilesRaw.Height);

            this.nc = nc;

            tiles = new Bitmap[NUM_TILES_ACROSS, NUM_TILES_DOWN];

            // Create tile array
            for (int col = 0; col < NUM_TILES_ACROSS; ++col)
            {
                for (int row = 0; row < NUM_TILES_DOWN; ++row)
                {
                    tiles[col, row] = CopyBitmap(tilesRaw, new Rectangle(col * tileSize, row * tileSize, tileSize, tileSize));
                }
            }
        }
Exemplo n.º 4
0
        public WindowController(NetHackController nc)
        {
            font = new Font(FontFamily.GenericMonospace, 16, GraphicsUnit.Pixel);

            tilesRaw = new Bitmap(@"..\..\nhtiles.bmp"); // Hard coded for now

            tileSize = tilesRaw.Width / NUM_TILES_ACROSS;

            render = new Bitmap(tilesRaw.Width, tilesRaw.Height);

            this.nc = nc;

            tiles = new Bitmap[NUM_TILES_ACROSS, NUM_TILES_DOWN];

            // Create tile array
            for (int col = 0; col < NUM_TILES_ACROSS; ++col)
            {
                for (int row = 0; row < NUM_TILES_DOWN; ++row)
                {
                    tiles[col, row] = CopyBitmap(tilesRaw, new Rectangle(col * tileSize, row * tileSize, tileSize, tileSize));
                }
            }
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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);
        }