c#飞行棋游戏头
来源:互联网 发布:淘宝卖春药输入什么 编辑:程序博客网 时间:2024/05/16 09:06
固定资源
我们在写游戏的时候,界面上显示的有些东西是不变的,比如游戏头,这样我们可以封装成一个方法。
Console.ForegroudColor属性表示控制台的前景色;
- 画游戏头
- 初始化地图(加载地图所需要的资源)
- 画地图
- 玩游戏
初始化地图
我们用int型数组存这个地图,把数字变成地图上的字符串的过程,就是初始化地图的过程
//我用0表示普通,显示给用户就是 □//....1...幸运轮盘,显示组用户就◎ //....2...地雷,显示给用户就是 ☆//....3...暂停,显示给用户就是 ▲//....4...时空隧道,显示组用户就 卐 int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆int[] pause = { 9, 27, 60, 93 };//暂停▲ int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卐
方法里面尽量不要出现Console.Write等;这样可以实现更大的兼容性;
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 飞行棋游戏{ class Program { //我们用静态字段模拟全局变量 public static int[] maps=new int[100]; public static int[] playerpos = new int[2]; public static string[] playerNames = new string[2]; static void Main(string[] args) { GameShow(); Initial(); GetName(); //下面清屏; Console.Clear(); GameShow(); Console.WriteLine("{0}的士兵用A表示", playerNames[0]); Console.WriteLine("{0}的士兵用B表示", playerNames[1]); ShowMaps(); Console.ReadKey(); } public static void GetName() { Console.WriteLine("请输入玩家A的姓名:"); playerNames[0] = Console.ReadLine(); while (playerNames[0]=="") { Console.WriteLine("玩家A的名字不能为空,请重新输入"); playerNames[0] = Console.ReadLine(); } Console.WriteLine("请输入玩家B的名字:"); playerNames[1] = Console.ReadLine(); while (playerNames[1]==""||playerNames[1]==playerNames[0]) { if (playerNames[1]=="") { Console.WriteLine("玩家B的名字不能为空,请重新输入"); } else { Console.WriteLine("玩家B的名字不能和玩家A相同,请重新输入"); } playerNames[1] = Console.ReadLine(); } } public static void GameShow() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("************************"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("************************"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("************************"); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("*** 飞 行 棋 游 戏 ***"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("************************"); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("************************"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("************************"); } public static void Initial() { //我用0表示普通,显示给用户就是 □ //....1...幸运轮盘,显示组用户就◎ //....2...地雷,显示给用户就是 ☆ //....3...暂停,显示给用户就是 ▲ //....4...时空隧道,显示组用户就 卐 int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘◎ int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆ int[] pause = { 9, 27, 60, 93 };//暂停▲ int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道卐 for (int i = 0; i < luckyturn.Length; i++) { maps[luckyturn[i]] = 1; } for (int i = 0; i < landMine.Length; i++) { maps[landMine[i]] = 2; } for (int i = 0; i < pause.Length; i++) { maps[pause[i]]=3; } for (int i = 0; i < pause.Length; i++) { maps[pause[i]] = 4; } } public static void ShowPos(int i) { if (i == playerpos[0]) { if (playerpos[0] == playerpos[1]) { Console.Write("<>"); } else { Console.Write("A"); //return "A"; } } else if (i == playerpos[1]) { Console.Write("B"); //return "B"; } else { switch (maps[i]) { case 0: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("□"); //return "□"; break; case 1: Console.ForegroundColor = ConsoleColor.Red; Console.Write("◎"); break; case 2: Console.ForegroundColor = ConsoleColor.Green; Console.Write("☆"); break; case 3: Console.ForegroundColor = ConsoleColor.Blue; Console.Write("▲"); break; case 4: Console.ForegroundColor = ConsoleColor.DarkCyan; Console.Write("卐"); break; }//switch } } public static void ShowMaps() { //我用0表示普通,显示给用户就是 □ //....1...幸运轮盘,显示组用户就◎ //....2...地雷,显示给用户就是 ☆ //....3...暂停,显示给用户就是 ▲ //....4...时空隧道,显示组用户就 卐 Console.WriteLine("图例,□表示普通位,◎表示幸运轮盘,☆表示地雷,▲表示暂停,卐表示时空隧道"); #region 第一条横线 int i=0; for ( i= 0; i < 30; i++) { ShowPos(i); }//for #endregion #region 第一条竖线 for (; i < 35; i++) { Console.WriteLine(); for (int j = 0; j < 29; j++) { Console.Write(" "); } ShowPos(i); } #endregion #region 第二条横线 Console.WriteLine(); for (i=64; i >34; i--) { ShowPos(i); } #endregion #region 第三条竖线 Console.WriteLine(); for(i=65;i<70;i++) { ShowPos(i); Console.WriteLine(); } #endregion #region 第四条横线 for (; i < 100; i++) { ShowPos(i); } #endregion Console.WriteLine(); } }}
0 0
- c#飞行棋游戏头
- C#编写飞行棋游戏
- C#学习编写的飞行棋游戏
- 游戏小Demo-C#版飞行棋
- 骑士飞行棋游戏
- C#学习第六天 基础语法练习游戏--飞行棋
- c#学习 8/22 飞行棋游戏实现
- C#基础(10)——飞行棋游戏
- C#之飞行棋
- c#飞行棋项目
- C# 控制台 骑士飞行棋
- C#基础知识---飞行棋小游戏
- C#总结--骑士飞行棋
- 黑马程序员-C#中的方法与飞行棋游戏设计思路笔记
- .net学习之C#基础提高 飞行棋游戏V1.0(源代码by:CJH)
- 黑马程序员--C#控制台小飞行棋
- 骑士飞行棋 - C#基础 练习项目
- C#面向过程复习之飞行棋
- 彻底理解PHP的SESSION机制
- Java异常
- 使用anorm
- Maltab相机的调用和使用
- 网络编程:InetAddress类,Socket套接字的使用
- c#飞行棋游戏头
- OpenCV 关于两张图片的整合问题
- HTTPS数字证书原理
- Maven仓库汇总
- 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序
- la 3135 Argus Data Structure
- Java中switch的判断类型
- 有没有标准的RTP API
- 斑点检测