IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发测试 -> MVC设计模式制作排行榜 -> 正文阅读

[开发测试]MVC设计模式制作排行榜

using UnityEngine;--------low版------------------------

public class UIHero:MonoBehaviour
{
    public string _name;
    public int score;
    
    public UIHero(string name, int score)
    {
        this._name = name;
        this.score = score;
    }
    
}
using UnityEngine;
using UnityEngine.UI;

public class UILeaderboard : MonoBehaviour
{
    //预设体
    public GameObject leaderPre;
    //生成列表的数组
    private GameObject[] _leaders;
    //英雄类数组
    public UIHero[] heroes;
    private void Start()
    {

        //生成英雄
        UIHero h1 = new UIHero("亚瑟", 80);
        UIHero h2 = new UIHero("妲己", 95);
        UIHero h3 = new UIHero("安琪拉", 96);
        UIHero h4 = new UIHero("赵云", 85);
        UIHero h5 = new UIHero("项羽", 70);
        UIHero h6 = new UIHero("王昭君", 97);
        UIHero h7 = new UIHero("夏侯惇", 81);
        UIHero h8 = new UIHero("白起", 70);
        UIHero h9 = new UIHero("老夫子", 84);
        UIHero h10 = new UIHero("不知火舞", 93);
        UIHero h11 = new UIHero("孙尚香", 99);
        UIHero h12 = new UIHero("孙悟空", 90);
        UIHero h13 = new UIHero("干将莫邪", 94);
        UIHero h14 = new UIHero("刘邦", 74);
        UIHero h15 = new UIHero("韩信", 88);
        UIHero h16 = new UIHero("刘禅", 70);
        UIHero h17= new UIHero("钟馗", 81);
        UIHero h18 = new UIHero("宫本武藏", 90);
        UIHero h19 = new UIHero("武则天", 93);
        UIHero h20 = new UIHero("吕布", 89);

        //将英雄添加到数组
        heroes[0] = h1;
        heroes[1] = h2;
        heroes[2] = h3;
        heroes[3] = h4;
        heroes[4] = h5;
        heroes[5] = h6;
        heroes[6] = h7;
        heroes[7] = h8;
        heroes[8] = h9;
        heroes[9] = h10;
        heroes[10] = h11;
        heroes[11] = h12;
        heroes[12] = h13;
        heroes[13] = h14;
        heroes[14] = h15;
        heroes[15] = h16;
        heroes[16] = h17;
        heroes[17] = h18;
        heroes[18] = h19;
        heroes[19] = h20;
        //生成一个空英雄
        //赋予列表长度
        _leaders = new GameObject[20];
        
        
        //根据分数进行冒泡排序 
        for (int i = 0; i < heroes.Length-1; i++)
        {
            for (int j = 0; j < heroes.Length-i-1; j++)
            {
                if (heroes[j].score<heroes[j+1].score)
                {
                    var nulll = heroes[j];
                    heroes[j] = heroes[j + 1];
                    heroes[j + 1] = nulll;
                }
            }
        }
        for (int i = 0; i <_leaders.Length ; i++)
        {
                //生成预设体
                _leaders[i] = Instantiate(leaderPre, gameObject.transform);
                
                //生成三个文字
                _leaders[i].transform.GetChild(0).GetComponent<Text>().text = (i+1).ToString();
                _leaders[i].transform.GetChild(1).GetComponent<Text>().text = heroes[i]._name;
                _leaders[i].transform.GetChild(2).GetComponent<Text>().text = heroes[i].score.ToString();
        }
        
    }

    private void Update()
    {
       
    }
}
//数据模型类 主要负责数据
public class CharmModel
{
    public string Name
    {
        get;
        set;
    }

    public int Score
    {
        get;
        set;//
    }

    public int Number
    {
        get;
        set;
    }

    public CharmModel(string name, int score, int number)
    {
        Name = name;
        Score = score;
        Number = number;
    }
}








using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//排行榜视图类:负责UI数据的显示,向外界提供UI数据初始化的方法
public class CharmView : MonoBehaviour
{
    private Text numberText;
    private Text nameText;
    private Text scoreText;

    private void Awake()
    {
        nameText = transform.Find("Msg2").GetComponent<Text>();
        numberText = transform.Find("Msg1").GetComponent<Text>();
        scoreText = transform.Find("Msg3").GetComponent<Text>();
    }

    public void Init(CharmModel charmModel)
    {
        nameText.text = charmModel.Name;
        numberText.text = charmModel.Number.ToString();
        scoreText.text = charmModel.Score.ToString();
    }
}







using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;

//排行榜控制类,负责数据的处理,游戏逻辑的相关内容
public class CharmController : MonoBehaviour
{
    //创建预设体
    public GameObject rankPre;
    //数据集合
    private List<CharmModel> _charmModels;
    //视图集合
    private List<CharmView> _charmViews;
    //冒泡优化开关
    private bool k;
    //人物名字号码
    private int playerNum;
    //要删除人物的名字
    private string remName;
    //声明模型数组
    private CharmModel[] topArr;
   

