![batalha naval games batalha naval games](https://a-static.mlcdn.com.br/1500x1500/jogo-batalha-naval-grow/papelariapigmeu/5285699935/269fc6d8f3d9186e1c4eadb07ca2def1.jpg)
07-26-2005 - Complete package sent to The Code Project.A map of one player's ships and the hits against them, from a game in progress.07-12-2005 - The beginning and the end of the first part of the article.I would like to thank Jesse Liberty for his books, Deitel family for their C# HTP, Daniel Turini for his article "I want to be a good programmer.how?", MSDN, of course, you and Code Project. I hope that you enjoy this article! The second part is coming soon. If you have any suggestions, doubts and critics, please send me an e-mail.
#BATALHA NAVAL GAMES HOW TO#
In the next article I will explain using socket connections in applications and how to draw the "X"s on the battlefield.
#BATALHA NAVAL GAMES SERIES#
Guys, this first part of the series has ended. You can use the PointF object but it only works with floating point. I use the Point object with integers to define the point that my squares are drawn. To fill an imaginary line in my form in each iteration, I sum 50 in X coordinate, this process continues filling 5 imaginary lines in the form. The method DrawRectangle that I use, has five parameters: a Pen object, X coordinate, Y coordinate, width and height. There is another loop for the squares that uses the Point object pLocation. Look at this part of the code:Ĭopy Code for( int iOtherCount = 0 iOtherCount < 5 iOtherCount++) This is done only for defining a coordinate in the PointF's pfLocation object. The same process occurs with the letters, but they are drawn in the vertical position, but this time the pfLocation.X is first assigned with the value 10 and pfLocation.Y is summed with 40.
After this I continue with my sum, now with the value 50, because I need to go to the half of the next square and draw the next number. Why? I need to put the letters on the top of the first 5 squares aligned with their centers, so I sum 25 in my pfLocation.X and draw my first number. Now, how are these used to draw the battlefield? If you notice below, the variables iRow and iCol are set to 0, the value 25 is added to pfLocation.X property and pfLocation.Y is assigned with the value contained in the fLocal variable. Below there are three float variables, a Font and a SolidBrush and two Point objects, and one of them is a PointF that is called pfLocation. In my Draw method, a string with coordinates "12345abcde" and a 2x5 matrix are created. M_FormGraphs.DrawRectangle(pen, pLocation.X, to draw 1 square in each column for( int j = 0 j < 5 j++) to draw 5 squares in a row for( int iOtherCount = 0 iOtherCount < 5 iOtherCount++) ICol].ToString(),font, sBlack, pfLocation) M_FormGraphs.DrawString(sCoordinates[iRow, Pen pen = new Pen( new SolidBrush(Color.Black), 3) įor( int iCount = 0 iCount <= 9 iCount++) SolidBrush sBlack = new SolidBrush(Color.Black) These are the variables that the method uses to draw the battle field in my class, see that I put them here with their values: How can I do this? I've created a class called BattleField. First of all I've needed to draw a battle field and coordinates (represented with letters and numbers, of course) in it. I've hit my head many times on the keyboard, mainly when I wanted to find a way to draw the "X" coordinates in the right places in both forms, but the application is done. But when I was coding, the reality was not so good. I wanted to write a simple C# game, and I thought: "Navy Battle is a good idea".
![batalha naval games batalha naval games](https://i.pinimg.com/564x/91/33/a7/9133a73049f4b520f62e27535bfd645c.jpg)
The great deal is you to have the book and to navigate in the MSDN. But if you don't have money, the documentation in the MSDN is a great help. If you don't have any idea what I'm talking about, I recommend you read the Deitel's book "C# How to Program". To better understand this article, you should know a little bit of socket connections (for the part 2), the namespace System.Drawing, and IO (for the part 2 too). This first part covers how to draw a navy battle battlefield. This article is the first part of a two-article series. A client-server application with sockets and IO to play Navy Battle.