小编Cis*_*ran的帖子

C#中的小行星游戏运动

我正在尝试制作游戏小行星.我现在的问题是,如果按下向上箭头键,它会将"船"向上移动10个像素.如果你按下LEFT箭头键,它会将"船"向左转5度,当你向左转或向右转时我就会发挥作用.然后尝试向上移动.它不会进入转向的方向.它只会将转向的"船"向Y方向移动10度.

What I am thinking of doing is having a variable called direction, think of this variable as a circle with 360 degrees. What I am trying to do is everytime I hit the Left Arrow, it will subtract 5 from direction, which started at 0 and goes backwards from 360 and thus set it to 355. I would then divide 355 by 10 and get 35.5. Then I would divide 10 by 35.5 and get .355. I would then …

c# angle game-physics bresenham

4
推荐指数
1
解决办法
2788
查看次数

空路径名称不合法

所以我正在尝试编译一个Asteroids游戏.它几乎正常工作,所有文件都到位等等......

当它遇到这个代码时会出现问题.

FileStream myFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
string myTempFile = @"F:\Documents\Junior School\Computer Programming (Java 1)\AsteroidsWithSound\AsteroidsWithSound\temp\mysound" + i.ToString() + ".wav";
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误/警告,不知道究竟它叫什么,但它说

ArgumentException未处理.空路径名称不合法.

我在网上看过像这样的代码块引起了这个问题但却找不到解决方案.任何帮助都是极好的.

编辑:文件名在此块中定义.

string filename = this.Player.FileName;
this.Player.Open("");
File.Delete(filename);
this.isReady = true;
Run Code Online (Sandbox Code Playgroud)

c# filestream argumentexception

4
推荐指数
1
解决办法
3万
查看次数

'在与指定绑定约束匹配的类型上调用构造函数会引发异常

所以我正在尝试构建一个访问Etsy API的程序,到目前为止,我要做的就是使用OAuth调用它,它会抛出此异常.

'对匹配指定绑定约束的类型'testEtsy.MainWindow'的构造函数的调用引发了异常.行号"3"和行位置"9".

这是我的XAML

<Window x:Class="testEtsy.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid></Grid>
Run Code Online (Sandbox Code Playgroud)

这是我在MainWindow.cs中的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace testEtsy
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }
        string[] orderNumbers = System.IO.File.ReadAllLines(@"F:\ordernumbers.txt");

        public static void getOAuthKey()
        {

            string ConsumerKey = "q6uqzk27z2yw4tl5s4qerdtp";
            string ConsumerSecret …
Run Code Online (Sandbox Code Playgroud)

c# xaml exception-handling

4
推荐指数
1
解决办法
3万
查看次数

键盘模拟按钮单击C#

好的,所以我正在制作一个Tic-Tac-Toe游戏来帮助我学习C#.我正在尝试为它添加一些功能,所以我希望人们能够在计算机上使用NumPad来模拟单击按钮.

这是我所拥有的,但是当我使用NumPad时,按钮不会单击.你们中的任何人都能看到原因吗?

    //===============================
    // start NumPad Simulate Clicks
    //   NumPad  MyButtons
    //   7 8 9   1 2 3
    //   4 5 6   4 5 6 
    //   1 2 3   7 8 9
    //===============================
    public void myControl_NumPad7(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.NumPad7)
        {
            button1_Click(null, null);
        }
    }
    public void myControl_NumPad8(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.NumPad8)
        {
            button2_Click(null, null);
        }
    }
    public void myControl_NumPad9(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.NumPad9)
        {
            button3_Click(null, null);
        } …
Run Code Online (Sandbox Code Playgroud)

c# click keypress simulate

2
推荐指数
1
解决办法
2万
查看次数

'insert_method_here'没有重载匹配委托'System.EventHandler'

我正在尝试构建一个具有按钮的程序,每次单击该按钮时,它都会移动按钮并添加到分数中.但是,我试图禁用Enter键,或按下时禁止命令.这是我到目前为止所拥有的

private void button1_Click(object sender, EventArgs e, KeyEventArgs k)
    {
        if (k.KeyCode == Keys.Enter)
        {
            k.SuppressKeyPress = true;
        }
        score = score + 10;
        timesClicked++;
        int rand1 = RandomNumber(1, 400);
        int rand2 = RandomNumber(1, 400);
        button1.Location = new Point(rand1, rand2);
        toolStripScore.Text = ("Your score is " + score);
        toolStripClicks.Text = ("You've clicked the button{0} times " + timesClicked);
        winCheck();
    }
