dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/samples snake.cs,1.2,1.3


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/samples snake.cs,1.2,1.3
Date: Tue, 11 Nov 2003 22:14:05 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/samples
In directory subversions:/tmp/cvs-serv8710/samples

Modified Files:
        snake.cs 
Log Message:


Modify the Snake game to use buffer-relative cursor co-ordinates with
Console.SetCursorPosition rather than window-relative to match the
Win32 requirements.


Index: snake.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/samples/snake.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** snake.cs    6 Nov 2003 01:15:40 -0000       1.2
--- snake.cs    11 Nov 2003 22:14:03 -0000      1.3
***************
*** 28,31 ****
--- 28,32 ----
        // Internal state.
        private bool monochrome;
+       private int originX, originY;
        private int left, top, width, height;
        private Occupied[] occupied;
***************
*** 64,67 ****
--- 65,70 ----
        public Snake(bool mono)
                        {
+                               originX = Console.CursorLeft;
+                               originY = Console.CursorTop;
                                monochrome = mono;
                                random = new Random();
***************
*** 69,72 ****
--- 72,81 ----
                        }
  
+       // Set the cursor position, using window-relative co-ordinates.
+       private void SetCursorPosition(int x, int y)
+                       {
+                               Console.SetCursorPosition(originX + x, originY 
+ y);
+                       }
+ 
        // Main entry point.
        public static void Main(String[] args)
***************
*** 163,167 ****
  
                                // Draw the top line.
!                               Console.SetCursorPosition(left - 1, top - 1);
                                Console.Write('+');
                                for(temp = 0; temp < width; ++temp)
--- 172,176 ----
  
                                // Draw the top line.
!                               SetCursorPosition(left - 1, top - 1);
                                Console.Write('+');
                                for(temp = 0; temp < width; ++temp)
***************
*** 172,176 ****
  
                                // Draw the bottom line.
!                               Console.SetCursorPosition(left - 1, top + 
height);
                                Console.Write('+');
                                for(temp = 0; temp < width; ++temp)
--- 181,185 ----
  
                                // Draw the bottom line.
!                               SetCursorPosition(left - 1, top + height);
                                Console.Write('+');
                                for(temp = 0; temp < width; ++temp)
***************
*** 183,189 ****
                                for(temp = 0; temp < height; ++temp)
                                {
!                                       Console.SetCursorPosition(left - 1, top 
+ temp);
                                        Console.Write('|');
!                                       Console.SetCursorPosition(left + width, 
top + temp);
                                        Console.Write('|');
                                }
--- 192,198 ----
                                for(temp = 0; temp < height; ++temp)
                                {
!                                       SetCursorPosition(left - 1, top + temp);
                                        Console.Write('|');
!                                       SetCursorPosition(left + width, top + 
temp);
                                        Console.Write('|');
                                }
