2020-11-10

记录c#学习笔记


第七章:类成员

实验8-1:

实验要求:
1. 定义2个类,玩家类(Player)、枪类(Gun)。
2. 枪类使用静态成员实现2种枪开枪功能,一种枪为“biu~biu~”,一
种枪为“boom~boom~”。
3. 玩家类都为实例成员,具有2把枪的开枪功能的方法(调用枪类的静
态方法);具有前进功能“gogogo!”;具有后退功能“跑啊!”。
4. 在Main函数中实例化玩家类,并循环判断用户输入数字进行操作。
前进:1,后退:2,开第一把枪:3,开第二把枪:4,退出:0。

 

实现:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace qiang
{
    class Player
    {
        public static  void Theone()
        {
            Console.WriteLine("gogogogo");
        }
        public static void Thetwo()
        {
            Console.WriteLine("跑啊!");
        }
    }
    class Gun
    {
        public static void shoot()
        {
            Console.WriteLine("biu---biu--biu-biu");
        }
        public static void  boom(){
            Console.WriteLine("boom-boom-boom");
        }
    }
    class Interface{
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎来到游戏界面");
            Console.WriteLine("前进:1,后退:2,开一枪:3,开第二枪:4,退出:0");
            while (true)
            {
                Console.WriteLine("请输入操作命令:");
                switch (Console.ReadLine())
                {
                    case "1":
                        Player.Theone();
                        break;
                    case"2":
                        Player.Thetwo();
                        break;
                    case"3":
                        Gun.shoot();
                        break;
                    case"4":
                        Gun.boom();
                        break;
                    case "0":
                        Console.WriteLine("关闭游戏:");
                        Console.ReadLine();
                        return;
                    default:
                        Console.WriteLine("无效操作,请重新输入:");
                        break;
                }
            }
        }
    }
}

实现效果如图所示:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值