|
You would need something along the lines of:
bool GameIsOn = true;
while (GameIsOn)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.LeftArrow:
{
}
case ConsoleKey.RightArrow:
{
}
case ConsoleKey.UpArrow:
{
}
case ConsoleKey.DownArrow:
{
}
case ConsoleKey.Escape:
{
GameIsOn = false;
}
default:
{ }
}
}
}
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Hi thanks!
I have actually tried that and that is almost what a want, however I'd like it to tick.
With this method you have have to press once for each step. I would like to start a loop of steps that loops until another directional key is pressed.
Any more thoughts?
|
|
|
|
|
Pffft!
You got me interested in writing the game myself now!
I'll probably post it as an article in a week or so.
But the way I'd do it is as follows:
void RunGame()
{
while (GameIsOn)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.LeftArrow:
CharacterDirection = Direction.Left;
break;
case ConsoleKey.RightArrow:
CharacterDirection = Direction.Right;
break;
case ConsoleKey.UpArrow:
CharacterDirection = Direction.Up;
break;
case ConsoleKey.DownArrow:
CharacterDirection = Direction.Down;
break;
case ConsoleKey.Escape:
GameIsOn = false;
break;
default:
break;
}
#endregion
}
AdvanceStep();
CheckCollision();
Thread.Sleep(100);
}
}
Now in the AdvanceStep() method you're going to have calculate the new position of the cursor and Console.Write() the new character placeholder. This will "tick" in the sense that you will see the character move in whatever direction you first choose, ten steps in 1 second. You can make that faster or slower based on the number of milliseconds you let that thread sleep.
There are things that you have to bear in mind. The Character's initial position [ (0,0) vs centre point ] the character's initial direction and so on. If for example you set the initial position at (0,0) and the initial direction is Right, then the character will move to the right (x-axis change only) until a button is pressed that will alter the direction.
If there are many attributes that you would like to add to your character, such as the length of the tail (we are talking about a snake-clone, right?), and also a history of the turns that were made (so that the tail will also turn at the correct locations) you might want to break into a class and if the list of positions can be lengthy (as can easily happen on a "big screen" with an expert player) then you might want to break that into its own vector class list.
If you have anymore questions, post some code as well, and we'll see how we can help you with where you are stuck
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Very nice thanks alot, yes I have solved most problems with the tail, borders food etc.
Thanks for spending the time on it!!
|
|
|
|
|
Glad to have helped
If you have anymore questions, we, and especially I, will be glad to help.
Check back in a week or so and see if I posted the article by then, then you can compare notes
Best of luck with your assignment.
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Hi everyone.
This is probably something I should be able to figure out by myself, but I'm not having much luck so I figured I'd ask.
The issue: I'm translating a system from java to C# and they use a java framework[^] that I'd really like to use, since it takes care of the most complex parts of the system, which I would otherwise have to implement myself. I have the source code of this framework.
I know there are several possibilities for using java libraries in C# (although I'm not familiar with any of them, so I'd appreciate suggestions). So far I've thought of using IKVM.NET[^] to generate a .dll, but I'm not sure what to do next, because in java in order to run the framework with your code you're supposed to use the option -javaagent[^] by adding
-javaagent:bin/deuceAgent.jar (where deuceAgent is the framework) to your java command line. I don't know what the equivalent in C# would be once I have my .dll, or whether there's an equivalent at all.
Any help? Thanks so much.
|
|
|
|
|
Hi all,
can anybody help me out here by providing me a solution.
I want to set a focus to masked TextBox control displayed over a cell in CellBeginEdit event.
MaskedTextbox.focus() is not working here
can anybody help me out ???
|
|
|
|
|
Do it using gridviews findcontrol method.
|
|
|
|
|
I have already tried that but no success
Control[] ctrl = datagridview.Controls.Find("name of textbox", true);
ctrl[0].Focus();
|
|
|
|
|
Try it like this.
MaskTextBox mt=datagridview.row[0].FindControl("nameof textbox")
mt.setFouus().
Hope this works.
|
|
|
|
|
there is no funciton like FindControl for datagridview
and there's no function like setFocus() for maskedtextbox
so r u serious in giving this solution?
|
|
|
|
|
sorry for the late reply. But i just did the same.
t1 = GridView1.Rows(0).FindControl("InstallmentDec")
t1.Text = dt.Rows(0)(12).ToString()
Its working for me.
Here use Foucus function in place of setting text will work fine.
|
|
|
|
|
Hi,
there is a stored procedure in Oracle that has a output parameter of type table of records.
What OracleType to use in C# to retrieve it?
Regards,
Adrian
|
|
|
|
|
|
|
|
In addition to SaMartens answer, if you are using .NET 3.5, you can use XDocument.Parse
|
|
|
|
|
i have created a CSV file with following format
"Test1";"Test2";"Test3"
when i tried to read that csv in Notepad using C#.net i am getiing with following format
"""Test1"";""Test2"";""Test3""" is there any way to resolve this
|
|
|
|
|
Hi,
what do you mean by "read that csv in Notepad using C#"? Maybe you could post the piece of code doing this?
Regards
Sebastian
|
|
|
|
|
Hi, according to the output, i think, the standard seperator in your system should be ',' not ';'.
|
|
|
|
|
If you are looking at the value in the debugger, you will see that sort of thing(though usually with backslashes (\)), but it's just the display format, nothing to worry about.
How did you create file? How are you reading it?
|
|
|
|
|
Hi,
I had window Form application in which some text is entered in TextBox and On a button Click, the text in the textbox should be copied through clipboard and those text has to be pasted on other window which has been opened.
I have copied the text through
if(String.IsEmptyORNull(TextBox1.Text))
string CopiedText = ClipBoard.SetText(TextBox1.Text);
i.e., For example, If I want to paste the copied text in the internet explorer in which http;//www.google.com/ is opened, I have to paste that copied text in the searchbox of google site opened in internet explorer.
I have tried to Find the handle through
IntPtr IEHwnd = FindWindow("IEFrame", Null);
and there after
If(IEHwnd != IntPtr.Zero)
{
MessageBox.Show("Handle Found");
SendMessage(IEHwnd, WM_PASTE,0,0);
}
But This is also doesn't effect?
How to approach?
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
Hello,
I am having an enumerator problem while making a custom panel user control. The control extends the System.Windows.Forms.Panel with properties to allow a user to draw a background gradients and rounded border edges.
I use a bit wise enumerator to control which rounded corners are drawn on the border. This all works fine until i make a public property that is accessible in the visual studio designer. The designer will display the default setting when the control is added to a form, but when you change the value of the property it crashes visual studio.
---
The enum...
public enum RectangleCorners
{
None = 0,
TopLeft = 1, TopRight = 2, BottomLeft = 4, BottomRight = 8,
All = TopLeft | TopRight | BottomLeft | BottomRight
}
---
the implementation...
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Ez_Backup.UserControls
{
public class Panel : System.Windows.Forms.Panel
{
private RoundedRectangle.RectangleCorners pRoundedBorderCorners;
public RoundedRectangle.RectangleCorners RoundedBorderCorners
{
get
{
return pRoundedBorderCorners;
}
set
{
RoundedBorderCorners = value;
base.Refresh();
}
}
}
}
I believe i possibly may be required to add some type of designer attribute. After an hour of google action I am here.
Please help me.
Thanks
|
|
|
|
|
First thing that jumped right(not left ) into my eyes was the lack of the Flags atributte.
You must use it if you want to create combination(s) of the Enums wich you are doing by using the bitwise or (|) operator.
Something like this:
[Flags]
enum Days
{
None = 0x0,
Sunday = 0x1,
Monday = 0x2,
Tuesday = 0x4,
Wednesday = 0x8,
Thursday = 0x10,
Friday = 0x20,
Saturday = 0x40
}
|
|
|
|