Hello everyone,
I'm new here since yesterday I was trying c# with code snippets here for vs2008 up to 2015.
I got the project successful. I will give my code template for C# here as a community driven.
The project must be upgraded from 2008.
Every time everyone needs to create a new code template, you should call references inside c# vesion.
For instance DarkGDK, DGDKLib. You must make to get the code done and built.
I'm here to help. So, any doubt I will try to give an answer soon as possible.
[code lang=c#]
/*
* Criado por SharpDevelop.
* Utilizador: astro
* Data: 19/02/2017
* Hora: 16:52
*
* Para alterar este modelo usar Ferramentas | Opções | Código | Alterar Cabeçalhos Standard
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using DarkGDK;
namespace GDKCs.properties
{
/// <summary>
/// Description of Class1.
/// </summary>
public class Class1
{
Bitmap image1;
//variables
private static Boolean LeftMouseDown;
private static Boolean[] KeyDown = new Boolean[104];
private static int lastScanCode;
public static void SetupKeyEvents() // Must be called once before any of the following functions
{
for (int i = 0; i <= KeyDown.Length; i++)
KeyDown[i] = false;
}
public static Boolean SingleKeyPress(DarkGDK.IO.Keys kKey)
{
if (DarkGDK.IO.Keyboard.State(kKey) && !KeyDown[DarkGDK.IO.Keyboard.ScanCode])
{
KeyDown[DarkGDK.IO.Keyboard.ScanCode] = true;
lastScanCode = DarkGDK.IO.Keyboard.ScanCode;
return true;
}
else if (DarkGDK.IO.Keyboard.ScanCode == 0) // Means we aren't pressing any key
{
KeyDown[lastScanCode] = false;
return false;
}
else
return false;
}
public static Boolean SingleLeftClick()
{
if (DarkGDK.IO.Mouse.LeftClick && !LeftMouseDown)
{
LeftMouseDown = true;
return true;
}
else if (!DarkGDK.IO.Mouse.LeftClick)
{
LeftMouseDown = false;
return false;
}
return false;
}
public void NGame(){
}
public void LGame()
{
}
public void OGame()
{
}
public void OptGame()
{
}
public void qGame(){
System.Environment.Exit(1);
}
public void Menu()
{
do
{
int c = 1;
switch(c){
case '1': Console.Write("New Game\n");
break;
case '2': Console.Write("Load Game\n");
break;
case '3': Console.Write("Online Game\n");
break;
case '4': Console.Write("Options\n");
break;
case '5': qGame();
break;
default: Console.Write("Error... Quitting\n");
break;
}
}while(true);
}
//Bitmap Loader
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\astro\"
+ @"DarkBasic\ekron.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for(x=0; x<image1.Width; x++)
{
for(y=0; y<image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
//PictureBox = image1;
// Display the pixel format in Label1.
//Label = "Pixel format: "+image1.PixelFormat.ToString();
}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
}
}
Thank you.