Esempio n. 1
0
        public static void Draw()
        {
            // Loop through each column, then nestedly loop through each element in the column.
            // This will draw the "map".
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Entity ent = grid[y][x];
                    if (ent != null)
                    {
                        ent.Draw();
                    }
                }
            }
            // Now for everything that moves. They will draw over the map.
            foreach (Entity ent in dyna)
            {
                ent.Draw();
            }

            // Status bar :v
            string status   = "HP: Alive\tGun: " + GetPlayer().gun;
            int    printPos = 0;

            foreach (char character in status.ToCharArray())
            {
                Stdscr.Add(23, printPos, character);
                printPos++;
            }
            printPos = 0;
        }
Esempio n. 2
0
 private static void AddStr(int y, int x, string str)
 {
     if (x >= 0 && x < Curses.Cols && y >= 0 && y < Curses.Lines)
     {
         Stdscr.Add(y, x, str);
     }
 }
Esempio n. 3
0
        public static void DrawBlock(int x, int y, string text)
        {
            string[] lines  = text.Split('\n');
            int      width  = text.IndexOf('\n');
            int      height = lines.Length;

            x -= width / 2;
            y -= width / 2;
            int rx = x;

            foreach (string line in lines)
            {
                foreach (char c in line.ToCharArray())
                {
                    if (x >= 80 || x < 0)
                    {
                        continue;
                    }
                    if (y >= 24 || y < 0)
                    {
                        continue;
                    }
                    try {
                        Stdscr.Add(y, x, c);
                    } catch { }
                    x++;
                }
                x = rx;
                y++;
            }
        }
Esempio n. 4
0
        public void DrawBlock(string text)
        {
            int y = 0;
            int x = 0;

            // This actually removes all new lines
            string[] lines = text.Split('\n');
            foreach (string line in lines)
            {
                foreach (char c in line.ToCharArray())
                {
                    if (x >= 80)
                    {
                        continue;
                    }
                    if (y >= 24)
                    {
                        break;
                    }
                    try {
                        Stdscr.Add(y, x, c);
                    } catch { }
                    x++;
                }
                x = 0;
                y++;
            }
        }
Esempio n. 5
0
 public void ClearToEnd(int ccol)
 {
     for (int c = ccol; c < w; c++)
     {
         Stdscr.Add(' ');
     }
 }
Esempio n. 6
0
		public void DrawItem (int nth, bool isSelected)
		{
			char ch;
			
			if (nth >= listing.Count)
				throw new Exception ("overflow");

			isSelected = HasFocus && isSelected;
				
			Move (y + (nth - top) + 1, x + 1);
			
			Listing.FileNode node = listing [nth];
			uint color;

			if (node == null)
				throw new Exception (String.Format ("Problem fetching item {0}", nth));

			if (node.Info.IsDirectory) {
				color = isSelected ? ColorFocus : ColorDir;
				ch = '/';
			} else {
				color = isSelected ? ColorFocus : ColorNormal;
				ch = ' ';
			}
			if (node.Marked)
				color = isSelected ? ColorHotFocus : ColorHotNormal;

			Stdscr.Attr = color;
			for (int i = 0; i < node.Nested; i++)
				Stdscr.Add ("  ");
			Stdscr.Add (ch);
			Stdscr.Add (node.Name);
		}
Esempio n. 7
0
        //		public override void Redraw ()
        //		{
        //			//int x = 0;
        //			int y = Terminal.Lines - 1;
        //			Move (y, 0);
        //
        //			for (int i = 0; i < labels.Length; i++) {
        //				Stdscr.Attr = Terminal.ColorBasic;
        //				Stdscr.Add (i == 0 ? "1" : String.Format (" {0}", i + 1));
        //				Stdscr.Attr = ColorFocus;
        //				try {
        //					Stdscr.Add ("{0,-6}", labels [i]);
        //				} catch {
        //					Console.WriteLine ("{0}:{1}", Curses.Lines, Curses.Cols);
        //				}
        //			}
        //		}
        public override void Redraw()
        {
                        #if DEBUG
            Debug.Print("Button redraw - start");
                        #endif
            int y = Terminal.Lines - 1;
            Move(y, 0);

            for (int i = 0; i < labels.Length; i++)
            {
                                #if DEBUG
                int curX;
                int curY;
                Curses.StdScr.GetCursorYX(out curX, out curY);
                Debug.Print("Button redraw - x:{0} y:{1} - {2}", curX, curY, labels [i]);
                                #endif
                Stdscr.Attr = Terminal.ColorBasic;
                Stdscr.Add(i == 0 ? "1" : String.Format(" {0}", i + 1));
                Stdscr.Attr = ColorFocus;
                try {
                    Stdscr.Add("{0,-6}", labels [i]);
                } catch {
                                        #if DEBUG
                    Debug.Print("Exception: Button Redraw - Stdscr.Add {0,-6}", labels [i]);
                                        #endif
                }
            }
                        #if DEBUG
            Debug.Print("Button redraw - end");
                        #endif
        }
