잊지 않겠습니다.

사다리 게임

.NET Framework 2009. 1. 7. 13:34


저녁시간에 사다리 타는 것을 이야기하던것이 갑자기 생각나서 집에서 뚝딱 거리면서 만들어본것.

 

NodePoint -> NodePointGroup -> LadderGame 으로 소유하는 것으로 구조를 꾸미고,

NodePoint에서는 각 Node에서의 정보 저장

NodePointGroup에서는 Node간의 관계에 대한 정보

LadderGame에서는 각각의 Node를 움직이고, 게임의 초기화를 하는 것으로 구성.

 

Windows Form으로 간단히 구성

LadderGameDisplay라는 UserController를 이용해서 사다리 게임을 Display

 

졸면서, 옆에 KGB 3병 먹으면서 짠 알콜 코드. ㅋㅋㅋ

이제 이름을 각각 넣는것과 마지막 부분에 걸리는 내용을 넣으면 되는데..

사용자 입력 부분이라서 가장 귀찮은 코드가 될것 같음. LINQ 이용해서 DB에도 연결을 시켜볼까.. 고민도 되고. ㅋㅋ

Posted by Y2K
,

WinForm의 상속

.NET Framework 2009. 1. 7. 13:09
  • WinForm의 상속에서 각각의 접근 한정자에 따라 변화하는 것
    • Public : 모든 것을 다 사용할 수 있고, 외부에도 노출이 된다.
    • Protected : 상속받은 상태에서만 사용 가능
    • Private : 상속 받은 상태에서도, 폼의 구성요소를 수정 또는 변경하지 못한다. [Menu 등의 위치들도 마찬가지]


  • abstract 의 사용
    • WinForm에서도 기본적으로 abstract도 사용 가능하나, 여간해서는 사용안하는 것이 좋다.
    • Designer을 사용하지 못한다. : abstract로 선언된 폼은 designer에서 사용이 불가능하다.
    • virtual로 해서 각 필요한 내부 함수들을 외부로 노출하는 것이 좋을것 같다.
Posted by Y2K
,
1) Create the Image attribute
System.Drawing.Imaging.ImageAttributes attrib = new System.Drawing.Imaging.ImageAttributes();

2) Set the transparency color key (black for the example)
attrib.SetColorKey(Color.Black, Color.Black);

: 투명으로 지정될 Color를 정해준다. 


3) Draw the image using the image attribute
e.Graphics.DrawImage(backgroundIm, destRect, 0, 0, backgroundIm.Width, backgroundIm.Height, GraphicsUnit.Pixel, attrib);

 

And here is the result with a light green background!

Posted by Y2K
,
KeyDown, KeyUp Event를 이용하거나, Control.ModifierKeys 값을 이용해준다.

일반적으로 Keyboard의 값을 즉각적으로 이용할때는 Event를, 마우스 등과의 같은 동시 이용을 위해서는 ModifierKeys값을 이용하게 된다.
Posted by Y2K
,
  • Programing을 하는 사람들의 생각대로 움직이지 않는다.
    • API 단에서 값의 변경을 취한다
    • Windows Server : Max(200)
    • Windows XP Professional, Home Edition : Max(5)

 : 그래서 이상하게 안되었던 것이였어... -_-

Posted by Y2K
,
Posted by Y2K
,

Digest Auth

            CredentialCache webservCredentials = new CredentialCache();
            webservCredentials.Add(new Uri("http://123.123.123.123:8888/MobileAccessVersion.asmx"), "Digest", new NetworkCredential("ykyoon", "*****", "***"));
            webService.Credentials = webservCredentials;

Basic Auth

            CredentialCache webservCredentials = new CredentialCache();
            webservCredentials.Add(new Uri("http://123.123.123.123:8888/MobileAccessVersion.asmx"), "Basic", new NetworkCredential("ykyoon", "*****", "***"));
            webService.Credentials = webservCredentials;

 

상당히 편하게 구현이 가능한 방법

일부러 MD5로 압축하거나, Base64로 따로 인코딩을 할 필요도 없이 아주 산뜻하게 끝이 난다. ^^

Posted by Y2K
,

A cookie is stored on the client's machine by their web browser software. To set a cookie, we include information in an HttpResponse that instructs the browser to save a cookie on the client's system. Here's the basic code for writing a Cookie in ASP.NET 

Using System.Web;



Response.Cookies["BackgroundColor"].Value = "Red";




And to read the cookie back : 

Response.Write

(Request.Cookies["BackgroundColor"].Value);




Note that for security reasons you can only read a cookie that was set within the same domain name. 

Sometimes you may need a collection of stored items, such as user address details. In this case you could read in a cookie collection like this: 

HttpCookieCollection cookies = Request.Cookies;

for(int n=0;n<cookies.Count;n++)

{

    HttpCookie cookie = cookies[n];

    Response.Write("<hr/>Name: <b>" + cookie.Name + "</b><br />");

    Response.Write("Expiry: " + cookie.Expires + "<br />");

    Response.Write("Address1: " + cookie.Address1+ "<br />");

    Response.Write("Address2: " + cookie.Address2+ "<br />");

    Response.Write("City: " + cookie.City+ "<br />");

    Response.Write("Zip: " + cookie.Zip+ "<br />");

}


