C# 有没有一种方法,我如何使程序在每次分数增加1时,将障碍速度增加1?
有没有一种方法,我如何使程序在每次分数增加1时,将障碍速度增加1?(包含所有if语句的部分)。我想这一定是某种循环,但也许我完全错了。希望有人能帮忙 我是新的编码,所以如果你能像孩子一样解释它,那就太好了 我的节目:C# 有没有一种方法,我如何使程序在每次分数增加1时,将障碍速度增加1?,c#,C#,有没有一种方法,我如何使程序在每次分数增加1时,将障碍速度增加1?(包含所有if语句的部分)。我想这一定是某种循环,但也许我完全错了。希望有人能帮忙 我是新的编码,所以如果你能像孩子一样解释它,那就太好了 我的节目: namespace Arnold { public partial class Form1 : Form { bool jumping = false; int jumpSpeed; int force = 15;
namespace Arnold
{
public partial class Form1 : Form
{
bool jumping = false;
int jumpSpeed;
int force = 15;
int score = 0;
int obstacleSpeed = 15;
Random rand = new Random();
int posisition;
bool isGameOver = false;
public Form1()
{
InitializeComponent();
GameReset();
}
private void mainGameTimerEvent(object sender, EventArgs e)
{
player.Top += jumpSpeed;
txtScore.Text = "score: " + score;
if (jumping == true && force < 0)
{
jumping = false;
}
if (jumping == true)
{
jumpSpeed = -25;
force -= 1;
}
else
{
jumpSpeed = 25;
}
if (player.Top > 364 && jumping == false)
{
force = 15;
player.Top = 365;
jumpSpeed = 0;
}
foreach (Control x in this.Controls)
{
if (x is PictureBox && (string)x.Tag == "Heli")
{
x.Left -= obstacleSpeed;
if (x.Left < -100)
{
x.Left = this.ClientSize.Width + rand.Next(200, 500) + (x.Width * 15);
}
if (player.Bounds.IntersectsWith(x.Bounds))
{
gameTimer.Stop();
player.Image = Properties.Resources.Explosion_2_0;
txtScore.Text += " Press R to restart the game! Or press Q to exit!";
isGameOver = true;
}
}
if (x is PictureBox && (string)x.Tag == "obstacle")
{
x.Left -= obstacleSpeed;
if (x.Left < -100)
{
x.Left = this.ClientSize.Width + rand.Next(200, 500) + (x.Width * 15);
score++;
}
if (player.Bounds.IntersectsWith(x.Bounds))
{
gameTimer.Stop();
player.Image = Properties.Resources.Explosion_2_0;
txtScore.Text += " Press R to restart the game! Or press Q to exit!";
isGameOver = true;
}
}
}
if (score > 5)
{
obstacleSpeed = 20;
}
if(score > 10)
{
obstacleSpeed = 25;
}
if (score > 15)
{
obstacleSpeed = 30;
}
if (score > 20)
{
obstacleSpeed = 35;
}
if (score > 25)
{
obstacleSpeed = 40;
}
if (score > 30)
{
obstacleSpeed = 45;
}
if (score > 35)
{
obstacleSpeed = 50;
}
if (score > 40)
{
obstacleSpeed = 55;
}
if (score > 45)
{
obstacleSpeed = 60;
}
if (score > 50)
{
obstacleSpeed = 65;
}
if (score > 55)
{
obstacleSpeed = 70;
}
if (score > 60)
{
obstacleSpeed = 75;
}
if (score > 65)
{
obstacleSpeed = 80;
}
if (score > 70)
{
obstacleSpeed = 85;
}
if (score > 75)
{
obstacleSpeed = 90;
}
}
private void keyisdown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space && jumping == false)
{
jumping = true;
}
}
private void keyisup(object sender, KeyEventArgs e)
{
if (jumping == true)
{
jumping = false;
}
if (e.KeyCode == Keys.R && isGameOver == true)
{
GameReset();
}
if (e.KeyCode == Keys.Q && isGameOver == true)
{
txtScore.Text = "Are you sure you want to exit the program? (Y/N)";
}
if (e.KeyCode == Keys.Y)
{
Environment.Exit(0);
}
if (e.KeyCode == Keys.N)
{
GameReset();
}
}
private void GameReset()
{
force = 15;
jumpSpeed = 0;
jumping = false;
score = 0;
obstacleSpeed = 15;
txtScore.Text = "Score" + score;
player.Image = Properties.Resources.figur_færdig;
isGameOver = false;
player.Top = 365;
foreach (Control x in this.Controls)
{
if (x is PictureBox && (string)x.Tag == "obstacle")
{
posisition = this.ClientSize.Width + rand.Next(500, 800) + (x.Width * 10);
x.Left = posisition;
}
}
gameTimer.Start();
}
}
}
名称空间Arnold
{
公共部分类Form1:Form
{
布尔跳跃=错误;
国际跳跃速度;
内力=15;
智力得分=0;
int obstacleSpeed=15;
Random rand=新的Random();
内定位;
bool-isGameOver=false;
公共表格1()
{
初始化组件();
GameReset();
}
private void mainGameTimerEvent(对象发送方,事件参数e)
{
player.Top+=跳跃速度;
txtScore.Text=“分数:”+分数;
如果(跳跃==真&&force<0)
{
跳跃=错误;
}
如果(跳跃==真)
{
跳跃速度=-25;
力-=1;
}
其他的
{
跳跃速度=25;
}
如果(player.Top>364&&jumping==false)
{
力=15;
player.Top=365;
跳跃速度=0;
}
foreach(此.Controls中的控件x)
{
如果(x是PictureBox&&(string)x.Tag==“Heli”)
{
x、 左-=障碍速度;
如果(x.左<-100)
{
x、 Left=this.ClientSize.Width+rand.Next(200500)+(x.Width*15);
}
if(玩家边界与(x边界)相交)
{
gameTimer.Stop();
player.Image=Properties.Resources.Explosion_2_0;
Text+=“按R键重新启动游戏!或按Q键退出!”;
isGameOver=true;
}
}
如果(x是PictureBox&&(string)x.Tag==“障碍物”)
{
x、 左-=障碍速度;
如果(x.左<-100)
{
x、 Left=this.ClientSize.Width+rand.Next(200500)+(x.Width*15);
分数++;
}
if(玩家边界与(x边界)相交)
{
gameTimer.Stop();
player.Image=Properties.Resources.Explosion_2_0;
Text+=“按R键重新启动游戏!或按Q键退出!”;
isGameOver=true;
}
}
}
如果(分数>5)
{
障碍速度=20;
}
如果(分数>10)
{
障碍速度=25;
}
如果(分数>15)
{
障碍速度=30;
}
如果(分数>20)
{
障碍速度=35;
}
如果(分数>25)
{
障碍速度=40;
}
如果(分数>30)
{
障碍速度=45;
}
如果(分数>35)
{
障碍速度=50;
}
如果(分数>40)
{
障碍速度=55;
}
如果(分数>45)
{
障碍速度=60;
}
如果(分数>50)
{
障碍速度=65;
}
如果(分数>55)
{
障碍速度=70;
}
如果(分数>60)
{
障碍速度=75;
}
如果(得分>65)
{
障碍速度=80;
}
如果(分数>70)
{
障碍速度=85;
}
如果(分数>75)
{
障碍速度=90;
}
}
私有void keyisdown(对象发送方,KeyEventArgs e)
{
if(e.KeyCode==Keys.Space&&jumping==false)
{
跳跃=正确;
}
}
私有void keyisup(对象发送方,KeyEventArgs e)
{
如果(跳跃==真)
{
跳跃=错误;
}
if(e.KeyCode==Keys.R&&isGameOver==true)
{
GameReset();
}
if(e.KeyCode==Keys.Q&&isGameOver==true)
{
txtScore.Text=“您确定要退出该程序吗?(Y/N)”;
}
if(e.KeyCode==Keys.Y)
{
环境。退出(0);
}
if(e.KeyCode==Keys.N)
{
GameReset();
}
}
私有void GameReset()
{
力=15;
跳跃速度=0;
跳跃=错误;
得分=0;
障碍速度=15;
txtScore.Text=“Score”+分数;
player.Image=Properties.Resources.figuræfærdig;
isGameOver=false;
player.Top=365;
foreach(此.Controls中的控件x)
{
如果(x是PictureBox&&(string)x.Tag==“障碍物”)
{
posisition=this.ClientSize.Width+rand.Next(500800)+(x.Width*10);
x、 左=位置;
}
}
配子
int _score;
int speed;
private int score
{
get
{
return _score;
}
set
{
_score = value;
OnScoreChanged();
}
}
private void OnScoreChanged()
{
speed++;
}
private int score
{
get
{
return _score;
}
set
{
if(_score < value) // When the value of score increases
{
OnScoreIncreased();
}
else if(_score > value) // When the value of score decreases
{
OnScoreDecreased();
}
else
{
_score = value;
}
}
}