***************
*** 198,202 ****
                                                if(occ == Occupied.Star)
                                                {
!                                                       
Console.SetCursorPosition(left + x, top + y);
                                                        if(!monochrome)
                                                        {
--- 207,211 ----
                                                if(occ == Occupied.Star)
                                                {
!                                                       SetCursorPosition(left 
+ x, top + y);
                                                        if(!monochrome)
                                                        {
***************
*** 209,213 ****
                                                else if(occ == Occupied.Wall)
                                                {
!                                                       
Console.SetCursorPosition(left + x, top + y);
                                                        if(!monochrome)
                                                        {
--- 218,222 ----
                                                else if(occ == Occupied.Wall)
                                                {
!                                                       SetCursorPosition(left 
+ x, top + y);
                                                        if(!monochrome)
                                                        {
***************
*** 220,224 ****
                                                else if(occ != Occupied.Empty)
                                                {
!                                                       
Console.SetCursorPosition(left + x, top + y);
                                                        if(!monochrome)
                                                        {
--- 229,233 ----
                                                else if(occ != Occupied.Empty)
                                                {
!                                                       SetCursorPosition(left 
+ x, top + y);
                                                        if(!monochrome)
                                                        {
***************
*** 243,247 ****
        private void ShiftCursor()
                        {
!                               Console.SetCursorPosition(0, top + height + 2);
                        }
  
--- 252,256 ----
        private void ShiftCursor()
                        {
!                               SetCursorPosition(0, top + height + 1);
                        }
  
***************
*** 258,262 ****
                                                if(draw)
                                                {
!                                                       
Console.SetCursorPosition(left + x, top + y);
                                                        if(!monochrome)
                                                        {
--- 267,271 ----
                                                if(draw)
                                                {
!                                                       SetCursorPosition(left 
+ x, top + y);
                                                        if(!monochrome)
                                                        {
***************
*** 275,279 ****
        private void PrintScore()
                        {
!                               Console.SetCursorPosition(width - 14, height + 
2);
                                if(!monochrome)
                                {
--- 284,288 ----
        private void PrintScore()
                        {
!                               SetCursorPosition(width - 14, height + 2);
                                if(!monochrome)
                                {
***************
*** 304,308 ****
  
                                // Draw the top line.
!                               Console.SetCursorPosition(left, top);
                                Console.Write('+');
                                for(temp = 2; temp < width; ++temp)
--- 313,317 ----
  
                                // Draw the top line.
!                               SetCursorPosition(left, top);
                                Console.Write('+');
                                for(temp = 2; temp < width; ++temp)
***************
*** 313,317 ****
  
                                // Draw the bottom line.
!                               Console.SetCursorPosition(left, top + height - 
1);
                                Console.Write('+');
                                for(temp = 2; temp < width; ++temp)
--- 322,326 ----
  
                                // Draw the bottom line.
!                               SetCursorPosition(left, top + height - 1);
                                Console.Write('+');
                                for(temp = 2; temp < width; ++temp)
***************
*** 324,328 ****
                                for(temp = 1; temp < (height - 1); ++temp)
                                {
!                                       Console.SetCursorPosition(left, top + 
temp);
                                        Console.Write('|');
                                        if(!monochrome)
--- 333,337 ----
                                for(temp = 1; temp < (height - 1); ++temp)
                                {
!                                       SetCursorPosition(left, top + temp);
                                        Console.Write('|');
                                        if(!monochrome)
***************
*** 349,353 ****
                                                (ConsoleColor.Gray, 
ConsoleColor.Black);
                                }
!                               Console.SetCursorPosition(left + 4, top + 2);
                                Console.Write(msg);
  
--- 358,362 ----
                                                (ConsoleColor.Gray, 
ConsoleColor.Black);
                                }
!                               SetCursorPosition(left + 4, top + 2);
                                Console.Write(msg);
  
***************
*** 472,476 ****
                                                (ConsoleColor.DarkGreen, 
ConsoleColor.DarkGreen);
                                }
!                               Console.SetCursorPosition(newX + left, newY + 
top);
                                Console.Write('#');
                                occupied[headX + headY * width] = piece;
--- 481,485 ----
                                                (ConsoleColor.DarkGreen, 
ConsoleColor.DarkGreen);
                                }
!                               SetCursorPosition(newX + left, newY + top);
                                Console.Write('#');
                                occupied[headX + headY * width] = piece;
***************
*** 487,491 ****
                                                        (ConsoleColor.Gray, 
ConsoleColor.Black);
                                        }
!                                       Console.SetCursorPosition(tailX + left, 
tailY + top);
                                        Console.Write(' ');
                                        occupied[tailX + tailY * width] = 
Occupied.Empty;
--- 496,500 ----
                                                        (ConsoleColor.Gray, 
ConsoleColor.Black);
                                        }
!                                       SetCursorPosition(tailX + left, tailY + 
top);
                                        Console.Write(' ');
                                        occupied[tailX + tailY * width] = 
Occupied.Empty;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]