I have encountered a new problem. I included the clearing function you supplied above. No matter what I do, anything I put in between the two while statements gets skipped over like it's not even there. The switches only go through 4 times, and it should be 5.
Code:
using System;
using nsClearConsole;
namespace Consoleapp1
{
public class Character
{
public string name;
public int level;
public int xp;
public int attack;
public int str;
public int dex;
public int con;
public int hp;
public int ac;
public int ranged;
public int melee;
public int dodge;
public int block;
public int dmg;
public Character()
{
this.level = 0;
this.xp = 0;
this.attack = 0;
this.str = 0;
this.dex = 0;
this.con = 0;
this.hp = 0;
this.ac = 0;
this.ranged = 0;
this.melee = 0;
this.dodge = 0;
this.block = 0;
this.dmg = 0;
this.name = "";
}
}
public class Class1
{
public static void Main(string[] args)
{
Character player = new Character();
Console.Write("Welcome to C# test game\n");
Console.Write("Press enter to start creating your character\n");
Console.ReadLine();
CharGen(player);
}
public static void CharGen(Character player)
{
ClearConsole ClearMyConsole = new ClearConsole();
ClearMyConsole.Clear();
Console.Write("Enter your name:");
player.name = Console.ReadLine();
ClearMyConsole.Clear();
Console.WriteLine("You have 5 attribute points, please choose where to put them.");
Console.ReadLine();
int points = 5;
player.str = 10;
player.dex = 10;
player.con = 10;
int temp;
while(points != 0)
{
ClearMyConsole.Clear();
Console.WriteLine("(1)Strength-{0}\n(2)Dexterity-{1}\n(3)Consitution-{2}\nPoints remaining-{3}",player.str,player.dex,player.con,points);
temp = Console.Read();
switch(temp)
{
case '1':
player.str++;
points--;
break;
case '2':
player.dex++;
points--;
break;
case '3':
player.con++;
points--;
break;
default:
break;
}//switch
}//while
Console.WriteLine("Hello");
Console.WriteLine("Hello");
Console.WriteLine("Hello");
Console.ReadLine();
Console.WriteLine("Hello");
Console.WriteLine("Hello");
Console.WriteLine("Hello");
points = 5;
while(points != 0)
{
ClearMyConsole.Clear();
Console.WriteLine("(1)Ranged-{0}\n(2)Melee-{1}\n(3)Blocking-{2}\n(4)Dodging-{3}\nPoints remaining-{4}",player.ranged,player.melee,player.block,player.dodge,points);
temp = Console.Read();
switch(temp)
{
case '1':
player.ranged++;
points--;
break;
case '2':
player.melee++;
points--;
break;
case '3':
player.block++;
points--;
break;
case '4':
player.dodge++;
points--;
break;
default:
break;
}//switch
}//while
}//main
}//class
}//namespace
(class2) for the console clearing code
Code:
using System;
using System.Runtime.InteropServices;
namespace nsClearConsole
{
/// <summary>
/// Summary description for ClearConsole.
/// </summary><BR/>
public class ClearConsole
{
private const int STD_OUTPUT_HANDLE = -11;
private const byte EMPTY = 32;
[StructLayout(LayoutKind.Sequential)]
struct COORD
{
public short x;
public short y;
}
[StructLayout(LayoutKind.Sequential)]
struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}
[StructLayout(LayoutKind.Sequential)]
struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public int wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}
[DllImport("kernel32.dll", EntryPoint="GetStdHandle", SetLastError=true, CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", EntryPoint="FillConsoleOutputCharacter", SetLastError=true, CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int FillConsoleOutputCharacter(int hConsoleOutput, byte cCharacter, int nLength, COORD dwWriteCoord, ref int lpNumberOfCharsWritten);
[DllImport("kernel32.dll", EntryPoint="GetConsoleScreenBufferInfo", SetLastError=true, CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int GetConsoleScreenBufferInfo(int hConsoleOutput, ref CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
[DllImport("kernel32.dll", EntryPoint="SetConsoleCursorPosition", SetLastError=true, CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int SetConsoleCursorPosition(int hConsoleOutput, COORD dwCursorPosition);
private int hConsoleHandle;
public ClearConsole()
{
//
// TODO: Add constructor logic here.
//
hConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
}
public void Clear()
{
int hWrittenChars = 0;
CONSOLE_SCREEN_BUFFER_INFO strConsoleInfo = new CONSOLE_SCREEN_BUFFER_INFO();
COORD Home;
Home.x = Home.y = 0;
GetConsoleScreenBufferInfo(hConsoleHandle, ref strConsoleInfo);
FillConsoleOutputCharacter(hConsoleHandle, EMPTY, strConsoleInfo.dwSize.x * strConsoleInfo.dwSize.y, Home, ref hWrittenChars);
SetConsoleCursorPosition(hConsoleHandle, Home);
}
}
}