Skip to content

Instantly share code, notes, and snippets.

@RichardB01
Created September 6, 2014 18:00
Show Gist options
  • Save RichardB01/cb9d6c32cd75efefc1a3 to your computer and use it in GitHub Desktop.
Save RichardB01/cb9d6c32cd75efefc1a3 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML;
using SFML.Window;
using SFML.Graphics;
namespace Chess
{
class Chess
{
private RenderWindow _window;
public void Start()
{
AssetManager.LoadSprites();
// Create window instance.
_window = new RenderWindow(new VideoMode(520, 520), "Chess", Styles.Default);
_window.SetVisible(true);
_window.Closed += new EventHandler(OnClosed);
Pieces.Pawn pawn = new Pieces.Pawn(Colours.Black, 1, 1);
// Main loop.
while (_window.IsOpen())
{
_window.DispatchEvents();
_window.Clear(Color.Black);
_window.Draw(pawn.Sprite);
var moves = pawn.Moves;
foreach (var move in moves)
{
var offset = move.Key;
var type = move.Value;
var X = pawn.Position.X + offset.X;
var Y = pawn.Position.Y + offset.Y;
X = X * 65;
Y = Y * 65;
Color col = new Color();
if (type == 1) col = Color.Green;
if (type == 2) col = Color.Red;
RectangleShape shape = new RectangleShape();
shape.Size = new Vector2f(65, 65);
shape.Position = new Vector2f(X, Y);
shape.FillColor = col;
_window.Draw(shape);
}
_window.Display();
}
}
// Check for closures.
void OnClosed(object sender, EventArgs e)
{
_window.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment