玩家结构体和枚举

img

玩家结构体包含了玩家类型玩家位置玩家初始化构造函数还有画自己的函数方法

玩家结构体
enum E_PlayerType//玩家类型的枚举
{
    Player,
    Robot,
}
struct Player
{
    public E_PlayerType type;
    //用地图上的索引代替坐标
    public mapIndex;
    public Player(int index,E_PlayerType type)
    {
        mapIndex=index;
        this.type=type;
    }
    //用Map结构体申明一个mapInfo作为参数传入Draw
    public void Draw (Map mapInfo)
    {
        //用Grid结构体申明一个变量grid,再从mapInfo中获取索引信息
        Grid grid=mapInfo.grids[mapIndex];
        Console.SetCursorPosition(grid.pos.x,grid.pos.y);
        switch (E_PlayerType)
        {
            case E_PlayerType.Player:
            Console.Foregroundcolor=ConsoleColor.Cyan;
            Console.Write("★");
            break;
            case E_PlayerType.Robot:
            Console.Foregroundcolor=ConsoleColor.Megenta;
            Console.Write("▲");
            break;
        }
    }
}

玩家初始化
Player player = new Player(0,E_PlayerType.Player);
Player robot = new Player(0,E_PlayerType.Robot);
DrawPlayer(player,robot,map);
玩家初始化
static void DrawPlayer(Player player,Player robot,Map map)
{
    if(player.mapIndex==robot.mapIndex)
    {
        Grid grid = map.grids[player.mapIndex];
        Console.SetCursorPosition(grid.pos.x,grid.pos_y);
        Console.Foregroundcolor = ConsoleColor.DrakGreen;
        Console.Write("⚪");
    }
    else
    {
        player.Draw(map);
        robot.Draw(map);
    }
}
posted @   cannedmint  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示