用C#制作RPG游戏

有点简陋,呵呵。

首先血量,攻击力等弄个属性以方便以后扩展程序:

    public int HP { get; set; }//血量
    public long ATK { get; set; }//攻击力
    public int defense { get; set; }//防御力
    public int money { get; set; }//钱
    public short san { get; set; }//san值
    public long Monster1_HP { get; set; }
    public long Monster2_HP { get; set; }
    public int Monster1_ATK { get; set; }
    public int Monster2_ATK { get; set; }

等以后一时兴起可以在属性块中增添逻辑以此来改变各种值。例如如果我想弄个困难就可以在属性块中进行相应的逻辑处理 (如下所示):

public double A;
public double a
{
get
{
return A;
}
set
{
A=value*0.3;
}
}

因为现在属性块中没有逻辑,所以可以使用自动属性。这时,编译器会给你自动配个字段

关于属性,1.读取该值时花的时间不应太长。2.用属性还可以增加安全性,一般与属性配对的字段都用private来修饰。3.别动不动对一些无关紧要的字段用属性,这没必要,反而增加开销

然后我们在基类中用个构造函数:

    public Basis(int hp, long atk, int Money, short San, int Defense, int monster1_HP, int monster2_HP, int monster1_ATK, int monster2_ATK)
    {
        HP = hp;
        ATK = atk;
        money = Money;
        san = San;
        defense = Defense;
        Monster1_HP = monster1_HP;
        Monster2_HP = monster2_HP;
        Monster1_ATK = monster1_ATK;
        Monster2_ATK = monster2_ATK;

    }

当我们在继承的类中有 有参构造函数时,要在派生类中提供对应的实参,这可以用base关键字解决:

