73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using CoopSweeper.GameTypes;
|
|
using CoopSweeper.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace CoopSweeper
|
|
{
|
|
class Program
|
|
{
|
|
const int MAP_POS_X = 3;
|
|
const int MAP_POS_Y = 3;
|
|
|
|
static List<IView> _views = new List<IView>();
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Console.OutputEncoding = Encoding.UTF8;
|
|
Console.ForegroundColor = ConsoleColor.White;
|
|
Console.BackgroundColor = ConsoleColor.Black;
|
|
Console.SetCursorPosition(0, 0);
|
|
Console.CursorVisible = false;
|
|
Console.Clear();
|
|
var game = new Game();
|
|
_views.Add(new GameView(game) { Position = new Position(1, 3) });
|
|
_views.Add(new MenuBarView() { Position = new Position(0, 2) });
|
|
StartNewGame(game);
|
|
game.GameFinished += won =>
|
|
{
|
|
Console.SetCursorPosition(0, 0);
|
|
if (won)
|
|
Console.Write("You won!");
|
|
else
|
|
Console.Write("You lost!");
|
|
Draw(false);
|
|
Console.ReadKey(true);
|
|
StartNewGame(game);
|
|
};
|
|
ConsoleKey key = (ConsoleKey)(-1);
|
|
Draw(true);
|
|
while ((key = Console.ReadKey(true).Key) != ConsoleKey.Escape)
|
|
{
|
|
HandleKeyEvent(key);
|
|
Draw(false);
|
|
Console.SetCursorPosition(0, 0);
|
|
Console.CursorVisible = false;
|
|
}
|
|
}
|
|
|
|
private static void Draw(bool fullRedraw)
|
|
{
|
|
foreach(var view in _views)
|
|
view.Draw(fullRedraw);
|
|
}
|
|
|
|
private static void HandleKeyEvent(ConsoleKey key)
|
|
{
|
|
foreach(var view in _views)
|
|
if (view.HandleKeyEvent(key))
|
|
break;
|
|
}
|
|
|
|
public static void StartNewGame(Game game)
|
|
{
|
|
game.GenerateGame(100, 30, 15);
|
|
Console.Clear();
|
|
Console.SetCursorPosition(0, 0);
|
|
Draw(true);
|
|
}
|
|
}
|
|
}
|