Run Code Online (Sandbox Code Playgroud)

这是我为阻止输入密钥进入而添加的内容.

if (k.KeyCode == Keys.Enter) { k.SuppressKeyPress = true; }
Run Code Online (Sandbox Code Playgroud)

然而,它会生成错误..."'button1_Click'没有重载匹配委托'System.EventHandler'"当单击以显示位置时,它会打开Form1.Designer的代码并指向此行."this.button1.Click + = new System.EventHandler(this.button1_Click);"

任何有关解决此问题的帮助都将非常感激.

c# error-handling suppression keyeventargs

2
推荐指数
1
解决办法
3万
查看次数

用C#杀死一个进程

所以我只想尝试探索C#的复杂性,我想制作一个简单的程序来杀死一个进程.是的,我知道,这就是任务管理器的用途,但这应该是一次学习经历,这是我到目前为止所做的.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace endProcess
{
    class Program
    {

        private Process GetaProcess(string processname)
        {
            Process[] aProc = Process.GetProcessesByName(processname);

            if (aProc.Length > 0)
                return aProc[0];

            else return null;
        }
        string selectProcess = "";
        static void Main(string[] args)
        {
            Console.WriteLine("What process do you want to kill?");
            selectProcess = Console.ReadLine();
            Process myprc = Call GetAProcess(selectProcess);
            myprc.Kill();
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这个问题出现在我发表评论的地方.它说GetAProcess之后应该有一个分号,我不明白为什么.任何帮助将非常感激.

c#

2
推荐指数
1
解决办法
1175
查看次数

字段永远不会分配给并且始终将其默认值保留为null

我目前在类文件中有2个bool数组,如下所定义

public static bool[] bArray;
public static bool[] randomRemove;
Run Code Online (Sandbox Code Playgroud)

我填写bArray像这样

public static void fillArray()
{
    for (int x = 0; x < 54; x++)
    {
        bArray[x] = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

我填写randomRemove像这样

for (int i = 0; i < sizeOfArray; i++)
{
    randomRemove[i] = false;
}
Run Code Online (Sandbox Code Playgroud)

sizeOfArray我使用的字符串数组的长度在哪里.

我对每个bool数组都有两个警告,表示它们从未被赋值,并且总是将其默认值设置为null,但我显然有代码分配它们.每当我尝试单击使用数组的按钮时,我都会遇到运行时错误.这有什么原因吗?

c# null warnings runtime-error default-value

2
推荐指数
1
解决办法
6649
查看次数

比较C#中的字符串

好的,我试图每15秒比较两个字符串,然后更新信息框.

以下是我到目前为止从Web获取文本文档并将其存储到字符串中的代码:

public String GetData(String url)
{
    WebRequest request = WebRequest.Create(url);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    String data = reader.ReadToEnd();
    reader.Close();
    dataStream.Close();
    response.Close();
    return data;
}
Run Code Online (Sandbox Code Playgroud)

这就是我试图比较字符串的方法.

public void CompareStrings()
{
    int x;
    x = 1;
    String data = GetData("http://xcastradio.com/stats/nowplaying.txt");
    string savedData = data;
    while (x > 0 && x < 100000001)
    {
        x++;
    }
    String data1 = GetData("http://xcastradio.com/stats/nowplaying.txt");
    NowPlayingInfo1.Text = data;
    NowPlaying np = new NowPlaying();
    if (data1 != savedData)
    { …
Run Code Online (Sandbox Code Playgroud)

c# string compare

1
推荐指数
1
解决办法
776
查看次数

C++中的运算符重载

所以我在基础编程II课程.我们必须创建一个程序,使4个不同的函数改变运算符的工作方式.我已经查找了多个显示如何执行此操作的示例和文本集,但我无法确定任何代码的含义.对我来说这样的事情应该有效.

int operator++()
{
    variableA--;
}
Run Code Online (Sandbox Code Playgroud)

对我来说,这说如果你遇到一个++,那么 - 从变量,现在很明显它不会像这样工作.我发现的所有示例都创建了自己的数据类型.有没有办法使用a int或a 来超载运算符double

c++ overloading operator-overloading operator-keyword

0
推荐指数
1
解决办法
198
查看次数