Esempio n. 8
0
 void DrawStatus()
 {
     Move(y, x);
     Stdscr.Attr = Container.ContainerColorFocus;
     for (int i = 0; i < w; i++)
     {
         Stdscr.Add(' ');
     }
     Move(y, x);
     Stdscr.Add("File: FOOBAR");
 }
Esempio n. 9
0
        private static void Main2()
        {
            Stdscr.Blocking = false;
            Curses.Echo     = false;

            if (Curses.HasColors)
            {
                Curses.StartColor();
                for (short i = 1; i < 8; ++i)
                {
                    Curses.InitPair(i, color_table[i], Colors.BLACK);
                }
            }

            rng = new Random();
            int flag = 0;

            while (Stdscr.GetChar() == -1)
            {
                int start, end, row, diff, direction;
                do
                {
                    start     = rng.Next(Curses.Cols - 3);
                    end       = rng.Next(Curses.Cols - 3);
                    start     = (start < 2) ? 2 : start;
                    end       = (end < 2) ? 2 : end;
                    direction = (start > end) ? -1 : 1;
                    diff      = Math.Abs(start - end);
                } while (diff < 2 || diff >= Curses.Lines - 2);

                Stdscr.Attr = Attrs.NORMAL;
                for (row = 1; row < diff; ++row)
                {
                    Stdscr.Add(Curses.Lines - row, row * direction + start, (direction < 0) ? "\\" : "/");
                    if (flag++ > 0)
                    {
                        MyRefresh();
                        Stdscr.Erase();
                        flag = 0;
                    }
                }

                if (flag++ > 0)
                {
                    MyRefresh();
                    flag = 0;
                }

                Explode(Curses.Lines - row, diff * direction + start);
                Stdscr.Erase();
                MyRefresh();
            }
        }
Esempio n. 10
0
 // Fills with blanks from the current column/row
 // until the end of the widget area
 public void ClearToEnd(int ccol, int crow)
 {
     for (int r = crow; r < h; r++)
     {
         Move(r + y, ccol + x);
         for (int c = ccol; c < w; c++)
         {
             Stdscr.Add(' ');
         }
         ccol = 0;
     }
 }
Esempio n. 11
0
        private void Run()
        {
            Initialize();
            while (true)
            {
                Stdscr.Erase();
                for (int i = 0; i < lines.Length; ++i)
                {
                    if (offsets[i] <= 0)
                    {
                        lines[i]   = null;
                        offsets[i] = 0;
                    }
                    if (lines[i] == null)
                    {
                        lines[i]   = TEXT_LINES[rng.Next(TEXT_LINES.Length)];
                        offsets[i] = colcount + lines[i].Length;
                    }
                    int    of  = colcount - offsets[i];
                    string str = lines[i];
                    if (of < 0)
                    {
                        int ln = Math.Min(str.Length + of, colcount);
                        str = str.Substring(-of, ln);
                        of  = 0;
                    }
                    else
                    {
                        int ln = Math.Min(Math.Min(offsets[i], str.Length), colcount);
                        str = str.Substring(0, ln);
                    }
                    Stdscr.Add(i, of, str);
                    offsets[i]--;
                }
                Stdscr.Refresh();

                switch (Stdscr.GetChar())
                {
                case 'q':
                case 'Q':
                    Curses.CursorVisibility = 1;
                    return;

                default: break;
                }
                Curses.NapMs(100);
            }
        }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            // C style from http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html