Posted by Y2K
,

this is ThreadAbort Exception in Response.Redirect because of Response.End() is not completed.

 

if use Response.Redirect in try..catch block, this exception is frequent.

and this exception(System.Threading.Thread.AbortThread) is especially exception. if you catch the exception in try.. catch block, this exception is re-thrown by .NET Framework. so application programmer cannot resolve this problem.

 

So, remove System.Threading.Thread.Abort is good reason for this case.

In Response.Redirect have 2 overloaded functions.

1. Response.Redirect(string url)

2. Response.Redirect(string url, bool endResponse)

 

Response.Redirect(string url) is equal with Response.Redirect(string url, true).

if endResponse is false, Response.End() event is not occured.

Posted by Y2K
,

Seven Segment

.NET Framework 2009. 1. 7. 13:06

using System;
using System.Drawing;

namespace Chapter10_App
{
 /// <summary>
 /// SevenSegmentDisplay에 대한 요약 설명입니다.
 /// </summary>
 public class SevenSegmentDisplay
 {
  Graphics _grfx;
  static byte[,] bySegment = { {1, 1, 1, 0, 1, 1, 1},  //0
         {0, 0, 1, 0, 0, 1, 0},  //1
         {1, 0, 1, 1, 1, 0, 1},  //2
         {1, 0, 1, 1, 0, 1, 1},  //3
         {0, 1, 1, 1, 0, 1, 0},  //4
         {1, 1, 0, 1, 0, 1, 1},  //5
         {1, 1, 0, 1, 1, 1, 1},  //6
         {1, 0, 1, 0, 0, 1, 0},  //7
         {1, 1, 1, 1, 1, 1, 1},  //8
         {1, 1, 1, 1, 0, 1, 1} }; //9
  readonly Point[][] _apt = new Point[7][];
     

  public SevenSegmentDisplay(Graphics grfx)
  {
   _grfx = grfx;
   
   _apt[0] = new Point[]{new Point(3, 2), new Point(39, 2),
          new Point(31, 10), new Point(11, 10)};
   _apt[1] = new Point[]{new Point(2, 3), new Point(10, 11),
          new Point(10, 31), new Point(2, 35)};
   _apt[2] = new Point[]{new Point(40, 3), new Point(40, 35),
          new Point(32, 31), new Point(32, 11)};
   _apt[3] = new Point[]{new Point(3, 36), new Point(11, 32),
          new Point(31, 32), new Point(39, 36),
          new Point(31, 40), new Point(11, 40)};
   _apt[4] = new Point[]{new Point(2, 37), new Point(10, 41),
          new Point(10, 61), new Point(2, 69)};
   _apt[5] = new Point[]{new Point(40, 37), new Point(40, 69),
          new Point(32, 61), new Point(32, 41)};
   _apt[6] = new Point[]{new Point(11, 62), new Point(31, 62),
          new Point(39, 70), new Point(3, 70)};

  }

  public SizeF MeasureString(string str, Font font)
  {
   SizeF sizef = new SizeF(0, _grfx.DpiX * font.SizeInPoints / 72);

   for(int i = 0 ; i < str.Length ; i++)
   {
    if( (Char.IsDigit(str[i])) || (str[i] == '=>') )
    {
     sizef.Width += 42 * _grfx.DpiX * font.SizeInPoints / 72 / 72;
    }
   }

   return sizef;
  }
  
  void Fill(Point[] apt, Font font, Brush brush, float x, float y)
  {
   PointF[] aptf = new PointF[apt.Length];

   for(int i = 0 ; i < apt.Length ; i++)
   {
    aptf[i].X = x + apt[i].X * _grfx.DpiX * font.SizeInPoints / 72 / 72;
    aptf[i].Y = y + apt[i].Y * _grfx.DpiY * font.SizeInPoints / 72 / 72;
   }
   _grfx.FillPolygon(brush, aptf);
  }

  float Number(int num, Font font, Brush brush, float x, float y)
  {
   for(int i = 0 ; i < _apt.Length ; i++)
   {
    if(bySegment[num, i] == 1)
    {
     Fill(_apt[i], font, brush, x, y);
    }
   }

   return x + 42 * _grfx.DpiX * font.SizeInPoints / 72 / 72;
  }

  float Colon(Font font, Brush brush, float x, float y)
  {
   Point[][] apt = new Point[2][];

   apt[0] = new Point[]{ new Point(2, 21), new Point(6, 17),
         new Point(10, 21), new Point(6, 25)};
   apt[1] = new Point[]{ new Point(2, 51), new Point(6, 47),
         new Point(10, 51), new Point(6, 55)};

   for(int i = 0 ; i < apt.Length ; i++)
   {
    Fill(apt[i], font, brush, x, y);
   }

   return x + 12 * _grfx.DpiX * font.SizeInPoints / 72  / 72;
  }

  public void DrawString(string str, Font font, Brush brush, float x, float y)
  {
   for(int i = 0 ; i < str.Length ; i++)
   {
    if(Char.IsDigit(str[i]))
    {
     x = Number(str[i] - '0', font, brush, x, y);
    }
    else if(str[i] == '=>')
    {
     x = Colon(font, brush, x, y);
    }
   }
  }
 }
}

Posted by Y2K
,