|
fellas been developing a c# battleship game and have did go enuf so far
quick question, when i shot at the grid i write back the coordinates such as 1-1, but this is trying to compare it will the coordinates of the sub(for example) which is 1-1,2-1, but i tseems to trying to compare againest the entire coordinates how would i extract the 1-1 or the 2-1??
the cooridnates can go past 10 meaning it cant be a set number
any help please?
thanks
|
|
|
|
|
Take Chris's advice from your previous post... make a 2-dimensional array of type bool, then just check to see if that bool is true to see if there is a ship at that location. If you are dead set on doing it with strings, then you should use the string.Split(',') method, then see if the resulting collection contains the string 1-1. Conversely, you could use the string.Contains("1-1") method as well (I think the second is a method, but I am not certain). Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hello, This is the sample code i have prepired for you now.
public void fnCutText()
{ //Code By Dipak (dipak.dipak@gmail.com)
String strMyString = "abcd,efgh,ijkl,mnop,qrst";
String strTemp = "";
String[] strStrings = new String[100]; int i;
for (i = 0; strMyString.Length > 0; i++)
{
if (strMyString.Contains(","))
{
strTemp = strMyString.Substring(0, strMyString.IndexOf(","));
strStrings[i] = strTemp;
strMyString = strMyString.Substring(strMyString.IndexOf(",") + 1);
}
else
{
strStrings[i] = strMyString;
strMyString = "";
}
}
}
I think u can continue your work.
Best of Luck.
Good Night.
Dipak
|
|
|
|
|
Use string.split(",".tochararray())
|
|
|
|
|
I have this app that sometimes when a user logs in,it will tell the user that the method cannot be called on null values.But when I restart the IIS and still log in with the same name and password,the app will accept.And it will run again for sometime and again it will be giving the same error that method cannot be called on null values.But each time I restart the IIS on the server,the error will disappear.Please do anybody have any clue why this is like this?
|
|
|
|
|
Do you have this working yet?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
|
Hi,
I'm really stuck here. I'm using reflection to perform an action of all fields that implement a certain interface in a class.
For normal fields, this works fine, but some of the members are generic Dictionary classes in which the content to perform an action on is in the TValue part. Somehow I need to extract that data from the dictionary.
I've been staring at MSDN pages for a few hours now and trying all sorts of things, help would be very much appreciated.
Here's the piece of code.
private void BindToComdriver(ABaseData target)
{
FieldInfo[] fields = target.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
foreach (FieldInfo field in fields)
{
Type[] interfaces = field.FieldType.GetInterfaces();
if (t == typeof(ICollection) || t is ICollection)
{
ICollection col = field.GetValue(target) as ICollection;
object[] oma = new object[col.Count];
col.CopyTo(oma, 0);
Type generic_type = field.FieldType.GetGenericTypeDefinition();
foreach (object m in oma)
{
if (generic_type.GetGenericArguments().Length > 1)
{
}
}
}
if(t == typeof(IBindable) || t is IBindable)
{
Bind(field.GetValue(target));
}
}</tkey,>
Standards are great! Everybody should have one!
|
|
|
|
|
foreach(Type var in genericarguments)
{
if(var.GetInterface("name",true) != null)
//do actions...
}
I think, but not sure...
modified on Thursday, December 13, 2007 11:05:18 AM
|
|
|
|
|
Thanks for the reply. Unfortunately that's not working... Any ideas on how to extract the instance value of TValue ?
Standards are great! Everybody should have one!
|
|
|
|
|
I need ideas for scaling down an image. I tried Image.GetThumbnailImage() , I am able to scale it down, but it lost the clarity. So is there any efficient method to scale the image without loosing clarity ?
|
|
|
|
|
Microsoft recommends Image.GetThumbnailImage() only for Targetsizes <= 120x120. (found here[^])
did you try Image myImg = new Bitmap(sourceImage, someWidth, someHeight); ?
i had good results also with Graphics.DrawImage(someImage, someRect); if you only want to draw it somewhere..
greets
m@u
|
|
|
|
|
You may resize an image using DrawImage method of graphics object.
Following is a small code snippet showing this-
--------------------Code Start-------------------
Bitmap SourceImage= (System.Drawing.Bitmap ) Image.FromFile("C:\\img1.jpg");
Bitmap ScaledImage = new Bitmap(50, 50); //you may set size of scaled image here.
Graphics g = Graphics.FromImage(ScaledImage);
g.DrawImage(SourceImage, new Rectangle(0, 0, 50, 50), new Rectangle(0, 0, SourceImage.Width, SourceImage.Height), GraphicsUnit.Pixel);
ScaledImage.Save("C:\\scaledimg.jpg");
-------------------------Code End--------------------
I hope this helps .
-Dave.
Dave Traister,
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
The GetThumbnailImage method uses the embedded thumbnail if there is one, so you can only successfully use it to actually create thumbnails.
For larger miniatures, you have to do the work yourself:
Create a Bitmap object with the size you want, create a Graphics object to draw on the bitmap using the Graphics.FromImage method. Draw the image onto the bitmap using the DrawImage method.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
|
Hello All
I am trying to catch a right button down event for a control before the form sends it to this control; I tried to do that through overriding the WndProc
But it fails!
Is there any way to do that?
|
|
|
|
|
There is an option in the designer to have the form catch key presses before it sends them to a control, perhaps there is another for mouse events. I'd check myself, but i have to go.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
fellas
i am making a game of battleships and i have server and client talking sending and recieve etc
i can place all my battle ships and get the row and col, problem i cannot think on how to get the coorindates into an array in order to store and get them checked when a player sends a shot
here are the corrindates any help would be greatly appriceated
6-13,7-13,
11-10,12-10,13-10,
11-7,12-7,13-7,14-7,
6-5,7-5,8-5,9-5,10-5,11-5,
thanks
|
|
|
|
|
Just store the whole battle grid in an array. Use 0's for empty coordinates and use 1's to represent where a boat is placed. Then you can easily check the X,Y positions in the array for 0 or 1 to signify hit or miss.
|
|
|
|
|
I want to use pointers.bt the problem is c# does not provide pointers.
Is there any other method?
Regards,
chanzeb chaudhary....
|
|
|
|
|
C# does provide for pointers, but you need to compile with 'unsafe' code, so you need to set that option.
And then use the <font color="333333">unsafe</font> keyword, either for your class, or just like an if statement:
unsafe class myClass
{
}
class myClass
{
static void main(string[] args)
{
unsafe {
}
}
}
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
You can use pointers in C#. All you have to do is mark a method as unsafe (and change the assembly to allow unsafe code) and you are good to go.
|
|
|
|
|
Can we Serialize the static variables and generic lists ?
B V KIRAN KUMAR
|
|
|
|
|
Bhimuni wrote: Can we Serialize the static variables and generic lists ?
What have you tried? The best way to find something out like this is to write a piece of code that attempts to do just what you have asked. This way, you learn problem solving skills, rather than relying on somebody else to do your thinking for you - especially as they may well end up giving you incorrect information.
|
|
|
|
|
I have hosted a dhtml control on a C# form. I can not figure out a way to catch its text drag events.
|
|
|
|