//			initscr();			/* Start curses mode          */
//			printw("Hello World !!!");	/* Print Hello World		  */
//			refresh();			/* Print it on to the real screen */
//			getch();			/* Wait for user input */
//			endwin();			/* End curses mode		  */

            Curses.InitScr();
            Stdscr.Add("Hello World !!!");
            Stdscr.Refresh();
            Stdscr.GetChar();
            Curses.Beep();
            Curses.EndWin();
        }
Esempio n. 13
0
        private static void Main2()
        {
            rng = new Random();
            if (Curses.HasColors)
            {
                Curses.StartColor();
                short bg = Colors.BLACK;
                try
                {
                    Curses.UseDefaultColors();
                    bg = -1;
                }
                catch (CursesException) { }
                Curses.InitPair(1, Colors.BLUE, bg);
                Curses.InitPair(2, Colors.CYAN, bg);
            }
            Curses.Newlines         = true;
            Curses.Echo             = false;
            Curses.CursorVisibility = 0;
            Stdscr.ReadTimeout      = 0;
            Stdscr.Keypad           = true;

            int r = Curses.Lines - 4, c = Curses.Cols - 4;

            int[] xpos = new int[5];
            int[] ypos = new int[5];
            for (int j = 0; j < 5; ++j)
            {
                xpos[j] = rng.Next(c) + 2;
                ypos[j] = rng.Next(r) + 2;
            }

            for (int j = 0; ;)
            {
                int x = rng.Next(c) + 2;
                int y = rng.Next(r) + 2;

                Stdscr.Add(y, x, '.');

                Stdscr.Add(ypos[j], xpos[j], 'o');

                j = NextJ(j);
                Stdscr.Add(ypos[j], xpos[j], 'O');

                j = NextJ(j);
                Stdscr.Add(ypos[j] - 1, xpos[j], '-');
                Stdscr.Add(ypos[j], xpos[j] - 1, "|.|");
                Stdscr.Add(ypos[j] + 1, xpos[j], '-');

                j = NextJ(j);
                Stdscr.Add(ypos[j] - 2, xpos[j], '-');
                Stdscr.Add(ypos[j] - 1, xpos[j] - 1, "/ \\");
                Stdscr.Add(ypos[j], xpos[j] - 2, "| O |");
                Stdscr.Add(ypos[j] + 1, xpos[j] - 1, "\\ /");
                Stdscr.Add(ypos[j] + 2, xpos[j], '-');

                j = NextJ(j);
                Stdscr.Add(ypos[j] - 2, xpos[j], ' ');
                Stdscr.Add(ypos[j] - 1, xpos[j] - 1, "   ");
                Stdscr.Add(ypos[j], xpos[j] - 2, "     ");
                Stdscr.Add(ypos[j] + 1, xpos[j] - 1, "   ");
                Stdscr.Add(ypos[j] + 2, xpos[j], ' ');

                xpos[j] = x;
                ypos[j] = y;

                switch (Stdscr.GetChar())
                {
                case 'q':
                case 'Q':
                    Curses.CursorVisibility = 1;
                    return;

                case 's':
                    Stdscr.Blocking = true;
                    break;

                case ' ':
                    Stdscr.Blocking = false;
                    break;

                default: break;
                }
                Curses.NapMs(50);
            }
        }
Esempio n. 14
0
        void DrawView()
        {
            int  col = 0;
            bool skip_until_newline = false;

            Stdscr.Attr = Container.ContainerColorNormal;
            Move(y + 1, x);
            SetPosition(top_byte);
            for (int row = 0; row < h;)
            {
                int c = GetChar();
                switch (c)
                {
                /* End of file */
                case -1:
                    ClearToEnd(col, row);
                    row = h;
                    continue;

                case 10:
                    ClearToEnd(col);
                    col = 0;
                    row++;
                    skip_until_newline = false;
                    Move(y + row, x + col);
                    continue;

                case 9:
                    for (int nc = (col / 8 + 1) * 8; col < nc; col++)
                    {
                        Stdscr.Add(' ');
                    }

                    continue;

                case 13:
                    continue;
                }

                // Control chars or unicode > 0xffff
                if (c < 32 || c > 0xffff)
                {
                    c = '.';
                }

                if (skip_until_newline)
                {
                    continue;
                }

                Stdscr.Add((char)c);
                col++;
                if (col > w)
                {
                    if (Wrap)
                    {
                        col = 0;
                        row++;
                    }
                    else
                    {
                        skip_until_newline = true;
                    }
                }
            }
        }