-1
我正在创建一个僵尸生存RPG游戏,并且当我按下按钮(从“MainGame”形式的移动按钮) “Look-Out”表单中的字符串会变成我想要的任何内容。 (当用户点击移动按钮,玩家可以看到不同的项目则是最后一次。)c#如何从Form 1中更改字符串按钮单击Form 2
这里是我的代码:
表1(按键移动点击)
public void btn_move_Click(object sender, EventArgs e)
{
if (locationArea == 165 && locationDistrict == 1 && locationSection == 1)
{
}
//SURVIVAL
if (thirst < 0)
{
thirst = 0;
}
if (hunger < 0)
{
hunger = 0;
}
if (thirst == 0)
{
tmr_health.Start();
}
if (hunger == 0)
{
tmr_health.Start();
}
//BEAT GAME
if (gameprogress == 0 && difficultynormal == 1)
{
tmr_health.Stop();
MessageBox.Show("Normal win text", "Congratulations!");
this.Close();
}
if (gameprogress == 0 && difficultyhardcore == 1)
{
tmr_health.Stop();
MessageBox.Show("Hardcore win text", "Congratulations!");
this.Close();
}
if (gameprogress == 0 && difficultyinsane == 1)
{
tmr_health.Stop();
MessageBox.Show("Insane win text", "Congratulations!");
this.Close();
}
if (gameprogress == 0 && difficultyimpossible == 1)
{
tmr_health.Stop();
MessageBox.Show("Impossible win text", "Congratulations!");
this.Close();
}
if (rb_crouching.Checked == true)
{
timehour = timehour + 1;
}
gameprogress = gameprogress - 1;
//Int to Label
lbl_gameprogressvalue.Text = gameprogress.ToString();
lbl_locationDistrictValue.Text = locationDistrict.ToString();
lbl_timeHour.Text = timehour.ToString();
lbl_locationSectionValue.Text = locationSection.ToString();
lbl_locationAreaValue.Text = locationArea.ToString();
lbl_ingamehungervalue.Text = hunger.ToString();
lbl_ingamethirstvalue.Text = thirst.ToString();
//STAT DEPLEATION
if (rb_walking.Checked == true)
{
thirst = thirst - 10;
hunger = hunger - 5;
}
if (rb_jogging.Checked == true)
{
thirst = thirst - 15;
hunger = hunger - 10;
}
if (rb_sprinting.Checked == true)
{
thirst = thirst - 20;
hunger = hunger - 15;
}
if (rb_crouching.Checked == true)
{
thirst = thirst - 5;
hunger = hunger - 5;
}
timehour = timehour + 1;
locationSection = locationSection + 1;
if (timehour > 12 && lbl_timeEnding.Text == "AM")
{
timehour = 1;
lbl_timeEnding.Text = PM;
}
if (lbl_timeEnding.Text == PM && timehour > 12)
{
lbl_timeEnding.Text = "AM";
timehour = 1;
dateday = dateday + 1;
dayssurvived = dayssurvived + 1;
lbl_dayssurvivedvalue.Text = dayssurvived.ToString();
lbl_dateDay.Text = dateday.ToString();
}
if (locationSection == 11)
{
locationSection = 0;
locationDistrict = locationDistrict + 1;
}
if (locationDistrict == 6)
{
locationDistrict = 0;
locationArea = locationArea + 1;
}
}
表2(数据这需要改变)
public partial class Look_out : Form
{
string item1 = "";
string item2 = "";
string item3 = "";
string item4 = "";
string item5 = "";
public Look_out()
{
InitializeComponent();
item1 = "Butterfly Knife";
item2 = "";
//String to Label
lbl_item1.Text = item1;
lbl_item2.Text = item2;
lbl_item1.Visible = true;
if (item1 == "")
{
}
}
}
你需要在'Loo中写入方法k_out'类来接受字符串并且做你想要的东西 – jdphenix
你也应该考虑使用[switch语句](https://msdn.microsoft.com/en-us/library/06tc147t.aspx)而不是嵌套很多如果声明。 – Eminem