ConsoleGamesLib 1.1.0
dotnet add package ConsoleGamesLib --version 1.1.0
NuGet\Install-Package ConsoleGamesLib -Version 1.1.0
<PackageReference Include="ConsoleGamesLib" Version="1.1.0" />
paket add ConsoleGamesLib --version 1.1.0
#r "nuget: ConsoleGamesLib, 1.1.0"
// Install ConsoleGamesLib as a Cake Addin
#addin nuget:?package=ConsoleGamesLib&version=1.1.0
// Install ConsoleGamesLib as a Cake Tool
#tool nuget:?package=ConsoleGamesLib&version=1.1.0
Sprite can be typically used as a simple brick block in a breakout game. For creating a game you should create a Player class that inherits Sprite, and implement "HandleKeys" for your player(s). Typical inherited Player class:
public class Player: Sprite { public Player(string name = "P1", PlayerType type = PlayerType.Bottom, int x = 10, int y = 26) : base(x, y, GenerateColImage(type)) { InitialPos = (x, y); Name = name; Type = type; LivesTextSprite = new DynamicTextSprite(0, 10, $"{Name} Lives: "); ReInit(); } public PlayerType Type { get; set; }
internal new void ReInit()
{
if (NewGame) //i.e. user pressed N (or App just started).
{
Score = 0;
Lives = 8;
}
base.ReInit();
}
public virtual void HandleKeys(ConsoleKey key)
{
if (Type == PlayerType.Bottom)
{
if (key == ConsoleKey.S)
if (Dx < 0) Dx += -0.5; // or call relevant function
else Dx = -1;
else if (key == ConsoleKey.F)
if (Dx > 0) Dx += 0.5;
else Dx = 1; // or call relevant function
else if (key == ConsoleKey.D)
Dx = 0;
}
}
} }
Sprite instantiation (a red brick in this example): new Sprite(0, 0, new[] { (0, 0, "█████▌", ConsoleColor.Red) });
Player instantiations: new Player(), new Player("P3", PlayerType.Right, 71, 13)
Typical game loop:
while (true)
{
while (!Console.KeyAvailable)
{ //game loop
if (!Sprite.NewGame) //this must be a separate if (the way it was before the while ended and gave control to a
//blocking call (for the key, while there was no key).
{
ball.Move();
ball.ProcessCollisions(sprites, players); //at this stage processing on all players
//causes the game to slow down. Can you guess why?
snake.Move();
foreach (var player in players)
player.Move();
snake.ProcessCollisions(new Sprite[] { ball });
}
Thread.Sleep(speed);
}
var key = Console.ReadKey(true).Key; //key press handling
if (key == ConsoleKey.Escape)
break; //exit game
else
HandleKey(key);
}
private static void HandleKey(ConsoleKey key)
{
if (key == ConsoleKey.N)
GameReInit();
//control game speed.
else if (key == ConsoleKey.Add)
speed = speed * 8 / 10;
else if (key == ConsoleKey.Subtract)
speed = speed * 10 / 8;
else
{
foreach (var player in players)
player.HandleKeys(key);
snake.HandleKeys(key);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.2-beta2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Sprite can be typically used as a simple brick block in a breakout game.
For creating a game you should create a Player class that inherits Sprite, and implement "HandleKeys" for your player(s).