C#三人飞行棋

C#三人飞行棋

#region 1控制台设置int w = 50, h = 30;
ConsoleInit(w, h);
#endregion#region 2 场景选择实例//声明一个表示场景标识的变量
E_SceneType nowSceneType = new E_SceneType();
while (true)
{switch (nowSceneType){case E_SceneType.Begion://开始场景逻辑Console.Clear();BeginOrEndScene(w, h,ref nowSceneType);break;case E_SceneType.Game://游戏场景逻辑Console.Clear();GameScene(w, h,ref nowSceneType);break;case E_SceneType.End://结束场景逻辑Console.Clear();BeginOrEndScene(w, h, ref nowSceneType);break;default:break;}
}#endregion#region 1 控制台初始化
static void ConsoleInit(int w, int h)
{//基础设置//光标设置Console.CursorVisible = false;//舞台大小Console.SetWindowSize(w, h);Console.SetBufferSize(w, h);
}#endregion#region 3 开始场景逻辑static void BeginOrEndScene(int w, int h, ref E_SceneType nowSceneType)
{Console.ForegroundColor = ConsoleColor.White;Console.SetCursorPosition(nowSceneType == E_SceneType.Begion ? w / 2 - 3 : w / 2 - 4, 8);Console.Write(nowSceneType==E_SceneType.Begion ? "飞行棋" : "结束游戏");//默认开始游戏int nowSelIndex = 0;bool isQuitBegin = false;while (true){Console.SetCursorPosition(nowSceneType == E_SceneType.Begion ? w / 2 - 4 : w / 2 - 5, 13);Console.ForegroundColor = nowSelIndex == 0 ? ConsoleColor.Red : ConsoleColor.White;Console.Write(nowSceneType == E_SceneType.Begion ? "开始游戏" : "游戏主菜单");Console.ForegroundColor = nowSelIndex == 1 ? ConsoleColor.Red : ConsoleColor.White;Console.SetCursorPosition(w / 2 - 4, 15);Console.Write("退出游戏");//通过Readkey可以得到一个输入的枚举类型switch (Console.ReadKey(true).Key){case ConsoleKey.W:--nowSelIndex;if (nowSelIndex < 0){nowSelIndex = 1;}break;case ConsoleKey.S:++nowSelIndex;if (nowSelIndex > 1){nowSelIndex = 0;}break;case ConsoleKey.J:if (nowSelIndex == 0){nowSceneType = nowSceneType == E_SceneType.Begion ? E_SceneType.Game : E_SceneType.Begion;isQuitBegin = true;}else{Environment.Exit(0);}break;}if (isQuitBegin){break;}}
}
#endregion#region 4 游戏场景逻辑
static void GameScene(int w, int h,ref E_SceneType nowSceneType)
{DrawWall(w, h);//Grid grid = new Grid(5,5,E_Grid_Type.Boom);//grid.Draw();//绘制地图Map map = new Map(10,3,111);map.Draw();//绘制玩家Player player1 = new Player(0,E_Player_Type.Player1);Player player2 = new Player(0,E_Player_Type.Player2);Player computer =new Player(0,E_Player_Type.Computer);DrawPlayer(player1,player2,computer,map);bool isGameOver=false;while (true){Console.ReadKey(true);isGameOver = RandomMove(w,h,ref player1,ref player2,ref computer,map);map.Draw();DrawPlayer(player1, player2, computer, map);if (isGameOver){Console.ReadKey(true);nowSceneType = E_SceneType.End;break;}Console.ReadKey(true);isGameOver = RandomMove(w, h, ref player2, ref player1, ref computer, map);map.Draw();DrawPlayer(player1, player2, computer, map);if (isGameOver){Console.ReadKey(true);nowSceneType = E_SceneType.End;break;}Console.ReadKey(true);isGameOver = RandomMove(w, h, ref computer, ref player1, ref player2, map);map.Draw();DrawPlayer(player1, player2, computer, map);if (isGameOver){Console.ReadKey(true);nowSceneType = E_SceneType.End;break;}}
}#endregion#region 4 绘制不变内容(红墙 提示等)static void DrawWall(int w, int h)
{Console.ForegroundColor = ConsoleColor.Red;for (int i = 0; i < w; i += 2){Console.SetCursorPosition(i, 0);Console.Write("■");Console.SetCursorPosition(i, h - 1);Console.Write("■");Console.SetCursorPosition(i, h-6);Console.Write("■");Console.SetCursorPosition(i, h-11);Console.Write("■");}for (int i = 0; i < h; i++){Console.SetCursorPosition(0, i);Console.Write("■");Console.SetCursorPosition(w - 2, i);Console.Write("■");}//样式●■★◎ ▲ ◆ ⊙ ¤Console.ForegroundColor = ConsoleColor.White;Console.SetCursorPosition(2,h-10);Console.Write("□:普通格子");Console.ForegroundColor = ConsoleColor.Gray  ;Console.SetCursorPosition(22, h - 10);Console.Write("◆:玩家3");Console.ForegroundColor = ConsoleColor.Blue;Console.SetCursorPosition(2, h - 9);Console.Write("⊙:暂停,一回合不动");Console.ForegroundColor = ConsoleColor.DarkRed;Console.SetCursorPosition(26, h - 9);Console.Write("●:炸弹,倒退5格");Console.ForegroundColor = ConsoleColor.White;Console.SetCursorPosition(2, h - 8);Console.Write("¤:时空隧道,随机倒退,前进,暂停");Console.ForegroundColor = ConsoleColor.Cyan;Console.SetCursorPosition(2, h - 7);Console.Write("★:玩家");Console.ForegroundColor = ConsoleColor.Magenta;Console.SetCursorPosition(12, h - 7);Console.Write("▲:玩家2");///Console.ForegroundColor = ConsoleColor.Yellow;Console.SetCursorPosition(22, h - 7);Console.Write("◎:玩家和电脑重合");Console.ForegroundColor = ConsoleColor.White;Console.SetCursorPosition(2, h - 5);Console.Write("按任意键开始扔骰子");}#endregion#region 8 扔骰子 函数
static void ClearInfo(int w,int h)
{Console.SetCursorPosition(2, h - 5);Console.Write("                                        ");Console.SetCursorPosition(2, h - 4);Console.Write("                                        ");Console.SetCursorPosition(2, h - 3);Console.Write("                                        ");Console.SetCursorPosition(2, h - 2);Console.Write("                                        ");
}
static bool RandomMove(int w, int h, ref Player p, ref Player p2,ref Player c, Map map)
{ClearInfo(w,h);if (p.type == E_Player_Type.Player1){Console.ForegroundColor = ConsoleColor.Cyan;}else if (p.type == E_Player_Type.Player2){Console.ForegroundColor = ConsoleColor.Magenta;}else{Console.ForegroundColor = ConsoleColor.Gray;}if (p.isPause){Console.SetCursorPosition(2,h-5);if (p.type == E_Player_Type.Player1){Console.Write("玩家1处于暂停点,玩家1需要暂停一回合");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2处于暂停点,玩家2需要暂停一回合");}else{Console.Write("玩家3处于暂停点,玩家3需要暂停一回合");}p.isPause = false;return false;}Random r = new Random();int randomNum = r.Next(1, 7);p.nowIndex += randomNum;Console.SetCursorPosition(2,h-5);if (p.type == E_Player_Type.Player1){Console.Write("玩家1扔出的点数为:"+randomNum);}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2扔出的点数为:"+randomNum);}else{Console.Write("玩家3扔出的点数为:" + randomNum);}if (p.nowIndex >= map.grids.Length - 1){p.nowIndex = map.grids.Length - 1;Console.SetCursorPosition(2, h - 4);if (p.type == E_Player_Type.Player1){Console.Write("玩家1获胜");Console.SetCursorPosition(2, h - 3);Console.Write("按任意键结束游戏");return true;}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2获胜");Console.SetCursorPosition(2, h - 3);Console.Write("按任意键结束游戏");return true;}else{Console.Write("玩家3获胜");Console.SetCursorPosition(2, h - 3);Console.Write("按任意键结束游戏");return true;}return true;}else{Grid grid = map.grids[p.nowIndex];switch (grid.type){case E_Grid_Type.Normal:Console.SetCursorPosition(2,h-4);if (p.type == E_Player_Type.Player1){Console.Write("玩家1处于安全位置");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2处于安全位置");}else{Console.Write("玩家3处于安全位置");}Console.SetCursorPosition(2, h - 3);if (p.type == E_Player_Type.Player1){Console.Write("请按任意键,玩家2开始仍骰子");}else if (p.type == E_Player_Type.Player2){Console.Write("请按任意键,玩家3开始仍骰子");}else{Console.Write("请按任意键,玩家1开始仍骰子");}break;case E_Grid_Type.Boom://炸弹退格p.nowIndex -= 5;if (p.nowIndex < 0){p.nowIndex = 0;}Console.SetCursorPosition(2, h - 4);if (p.type == E_Player_Type.Player1){Console.Write("玩家1踩到了炸弹,退后5格");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2踩到了炸弹,退后5格");}else{Console.Write("玩家3踩到了炸弹,退后5格");}Console.SetCursorPosition(2, h - 3);if (p.type == E_Player_Type.Player1){Console.Write("请按任意键,玩家2开始仍骰子");}else if (p.type == E_Player_Type.Player2){Console.Write("请按任意键,玩家3开始仍骰子");}else{Console.Write("请按任意键,玩家1开始仍骰子");}break;case E_Grid_Type.Pause://暂停一回合p.isPause = true;Console.SetCursorPosition(2, h - 4);if (p.type == E_Player_Type.Player1){Console.Write("玩家1暂停一回合");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2暂停一回合");}else{Console.Write("玩家3暂停一回合");}Console.SetCursorPosition(2, h - 3);if (p.type == E_Player_Type.Player1){Console.Write("请按任意键,玩家2开始仍骰子");}else if (p.type == E_Player_Type.Player2){Console.Write("请按任意键,玩家3开始仍骰子");}else{Console.Write("请按任意键,玩家1开始仍骰子");}break;case E_Grid_Type.Tunnel:Console.SetCursorPosition(2, h - 4);if (p.type == E_Player_Type.Player1){Console.Write("玩家1进入了时空隧道");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2进入了时空隧道");}else{Console.Write("玩家3进入了时空隧道");}//随机randomNum = r.Next(1,91);if (randomNum<30){p.nowIndex -= 5;if(p.nowIndex < 0){p.nowIndex = 0;}Console.SetCursorPosition(2, h - 3);if (p.type == E_Player_Type.Player1){Console.Write("玩家1退5格");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2退5格");}else{Console.Write("玩家3退5格");}}else if (randomNum <= 60){p.isPause = true;Console.SetCursorPosition(2, h - 3);if (p.type == E_Player_Type.Player1){Console.Write("玩家1暂停一回合");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2暂停一回合");}else{Console.Write("玩家3暂停一回合");}}else{p.nowIndex += 3;if(p.nowIndex >= map.grids.Length - 1){p.nowIndex = map.grids.Length - 2;}Console.SetCursorPosition(2, h - 3);if (p.type == E_Player_Type.Player1){Console.Write("玩家1前进格3格");}else if (p.type == E_Player_Type.Player2){Console.Write("玩家2前进格3格");}else{Console.Write("玩家3前进格3格");}}Console.SetCursorPosition(2, h - 2);if (p.type == E_Player_Type.Player1){Console.Write("请按任意键,玩家2开始仍骰子");}else if (p.type == E_Player_Type.Player2){Console.Write("请按任意键,玩家3开始仍骰子");}else{Console.Write("请按任意键,玩家1开始仍骰子");}break;default:break;}}return false;
}#endregion#region 7 绘制玩家
static void DrawPlayer(Player player1,Player player2,Player computer,Map map)
{if (player1.nowIndex == computer.nowIndex && player1.nowIndex == player2.nowIndex && player2.nowIndex == computer.nowIndex){Grid grid = map.grids[player2.nowIndex];Console.ForegroundColor = ConsoleColor.Yellow;Console.SetCursorPosition(grid.pos.x, grid.pos.y);Console.Write("◎");}else if (player1.nowIndex == computer.nowIndex){Grid grid = map.grids[player1.nowIndex];Console.ForegroundColor = ConsoleColor.Yellow;Console.SetCursorPosition(grid.pos.x, grid.pos.y);Console.Write("◎");player2.Draw(map);}else if (player1.nowIndex == player2.nowIndex){Grid grid = map.grids[player1.nowIndex];Console.ForegroundColor = ConsoleColor.Yellow;Console.SetCursorPosition(grid.pos.x, grid.pos.y);Console.Write("◎");computer.Draw(map);}else if (player2.nowIndex == computer.nowIndex){Grid grid = map.grids[player2.nowIndex];Console.ForegroundColor = ConsoleColor.Yellow;Console.SetCursorPosition(grid.pos.x, grid.pos.y);Console.Write("◎");player1.Draw(map);}else{player1.Draw(map);player2.Draw(map);computer.Draw(map);}
}
#endregion#region 2 场景选择设置
/// <summary>
/// 游戏场景枚举类型
/// </summary>
enum E_SceneType
{/// <summary>/// 开始场景/// </summary>Begion,/// <summary>/// 游戏场景/// </summary>Game,/// <summary>/// 结束场景/// </summary>End,
}
#endregion#region 5 格子结构体和格子枚举
/// <summary>
/// 格子类型 枚举
/// </summary>
enum E_Grid_Type
{/// <summary>/// 普通格子/// </summary>Normal,/// <summary>/// 炸弹/// </summary>Boom,/// <summary>/// 暂停/// </summary>Pause,/// <summary>/// 时空隧道/// </summary>Tunnel,
}struct Vector2
{public int x;public int y;public Vector2(int x, int y){this.x = x; this.y = y;}
}
struct Grid
{//格子类型public E_Grid_Type type;//格子位置public Vector2 pos;//初始化构造函数public Grid(int x,int y,E_Grid_Type type){pos.x = x; pos.y = y;this.type = type;}public void Draw(){Console.SetCursorPosition(pos.x, pos.y);switch (type){case E_Grid_Type.Normal:Console.ForegroundColor= ConsoleColor.White;Console.Write("□");break;case E_Grid_Type.Boom:Console.ForegroundColor = ConsoleColor.DarkRed;Console.Write("●");break;case E_Grid_Type.Pause:Console.ForegroundColor = ConsoleColor.Blue;Console.Write("⊙");break;case E_Grid_Type.Tunnel:Console.ForegroundColor = ConsoleColor.White;Console.Write("¤");break;default:break;}}
}#endregion#region 6 地图结构体struct Map
{public Grid[] grids;public Map(int x,int y,int num){grids = new Grid[num];//用于位置改变计数的变量int indexX = 0, indexY = 0, stepNum = 2;    //x的步长Random random = new Random();int randomNum;for (int i = 0; i < num; i++){randomNum = random.Next(0, 101);if (randomNum < 85 || i == 0 || i == num - 1){grids[i].type = E_Grid_Type.Normal;}else if (randomNum>=85 && randomNum<90){grids[i].type = E_Grid_Type.Boom;}else if (randomNum >=90 && randomNum<95){grids[i].type = E_Grid_Type.Pause;}else{grids[i].type = E_Grid_Type.Tunnel;}grids[i].pos = new Vector2(x, y);if (indexX ==14){y += 1;++indexY;if (indexY ==2){indexX = 0;indexY = 0;stepNum = -stepNum; //反向步长}}else{x += stepNum;++indexX;}}}public void Draw(){for (int i = 0; i < grids.Length; i++){grids[i].Draw();}}
}#endregion#region 7 玩家枚举和玩家结构体
enum E_Player_Type
{/// <summary>/// 玩家1/// </summary>Player1,/// <summary>/// 玩家2/// </summary>Player2,/// <summary>/// 电脑/// </summary>Computer,
}struct Player
{public E_Player_Type type;public int nowIndex;public bool isPause; public Player(int index,E_Player_Type type){nowIndex = index;this.type = type;isPause = false;}public void Draw(Map mapInfo){Grid grid = mapInfo.grids[nowIndex];Console.SetCursorPosition(grid.pos.x, grid.pos.y);switch (type){case E_Player_Type.Player1:Console.ForegroundColor = ConsoleColor.Cyan;Console.Write("★");break;case E_Player_Type.Player2:Console.ForegroundColor = ConsoleColor.Magenta;Console.Write("▲");break;case E_Player_Type.Computer:Console.ForegroundColor = ConsoleColor.Gray;Console.Write("◆");break;default:break;}}
}
#endregion

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/6229.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

吴恩达机器学习笔记 三十七 电影推荐系统 使用特征 成本函数 协同过滤算法

以电影评分系统为例&#xff0c;令 r(i, j) 来表示用户 j 已经对电影 i 评分&#xff0c; y&#xff08;i, j&#xff09;表示评分具体是多少。 假如每部电影有自己的特征&#xff0c;那么用户 j 对电影 i 的评分预测为 w(j) * x(i) b(j) r(i, j) &#xff1a;一个用户 j 是否…

global IoT SIM解决方案

有任何关于GSMA\IOT\eSIM\RSP\业务应用场景相关的问题&#xff0c;欢迎W: xiangcunge59 一起讨论, 共同进步 (加的时候请注明: 来自CSDN-iot). Onomondo提供的全球IoT SIM卡解决方案具有以下特点和优势&#xff1a; 1. **单一全球配置文件**&#xff1a;Onomondo的SIM卡拥…

【C++风云录】破解聊天机器人开发:寻找最适合你的工具

重量级面面观&#xff1a;六大顶级聊天机器人开发工具的对比 前言 在本文中&#xff0c;我们将深入探讨六种不同的C集成聊天机器人开发工具&#xff0c;包括Botkit, DialogueFlow, Rasa, Wit.ai, IBM Watson Assistant和 Microsoft Bot Framework。每个工具都将从选择原因&am…

Flink checkpoint 源码分析- Checkpoint barrier 传递源码分析

背景 在上一篇的博客里&#xff0c;大致介绍了flink checkpoint中的触发的大体流程&#xff0c;现在介绍一下触发之后下游的算子是如何做snapshot。 上一篇的文章: Flink checkpoint 源码分析- Flink Checkpoint 触发流程分析-CSDN博客 代码分析 1. 在SubtaskCheckpointCoo…

Vue3+ts(day05:ref、props、生命周期、hook)

学习源码可以看我的个人前端学习笔记 (github.com):qdxzw/frontlearningNotes 觉得有帮助的同学&#xff0c;可以点心心支持一下哈&#xff08;笔记是根据b站上学习的尚硅谷的前端视频【张天禹老师】&#xff0c;记录一下学习笔记&#xff0c;用于自己复盘&#xff0c;有需要学…

开源AI智能名片S2B2C商城系统:移动技术的深度整合与应用

在数字化营销的新时代&#xff0c;开源AI智能名片S2B2C商城系统通过深度整合移动技术MAC ID、Beacon和DSP&#xff0c;为企业带来了前所未有的营销机遇。这一系统不仅提高了营销效率&#xff0c;还极大地提升了客户体验&#xff0c;并有效降低了营销成本。下面&#xff0c;我们…

【JAVA基础之反射】反射详解

&#x1f525;作者主页&#xff1a;小林同学的学习笔录 &#x1f525;mysql专栏&#xff1a;小林同学的专栏 1.反射 1.1 概述 是在运行状态中&#xff0c;对于任意一个类&#xff0c;都能够知道这个类的所有属性和方法&#xff1b; 对于任意一个对象&#xff0c;都能够调用它…

SQL注入漏洞扫描---sqlmap

what SQLMap是一款先进的自动执行SQL注入的审计工具。当给定一个URL时&#xff0c;SQLMap会执行以下操作&#xff1a; 判断可注入的参数。判断可以用哪种SQL注入技术来注入。识别出目标使用哪种数据库。根据用户的选择&#xff0c;读取哪些数据库中的数据。 更详细语法请参考…

BJFUOJ-C++程序设计-实验3-继承和虚函数

A TableTennisPlayer 答案&#xff1a; #include<iostream> #include<cstring> using namespace std;class TableTennisPlayer{ private:string firstname;string lastname;bool hasTable;public:TableTennisPlayer(const string &, const string &, bool…

leetCode65. 有效数字

leetCode65. 有效数字 题目思路 代码 class Solution { public:bool isNumber(string s) {int l 0, r s.size() - 1;// 1.忽略前后的空格while(l < r && s[l] ) l;while(l < r && s[r] ) r--;if(l > r) return false;s s.substr(l,r - l 1)…

Git的基本操作和使用

git分支指令 列出所有本地分支 git branchmaster是绿的 前面有个 表示当前分支是master* 列出所有远程分支 git branch -r列出所有本地分支和远程分支 git branch -a新建一个分支&#xff0c;但依然停留在当前分支 git branch [branch-name]新建一个分支&#xff0c;并切…

httpcanary抓包某游戏思路及教程[第1期]

游戏介绍&#xff1a; 这期在线读档0花购买教程&#xff0c;存档版教程。下一期在线购买无限鲜花累计充值安卓全系统适配修改教程。 小白勿入&#xff0c;技术流资料 网盘自动获取 链接&#xff1a;https://pan.baidu.com/s/1lpzKPim76qettahxvxtjaQ?pwd0b8x 提取码&#x…

设计模式动态代理

什么是设计模式? 一个问题通常有n种解法&#xff0c;其中肯定有一种解法是最优的&#xff0c;这个最优的解法被人总结出来了&#xff0c;称之为设计模式。 设计模式有20多种&#xff0c;对应20多种软件开发中会遇到的问题。 关于设计模式的学习&#xff0c;主要学什么&#…

onedrive下載zip檔案有20G限制,如何解決

一般來說&#xff0c;OneDrive網頁版對文件下載大小的限制如下圖所示&#xff0c;更多資訊&#xff0c;請您參考這篇文章&#xff1a;OneDrive 和 SharePoint 中的限制 - Microsoft Support 因此我們推薦您使用OneDrive同步用戶端來同步到本地電腦&#xff0c;您也可以選擇只同…

MFC 列表控件删除实例(源码下载)

1、本程序基于前期我的博客文章《MFC下拉菜单打钩图标存取实例&#xff08;源码下载) 》 2、程序功能选中列表控件某一项&#xff0c;删除按钮由禁止变为可用&#xff0c;点击删除按钮&#xff0c;选中的项将删除。 3、首先在主界面添加一个删除参数按钮。 4、在myDlg.cpp 文件…

巨人网络发布2023年年报:全力拥抱AI浪潮,开启游戏产业新篇章

易采游戏网5月3日消息&#xff0c;国内知名游戏公司巨人网络发布了其2023年度财务报告&#xff0c;报告显示&#xff0c;公司在过去一年中积极拥抱AI技术&#xff0c;实现了业绩的稳步增长&#xff0c;为游戏产业带来了新的活力与机遇。 在报告中&#xff0c;巨人网络详细阐述了…

【C++】STL简介

&#x1f525;个人主页&#xff1a; Forcible Bug Maker &#x1f525;专栏&#xff1a; C 目录 前言什么是STL&#xff1f;STL的历史STL的版本STL六大组件STL的优缺点STL的优点&#xff1a;STL的缺点&#xff1a; 如何学习STL结语 前言 本篇博客主要内容&#xff1a;STL简介。…

240503-关于Unity的二三事

240503-关于Unity的二三事 1 常用快捷键 快捷键描述CtrlP播放/停止Ctrl1打开Scene窗口Ctrl2打开Game窗口Ctrl3打开Inspect窗口Ctrl4打开Hierarchy窗口Ctrl5打开Project窗口Ctrl6打开Animation窗口 2 关联VisualStudio2022 3 节约时间&#xff1a;将最新声明的参数移动到最上…

react 列表渲染 key解析和 vue的key解析的底层逻辑

前言 在学习react的过程中&#xff0c;了解到key的解析原理&#xff0c;发现和vue的解析原理基本上一致。框架的名称各有不同&#xff0c;在一些底层的模块上有相似。 react key解析原理 react 在修改数据的时候&#xff0c;会创建一个新的虚拟dom&#xff0c;然后用新的虚拟…

软设之信号量与pv操作

临界资源:诸进程间需要互斥方式对其进行共享的资源。 访问临界资源那段代码称为临界区。 信号量:是一种特殊的变量。可以用来表示资源数量。当信号量为负时还可以表示排队进程数。 P表示要资源&#xff0c;V表示释放资源。 当进行互斥操作时&#xff0c;假定有2台打印机&am…