    private void Awake()
    {
        //初始化数据列表
        _charmModels=new List<CharmModel>();
        //初始化视图列表
        _charmViews=new List<CharmView>();
        //初始化数组
        topArr=new CharmModel[5];
        
    }

    private void Start()
    {
        LoadData();
        //Sort();
        //DisplayData();
        DisPlayArrData();
    }

    /// <summary>
    /// 初始化数据
    /// </summary>
    private void LoadData()
    {
        CharmModel c1=new CharmModel("孙悟空",88,1);
        _charmModels.Add(c1);
        CharmModel c2=new CharmModel("唐僧",78,1);
        _charmModels.Add(c2);
        CharmModel c3=new CharmModel("沙和尚",89,1);
        _charmModels.Add(c3);
        CharmModel c4=new CharmModel("白龙马",87,1);
        _charmModels.Add(c4);
        CharmModel c5=new CharmModel("白骨精",98,1);
        _charmModels.Add(c5);
        CharmModel c6=new CharmModel("如来佛祖",58,1);
        _charmModels.Add(c6);
        CharmModel c7=new CharmModel("观世音菩萨",82,1);
        _charmModels.Add(c7);
        CharmModel c8=new CharmModel("哪吒",81,1);
        _charmModels.Add(c8);
        topArr = _charmModels.ToArray();
        //Sort();
        ArrSort();
    }

    /// <summary>
    /// 创建单元格
    /// </summary>
    /// <returns></returns>
    private CharmView CreatView()
    {
        //创建预设体
        GameObject obj = Instantiate(rankPre, transform);
        //添加单元格组件
        CharmView view = obj.AddComponent<CharmView>();
        //添加到集合内
        _charmViews.Add(view);
        return view;
    }
    /// <summary>
    /// 刷新数据
    /// </summary>
    private void DisplayData()
    {
        for (int i = 0; i < _charmModels.Count; i++)
        {
            //传递数据
            CreatView().Init(_charmModels[i]);
        }
    }
    /// <summary>
    /// 对数组数据进行刷新
    /// </summary>
    private void DisPlayArrData()
    {
        for (int i = 0; i < topArr.Length; i++)
        {
            CreatView().Init(topArr[i]);
        }
    }

    /// <summary>
    /// 进行数据排序
    /// </summary>
    private void Sort()
    {
        for (int i = 0; i < _charmModels.Count-1; i++)
        {
            bool k = false;
            for (int j = 0; j < _charmModels.Count-1-i; j++)
            {
                if (_charmModels[j].Score<_charmModels[j+1].Score)
                {
                    CharmModel mm;
                    mm = _charmModels[j];
                    _charmModels[j] = _charmModels[j + 1];
                    _charmModels[j + 1] = mm;
                    k = true;
                }
            }

            if (!k)
            {
                break;
            }
        }

        for (int i = 0; i < _charmModels.Count; i++)
        {
            _charmModels[i].Number = i + 1;
        }
    }

    /// <summary>
    /// 对数组进行排序
    /// </summary>
    private void ArrSort()
    {
        for (int i = 0; i < topArr.Length-1; i++)
        {
            k = false;
            for (int j = 0; j < topArr.Length-1-i; j++)
            {
                if (topArr[j].Score<topArr[j+1].Score)
                {
                    CharmModel cc;
                    cc = topArr[j];
                    topArr[j] = topArr[j + 1];
                    topArr[j + 1] = cc;
                    k = true;
                }
            }

            if (!k)
            {
                break;
            }
        }

        for (int i = 0; i < topArr.Length; i++)
        {
            topArr[i].Number = i + 1;
        }
    }
    /// <summary>
    /// 更新数据
    /// </summary>
    private void RefreshData()
    {
        for (int i = 0; i < _charmModels.Count; i++)
        {
            //传递数据
            _charmViews[i].Init(_charmModels[i]);
        }
    }

    /// <summary>
    /// 对数组数据进行跟新
    /// </summary>
    private void RefreshData(CharmModel[] topArr)
    {
        for (int i = 0; i < topArr.Length; i++)
        {
            _charmViews[i].Init(topArr[i]);
        }
    }
    /// <summary>
    /// 添加玩家
    /// </summary>
    private void AddPlayer()
    {
        playerNum++;
        int score = Random.Range(1, 100);
        CharmModel cc=new CharmModel("玩家"+playerNum,score,0);
        _charmModels.Add(cc);

        CreatView();
        Sort();
        RefreshData();
    }

    
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            //AddPlayer();
            playerNum++;
            int score = Random.Range(1, 100);
            CharmModel cc=new CharmModel("玩家"+playerNum,score,0);
            _charmModels.Add(cc);
            //替换对后一名
            topArr[7] = cc;
            //重新排序
            ArrSort();
            //刷新数据
            RefreshData(topArr);
            
        }

        
    }
}
using UnityEngine;
//数据模型类 主要负责数据
public class UIGradeModel
{
    public string Name
    {
        get;
        set;
    }

