static void Main(string[] args) { Console.SetWindowSize(25, 10); Console.Title = "2048 Game"; canvas = new ConsoleCanvas(21, 9); buffer = canvas.GetBuffer(); colorBuffer = canvas.GetColorBuffer(); nums = new int[4, 4]; RandNewNum(); // 先刷新一次界面 canvas.ClearBuffer_DoubleBuffer(); DrawAll(); canvas.Refresh_DoubleBuffer(); while (true) { GameLogic(); canvas.ClearBuffer_DoubleBuffer(); DrawAll(); canvas.Refresh_DoubleBuffer(); } }
static void StageLogic() { // test~~ var lines = ReadMapFile("../../level0.txt"); var boxes = TranslateMap(lines); allBoxes.AddRange(boxes); RefreshRules(); // 初始化图像 canvas.ClearBuffer_DoubleBuffer(); DrawAll(); canvas.Refresh_DoubleBuffer(); int step = 0; Dictionary <int, List <Box> > history = new Dictionary <int, List <Box> >(); while (true) { int run = Input(); if (run == 1) { history[step] = new List <Box>(); foreach (var box in allBoxes) { history[step].Add(box.Copy()); } step++; } else if (run == -1) { if (step >= 1) { step--; allBoxes.Clear(); allBoxes.AddRange(history[step]); } } if (run != 0) { canvas.ClearBuffer_DoubleBuffer(); DrawAll(); canvas.Refresh_DoubleBuffer(); RefreshRules(); } } canvas.ClearBuffer_DoubleBuffer(); DrawAll(); canvas.Refresh_DoubleBuffer(); return; }
static void Main(string[] args) { canvas = new ConsoleCanvas(width, height); buffer = canvas.GetBuffer(); color_buffer = canvas.GetColorBuffer(); Rule.Init(); int level = 1; if (args.Length > 1) { level = int.Parse(args[1]); } bool game_ok = true; while (game_ok) { // 关卡 StageLogic(); canvas.ClearBuffer_DoubleBuffer(); DrawAll(); canvas.Refresh_DoubleBuffer(); Console.ReadLine(); } }
static void DrawAll(int[,] Mine) // 显示 { canvas.ClearBuffer_DoubleBuffer(); DrawOther(Mine); DrawBelowInfo(); canvas.Refresh_DoubleBuffer(); }
static void Main(string[] args) { int flag = minesweeper; canvas = new ConsoleCanvas(width, height + 3); buffer = canvas.GetBuffer(); color_buffer = canvas.GetColorBuffer(); player.SetPos(0, 0); // 默认位置 System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); // 计算用时 int[,] mine = initMine(); int[,] saveMine = SaveMap(mine); int[,] userMine = InitUser(mine.GetLength(0), mine.GetLength(1)); bool b = true; string res = "不好意思,您输了。下次走运!"; sw.Start(); // 计时开始 while (b) { below_text = "按U标记,按A打开,按IJKL移动"; level_target = $"当前雷数{minesweeper},剩余标记{flag}"; DrawAll(userMine); // 显示棋盘 int count = InputNum(); if (count == 1) { b = StartGame(mine, userMine); // if (GameOver(userMine, saveMine)) { res = "恭喜!您赢了!"; break; } } else if (count == 0) { if (userMine[player.i, player.j] != -10 && userMine[player.i, player.j] < 0) { userMine[player.i, player.j] = -10; flag--; } else if (userMine[player.i, player.j] == -10) { userMine[player.i, player.j] = -2; flag++; } } } sw.Stop(); // 计时结束 canvas.ClearBuffer_DoubleBuffer(); DrawOther(saveMine); canvas.Refresh_DoubleBuffer(); Console.WriteLine(); Console.Write(res); Console.WriteLine("时间:{0} 秒", sw.ElapsedMilliseconds / 1000); Console.ReadLine(); }
public void Draw() { canvas.ClearBuffer_DoubleBuffer(); //Msg Draw drawMsg(); canvas.Refresh_DoubleBuffer(); }
public void draw() { //TODO: 更换Canvas绘制系统 // new canvas system stagecanvas.ClearBuffer_DoubleBuffer(); // draw area DrawMap(); DrawAnimation(); DrawPlayer(); stagecanvas.Refresh_DoubleBuffer(); gameMsgUI.Draw(); playerStatusUI.Draw(); // gameMsgCanvas.ClearBuffer_DoubleBuffer(); // playerStatusUICanvas.ClearBuffer_DoubleBuffer(); // gameMsgCanvas.Refresh_DoubleBuffer(); // playerStatusUICanvas.Refresh_DoubleBuffer(); }
//static ConsoleColor[,] forecolor_buffer = null; //static ConsoleColor[,] backcolor_buffer = null; static void Main(string[] args) { string url_root = "http://127.0.0.1:8080/?timestamp=" + ""; string url = url_root; canvas = new ConsoleCanvas(canvas_width, canvas_height); buffer = canvas.GetBuffer(); //forecolor_buffer = canvas.GetForecolorBuffer(); //backcolor_buffer = canvas.GetBackcolorBuffer(); while (true) { DeliveryData data = Handler(url); if (!data.isPlayerReady)//人不齐时等待 { Console.WriteLine("等待玩家中......"); Thread.Sleep(100); Console.Clear(); url = url_root + data.cur_timestamp; continue; } canvas.ClearBuffer_DoubleBuffer(); InitMap(); ParseToChar(data); if (data.isGameOver) { if (data.player_idx < 2) { ParseInfo("游戏结束!" + (data.winner_idx == data.player_idx ? "你赢了!" : "你输了..."), 15); } else { ParseInfo("观战结束!" + data.winner_idx + "号玩家获胜!", 15); } //ParseInfo("房间将在5秒后重启......", 19); canvas.Refresh_DoubleBuffer(); break; } if (data.player_idx < 2 && data.isReady)//当玩家回合 { ParseInfo("请选择打击位置", 15); canvas.Refresh_DoubleBuffer(); int left = 5 * 2; int top = 5; int idx = 44; ConsoleKeyInfo cki; while (true) { cki = BlinkAt(ref left, ref top, mapForPaint[0, idx]); if (cki.Key == ConsoleKey.A) { if (left > 1 * 2) { left -= 2; idx--; } else { left = 2; } } else if (cki.Key == ConsoleKey.S) { if (top < 10) { top++; idx += 10; } else { top = 10; } } else if (cki.Key == ConsoleKey.D) { if (left < 10 * 2) { left += 2; idx++; } else { left = 20; } } else if (cki.Key == ConsoleKey.W) { if (top > 1) { top--; idx -= 10; } else { top = 1; } } else { if (mapForPaint[0, idx] == '_') { url = url_root + data.cur_timestamp + "&mapidx=" + idx.ToString(); break; } } } } else if (data.player_idx < 2)//当非玩家回合 { //canvas.ClearBuffer_DoubleBuffer(); //InitMap(); //ParseToChar(data); ParseInfo("对方正在考虑中......", 15); canvas.Refresh_DoubleBuffer(); url = url_root + data.cur_timestamp; Thread.Sleep(100); } else//观众 { //canvas.ClearBuffer_DoubleBuffer(); //InitMap(); //ParseToChar(data); ParseInfo("观战中......", 15); canvas.Refresh_DoubleBuffer(); url = url_root + data.cur_timestamp; Thread.Sleep(100); } } Console.ReadKey(); }