分享給大家一個很久之前寫的一個純C#控制臺 3D闖關(guān)游戲代碼 直接復(fù)制就可以用?
?初學(xué)者可以看看? 學(xué)習(xí)一下編程思想還有游戲思想.
好了 話不多說上代碼大家自己看哈.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace DevilDungeonCV
{
? ? class Program
? ? {
? ? ? ? static string[,] map = new string[20, 20];
? ? ? ? static List enemyList = new List();
? ? ? ? static List chestList = new List();
? ? ? ? static string msgbox = "";
? ? ? ? static bool isBattle = false, isDead = false;
? ? ? ? static Enemy tarEnemy = null;
? ? ? ? const int BOSS_LEVEL = 10;
? ? ? ? static Enemy boss = null;
? ? ? ? static int level = 0, enemyDizzy = 0, battleRound = 0;
? ? ? ? static void Main()
? ? ? ? {
? ? ? ? ? ? Console.SetBufferSize(77, 30);
? ? ? ? ? ? Console.SetWindowSize(77, 30);
? ? ? ? ? ? Console.CursorVisible = false;
? ? ? ? ? ? Start();
? ? ? ? ? ? while (true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Update();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? static void Start()
? ? ? ? {
? ? ? ? ? ? Player.Reset();
? ? ? ? ? ? isDead = false;
? ? ? ? ? ? isBattle = false;
? ? ? ? ? ? tarEnemy = null;
? ? ? ? ? ? boss = new Enemy(0,0,true);
? ? ? ? ? ? level = 0;
? ? ? ? ? ? battleRound = 0;
? ? ? ? ? ? enemyDizzy = 0;
? ? ? ? ? ? msgbox = "歡迎來到惡魔地牢? (方向鍵移動)\n★ = 玩家\nθ = 道具\(yùn)n︾ = 下一層\n<請按鍵分配屬性點>\n1:力量 2:防御 3:敏捷 4:智力\n";
? ? ? ? ? ? MapGenerator();
? ? ? ? }
? ? ? ? static void Update()
? ? ? ? {
? ? ? ? ? ? PrintMap();
? ? ? ? ? ? StatusBar();
? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? BattleBar();
? ? ? ? ? ? Info();
? ? ? ? ? ? if (isDead)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ConfirmDead();
? ? ? ? ? ? }
? ? ? ? ? ? else if (boss==null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MissionCompeleted();
? ? ? ? ? ? }
? ? ? ? ? ? else if (isBattle)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Battle(tarEnemy);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? EnemyController();
? ? ? ? ? ? ? ? PlayerController();
? ? ? ? ? ? }
? ? ? ? ? ? Console.Clear();
? ? ? ? }
? ? ? ? static Enemy GetTargetEnemy(int x, int y, bool isBoss = false)
? ? ? ? {
? ? ? ? ? ? if (isBattle)
? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? msgbox += "進(jìn)入戰(zhàn)斗\n";
? ? ? ? ? ? if (isBoss)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? isBattle = true;
? ? ? ? ? ? ? ? battleRound = 0;
? ? ? ? ? ? ? ? enemyDizzy = 0;
? ? ? ? ? ? ? ? return boss;
? ? ? ? ? ? }
? ? ? ? ? ? for (int i = 0; i < enemyList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Enemy enemy = enemyList[i];
? ? ? ? ? ? ? ? if (enemy.x == x && enemy.y == y)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? isBattle = true;
? ? ? ? ? ? ? ? ? ? battleRound = 0;
? ? ? ? ? ? ? ? ? ? enemyDizzy = 0;
? ? ? ? ? ? ? ? ? ? return enemy;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return null;
? ? ? ? }
? ? ? ? static void Battle(Enemy enemy)
? ? ? ? {
? ? ? ? ? ? const int ATTACK = 0, SKILL1 = 1, SKILL2 = 2, SKILL3 = 3, ESCAPE = 4;
? ? ? ? ? ? int action = ATTACK;
? ? ? ? c:
? ? ? ? ? ? ConsoleKey key = Console.ReadKey(true).Key;
? ? ? ? ? ? switch (key)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case ConsoleKey.Spacebar:
? ? ? ? ? ? ? ? ? ? action = ATTACK;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.Q:
? ? ? ? ? ? ? ? ? ? if (CanSpell(1) == "")
? ? ? ? ? ? ? ? ? ? ? ? action = SKILL1;
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? msgbox += CanSpell(1);
? ? ? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.W:
? ? ? ? ? ? ? ? ? ? if (CanSpell(2) == "")
? ? ? ? ? ? ? ? ? ? ? ? action = SKILL2;
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? msgbox += CanSpell(2);
? ? ? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.E:
? ? ? ? ? ? ? ? ? ? if (CanSpell(3) == "")
? ? ? ? ? ? ? ? ? ? ? ? action = SKILL3;
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? msgbox += CanSpell(3);
? ? ? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.R:
? ? ? ? ? ? ? ? ? ? action = ESCAPE;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? }
? ? ? ? ? ? battleRound++;
? ? ? ? ? ? msgbox += "<回合 " + battleRound + ">\n";
? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? //玩家動作
? ? ? ? ? ? switch (action)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case ATTACK:
? ? ? ? ? ? ? ? ? ? int dmg = enemy.GetHurt(Player.atk, Player.dex);
? ? ? ? ? ? ? ? ? ? switch (dmg)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? case -1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += enemy.name + " 閃避了攻擊\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += enemy.name + " 格擋了傷害\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += enemy.name + " 受到 " + dmg + " 傷害\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case SKILL1:
? ? ? ? ? ? ? ? ? ? dmg = Event.rnd.Next(4, 7) + Player.Int;
? ? ? ? ? ? ? ? ? ? msgbox += "施放<火球術(shù)> " + enemy.name + " 受到 " + dmg + " 傷害\n";
? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? enemy.life -= dmg;
? ? ? ? ? ? ? ? ? ? Player.mana -= 3;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case SKILL2:
? ? ? ? ? ? ? ? ? ? dmg = Event.rnd.Next(8, 13) + Player.Int * 3;
? ? ? ? ? ? ? ? ? ? msgbox += "施放<治愈術(shù)> 回復(fù) " + dmg + " 生命\n";
? ? ? ? ? ? ? ? ? ? Player.life += dmg;
? ? ? ? ? ? ? ? ? ? Player.mana -= 5;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case SKILL3:
? ? ? ? ? ? ? ? ? ? dmg = Event.rnd.Next(1, 3) + Player.Int;
? ? ? ? ? ? ? ? ? ? msgbox += "施放<眩暈術(shù)> " + enemy.name + " 眩暈 " + (dmg + 1) + " 回合\n";
? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? Player.mana -= 4;
? ? ? ? ? ? ? ? ? ? enemyDizzy = dmg;
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? case ESCAPE:
? ? ? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 2) == 0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? isBattle = false;
? ? ? ? ? ? ? ? ? ? ? ? msgbox += "<逃跑成功>\n";
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? msgbox += "<逃跑失敗>\n";
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? //msgbox += "> ";
? ? ? ? ? ? if (enemy.life > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (enemyDizzy == 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int dmg = Player.GetHurt(enemy.atk, enemy.dex);
? ? ? ? ? ? ? ? ? ? switch (dmg)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? case -1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "你閃避了攻擊\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "你格擋了傷害\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (Player.life > 0)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "你受到 " + dmg + " 傷害\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.life = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "你死了\n(按R鍵重新開始)\n";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? isDead = true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? msgbox += enemy.name + " 眩暈中\(zhòng)n";
? ? ? ? ? ? ? ? ? ? enemyDizzy--;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? msgbox += "敵人死亡\n";
? ? ? ? ? ? ? ? //如果敵人是BOSS
? ? ? ? ? ? ? ? if (enemy == boss)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? boss = null;
? ? ? ? ? ? ? ? ? ? isBattle = false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Player.exp += enemy.exp;
? ? ? ? ? ? ? ? if (Player.exp >= Player.lv * 2)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? msgbox += "<等級提升> (獲得 1 屬性點)\n";
? ? ? ? ? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? ? ? ? ? Player.exp -= Player.lv * 2;
? ? ? ? ? ? ? ? ? ? Player.lv++;
? ? ? ? ? ? ? ? ? ? Player.life += 8;
? ? ? ? ? ? ? ? ? ? Player.mana += 8;
? ? ? ? ? ? ? ? ? ? Player.ap++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? enemyList.Remove(enemy);
? ? ? ? ? ? ? ? isBattle = false;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? static bool isHeight(int _val)
? ? ? ? {
? ? ? ? ? ? for (int i = 0; i < 4; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? switch (i)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? ? ? ? ? if (_val < Player.atk)
? ? ? ? ? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? ? ? if (_val < Player.def)
? ? ? ? ? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? ? ? if (_val < Player.dex)
? ? ? ? ? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? ? ? if (_val < Player.Int)
? ? ? ? ? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return true;
? ? ? ? }
? ? ? ? static void StatusBar()
? ? ? ? {
? ? ? ? ? ? Console.SetCursorPosition(41, 0);
? ? ? ? ? ? Console.WriteLine("┌───────狀態(tài)───────┐");
? ? ? ? ? ? Console.SetCursorPosition(41, 1);
? ? ? ? ? ? Console.WriteLine("│等級:? ? 經(jīng)驗:? ? 點數(shù):? ? │");
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.White;
? ? ? ? ? ? Console.SetCursorPosition(49, 1); Console.Write(Player.lv);
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Green;
? ? ? ? ? ? Console.SetCursorPosition(60, 1); Console.Write(Player.exp);
? ? ? ? ? ? Console.ForegroundColor = Player.ap >0 ? ConsoleColor.Yellow : ConsoleColor.DarkYellow;
? ? ? ? ? ? Console.SetCursorPosition(71, 1); Console.Write(Player.ap);
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Gray;
? ? ? ? ? ? Console.SetCursorPosition(41, 2);
? ? ? ? ? ? Console.WriteLine("│生命:? ? 力量:? ? 防御:? ? │");
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Red;
? ? ? ? ? ? Console.SetCursorPosition(49, 2); Console.Write(Player.life);
? ? ? ? ? ? Console.ForegroundColor = isHeight(Player.atk) ? ConsoleColor.Red :ConsoleColor.DarkRed;
? ? ? ? ? ? Console.SetCursorPosition(60, 2); Console.Write(Player.atk);
? ? ? ? ? ? Console.ForegroundColor = isHeight(Player.def) ? ConsoleColor.Yellow : ConsoleColor.DarkYellow;
? ? ? ? ? ? Console.SetCursorPosition(71, 2); Console.Write(Player.def);
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Gray;
? ? ? ? ? ? Console.SetCursorPosition(41, 3);
? ? ? ? ? ? Console.WriteLine("│法力:? ? 敏捷:? ? 智力:? ? │");
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Blue;
? ? ? ? ? ? Console.SetCursorPosition(49, 3); Console.Write(Player.mana);
? ? ? ? ? ? Console.ForegroundColor = isHeight(Player.dex) ? ConsoleColor.Magenta : ConsoleColor.DarkMagenta;
? ? ? ? ? ? Console.SetCursorPosition(60, 3); Console.Write(Player.dex);
? ? ? ? ? ? Console.ForegroundColor = isHeight(Player.Int) ? ConsoleColor.Cyan : ConsoleColor.DarkCyan;
? ? ? ? ? ? Console.SetCursorPosition(71, 3); Console.Write(Player.Int);
? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Gray;
? ? ? ? ? ? Console.SetCursorPosition(41, 4);
? ? ? ? ? ? Console.WriteLine("└────────────────┘");
? ? ? ? ? ? Console.WriteLine();
? ? ? ? }
? ? ? ? static void BattleBar()
? ? ? ? {
? ? ? ? ? ? if (!isBattle)
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? int i = 5, l = 41;
? ? ? ? ? ? Console.SetCursorPosition(41, i);
? ? ? ? ? ? Console.WriteLine("┌──戰(zhàn)斗──┐"); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│敵人:? ? ? │"); Console.SetCursorPosition(l + 8, i); Console.Write(tarEnemy.name); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│生命:? ? ? │"); Console.SetCursorPosition(l + 8, i); Console.Write(tarEnemy.life); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│攻擊:? ? ? │"); Console.SetCursorPosition(l + 8, i); Console.Write(tarEnemy.atk); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│防御:? ? ? │"); Console.SetCursorPosition(l + 8, i); Console.Write(tarEnemy.def); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│敏捷:? ? ? │"); Console.SetCursorPosition(l + 8, i); Console.Write(tarEnemy.dex); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("└──────┘");
? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? //操作
? ? ? ? ? ? i = 5; l = 57;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("┌───操作───┐"); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│空格鍵:<攻擊>? │"); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│技能 Q:? ? ? ? │"); Console.SetCursorPosition(l + 10, i);
? ? ? ? ? ? if (Player.skill1) Console.Write("<火球術(shù)>"); else Console.Write("<無>"); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│技能 W:? ? ? ? │"); Console.SetCursorPosition(l + 10, i);
? ? ? ? ? ? if (Player.skill2) Console.Write("<治愈術(shù)>"); else Console.Write("<無>"); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("│道具 E:? ? ? ? │"); Console.SetCursorPosition(l + 10, i);
? ? ? ? ? ? if (Player.skill3) Console.Write("<眩暈術(shù)>"); else Console.Write("<無>"); i++;
? ? ? ? ? ? Console.SetCursorPosition(l, i); i++;
? ? ? ? ? ? Console.WriteLine("│按鍵 R:<逃跑>? │");
? ? ? ? ? ? Console.SetCursorPosition(l, i);
? ? ? ? ? ? Console.WriteLine("└────────┘");
? ? ? ? ? ? Console.WriteLine();
? ? ? ? }
? ? ? ? static void MsgboxBar()
? ? ? ? {
? ? ? ? ? ? Console.SetCursorPosition(41, 12);
? ? ? ? ? ? Console.WriteLine("┌───────信息───────┐");
? ? ? ? ? ? for (int i = 1; i < 7; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.SetCursorPosition(41, 12 + i);
? ? ? ? ? ? ? ? Console.WriteLine("│? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? │");
? ? ? ? ? ? }
? ? ? ? ? ? Console.SetCursorPosition(41, 19);
? ? ? ? ? ? Console.WriteLine("└────────────────┘");
? ? ? ? ? ? List msgList = new List();
? ? ? ? ? ? msgList.Clear();
? ? ? ? ? ? int t = 0;
? ? ? ? ? ? for (int i = 0; i < msgbox.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? i = msgbox.IndexOf("\n", i);
? ? ? ? ? ? ? ? if (i != -1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? t++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //1\n2\n3\n4\n5\n6\n
? ? ? ? ? ? if (t > 6)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? msgbox = msgbox.Substring(msgbox.IndexOf("\n") + 1, msgbox.Length - msgbox.IndexOf("\n") - 1);
? ? ? ? ? ? }
? ? ? ? ? ? string s = "";
? ? ? ? ? ? int p0 = 0, p1 = 0;
? ? ? ? ? ? for (int i = 0; i < 6; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? p1 = msgbox.IndexOf("\n", p0);
? ? ? ? ? ? ? ? if (p1 == -1)
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? s = p1 - p0 > 20 ? msgbox.Substring(p0, 19) + "..." : msgbox.Substring(p0, p1 - p0);
? ? ? ? ? ? ? ? p0 = p1 + 1;
? ? ? ? ? ? ? ? Console.SetCursorPosition(43, 13 + i);
? ? ? ? ? ? ? ? if (s.Contains("歡迎來到")|| s.Contains("按R鍵") || s.Contains("恭喜通關(guān)"))
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Cyan;
? ? ? ? ? ? ? ? else if (s.Contains("★"))
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Yellow;
? ? ? ? ? ? ? ? else if (s.Contains("θ") || s.Contains("等級提升"))
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkCyan;
? ? ? ? ? ? ? ? else if (s.Contains("︾"))
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkYellow;
? ? ? ? ? ? ? ? else if (s.Contains("進(jìn)入戰(zhàn)斗") || s.Contains("你死了") || s.Contains("您已擊敗惡魔"))
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkRed;
? ? ? ? ? ? ? ? else if (s.Contains("發(fā)現(xiàn)"))
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkCyan;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Gray;
? ? ? ? ? ? ? ? Console.WriteLine(s);
? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Gray;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? static void ConfirmDead()
? ? ? ? {
? ? ? ? c:
? ? ? ? ? ? ConsoleKey key = Console.ReadKey(true).Key;
? ? ? ? ? ? if (key == ConsoleKey.R)
? ? ? ? ? ? ? ? Start();
? ? ? ? ? ? else
? ? ? ? ? ? ? ? goto c;
? ? ? ? }
? ? ? ? static void MissionCompeleted()
? ? ? ? {
? ? ? ? ? ? msgbox += "恭喜通關(guān)\n您已擊敗惡魔,并成為了新的惡魔搂鲫!\n";
? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? MsgboxBar();
? ? ? ? ? ? MsgboxBar();
? ? ? ? c:
? ? ? ? ? ? ConsoleKey key = Console.ReadKey(true).Key;
? ? ? ? ? ? if (key == ConsoleKey.R)
? ? ? ? ? ? ? ? Start();
? ? ? ? ? ? else
? ? ? ? ? ? ? ? goto c;
? ? ? ? }
? ? ? ? static void PlayerController()
? ? ? ? {
? ? ? ? c:
? ? ? ? ? ? int x = Player.x, y = Player.y;
? ? ? ? ? ? ConsoleKey key = Console.ReadKey(true).Key;
? ? ? ? ? ? switch (key)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case ConsoleKey.UpArrow:
? ? ? ? ? ? ? ? ? ? y--;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.DownArrow:
? ? ? ? ? ? ? ? ? ? y++;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.LeftArrow:
? ? ? ? ? ? ? ? ? ? x--;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.RightArrow:
? ? ? ? ? ? ? ? ? ? x++;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case ConsoleKey.D1:
? ? ? ? ? ? ? ? ? ? AddAp(1); goto c;
? ? ? ? ? ? ? ? case ConsoleKey.D2:
? ? ? ? ? ? ? ? ? ? AddAp(2); goto c;
? ? ? ? ? ? ? ? case ConsoleKey.D3:
? ? ? ? ? ? ? ? ? ? AddAp(3); goto c;
? ? ? ? ? ? ? ? case ConsoleKey.D4:
? ? ? ? ? ? ? ? ? ? AddAp(4); goto c;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? }
? ? ? ? ? ? //越界判斷
? ? ? ? ? ? if (x < 1 && x < map.GetLength(0) - 1 && y < 1 && y < map.GetLength(1) - 1)
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? //碰撞判斷
? ? ? ? ? ? Object obj = HitTest(x, y);
? ? ? ? ? ? switch (obj)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case Object.Wall:
? ? ? ? ? ? ? ? ? ? //msgbox += "無作為\n";
? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? ? ? case Object.Enemy:
? ? ? ? ? ? ? ? ? ? //msgbox += "【進(jìn)入戰(zhàn)斗】\n";
? ? ? ? ? ? ? ? ? ? tarEnemy = GetTargetEnemy(x, y);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case Object.Chest:
? ? ? ? ? ? ? ? ? ? OpenChest(x, y);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case Object.Boss:
? ? ? ? ? ? ? ? ? ? tarEnemy = GetTargetEnemy(0, 0,true);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case Object.Exit:
? ? ? ? ? ? ? ? ? ? MapGenerator();
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? msgbox += "玩家移動\n";
? ? ? ? ? ? ? ? ? ? Player.x = x;
? ? ? ? ? ? ? ? ? ? Player.y = y;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? static void EnemyController()
? ? ? ? {
? ? ? ? ? ? for (int i = 0; i < enemyList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Enemy enemy = enemyList[i];
? ? ? ? ? ? ? ? //移動部分
? ? ? ? ? ? ? ? int x = enemy.x, y = enemy.y;
? ? ? ? ? ? ? ? int r = Event.rnd.Next(3, 8);
? ? ? ? ? ? ? ? for (int _y = y - r; _y <= y + r; _y++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? for (int _x = x - r; _x <= x + r; _x++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? //如果玩家在視野內(nèi)
? ? ? ? ? ? ? ? ? ? ? ? if (_x == Player.x && _y == Player.y)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? //優(yōu)先上下
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 2) == 0)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (Player.y < y)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? y--;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (Player.y > y)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? y++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (Player.x < x)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x--;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (Player.x > x)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? //優(yōu)先左右
? ? ? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (Player.x < x)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x--;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (Player.x > x)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (Player.y < y)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? y--;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (Player.y > y)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? y++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? goto c;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? int dir = Event.rnd.Next(0, 4);
? ? ? ? ? ? ? ? switch (dir)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? ? ? ? ? y--;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? ? ? y++;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? ? ? x--;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? ? ? x++;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? c:
? ? ? ? ? ? ? ? Object obj = HitTest(x, y);
? ? ? ? ? ? ? ? switch (obj)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? case Object.Wall:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case Object.Enemy:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case Object.Player:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case Object.Chest:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case Object.Boss:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case Object.Exit:
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? ? ? enemy.x = x;
? ? ? ? ? ? ? ? ? ? ? ? enemy.y = y;
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? static void AddAp(int att)
? ? ? ? {
? ? ? ? ? ? if (Player.ap <= 0)
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? Player.ap--;
? ? ? ? ? ? switch (att)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? Player.atk++;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? Player.def++;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? Player.dex++;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? ? ? Player.Int++;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? msgbox += "<剩余屬性點 " + Player.ap + " >\n";
? ? ? ? ? ? StatusBar();
? ? ? ? ? ? MsgboxBar();
? ? ? ? }
? ? ? ? static string CanSpell(int skill)
? ? ? ? {
? ? ? ? ? ? string msg = "";
? ? ? ? ? ? switch (skill)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? if (Player.skill1)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (Player.mana < 3)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg = "<法力不足>\n";
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? msg = "<尚未習(xí)得該技能>\n";
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? if (Player.skill2)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (Player.mana < 5)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg = "<法力不足>\n";
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? msg = "<尚未習(xí)得該技能>\n";
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? if (Player.skill3)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (Player.mana < 4)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? msg = "<法力不足>\n";
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? msg = "<尚未習(xí)得該技能>\n";
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? return msg;
? ? ? ? }
? ? ? ? static void OpenChest(int x, int y)
? ? ? ? {
? ? ? ? ? ? for (int i = 0; i < chestList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Chest chest = chestList[i];
? ? ? ? ? ? ? ? if (chest.x == x && chest.y == y)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? msgbox += "發(fā)現(xiàn) " + chest.treasure + " ";
? ? ? ? ? ? ? ? ? ? switch (chest.treasure)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? case "生命藥水":
? ? ? ? ? ? ? ? ? ? ? ? ? ? int val = Event.rnd.Next(5, 11);
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "增加 " + val + " 生命";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.life += val;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case "法力藥水":
? ? ? ? ? ? ? ? ? ? ? ? ? ? val = Event.rnd.Next(5, 11);
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "增加 " + val + " 法力";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.mana += val;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case "短劍":
? ? ? ? ? ? ? ? ? ? ? ? ? ? val = Event.rnd.Next(1, 4);
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "增加 " + val + " 力量";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.atk += val;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case "盔甲":
? ? ? ? ? ? ? ? ? ? ? ? ? ? val = Event.rnd.Next(1, 3);
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "增加 " + val + " 防御";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.def += val;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case "火球術(shù)卷軸":
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "學(xué)會了 火球術(shù)";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.skill1 = true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case "治愈術(shù)卷軸":
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "學(xué)會了 治愈術(shù)";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.skill2 = true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case "眩暈術(shù)卷軸":
? ? ? ? ? ? ? ? ? ? ? ? ? ? msgbox += "學(xué)會了 眩暈術(shù)";
? ? ? ? ? ? ? ? ? ? ? ? ? ? Player.skill3 = true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? msgbox += "\n";
? ? ? ? ? ? ? ? ? ? chestList.Remove(chest);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? enum Object
? ? ? ? {
? ? ? ? ? ? Ground, Wall, Enemy, Player, Chest, Boss, Exit
? ? ? ? };
? ? ? ? static Object HitTest(int x, int y)
? ? ? ? {
? ? ? ? ? ? if (map[x, y] == "□")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return Object.Wall;
? ? ? ? ? ? }
? ? ? ? ? ? if (x == map.GetLength(0) - 2 && y == map.GetLength(1) - 1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return Object.Exit;
? ? ? ? ? ? }
? ? ? ? ? ? //敵人
? ? ? ? ? ? for (int i = 0; i < enemyList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Enemy enemy = enemyList[i];
? ? ? ? ? ? ? ? if (x == enemy.x && y == enemy.y)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? return Object.Enemy;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //寶箱
? ? ? ? ? ? for (int i = 0; i < chestList.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Chest chest = chestList[i];
? ? ? ? ? ? ? ? if (x == chest.x && y == chest.y)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? return Object.Chest;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? if (x == Player.x && y == Player.y)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return Object.Player;
? ? ? ? ? ? }
? ? ? ? ? ? //BOSS
? ? ? ? ? ? if(level == BOSS_LEVEL)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(x>=8 && x<=11 && y>=8 && y <= 11)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (!(x == 8 && y == 8) && !(x == 11 && y == 8) && !(x == 11 && y == 9) && !(x == 11 && y == 11))
? ? ? ? ? ? ? ? ? ? ? ? return Object.Boss;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return Object.Ground;
? ? ? ? }
? ? ? ? static void PrintMap()
? ? ? ? {
? ? ? ? ? ? for (int y = 0; y < map.GetLength(1); y++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int x = 0; x < map.GetLength(0); x++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (x == Player.x && y == Player.y)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Yellow;
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("★");
? ? ? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //敵人列表
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < enemyList.Count; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Enemy enemy = enemyList[i];
? ? ? ? ? ? ? ? ? ? ? ? if (x == enemy.x && y == enemy.y)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkMagenta;
? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.Write(enemy.display);
? ? ? ? ? ? ? ? ? ? ? ? ? ? goto w;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //寶箱列表
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < chestList.Count; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Chest chest = chestList[i];
? ? ? ? ? ? ? ? ? ? ? ? if (x == chest.x && y == chest.y)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkCyan;
? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.Write("θ");
? ? ? ? ? ? ? ? ? ? ? ? ? ? goto w;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //BOSS
? ? ? ? ? ? ? ? ? ? if (level == BOSS_LEVEL)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? map[9, 8] = "△"; map[10, 8] = "△";
? ? ? ? ? ? ? ? ? ? ? ? map[8, 9] = "ψ"; map[9, 9] = "╲"; map[10, 9] = "╱";
? ? ? ? ? ? ? ? ? ? ? ? map[8, 10] = "|"; map[9, 10] = ")"; map[10, 10] = "("; map[11, 10] = "w ";
? ? ? ? ? ? ? ? ? ? ? ? map[8, 11] = "|"; map[9, 11] = "╱"; map[10, 11] = "╲";
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //BOSS顏色渲染
? ? ? ? ? ? ? ? ? ? if (level == BOSS_LEVEL && x >= 8 && x <= 11 && y >= 8 && y <= 11)
? ? ? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Red;
? ? ? ? ? ? ? ? ? ? else if (x == map.GetLength(0) - 2 && y == map.GetLength(1) - 1)
? ? ? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.DarkYellow;
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? Console.ForegroundColor = ConsoleColor.Gray;
? ? ? ? ? ? ? ? ? ? Console.Write(map[x, y]);
? ? ? ? ? ? ? ? ? ? w:;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? }
? ? ? ? ? ? if (isDead)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.SetCursorPosition(0, 0);
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□? ? ? ? ? ? ? ? ? ? □□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□? □□□□□□□□□□? □□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□? □□□□□□□□□□□□? □□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□? □? □□□□? □? □□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□? □□□□□□? □□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□? □? □□□□? □? □□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□? ? ? ? □□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□? □□□□? □□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□? □□□□□□□□□□□□? □□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□? □□□□□□□□□□? □□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□? ? ? ? ? ? ? ? ? ? □□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? if (boss==null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.SetCursorPosition(0, 0);
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□? ? ? ? ? ? ? ? ? ? □□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□? □□□□□□□□□□? □□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□? □□□□□□□□□□□□? □□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□? □□□□□□? □□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□? □? □□□□? □? □□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□□□□□□□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□? □□□□? □□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□? □□□□□? ? ? ? □□□□□? □□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□? □□□□□□□□□□□□? □□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□? □□□□□□□□□□? □□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□? ? ? ? ? ? ? ? ? ? □□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? Console.WriteLine("□□□□□□□□□□□□□□□□□□□□");
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? Console.SetCursorPosition(0, 0);
? ? ? ? ? ? Console.Write("第 " + level + " 層");
? ? ? ? }
? ? ? ? static void MapGenerator()
? ? ? ? {
? ? ? ? ? ? level++;
? ? ? ? ? ? Player.x = 1; Player.y = 1;
? ? ? ? ? ? enemyList.Clear();
? ? ? ? ? ? chestList.Clear();
? ? ? ? ? ? for (int y = 0; y < map.GetLength(1); y++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int x = 0; x < map.GetLength(0); x++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //邊界
? ? ? ? ? ? ? ? ? ? if (x == 0 || y == 0 || x == map.GetLength(0) - 1 || y == map.GetLength(1) - 1)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "□";
? ? ? ? ? ? ? ? ? ? ? ? if (x == map.GetLength(0) - 2 && y == map.GetLength(1) - 1 && level != BOSS_LEVEL)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "︾";
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? if (level == BOSS_LEVEL)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "? ";
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (y == 5 || y == 14)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (x >= 5 && x <= 14 && x != 9 && x != 10)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "□";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? else if (x == 14 || x == 5)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (y >= 5 && y <= 14 && y != 9 && y != 10)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "□";
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 8) == 0 && x != 1 && y != 1 && x != map.GetLength(0) - 2 && y != map.GetLength(1) - 2)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "□" ;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? map[x, y] = "? ";
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //生成敵人
? ? ? ? ? ? ? ? ? ? ? ? if (map[x, y] == "? ")
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 20) == 0 && x != 1 && y != 1 && x != map.GetLength(0) - 2 && y != map.GetLength(1) - 2)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? enemyList.Add(new Enemy(x, y));
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 80) == 0 && x != 1 && y != 1 && x != map.GetLength(0) - 2 && y != map.GetLength(1) - 2)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? chestList.Add(new Chest(x, y));
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? static void Info()
? ? ? ? {
? ? ? ? ? ? Console.SetCursorPosition(55, 20);
? ? ? ? ? ? Console.WriteLine("Developed by Linus C.");
? ? ? ? }
? ? }
? ? class Event
? ? {
? ? ? ? public static Random rnd = new Random();
? ? }
? ? class Player
? ? {
? ? ? ? public static int lv = 1, exp = 0, ap = 3, x = 1, y = 1, life = 20, mana = 10;
? ? ? ? public static bool skill1 = false, skill2 = false, skill3 = false;
? ? ? ? private static int _atk, _def, _dex, _int;
? ? ? ? public static int atk { get { return _atk; } set { _atk = value; } }
? ? ? ? public static int def { get { return _def; } set { _def = value; } }
? ? ? ? public static int dex { get { return _dex; } set { _dex = value; } }
? ? ? ? public static int Int { get { return _int; } set { _int = value; } }
? ? ? ? public static void Reset()
? ? ? ? {
? ? ? ? ? ? lv = 1; exp = 0; ap = 3; x = 1; y = 1;
? ? ? ? ? ? life = 20; mana = 10;
? ? ? ? ? ? skill1 = false; skill2 = false; skill3 = false;
? ? ? ? ? ? _atk = 2; _def = 1; _dex = 1; _int = 0;
? ? ? ? }
? ? ? ? //受傷判斷
? ? ? ? public static int GetHurt(int _atk, int _dex)
? ? ? ? {
? ? ? ? ? ? Random rnd = Event.rnd;
? ? ? ? ? ? _atk = _atk + rnd.Next(0, (int)(_atk * 0.5f));
? ? ? ? ? ? int mrate = 0;
? ? ? ? ? ? //對方敏捷-我方敏捷?
? ? ? ? ? ? int dex0 = _dex - dex;
? ? ? ? ? ? //如果對方敏捷高屁桑,從0~dex 為正值务蝠,否則 -dex~1
? ? ? ? ? ? if (dex0 > 0)
? ? ? ? ? ? ? ? mrate = Event.rnd.Next(0, dex0);
? ? ? ? ? ? else
? ? ? ? ? ? ? ? mrate = Event.rnd.Next(dex0, 1);
? ? ? ? ? ? //如果隨機(jī)數(shù)為負(fù)數(shù)
? ? ? ? ? ? if (mrate < 0)
? ? ? ? ? ? ? ? _atk = -1;
? ? ? ? ? ? else if (mrate > 0)
? ? ? ? ? ? ? ? _atk = _atk - def > 0 ? _atk - def : Event.rnd.Next(0, 2);
? ? ? ? ? ? //如果隨機(jī)數(shù)為0 則1/2幾率閃避
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 2) == 0)
? ? ? ? ? ? ? ? ? ? _atk = -1;
? ? ? ? ? ? ? ? else _atk = _atk - def > 0 ? _atk - def : Event.rnd.Next(0, 2);
? ? ? ? ? ? }
? ? ? ? ? ? life -= _atk > 0 ? _atk : 0;
? ? ? ? ? ? return _atk;
? ? ? ? }
? ? }
? ? class Enemy
? ? {
? ? ? ? public string name;
? ? ? ? public char display;
? ? ? ? public int x, y, life, atk, def, dex, exp;
? ? ? ? public Enemy(int _x, int _y,bool isBoss=false)
? ? ? ? {
? ? ? ? ? ? x = _x;
? ? ? ? ? ? y = _y;
? ? ? ? ? ? int r = Event.rnd.Next(0, 6);
? ? ? ? ? ? if (isBoss)
? ? ? ? ? ? ? ? r = 6;
? ? ? ? ? ? switch (r)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case 0:
? ? ? ? ? ? ? ? ? ? display = '鼠';
? ? ? ? ? ? ? ? ? ? name = "老鼠";
? ? ? ? ? ? ? ? ? ? life = 5;
? ? ? ? ? ? ? ? ? ? atk = 2;
? ? ? ? ? ? ? ? ? ? def = 1;
? ? ? ? ? ? ? ? ? ? dex = 0;
? ? ? ? ? ? ? ? ? ? exp = 1;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? display = '蝙';
? ? ? ? ? ? ? ? ? ? name = "蝙蝠";
? ? ? ? ? ? ? ? ? ? life = 4;
? ? ? ? ? ? ? ? ? ? atk = 2;
? ? ? ? ? ? ? ? ? ? def = 1;
? ? ? ? ? ? ? ? ? ? dex = 2;
? ? ? ? ? ? ? ? ? ? exp = 1;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? display = '蛛';
? ? ? ? ? ? ? ? ? ? name = "蜘蛛";
? ? ? ? ? ? ? ? ? ? life = 3;
? ? ? ? ? ? ? ? ? ? atk = 1;
? ? ? ? ? ? ? ? ? ? def = 0;
? ? ? ? ? ? ? ? ? ? dex = 4;
? ? ? ? ? ? ? ? ? ? exp = 1;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? display = '蛇';
? ? ? ? ? ? ? ? ? ? name = "蛇";
? ? ? ? ? ? ? ? ? ? life = 5;
? ? ? ? ? ? ? ? ? ? atk = 3;
? ? ? ? ? ? ? ? ? ? def = 1;
? ? ? ? ? ? ? ? ? ? dex = 3;
? ? ? ? ? ? ? ? ? ? exp = 2;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? ? ? display = '幽';
? ? ? ? ? ? ? ? ? ? name = "幽靈";
? ? ? ? ? ? ? ? ? ? life = 5;
? ? ? ? ? ? ? ? ? ? atk = 3;
? ? ? ? ? ? ? ? ? ? def = 4;
? ? ? ? ? ? ? ? ? ? dex = 2;
? ? ? ? ? ? ? ? ? ? exp = 2;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 5:
? ? ? ? ? ? ? ? ? ? display = '骷';
? ? ? ? ? ? ? ? ? ? name = "骷髏";
? ? ? ? ? ? ? ? ? ? life = 8;
? ? ? ? ? ? ? ? ? ? atk = 4;
? ? ? ? ? ? ? ? ? ? def = 3;
? ? ? ? ? ? ? ? ? ? dex = 2;
? ? ? ? ? ? ? ? ? ? exp = 3;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 6:
? ? ? ? ? ? ? ? ? ? display = '王';
? ? ? ? ? ? ? ? ? ? name = "惡魔";
? ? ? ? ? ? ? ? ? ? life = 30;
? ? ? ? ? ? ? ? ? ? atk = 8;
? ? ? ? ? ? ? ? ? ? def = 6;
? ? ? ? ? ? ? ? ? ? dex = 5;
? ? ? ? ? ? ? ? ? ? exp = 20;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? public int GetHurt(int _atk, int _dex)
? ? ? ? {
? ? ? ? ? ? Random rnd = Event.rnd;
? ? ? ? ? ? _atk = _atk + rnd.Next(0, (int)(_atk * 0.5f));
? ? ? ? ? ? int mrate = 0;
? ? ? ? ? ? //對方敏捷-我方敏捷?
? ? ? ? ? ? int dex0 = _dex - dex;
? ? ? ? ? ? //如果對方敏捷高,從0~dex 為正值导而,否則 -dex~1
? ? ? ? ? ? if (dex0 > 0)
? ? ? ? ? ? ? ? mrate = Event.rnd.Next(0, dex0);
? ? ? ? ? ? else
? ? ? ? ? ? ? ? mrate = Event.rnd.Next(dex0, 1);
? ? ? ? ? ? //如果隨機(jī)數(shù)為負(fù)數(shù)
? ? ? ? ? ? if (mrate < 0)
? ? ? ? ? ? ? ? _atk = -1;
? ? ? ? ? ? else if (mrate > 0)
? ? ? ? ? ? ? ? _atk = _atk - def > 0 ? _atk - def : Event.rnd.Next(0, 2);
? ? ? ? ? ? //如果隨機(jī)數(shù)為0 則1/2幾率閃避
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (Event.rnd.Next(0, 2) == 0)
? ? ? ? ? ? ? ? ? ? _atk = -1;
? ? ? ? ? ? ? ? else _atk = _atk - def > 0 ? _atk - def : Event.rnd.Next(0, 2);
? ? ? ? ? ? }
? ? ? ? ? ? life -= _atk > 0 ? _atk : 0;
? ? ? ? ? ? return _atk;
? ? ? ? }
? ? }
? ? class Chest? ?
? ? {
? ? ? ? public int x, y;
? ? ? ? public string treasure;
? ? ? ? public string[] treasureList = { "生命藥水", "法力藥水", "短劍", "盔甲", "火球術(shù)卷軸", "治愈術(shù)卷軸", "眩暈術(shù)卷軸" };
? ? ? ? public Chest(int _x, int _y)
? ? ? ? {
? ? ? ? ? ? x = _x;
? ? ? ? ? ? y = _y;
? ? ? ? ? ? int rnd = Event.rnd.Next(0, 185);
? ? ? ? ? ? if (rnd < 15)
? ? ? ? ? ? ? ? treasure = treasureList[6];
? ? ? ? ? ? else if (rnd >= 15 && rnd < 30)
? ? ? ? ? ? ? ? treasure = treasureList[5];
? ? ? ? ? ? else if (rnd >= 30 && rnd < 45)
? ? ? ? ? ? ? ? treasure = treasureList[4];
? ? ? ? ? ? else if (rnd >= 45 && rnd < 65)
? ? ? ? ? ? ? ? treasure = treasureList[3];
? ? ? ? ? ? else if (rnd >= 65 && rnd < 85)
? ? ? ? ? ? ? ? treasure = treasureList[2];
? ? ? ? ? ? else if (rnd >= 85 && rnd < 135)
? ? ? ? ? ? ? ? treasure = treasureList[0];
? ? ? ? ? ? else
? ? ? ? ? ? ? ? treasure = treasureList[1];
? ? ? ? }
? ? }
}