Yeah, normally I would've been a little more agitated but in this case it was human error that, at first, almost caught me too.
[QUOTE=Kylegar;19609691]asdf
yea, I had to write a quicksort algorithm for a class yesterday in C, which highly influenced that post XD. I don't get why they spend so long on this shit...once you get out of classes, they are all written for you, and, the concept is pretty simple. really, it's just a mind excersize nowadays[/QUOTE]
Quicksort? Really?
Sure, the concept of quicksort is simple to understand, but it took the collective efforts of computer science a good [I]20 years[/I] to write a bug-free quicksort implementation. There are piles and piles of nasty edge and corner cases where weird things can happen.
[editline]03:00PM[/editline]
[QUOTE=gparent;19610731]Well yeah, the only way that will work is definitely the best.
But otherwise default parameters would be preferred.
[editline]06:36PM[/editline]
That won't work, in his code the [B]parameter[/B] is called "1". At run time, the value could be anything.[/QUOTE]
It's a moot point. The C89 (earlier, perhaps?) standard says that variable names cannot begin with a numeric character. None of the code will compile.
His example was pretty lame as nobody knew if it was trying to get it to set vars as other vars by the default or vars as a fixed number by default.
You could always go ASM and manually pass it to the stack.
Are multidimensional arrays of objects possible in c#?
If so how do I do it with these classes:
I have a GameTile class:
[code]internal class ASCIIGameTile
{
int XCoOrd;
int YCoOrd;
char character;
Boolean passable;
ASCIIGameTile( int X, int Y, char sChar, Boolean pass)
{
XCoOrd = X;
YCoOrd = Y;
character = sChar;
passable = pass;
}
ASCIIGameTile( int X, int Y )
{
XCoOrd = X;
YCoOrd = Y;
character = '.';
passable = true;
}
void Draw()
{
Console.SetCursorPosition(XCoOrd, YCoOrd);
Console.Write(character);
}
}[/code]
And then I have a GameGrid class which I want to contain the array of GameTiles. The code for which is as follows so far:
[code]public class ASCIIGameGrid
{
int width;
int height;
ASCIIGameTile [,] Tiles;
ASCIIGameGrid()
{
width = Console.WindowWidth;
height = Console.WindowHeight;
Tiles = new [/code]
What do I need to do next to initialise the Tiles array?
[QUOTE=Wickedgenius;19612271]Are multidimensional arrays of objects possible in c#?
If so how do I do it with these classes:
I have a GameTile class:
[code]internal class ASCIIGameTile
{
int XCoOrd;
int YCoOrd;
char character;
Boolean passable;
ASCIIGameTile( int X, int Y, char sChar, Boolean pass)
{
XCoOrd = X;
YCoOrd = Y;
character = sChar;
passable = pass;
}
ASCIIGameTile( int X, int Y )
{
XCoOrd = X;
YCoOrd = Y;
character = '.';
passable = true;
}
void Draw()
{
Console.SetCursorPosition(XCoOrd, YCoOrd);
Console.Write(character);
}
}[/code]
And then I have a GameGrid class which I want to contain the array of GameTiles. The code for which is as follows so far:
[code]public class ASCIIGameGrid
{
int width;
int height;
ASCIIGameTile [,] Tiles;
ASCIIGameGrid()
{
width = Console.WindowWidth;
height = Console.WindowHeight;
Tiles = new [/code]
What do I need to do next to initialise the Tiles array?[/QUOTE]
My C# is a bit rusty (getting back into it) but I think it would be:
[code]
Tiles = new ASCIIGameTile[width, height];
[/code]
or whatever variables you want to use instead of width and height.
[QUOTE=Wishfallen;19612424]My C# is a bit rusty (getting back into it) but I think it would be:
[code]
Tiles = new ASCIIGameTile[width, height];
[/code]
or whatever variables you want to use instead of width and height.[/QUOTE]
The bit I'm most confused about is the constructor. I think if I can work out to make the array itself, it's adding the objects to it that I'm confused about.
[QUOTE=Jallen;19608089]:words:
So do I just follow the normal order of operations?[/QUOTE]
Just FYI in my own experience, I just associate visual importance with the operators. Basically, stuff in parenthesis above all, then powers and roots (they're essentially the same thing, nth root of x is just x^(1/n)), then multiplication and division (again, essentially the same thing, x/y is just x*(1/y)), and then addition and subtraction (once again, x - y is x + (-y)). I've never before heard of BODMAS and it sounds kind of useless and confusing.
So, basically:
log 12 - log 4 + log 3 = log 12 + -log 4 + log 3
Since its just addition of a negative, you can now reorder the expression however you want due to the commutative property of addition (and multiplication).
So, one way of evaluating it would be:
log 12 + log 3 + -log 4
log (12 * 3) + -log 4
log (12 * 3 * (1 / 4))
log (36 / 4)
log 9
[QUOTE=nullsquared;19612605]Just FYI in my own experience, I just associate visual importance with the operators. Basically, stuff in parenthesis above all, then powers and roots (they're essentially the same thing, nth root of x is just x^(1/n)), then multiplication and division (again, essentially the same thing, x/y is just x*(1/y)), and then addition and subtraction (once again, x - y is x + (-y)). I've never before heard of BODMAS and it sounds kind of useless and confusing.
So, basically:
log 12 - log 4 + log 3 = log 12 + -log 4 + log 3
Since its just addition of a negative, you can now reorder the expression however you want due to the commutative property of addition (and multiplication).
So, one way of evaluating it would be:
log 12 + log 3 + -log 4
log (12 * 3) + -log 4
log (12 * 3 * (1 / 4))
log (36 / 4)
log 9[/QUOTE]
Cool, thanks.
My maths knowledge is lacking in areas, I can work with it when I know how it all works but I don't know about a lot of maths stuff.
In general I usually only have to work with triginometry, vectors, matrices etc, but now we are going into things like searches, I think the binary search does something like Log n to the base 2 comparisons. It's important that I know it for stuff later on.
[QUOTE=Wickedgenius;19612489]The bit I'm most confused about is the constructor. I think if I can work out to make the array itself, it's adding the objects to it that I'm confused about.[/QUOTE]
new ASCIIGameTile[width, height] creates a 2D array that's width*height in size. Adding objects is just as easy too Tiles[x,y]=new ASCIIGameTile(...)
[QUOTE=Robber;19612743]new ASCIIGameTile[width, height] creates a 2D array that's width*height in size. Adding objects is just as easy too Tiles[x,y]=new ASCIIGameTile(...)[/QUOTE]
I've just been thinking about it and correct me if I'm wrong but would the best way be to use a loop nested inside another, the outer one looping through the first index, the inner one looping through the second index and then using Tiles[x,y] = new ASCIIGameTile(...) and then for each one I can construct it how I need it.
Thanks for the help guys, I tend to find it easier to find a solution when I'm getting a little input.
Yes, that's the best (and only) way to fill it.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Turnbasedgame
{
class Program
{
static void Main(string[] args)
{
int lives = 3;
int points = 0;
int treasurex = 5;
int treasurey = 5;
int playerx = 7;
int playery = 7;
int badguyx = 14;
int badguyy = 14;
int speed = 1;
string[,] board = new string[15, 15];
bool gameover = false;
moveplayer(ref playerx, ref playery);
intro();
//this is the intro procedure that tells the user how to play the game and plays a nice tune
fillboard(board);
// this function fills the array with spaces
board[playerx, playery] = "☺";
board[badguyx, badguyy] = "ö";
movetreasure(ref treasurex, ref treasurey);
board[treasurex, treasurey] =" ";
drawboard(board);
Console.Beep(800, 400);
Console.Beep(1000, 400);
Console.Beep(800, 400);
while (gameover != true)
{
if (lives == 0)
{
Console.Clear();
Console.WriteLine("GameOver You scored " + points + " points");
Console.ReadLine();
gameover = true;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("#####################");
Console.ForegroundColor = ConsoleColor.White ;
Console.WriteLine("Lives:" + lives);
Console.WriteLine("Total Points:" + points );
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("#####################");
Console.ResetColor();
ConsoleKeyInfo keypressed = Console.ReadKey();
Console.Beep(800, 50);
Console.Beep(1000, 50);
if (keypressed.Key == ConsoleKey.Spacebar)
{
Console.Clear();
Console.WriteLine("You have found the cheats. Superspeed enabled");
speed = 2;
}
if (keypressed.Key == ConsoleKey.RightArrow)
{
if (14 > playery)
{
fillboard(board);
playery = playery + speed;
board[playerx, playery] = "☺";
movebad(ref playerx, ref playery,ref badguyx,ref badguyy);
drawboard(board);
board[badguyx, badguyy] = "ö";
}
drawboard(board);
}
if (keypressed.Key == ConsoleKey.LeftArrow)
{
if (0 < playery)
{
fillboard(board);
playery = playery - speed;
board[playerx, playery] = "☺";
movebad(ref playerx, ref playery, ref badguyx, ref badguyy);
drawboard(board);
board[badguyx, badguyy] = "ö";
}
drawboard(board);
}
if (keypressed.Key == ConsoleKey.UpArrow)
{
if (0 < playerx)
{
fillboard(board);
playerx = playerx - speed;
board[playerx, playery] = "☺";
movebad(ref playerx, ref playery, ref badguyx, ref badguyy);
drawboard(board);
board[badguyx, badguyy] = "ö";
}
drawboard(board);
}
if (keypressed.Key == ConsoleKey.DownArrow)
{
if (14 > playerx)
{
fillboard(board);
playerx = playerx + speed;
board[playerx, playery] = "☺";
movebad(ref playerx,ref playery,ref badguyx,ref badguyy);
drawboard(board);
board[badguyx, badguyy] = "ö";
}
drawboard(board);
}
if (playerx == badguyx)
{
if (playery == badguyy)
{
Console.Beep(800, 200);
Console.Beep(600, 200);
Console.Beep(400, 200);
Console.Beep(200, 400);
lives = lives - 1;
Console.WriteLine("The Enemy ate a bit of you. I think you will survive " + lives + " more bites");
moveplayer(ref playerx, ref playery);
}
}
if (treasurex == playerx)
{
if (treasurey == playery)
{
Console.WriteLine("You have got the treasure");
Console.WriteLine("It has now been moved");
Console.Beep(800, 300);
Console.Beep(1000, 300);
Console.Beep(1200, 300);
points = points + 50;
movetreasure(ref treasurex, ref treasurey);
}
}
//for (int a = 0; a <= 250; a++)
// {
// Console.Beep(800, 50);
//}
}
}
public static void fillboard(string[,] board)
{
for (int i = 0; i <= board.GetUpperBound(1); i++)
{
for (int j = 0; j <= board.GetUpperBound(0); j++)
{
board[i, j] = "5";
}
}
}
public static void drawboard(string[,] board)
{
Console.Clear();
Console.WriteLine(" ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲");
for (int i = 0; i <= board.GetUpperBound(0); i++)
{
Console.Write("◄");
for (int j = 0; j <= board.GetUpperBound(1); j++)
{
Console.Write(board[i, j]);
}
Console.Write("►");
Console.WriteLine();
}
Console.WriteLine(" ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼");
}
public static int movetreasure(ref int x, ref int y)
{
Random randombox = new Random();
for (int a = 0; a < 2; a++)
{
int randomboard = randombox.Next(0, 14);
y = x;
x = randomboard;
randomboard = y;
}
return y;
}
public static int moveplayer(ref int x, ref int y)
{
Random randombox = new Random();
for (int a = 0; a < 2; a++)
{
int randomboard = randombox.Next(0, 14);
y = x;
x = randomboard;
randomboard = y;
}
return y;
}
public static int movebad( ref int mpx, ref int mpy,ref int bgx, ref int bgy)
{
if (mpx > bgx)
{
bgx = bgx + 1;
return bgx;
}
if (mpx < bgx)
{
bgx = bgx - 1;
return bgx;
}
if (mpy > bgy)
{
bgy = bgy + 1;
return bgy;
}
if (mpy < bgy)
{
bgy = bgy - 1;
return bgy;
}
return mpx;
}
public static void intro()
{
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine(" d888888b d8888b. d88888b .d8b. .d8888. db db d8888b. d88888b");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" `~~88~~' 88 `8D 88' d8' `8b 88' YP 88 88 88 `8D 88' ");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(" 88 88oobY' 88ooooo 88ooo88 `8bo. 88 88 88oobY' 88ooooo");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" 88 88`8b 88~~~~~ 88~~~88 `Y8b. 88 88 88`8b 88~~~~~ ");
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(" 88 88 `88. 88. 88 88 db 8D 88b d88 88 `88. 88. ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" YP 88 YD Y88888P YP YP `8888Y' ~Y8888P' 88 YD Y88888P ");
Console.WriteLine();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine(" db db db db d8b db d888888b ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" 88 88 88 88 888o 88 `~~88~~'");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(" 88ooo88 88 88 88V8o 88 88 ");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(" 88~~~88 88 88 88 V8o88 88 ");
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(" 88 88 88b d88 88 V888 88 ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine(" YP YP ~Y8888P' VP V8P YP");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(" |==============Welcome To Treasure Hunt=============|");
Console.WriteLine(" |☺ is you. Press the arrow keys to move! |");
Console.WriteLine(" |ö wants to eat you. Avoid him at all costs! |");
Console.WriteLine(" |The Treasure is hidden somewhere. Find it! |");
Console.WriteLine(" |The walls are made out of Glue. You will get stuck!|");
Console.WriteLine(" |==============Press Enter to Continue==============|");
Console.ResetColor();
Console.Title = ("T??????? ????");
Console.Beep(600, 200);
Console.Title = ("Tr?????? ????");
Console.Beep(400, 200);
Console.Title = ("Tre????? ????");
Console.Beep(800, 200);
Console.Title = ("Trea???? ????");
Console.Beep(400, 200);
Console.Title = ("Treas??? ????");
Console.Beep(600, 200);
Console.Title = ("Treasu?? ????");
Console.Beep(400, 200);
Console.Title = ("Treasur? ????");
Console.Beep(800, 200);
Console.Title = ("Treasure ????");
Console.Beep(400, 200);
Console.Title = ("Treasure H???");
Console.Beep(600, 200);
Console.Title = ("Treasure Hu??");
Console.Beep(400, 200);
Console.Title = ("Treasure Hun?");
Console.Beep(800, 200);
Console.Title = ("Treasure Hunt");
Console.Beep(800, 200);
Console.Beep(800, 200);
Console.Read();
}
}
}
[/code]I made a game using a 2d array in C# console. It might help with something
[QUOTE=ZomBuster;19598620]So I remade my voxel raytracer the right way, now it uses a bounding box and everything, and I threw in some ambient occlusion to make it pretty. It's still very buggy but whatever.[/QUOTE]
What exactly is a voxel raytracer? Is it a grid of cubes that you're tracing, basically?
Taking a look at a couple projects I never finished (or really started).
I finished an IRC log parser that gathers certain statistics for a channel I idle.
Next, I'll take another look at my XNA game engine and maybe start on a game concept that's been rolling around in my head for a couple months.
I'm working on a firefox extensions. Not much to show yet.
Anyone has a GOOD documentation site about this stuff? Yesterday I spent litteraly hours trying to figure out why my extension wouldn't install :aaa:
[QUOTE=Jallen;19612698]Cool, thanks.
My maths knowledge is lacking in areas, I can work with it when I know how it all works but I don't know about a lot of maths stuff.[/QUOTE]
I'm totally with you. I'm good at math, but the only reason I know about all the log and exponent shit is because I have to take a calculus class, where they made us derive and integrate the shit out of anything and everything. I had no idea that "log (a^b) == b log (a)" before that.
Just a matter of practice really.
[QUOTE=microsnakey;19612992][code]
loadsa code
[/code]I made a game using a 2d array in C# console. It might help with something[/QUOTE]
Cool, do you mind if I copy bits of the code if I find them useful?
[QUOTE=Wickedgenius;19613222]Cool, do you mind if I copy bits of the code if I find them useful?[/QUOTE]
sure
[QUOTE=gparent;19613136]I'm totally with you. I'm good at math, but the only reason I know about all the log and exponent shit is because I have to take a calculus class, where they made us derive and integrate the shit out of anything and everything. I had no idea that "log (a^b) == b log (a)" before that.
Just a matter of practice really.[/QUOTE]
[url]http://www.mathcentre.ac.uk/resources.php/231[/url]
I taught myself logarithms from that in a couple of hours. Got to love the internet.
This is why I don't like people saying "Oh you should be awesome at maths to do programming"
Really, as long as you have a logical mind you can simply learn what you need when you need it, or even not fully learn it and just use a reference.
I guess the background knowledge helps in finding more efficient solutions but I still feel that it's not necessary.
[QUOTE=Jallen;19613874]This is why I don't like people saying "Oh you should be awesome at maths to do programming"[/QUOTE]
this
I'm terrible at maths but it hasn't let me down yet, when I need something I can just research it online.
Yey multithreading! Made my own Threadpool, it's pretty simple but it works. Made it just to learn some more about multithreading but I'm most likely going to continue use it.
Now I'm going to try implement it for the terrain generation.
I'm interested in doing some OpenGL stuff(I've already used it with GLU and GLEW) and I'm wondering which libraries are commonly used/preferred?
[QUOTE=NovembrDobby;19613942]this
I'm terrible at maths but it hasn't let me down yet, when I need something I can just research it online.[/QUOTE]
Or just simply ask the programming section, good chance that someone is willing to share their knowledge.
[img]http://i47.tinypic.com/dpemnd.png[/img][B]
[URL]http://spamtheweb.com/ul/upload/130110/71776_holyshitabear.php[/URL]
[/B]Here's my new game called Holy Shit, It's a Bear, where you have to run away from a bear which is trying to devour you, I whipped this up in a couple of minutes, really early stuff.
Over the past two months or so, I've been building a robot. It's been done for a while now, but tomorrow is the competition I designed it for. It's basically a sumo bot, so it enters a ring with another bot, searches the ring for the enemy, chases it, and tries pushing it out, while avoiding being pushed out itself. It's programmed using PICBASIC, a variant of BASIC, and is controlled by a PIC16F628A chip. Aside from the chip itself, everything else has been designed, and built by myself. Assuming the bot isn't completely destroyed in the competition, I'll see if I can get a video up or something tomorrow.
Also, the bot is the very definition of overkill. In a competition with a 5-pound weight limit, and no weapons allowed, I built it out of bullet-proof glass.
[QUOTE=Parakon;19616152][img]http://i47.tinypic.com/dpemnd.png[/img][B]
[URL]http://spamtheweb.com/ul/upload/130110/71776_holyshitabear.php[/URL]
[/B]Here's my new game called Holy Shit, It's a Bear, where you have to run away from a bear which is trying to devour you, I whipped this up in a couple of minutes, really early stuff.[/QUOTE]
Too bad the bear can't tear you apart D:
[QUOTE=s0ul0r;19617230]Too bad the bear can't tear you apart D:[/QUOTE]
I don't think he is ready for feature requests yet.
How can gprof have a smaller time measurement? I get 0.00 on all my calls.
Here's a markup for the menu in a project I'm actually hoping to finish.
[IMG]http://i.imgur.com/NDWkul.jpg[/IMG]
Anyone else like working on projects with others? It helped me keep motivation some how, I had someone to discuss ideas with, I got a LOT done.
Only reason the project was never finished was because he ended up not really contributing much and then this was a closed source project and he used a part of the code in one of his projects and made it open source :\. Kinda put me off every time I tried to work on the project from there.
Sorry, you need to Log In to post a reply to this thread.