class B
	{
		public int b;
		public B(int a)
		{
			b=a;
		}
	}
   class A:B
   {
   public A():base (2)
   {
   }

可以用this关键字来用当前类的另外一些构造函数:

	   public int b;
   public A(int c)
   {
   b=c;
   }
   public A():this (4)
   {
	   
   }

不要把需要在某个特定时期执行的代码放在静态构造函数中,因为.NET库不确保它什么时候执行

一个类只能由一个静态函数 

swith有switch表达式,用=>来表示返回值,下划线表示默认值

技能代码:

public void Ji()
        {
            Random random = new();
            int jineng = random.Next(1, 4);
            if (hero > 0)
            {
                if (guai2 == 1 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到了平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                for (int i = 0; i < 3; i++)
                                {
                                    HP -= (Monster1_ATK -= defense);
                                    Monster1_ATK += defense;
                                    WriteLine("你遭到了连续打击");
                                    WriteLine($"你还有{HP}血");
                                }
                                break;
                            case 3:
                                Monster1_ATK += 30;
                                WriteLine($"怪物的攻击力升级了,现在为{Monster1_ATK}");
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血1");
                    }
                }

                if (guai2 == 2 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到1号怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                san -= 2;
                                WriteLine($"你遭到精神污染,san值为{san}");
                                break;
                            case 3:
                                Monster1_HP += 100;
                                WriteLine($"怪物的血量恢复了{Monster1_HP}");
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (guai2 == 2 && Monster2_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster2_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster2_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到2号怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                HP -= 200;
                                WriteLine($"你遭到了2号怪物的真实伤害{HP}");
                                break;
                            case 3:
                                Monster2_HP += 200;
                                WriteLine($"2号怪物的血量恢复了{Monster2_HP}");
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (guai2 == 3 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                if (san >= 40)
                                {
                                    san = 10;
                                    WriteLine($"你遭到了怪物的真理碾压,san值为{san}");
                                }
                                break;
                            case 3:
                                if (count % 4 == 0)
                                {
                                    HP -= 1250;
                                    WriteLine($"你一下子遭到了高级凝视,一下子失去大量血量,你还有{HP}血");
                                }
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (hero == 1 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 0)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                if (san < 60)
                                {
                                    Monster1_ATK += 1000;
                                    WriteLine($"恐惧,怪物的攻击力升级了,现在为{Monster1_ATK}");
                                }
                                break;
                            case 3:
                                if (Monster1_HP <= 0)
                                {
                                    Monster1_HP += 2000;
                                    WriteLine($"怪物的血量恢复了{Monster1_HP}");
                                }
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (hero == 2 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 0)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                if (HP <= 5000)
                                {
                                    HP -= 10000000;
                                    WriteLine($"你遭到了怪物的斩杀,还有{HP}血");
                                }
                                break;
                            case 3:
                                tag += 10;
                                break;
                        }
                        if (tag >= 10)
                        {
                            HP -= 300;
                            tag--;
                            WriteLine($"你遭到了火焰灼烧,还剩{HP}");
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
            }
        }

 商店代码

                if (input == "商店")
                {
                    Shop();
                }
                switch (input)
                {
                    case "血瓶":
                        if (money >= 300)
                        {
                            HP += 250;
                            money -= 300;
                            WriteLine($"你的血量为{HP}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "硬化药水":
                        if (money >= 500)
                        {
                            defense += 3;
                            money -= 500;
                            WriteLine($"你的防御力为{defense}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "巧克力":
                        if (money >= 600)
                        {
                            san += 5;
                            money -= 600;
                            WriteLine($"你的san值为{san}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "强化药水":
                        if (money >= 400)
                        {
                            ATK += 20;
                            money -= 400;
                            WriteLine($"你的攻击力为{ATK}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "八卦阵":
                        if (money >= 2000 && wuzhuang == 1)
                        {
                            defense += 50;
                            money -= 2000;
                            WriteLine($"你的防御力为{defense}");
                            WriteLine($"你的金币为{money}");
                            wuzhuang -= 1;
                            list.Remove("八卦阵--2000元");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                    case "圣剑":
                        if (money >= 1000 && sword == 1)
                        {
                            money -= 1000;
                            q2.Sworddef();
                            WriteLine($"你的金币为{money}");
                            list.Remove("圣剑--1000元");
                            sword -= 1;
                            GoodEnd += 1;
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                    case "鸟嘴面具":
                        if (money >= 1000 && bird == 1)
                        {
                            money -= 1000;
                            q2.Birddef();
                            WriteLine($"你的金币为{money}");
                            list.Remove("鸟嘴面具--1000元");
                            bird -= 1;
                            GoodEnd += 1;
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                    case "左右互搏":
                        if (money >= 4000 && orsoand == 1)
                        {
                            money -= 4000;
                            ATK += 200;
                            WriteLine($"你的金币为{money}");
                            WriteLine($"你的攻击力为{ATK}");
                            list.Remove("左右互搏--5000元");
                            orsoand -= 1;
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                }

初始化怪物血量:

        public void Monster()
        {
            var q2 = new Game();
            if (checkpoint == 3)
            {
                switch (guai2)
                {
                    case 1:
                        q2.Monster();
                        checkpoint -= 1;
                        Monster1_ATK = 150;
                        Monster1_HP = 8000;
                        WriteLine($"怪物的攻击力为{Monster1_ATK}");
                        WriteLine($"怪物的血量为{Monster1_HP}");
                        break;
                    case 2:
                        q2.Monster2();
                        checkpoint -= 1;
                        Monster1_ATK = 200;
                        Monster1_HP = 5000;
                        Monster2_ATK = 300;
                        Monster2_HP = 3000;
                        WriteLine($"怪物的攻击力为{Monster1_ATK}");
                        WriteLine($"怪物的血量为{Monster1_HP}");
                        WriteLine($"怪物的攻击力为{Monster2_ATK}");
                        WriteLine($"怪物的血量为{Monster2_HP}");
                        break;
                    case 3:
                        q2.Monster3();
                        checkpoint -= 1;
                        Monster1_ATK = 300;
                        Monster1_HP = 20000;
                        WriteLine($"怪物的攻击力为{Monster1_ATK}");
                        WriteLine($"怪物的血量为{Monster1_HP}");
                        break;
                }
            }
            if (checkpoint == 1 && hero == 1)
            {
                q2.Monster4();
                checkpoint -= 1;
                Monster1_HP = 20000;
                Monster1_ATK = 500;
                WriteLine($"怪物的攻击力为{Monster1_ATK}");
                WriteLine($"怪物的血量为{Monster1_HP}");
            }
            if (checkpoint == 1 && hero == 2)
            {
                q2.Monster5();
                checkpoint -= 1;
                Monster1_ATK = 900;
                Monster1_HP = 15000;
                WriteLine($"怪物的攻击力为{Monster1_ATK}");
                WriteLine($"怪物的血量为{Monster1_HP}");
            }
        }

完整代码如下:

using System.Collections.Generic;
using static System.Console;
using System;
using System.IO;
using static System.IO.Directory;
using static System.IO.Path;
using static System.Environment;
class Basis
{
    public int HP { get; set; }//血量
    public long ATK { get; set; }//攻击力
    public int defense { get; set; }//防御力
    public int money { get; set; }//钱
    public short san { get; set; }//san值
    public long Monster1_HP { get; set; }
    public long Monster2_HP { get; set; }
    public int Monster1_ATK { get; set; }
    public int Monster2_ATK { get; set; }
    public Basis(int hp, long atk, int Money, short San, int Defense, int monster1_HP, int monster2_HP, int monster1_ATK, int monster2_ATK)
    {
        HP = hp;
        ATK = atk;
        money = Money;
        san = San;
        defense = Defense;
        Monster1_HP = monster1_HP;
        Monster2_HP = monster2_HP;
        Monster1_ATK = monster1_ATK;
        Monster2_ATK = monster2_ATK;

    }
    public byte hero = 0;//判定英雄
    public short count = 1;//回合
    public static Random guai = new();
    public int guai2 = guai.Next(1, 4);//判定怪
    public byte GoodEnd = 0;//触发真结局点数
    public byte wuzhuang = 2;//装备
    public byte orsoand = 1;
    public byte sword = 1;
    public byte bird = 1;
    public List<string> list = new();//固定清单
    public sbyte checkpoint = 3;
    public int tag = 0;
}

class Game
{
    public void Text1()
    {
        ReadLine();
        Clear();
    }
    public void Welcome()
    {
        WriteLine("欢迎来到此游戏");
        WriteLine("额,呵呵,游戏开始");
        WriteLine("输入商店看东西,看完后随字符串买。如显示血瓶--300元则输入血瓶来购买");
        WriteLine("请先选择角色,这个很重要.输入狙击手来选择狙击手,按战士选择战士");
        WriteLine("按1杀怪,有两个怪的按2来杀第二个怪");
    }
    public void Warrior()
    {
        WriteLine("你叫塞恩,是一名强大的战士");
        WriteLine("在几百年前,人类的一颗星球遭到了一种神秘生物的袭击");
        Text1();
        WriteLine("人类引以为豪的星舰部队在神秘生物面前不堪一击");
        WriteLine("虽然人类帝国顽强抵抗,但神秘生物依然快速地占领了人类99%的空间站以及星球");
        WriteLine("剩余的人类全部聚集回地球,在地球上建立了最后的据点准备绝地反击");
    }
    public void Ju()
    {
        WriteLine("你就是一个十分普通的狙击手");
    }
    public void Sworddef()
    {
        WriteLine("一把奇异的宝剑出现在了你的面前");
        WriteLine("透过奇异的纹路你隐约发现剑身内的能量在流动");
        WriteLine("当你手握这把剑时,你便坚信--我的剑所触及的地方,就是我的国家(银魂)");
    }
    public void Birddef()
    {
        WriteLine("一个黑色的鸟嘴面具降到了你的手上");
        WriteLine("银质的鸟嘴中夹杂着奇异的药草");
        WriteLine("当你戴上它时,你便是黑死病人的唯一希望");
    }
    public void Monster()
    {
        WriteLine("你随着小队来到了一个废弃的太空站中");
        WriteLine("这时,一个身穿黑色套装掌握着原X力量的家伙出现在了你的面前");
    }
    public void Monster2()
    {
        WriteLine("你随着小队来到了一个废弃的太空站中");
        WriteLine("正当你们降落时,两只怪物闯进了你们的飞船");
    }
    public void Monster3()
    {
        WriteLine("在靠近空间站外围时,一个长满触须的家伙拦下了你们");
        WriteLine("在深嵌触须群中,一颗散发着死亡气息的眼睛在死死地盯着你们");
    }
    public void Monster4()
    {
        WriteLine("一个很普通的家伙走了过来");
    }
    public void Monster5()
    {
        WriteLine("你和你的小队一路横杀,最终来到了管理室");
        WriteLine("打开门,一个眼睛部分被衣帽遮住的男人翘着二郎腿坐在正中央");
        WriteLine("衣帽左黑右白,黑白交汇处绘制着一个猩红的眼睛");
    }
    public void Die()
    {
        WriteLine("你输了!弱者! !");
    }
    public void Achievement()//创建成就
    {
        var achievement = Combine(GetFolderPath(SpecialFolder.Personal), "Chengjiu", "Chengjiu01", "Chengjiu");
        WriteLine(achievement);
        CreateDirectory(achievement);
        string a = Combine(achievement, "成就.txt");//创建成就txt 文本文件
        StreamWriter text = File.CreateText(a);
        text.WriteLine("谢谢你的游玩:)");//写入文本
    }

    class BeginGame : Basis
    {
        public BeginGame() : base(0, 0, 0, 0, 0, 0, 0, 0, 0)
        {
        }
        public void A()
        {
            WriteLine($"你的血量为{HP}");
            WriteLine($"你的攻击力为{ATK}");
            WriteLine($"你的防御力为{defense}");
            WriteLine($"你的金币为{money}");
            WriteLine($"你的san值为{san}");
        }
        public void Shop()
        {
            WriteLine("血瓶--300元");
            WriteLine("硬化药水--500元");
            WriteLine("强化药水--400元");
            WriteLine("巧克力--600元");
            if (wuzhuang == 2 && orsoand == 1 && sword == 1 && bird == 1)
            {
                list.Add("八卦阵--2000元");
                list.Add("左右互搏--5000元");
                list.Add("圣剑--1000元");
                list.Add("鸟嘴面具--1000元");
                wuzhuang -= 1;
            }
            foreach (string a in list)
            {
                WriteLine(a);
            }
        }
        public void Monster()
        {
            var q2 = new Game();
            if (checkpoint == 3)
            {
                switch (guai2)
                {
                    case 1:
                        q2.Monster();
                        checkpoint -= 1;
                        Monster1_ATK = 150;
                        Monster1_HP = 8000;
                        WriteLine($"怪物的攻击力为{Monster1_ATK}");
                        WriteLine($"怪物的血量为{Monster1_HP}");
                        break;
                    case 2:
                        q2.Monster2();
                        checkpoint -= 1;
                        Monster1_ATK = 200;
                        Monster1_HP = 5000;
                        Monster2_ATK = 300;
                        Monster2_HP = 3000;
                        WriteLine($"怪物的攻击力为{Monster1_ATK}");
                        WriteLine($"怪物的血量为{Monster1_HP}");
                        WriteLine($"怪物的攻击力为{Monster2_ATK}");
                        WriteLine($"怪物的血量为{Monster2_HP}");
                        break;
                    case 3:
                        q2.Monster3();
                        checkpoint -= 1;
                        Monster1_ATK = 300;
                        Monster1_HP = 20000;
                        WriteLine($"怪物的攻击力为{Monster1_ATK}");
                        WriteLine($"怪物的血量为{Monster1_HP}");
                        break;
                }
            }
            if (checkpoint == 1 && hero == 1)
            {
                q2.Monster4();
                checkpoint -= 1;
                Monster1_HP = 20000;
                Monster1_ATK = 500;
                WriteLine($"怪物的攻击力为{Monster1_ATK}");
                WriteLine($"怪物的血量为{Monster1_HP}");
            }
            if (checkpoint == 1 && hero == 2)
            {
                q2.Monster5();
                checkpoint -= 1;
                Monster1_ATK = 900;
                Monster1_HP = 15000;
                WriteLine($"怪物的攻击力为{Monster1_ATK}");
                WriteLine($"怪物的血量为{Monster1_HP}");
            }
        }
        public void Ji()
        {
            Random random = new();
            int jineng = random.Next(1, 4);
            if (hero > 0)
            {
                if (guai2 == 1 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到了平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                for (int i = 0; i < 3; i++)
                                {
                                    HP -= (Monster1_ATK -= defense);
                                    Monster1_ATK += defense;
                                    WriteLine("你遭到了连续打击");
                                    WriteLine($"你还有{HP}血");
                                }
                                break;
                            case 3:
                                Monster1_ATK += 30;
                                WriteLine($"怪物的攻击力升级了,现在为{Monster1_ATK}");
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血1");
                    }
                }

                if (guai2 == 2 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到1号怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                san -= 2;
                                WriteLine($"你遭到精神污染,san值为{san}");
                                break;
                            case 3:
                                Monster1_HP += 100;
                                WriteLine($"怪物的血量恢复了{Monster1_HP}");
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (guai2 == 2 && Monster2_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster2_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster2_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到2号怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                HP -= 200;
                                WriteLine($"你遭到了2号怪物的真实伤害{HP}");
                                break;
                            case 3:
                                Monster2_HP += 200;
                                WriteLine($"2号怪物的血量恢复了{Monster2_HP}");
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (guai2 == 3 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 2)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                if (san >= 40)
                                {
                                    san = 10;
                                    WriteLine($"你遭到了怪物的真理碾压,san值为{san}");
                                }
                                break;
                            case 3:
                                if (count % 4 == 0)
                                {
                                    HP -= 1250;
                                    WriteLine($"你一下子遭到了高级凝视,一下子失去大量血量,你还有{HP}血");
                                }
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }
                if (hero == 1 && Monster1_HP >= 0 && count % 2 == 0 && checkpoint == 0)
                {
                    if (defense <= Monster1_ATK)
                    {
                        switch (jineng)
                        {
                            case 1:
                                HP -= (Monster1_ATK -= defense);
                                Monster1_ATK += defense;
                                WriteLine("你遭到怪物的平A");
                                WriteLine($"你还有{HP}血");
                                break;
                            case 2:
                                if (san < 60)
                                {
                                    Monster1_ATK += 1000;
                                    WriteLine($"恐惧,怪物的攻击力升级了,现在为{Monster1_ATK}");
                                }
                                break;
                            case 3:
                                if (Monster1_HP <= 0)
                                {
                                    Monster1_HP += 2000;
                                    WriteLine($"怪物的血量恢复了{Monster1_HP}");
                                }
                                break;
                        }
                    }
                    else
                    {
                        HP -= 1;
                        WriteLine($"你还有{HP}血");
                    }
                }

            }
        }
        public void Win()
        {
            switch (guai2)
            {
                case 1:
                    if (Monster1_HP <= 0)
                    {
                        checkpoint -= 1;
                    }
                    break;
                case 2:
                    if (Monster1_HP <= 0 && Monster2_HP <= 0)
                    {
                        checkpoint -= 1;
                    }
                    break;
                case 3:
                    if (Monster1_HP <= 0)
                    {
                        checkpoint -= 1;
                    }
                    break;
            }
            if (checkpoint == 1 && Monster1_HP <= 0)
            {
                GoodEnd += 1;
            }
            if (GoodEnd == 3)
            {
                WriteLine("你跟你的小队最终杀穿了太空站,成功的摧毁了控制中心");
                WriteLine("游戏结束。感谢您的游玩 :)");
            }
            if (Monster1_HP <= 0 && checkpoint <= 0 && GoodEnd < 3)
            {
                WriteLine("你击杀了眼前的敌人,但随着时间流逝,你慢慢发现眼前敌人的尸体正是自己的队友");
                WriteLine("你看向走廊,四个拥有着特异能力的博士正慢慢靠近这里");
            }
        }
        public void Main2()
        {
            var q2 = new Game();
            do
            {
                string input = ReadLine();
                if (input == "狙击手" && hero == 0)
                {
                    WriteLine("你选择的角色为狙击手");
                    HP = 5000;
                    ATK = 400;
                    defense = 20;
                    money = 3000;
                    san = 40;
                    hero += 1;
                    A();
                    q2.Text1();
                    q2.Ju();
                }
                if (input == "战士" && hero == 0)
                {
                    HP = 8000;
                    ATK = 300;
                    defense = 50;
                    money = 3000;
                    san = 60;
                    hero += 2;
                    A();
                    WriteLine("你选择的角色为战士");
                    WriteLine("请敲回车键");
                    q2.Text1();
                    q2.Warrior();
                }
                //
                if (input == "1" && checkpoint == 2)
                {
                    count++;
                    switch (guai2)
                    {
                        case 1:
                            if (Monster1_HP >= 0)
                            {
                                Monster1_HP -= ATK;
                                WriteLine($"敌人的血量还有{Monster1_HP}");
                            }
                            break;
                        case 2:
                            if (Monster1_HP >= 0)
                            {
                                Monster1_HP -= ATK;
                                WriteLine($"敌人的血量还有{Monster1_HP}");
                            }
                            break;
                        case 3:
                            if (Monster1_HP >= 0)
                            {
                                Monster1_HP -= ATK;
                                WriteLine($"敌人的血量还有{Monster1_HP}");
                            }
                            break;
                    }
                }
                if (input == "2" && Monster2_HP >= 0 && checkpoint == 2 && guai2 == 2)
                {
                    Monster2_HP -= ATK;
                    money += 100;
                    count++;
                    WriteLine($"敌方剩余血量为{Monster2_HP}");
                }
                if (hero == 1 && input == "1" && Monster1_HP >= 0 && checkpoint == 0)
                {
                    Monster1_HP -= ATK;
                    money += 100;
                    count++;
                    WriteLine($"敌方剩余血量为{Monster1_HP}");
                }
                if (hero == 2 && input == "1" && Monster1_HP >= 0 && checkpoint == 0)
                {
                    Monster1_HP -= ATK;
                    money += 100;
                    count++;
                    WriteLine($"敌方剩余血量为{Monster1_HP}");
                }

                Monster();
                Win();
                Ji();
                ///
                if (input == "商店")
                {
                    Shop();
                }
                switch (input)
                {
                    case "血瓶":
                        if (money >= 300)
                        {
                            HP += 250;
                            money -= 300;
                            WriteLine($"你的血量为{HP}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "硬化药水":
                        if (money >= 500)
                        {
                            defense += 3;
                            money -= 500;
                            WriteLine($"你的防御力为{defense}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "巧克力":
                        if (money >= 600)
                        {
                            san += 5;
                            money -= 600;
                            WriteLine($"你的san值为{san}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "强化药水":
                        if (money >= 400)
                        {
                            ATK += 20;
                            money -= 400;
                            WriteLine($"你的攻击力为{ATK}");
                            WriteLine($"你的金币为{money}");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够");
                            count++;
                        }
                        break;
                    case "八卦阵":
                        if (money >= 2000 && wuzhuang == 1)
                        {
                            defense += 50;
                            money -= 2000;
                            WriteLine($"你的防御力为{defense}");
                            WriteLine($"你的金币为{money}");
                            wuzhuang -= 1;
                            list.Remove("八卦阵--2000元");
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                    case "圣剑":
                        if (money >= 1000 && sword == 1)
                        {
                            money -= 1000;
                            q2.Sworddef();
                            WriteLine($"你的金币为{money}");
                            list.Remove("圣剑--1000元");
                            sword -= 1;
                            GoodEnd += 1;
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                    case "鸟嘴面具":
                        if (money >= 1000 && bird == 1)
                        {
                            money -= 1000;
                            q2.Birddef();
                            WriteLine($"你的金币为{money}");
                            list.Remove("鸟嘴面具--1000元");
                            bird -= 1;
                            GoodEnd += 1;
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                    case "左右互搏":
                        if (money >= 4000 && orsoand == 1)
                        {
                            money -= 4000;
                            ATK += 200;
                            WriteLine($"你的金币为{money}");
                            WriteLine($"你的攻击力为{ATK}");
                            list.Remove("左右互搏--5000元");
                            orsoand -= 1;
                            count++;
                        }
                        else
                        {
                            WriteLine("金币数量不够或已经购买");
                            count++;
                        }
                        break;
                }
                if (input == "z")
                {
                    A();
                    count++;
                }
                if (GoodEnd == 3)
                {
                    q2.Achievement();
                    break;
                }
                if (Monster1_HP <= 0 && checkpoint <= 0)
                {
                    break;
                }
                if (san <= 0 || HP <= 0)
                {
                    q2.Die();
                    break;
                }
            } while (true);
        }
        public static void Main()
        {
            var q = new BeginGame();
            Game game = new();
            game.Welcome();
            q.Main2();
            WriteLine("游戏结束,给个赞不过分吧");
            ReadLine();
        }
    }
}

没用的知识第X期:

在c#中,BeginInvoke过时了...

顺便推荐一下<<我有一座恐怖屋>>挺好看的

下期再见 :)

  • 5
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
当然可以!Unity是一个非常强大的3D游戏引擎,可以用来制作各种类型的游戏,包括FPS、RPG、赛车、模拟等等。下面是一些基本步骤和建议,帮助你使用Unity制作一款3D游戏: 1. 下载Unity并安装。你可以从官网(https://unity.com/)下载最新版本的Unity,并按照提示安装到你的电脑上。 2. 学习Unity的基本知识。在开始制作游戏之前,你需要了解Unity的基本概念和工具。可以参考Unity官方文档(https://docs.unity3d.com/Manual/index.html)和视频教程来学习。 3. 设计游戏场景。在Unity中,你可以使用场景编辑器来创建和编辑游戏场景。可以使用Unity自带的资源或者下载第三方资源来装饰场景,如树、草、建筑等等。 4. 创建游戏对象。在Unity中,你可以创建各种游戏对象,如角色、道具、怪物等等。可以使用Unity自带的3D模型或者导入自己制作的模型。 5. 编写游戏逻辑。使用C#或JavaScript等编程语言,编写游戏逻辑代码。例如,控制角色移动、攻击、跳跃等等。 6. 调试和测试。在制作游戏的过程中,需要不断地进行调试和测试,发现并修复bug和问题。 7. 发布游戏。在完成游戏制作后,可以将游戏发布到各种平台,如PC、移动设备、网页等等。可以通过Unity提供的发布工具来发布游戏。 以上是一些基本的步骤和建议,希望能够帮助你入门Unity制作3D游戏。如果你需要更详细的指导和教程,可以在网络上搜索相关的资源,或者参考Unity官方文档和社区。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值