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