Silverlight + new WCF instance chess game room list (13)

Source: Internet
Author: User

It's hot and bloody...

I created a room last time. Now I want to create multiple rooms.

Just like adding a Chess class to create many pawns, we now create a Game class to create many rooms:

Right-click the Code folder and choose create item> class> Game. cs. Similarly, remove [. Code] From the namespace.

 

Namespace NewChessProject
{
/// <Summary>
/// The game goes by autumn
/// </Summary>
Public class Game
{

}
}

 

Attributes of the previous room list:

Public List <gamoom> GameRoomList // room List
{
Get;
Set;
}

 

Next is a method for creating a room:

Public void CreateGameRoom (int count)
{
GameRoomList = new List <gamoom> ();
Int margin = 40;
Int GameRoomWidth = 120;
Int pageWidth = 800;
Int x = 0, y = 0;
Point location;
For (int I = 0; I <count; I ++)
{
// Calculate the room location
X = I % (pageWidth/GameRoomWidth) * GameRoomWidth + margin + I % (pageWidth/GameRoomWidth) * 20;
Y = (I/(pageWidth/GameRoomWidth) * GameRoomWidth + margin;
Location = new Point (x, y );
Gamoom = new gamoom (I + 1, location, GameRoomWidth );
GameRoomList. Add (gamoom );
}
}
Public void DrawIn (Panel control)
{
For (int I = 0; I <GameRoomList. Count; I ++)
{
GameRoomList [I]. DrawIn (control );
}
}

 

Since we set the total page width to 800, we need to set the Canvas width and height in Room. xaml:

 

<Grid x: Name = "LayoutRoot" Background = "White" Width = "800" Height = "600" HorizontalAlignment = "Left" verticalignment = "Top" Margin =, 0, 0 ">

</Grid>

OK. Now let's go back to the Room. xaml. cs code and create 30 rooms:

Public partial class Room: UserControl
{
Public Room ()
{
InitializeComponent ();
// Gamoom = new gamoom (1, new Point (120 );
// Gamoom. DrawIn (LayoutRoot );
Game game = new Game ();
Game. CreateGameRoom (30 );
Game. DrawIn (LayoutRoot );
}
}

 

Run F5 to check the effect:

I checked, adjusted, and compared it. I found that:

The difference between Grid layout and Canvas layout.

Therefore, you can replace the Grid label with the Canvas label:

<Canvas Background = "White" Height = "600" HorizontalAlignment = "Left" Margin = "800," Name = "LayoutRoot" verticalignment = "Top" Width = "">
</Canvas>

 

OK. Run F5 again. The room is normal:

OK. The list is displayed.

In the next section, we will start to talk about WCF communication. At the same time, the subsequent sections will adjust and supplement many of the previous code.

Now we provide part 1 of the Code: Click here to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.