    public int Number
    {
        get;
        set;
    }

    public int Score
    {
        get;
        set;
    }

    
    public UIGradeModel(string name, int score, int number)
    {
        Name = name;
        Number = number;
        Score = score;
    }
}







using UnityEngine;
using UnityEngine.UI;

public class UIGradeView : MonoBehaviour
{
    private Text nameText;
    private Text numberText;
    private Text scoreText;

    private void Awake()
    {
        nameText = transform.Find("Msg2").GetComponent<Text>();
        numberText = transform.Find("Msg1").GetComponent<Text>();
        scoreText = transform.Find("Msg3").GetComponent<Text>();
    }

    public void Init(UIGradeModel uiGradeModel)
    {
        nameText.text = uiGradeModel.Name;
        scoreText.text = uiGradeModel.Score.ToString();
        numberText.text = uiGradeModel.Number.ToString();
    }
}







using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class UIGradeController : MonoBehaviour
{
    public GameObject rankPre;
    private List<UIGradeModel> _uiGradeModels;
    private List<UIGradeView> _uiGradeViews;
    private bool k;
    private int playerNum;
    //private int rankNum = 8;
    private UIGradeModel[] gradeModels;

    private void Awake()
    {
        _uiGradeModels=new List<UIGradeModel>();
        _uiGradeViews=new List<UIGradeView>();
    }

    private void Start()
    {
        LoadData();
        DisPlayData();
    }

    private void LoadData()
    {
        UIGradeModel g1=new UIGradeModel("孙悟空",99,0);
        _uiGradeModels.Add(g1);
        UIGradeModel g2=new UIGradeModel("唐僧",89,0);
        _uiGradeModels.Add(g2);
        UIGradeModel g3=new UIGradeModel("沙和尚",92,0);
        _uiGradeModels.Add(g3);
        UIGradeModel g4=new UIGradeModel("白龙马",49,0);
        _uiGradeModels.Add(g4);
        UIGradeModel g5=new UIGradeModel("白骨精",95,0);
        _uiGradeModels.Add(g5);
        UIGradeModel g6=new UIGradeModel("如来佛祖",79,0);
        _uiGradeModels.Add(g6);
        UIGradeModel g7=new UIGradeModel("观世音菩萨",59,0);
        _uiGradeModels.Add(g7);
        UIGradeModel g8=new UIGradeModel("哪吒",96,0);
        _uiGradeModels.Add(g8);
        Sort();
    }

    private UIGradeView CreatView()
    {
        GameObject obj = Instantiate(rankPre, transform);
        UIGradeView view = obj.AddComponent<UIGradeView>();
        _uiGradeViews.Add(view);
        return view;
    }

    private void DisPlayData()
    {
        for (int i = 0; i < _uiGradeModels.Count; i++)
        {
            CreatView().Init(_uiGradeModels[i]);
        }
    }

    private void Sort()
    {
        for (int i = 0; i < _uiGradeModels.Count-1; i++)
        {
            k = false;
            for (int j = 0; j < _uiGradeModels.Count-1-i; j++)
            {
                UIGradeModel gg;
                if (_uiGradeModels[j].Score<_uiGradeModels[j+1].Score)
                {
                    gg = _uiGradeModels[j];
                    _uiGradeModels[j] = _uiGradeModels[j + 1];
                    _uiGradeModels[j + 1] = gg;
                    k = true;
                }
            }
            if (!k)
            {
                break;
            }
        }

        for (int i = 0; i < _uiGradeModels.Count; i++)
        {
            _uiGradeModels[i].Number = i + 1;
        }
    }

    private void RefreshData()
    {
        for (int i = 0; i < _uiGradeModels.Count; i++)
        {
            _uiGradeViews[i].Init(_uiGradeModels[i]);
        }
    }

    private void AddPlayer()
    {
        playerNum++;
        int score = Random.Range(1, 100);
        UIGradeModel gg=new UIGradeModel("玩家"+playerNum,score,0);
        _uiGradeModels.Add(gg);

        CreatView();
        Sort();
        RefreshData();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            AddPlayer();
            
        }
    }
}

  开发测试 最新文章
pytest系列——allure之生成测试报告(Wind
某大厂软件测试岗一面笔试题+二面问答题面试
iperf 学习笔记
关于Python中使用selenium八大定位方法
【软件测试】为什么提升不了?8年测试总结再
软件测试复习
PHP笔记-Smarty模板引擎的使用
C++Test使用入门
【Java】单元测试
Net core 3.x 获取客户端地址
上一篇文章      下一篇文章      查看所有文章
加:2021-08-26 12:24:47  更:2021-08-26 12:26:50 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/17 22:36:27-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码