Ah ok, well it happens even if I set the size to larger.
What's your intended goal? Put the first 5 in the player's hand and the second 5 in the computer's?
Yes, I would prefer to do it with lists however. I will eventually put a shuffle in there too.
Is this for a project or something or just spare time shenanigans?
Spare time shit. But I will be using the same kind of shiz in some projects so I am trying to learn the methods now.
Here's some code.
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TopTrumps
{
class Program
{
enum State
{
START,
CREATE,
DEAL,
PLAY
}
static void Main(string[] args)
{
var gameState = State.START;
List<Card> playersHand = new List<Card>();
List<Card> compsHand = new List<Card>();
List<Card> allCards = new List<Card>{
new Card("Black Knight", 75, 75),
new Card("Darkwraith Knight", 60, 60),
new Card("Undead Mage", 45, 50),
new Card("Tree Lizard", 30, 40),
new Card("Serpent Soldier", 55, 55),
new Card("Anor Londo Guard", 65, 70),
new Card("Drake", 85, 95),
new Card("Demonite Demon", 80, 85),
new Card("Hollow Soldier", 10, 25),
new Card("Giant Skeleton", 40, 65)
};
while (true)
{
if (gameState == State.START)
{
Console.WriteLine("Welcome to Top Trumps!");
Console.WriteLine();
Console.WriteLine("Please enter a player name: ");
string playerName = Console.ReadLine();
Console.Clear();
gameState = State.CREATE;
}
if (gameState == State.CREATE)
{
Console.WriteLine(allCards.Count + " cards created");
gameState = State.DEAL;
}
if (gameState == State.DEAL)
{
int count = 1;
foreach (Card card in allCards)
{
if (playersHand.Count != 5)
{
playersHand.Add(card);
Console.WriteLine("Card " + count++ + " assigned to Player.");
}
else
{
compsHand.Add(card);
Console.WriteLine("Card " + count++ + " assigned to Computer.");
}
}
gameState = State.PLAY;
}
}
}
}
class Card
{
public string name;
public int level;
public int vitality;
public Card(string nm, int lev, int vit)
{
name = nm;
level = lev;
vitality = vit;
}
}
}[/code]
I'll go over what I did in descending order.
First, I changed GameState to be an enum. This is to prevent state from being changed to something that doesn't exist (if you accidentally say gameState = "creat"; or something) and the program freaking out.
All the collections are now lists and initialized correctly.
I added a few writelines because it's cleaner than \n in a string.
During dealing, it counts up everything as it lets the player know a card has been assigned. Obviously this has been changed to a list.
And you didn't set your gameState after dealing was complete, so it was infinitely looping.
Should get you started - it works, too, obviously.
[IMG]http://puu.sh/2KWq0/86c8ccc4fd.png[/IMG]
[editline]1st May 2013[/editline]
In retrospect, the if (playersHand.Count != 5) should be if (playersHand.Count <= 5) because it increments and if the Count finds its way above 5 we will add cards we don't want to, but you can do that I'm sure.
I know you posted a decent explanation of what you changed but please avoid spoonfeeding code.
[QUOTE=SteveUK;40493059]I know you posted a decent explanation of what you changed but please avoid spoonfeeding code.[/QUOTE]
Yeah I'm too generous and have too much time on my hands. I'll try avoiding it in the future.
[QUOTE=Protocol7;40493087]Yeah I'm too generous and have too much time on my hands. I'll try avoiding it in the future.[/QUOTE]
If you do have the time, next time, just break it down into stages rather than putting a complete solution [i]then[/i] the explanation. He might just see the working code and not even look at what you changed and why you changed it.
Even though that is extremely helpful I agree with Steve. Although you still did a great job! Thanks for the help.
I am trying to make a calculator in C# and currently have this code, but for some reason it gives loads of confusing errors, any help is much appreciated.
[code] private void button1_Click(object sender, EventArgs e) {
int number1;
int number2;
float answer;
number1 = int.Parse(textBox1.Text);
number2 = int.Parse(textBox2.Text);
if (rbMinus.Checked == true)
(
answer = number1 - number2;
textBox3.Text = answer.ToString();
)
else if (rbMultiply.Checked == true)
(
answer = number1 * number2;
textBox3.Text = answer.ToString();
)
else if (rbPlus.Checked == true)
(
answer = number1 + number2;
textBox3.Text = answer.ToString();
)
else if (rbDivide.Checked == true)
(
answer = number1 / number2;
textBox3.Text = answer.ToString ();
)
else
(
MessageBox.Show ("Please select an option");
)
[/code]
You're using ( and ) for scoping (roughly: the stuff you'd indent is in a scope), these should be { and }.
And saying [i]if(* == true)[/i] is redundant, just do [i]if(*)[/i].
[editline]2nd May 2013[/editline]
[url=http://msdn.microsoft.com/en-us/library/aa691132(v=VS.71).aspx]Here's a more detailed description of a scope from MSDN.[/url]
Having problems trying to compile a Java test file that uses LWJGL with GCJ. Trying this line out in a terminal:
[quote]$ gcj --main=Test -o Test Test.java --classpath=/home/dave/Games/lwjgl/2.9.0/jar/lwjgl.jar:/home/dave/Games/lwjgl/2.9.0/jar/jinput.jar:/home/dave/Games/lwjgl/2.9.0/jar/lwjgl_util.jar
[/quote]
[quote=Output]/tmp/ccTlYs96.o: In function `void Test::pollInput()':
/home/dave/Games/ships/Test.java:43: undefined reference to `bool org::lwjgl::input::Mouse::isButtonDown(int)'
/home/dave/Games/ships/Test.java:44: undefined reference to `int org::lwjgl::input::Mouse::getX()'
/home/dave/Games/ships/Test.java:45: undefined reference to `int org::lwjgl::input::Mouse::getY()'
/home/dave/Games/ships/Test.java:47: undefined reference to `java::lang::String* org::lwjgl::input::Mouse::getButtonName(int)'
/home/dave/Games/ships/Test.java:51: undefined reference to `bool org::lwjgl::input::Mouse::isButtonDown(int)'
/home/dave/Games/ships/Test.java:52: undefined reference to `java::lang::String* org::lwjgl::input::Mouse::getButtonName(int)'
/home/dave/Games/ships/Test.java:55: undefined reference to `bool org::lwjgl::input::Keyboard::isKeyDown(int)'
/home/dave/Games/ships/Test.java:60: undefined reference to `bool org::lwjgl::input::Keyboard::getEventKeyState()'
/home/dave/Games/ships/Test.java:62: undefined reference to `wchar_t org::lwjgl::input::Keyboard::getEventCharacter()'
/home/dave/Games/ships/Test.java:63: undefined reference to `int org::lwjgl::input::Keyboard::getEventKey()'
/home/dave/Games/ships/Test.java:66: undefined reference to `int org::lwjgl::input::Keyboard::getEventKey()'
/home/dave/Games/ships/Test.java:69: undefined reference to `int org::lwjgl::input::Keyboard::getEventKey()'
/home/dave/Games/ships/Test.java:73: undefined reference to `int org::lwjgl::input::Keyboard::getEventKey()'
/home/dave/Games/ships/Test.java:76: undefined reference to `int org::lwjgl::input::Keyboard::getEventKey()'
/tmp/ccTlYs96.o:/home/dave/Games/ships/Test.java:76: more undefined references to `int org::lwjgl::input::Keyboard::getEventKey()' follow
/tmp/ccTlYs96.o: In function `void Test::pollInput()':
/home/dave/Games/ships/Test.java:59: undefined reference to `bool org::lwjgl::input::Keyboard::next()'
/home/dave/Games/ships/Test.java:51: undefined reference to `bool org::lwjgl::input::Mouse::isButtonDown(int)'
/home/dave/Games/ships/Test.java:55: undefined reference to `bool org::lwjgl::input::Keyboard::isKeyDown(int)'
/home/dave/Games/ships/Test.java:55: undefined reference to `bool org::lwjgl::input::Keyboard::isKeyDown(int)'
/home/dave/Games/ships/Test.java:79: undefined reference to `int org::lwjgl::input::Keyboard::getEventKey()'
/tmp/ccTlYs96.o: In function `void Test::start()':
/home/dave/Games/ships/Test.java:11: undefined reference to `org::lwjgl::opengl::DisplayMode::class$'
/home/dave/Games/ships/Test.java:11: undefined reference to `org::lwjgl::opengl::DisplayMode::DisplayMode(int, int)'
/home/dave/Games/ships/Test.java:11: undefined reference to `void org::lwjgl::opengl::Display::setDisplayMode(org::lwjgl::opengl::DisplayMode*)'
/home/dave/Games/ships/Test.java:12: undefined reference to `void org::lwjgl::opengl::Display::setTitle(java::lang::String*)'
/home/dave/Games/ships/Test.java:13: undefined reference to `void org::lwjgl::opengl::Display::create()'
/home/dave/Games/ships/Test.java:14: undefined reference to `bool org::lwjgl::input::Mouse::hasWheel()'
/home/dave/Games/ships/Test.java:17: undefined reference to `bool org::lwjgl::input::Mouse::hasWheel()'
/home/dave/Games/ships/Test.java:33: undefined reference to `void org::lwjgl::opengl::Display::update()'
/home/dave/Games/ships/Test.java:28: undefined reference to `bool org::lwjgl::opengl::Display::isCloseRequested()'
/home/dave/Games/ships/Test.java:36: undefined reference to `void org::lwjgl::opengl::Display::destroy()'
/tmp/ccTlYs96.o:(.rodata+0x20): undefined reference to `org::lwjgl::LWJGLException::class$'
collect2: error: ld returned 1 exit status
[/quote]
Same file worked in NetBeans with a proper setup to LWJGL, just can't figure out how to do it with GCJ in the terminal.
You apparently have to compile lwjgl to a native library as well, via
[code]$ gcj -c -fjni lwjgl.jar
$ gcj -o liblwjgl_native.so -fjni -Wl liblwjgl.so lwjgl.o[/code]
And you have to compile your project with -fjni as well and link to liblwjgl_native.so (-Wl liblwjgl_native.so).
[QUOTE=Protocol7;40490128]I think he means the Java equivalent of
[code]
foreach (int i in intArray)
{
//blah
}[/code]
Correct me if that's not the purpose of an enhanced for loop (I'm a C# guy.)[/QUOTE]
It's also called a foreach loop in Java, but for some reason they opted to make the keyword for instead of foreach. Some Java books call it an enhanced for, for that reason , I hate that name.
[QUOTE=ZeekyHBomb;40493981]You're using ( and ) for scoping (roughly: the stuff you'd indent is in a scope), these should be { and }.
And saying [i]if(* == true)[/i] is redundant, just do [i]if(*)[/i].
[editline]2nd May 2013[/editline]
[url=http://msdn.microsoft.com/en-us/library/aa691132(v=VS.71).aspx]Here's a more detailed description of a scope from MSDN.[/url][/QUOTE]
If this is WPF then the == true isn't optional because the checked property is a bool? (nullable bool).
[editline]oh[/editline] This seems to be Forms though, in WPF it's IsChecked.
[QUOTE=mobrockers2;40499482]It's also called a foreach loop in Java, but for some reason they opted to make the keyword for instead of foreach. Some Java books call it an enhanced for, for that reason , I hate that name.[/QUOTE]
The syntax is different for java entirely. Although they're putting the same shit in C++ 11 finally
Well , Protocol, I tried to attempt your logic with my nodes, and it works for most of the cases except for the middle 2 cases in the first tester.~.
Could I see your rendition of my logic? Don't forget since I had to do a lot of template and pointer fuckery to get it to work in C++ I could have easily screwed something up that makes mine work and yours not.
I'm having an issue with collision detection in my game. When the physical bullet hits an enemy, sometimes if they're near each other it'll shoot two of them at once, here's an example:
[img]http://puu.sh/2Lq9M.gif[/img]
Any idea what I could do to stop both dying at once?
[QUOTE=Kamern;40502476]I'm having an issue with collision detection in my game. When the physical bullet hits an enemy, sometimes if they're near each other it'll shoot two of them at once, here's an example:
[img]http://puu.sh/2Lq9M.gif[/img]
Any idea what I could do to stop both dying at once?[/QUOTE]
More precise hitboxes on both the zombies and your bullet? I'm assuming you tried the obvious (remove bullet on hit, etc)
Either that or you're going to have to make it so the player can move up/down and fire in rows.
More precise hit detection, make sure bullet stops moving immediately upon hitting a hitbox (it looks like it goes through the zombies a little bit and snags another one)
alternatively, just call it a feature. 2x rifle damage.
When you detect a collision between a bullet and zombie, set a flag that says such a collision has happened. When this flag is set, ignore collisions with that bullet.
[QUOTE=Chris220;40503924]When you detect a collision between a bullet and zombie, set a flag that says such a collision has happened. When this flag is set, ignore collisions with that bullet.[/QUOTE]
i'm not entirely sure, but aren't flags specific to the entire program? or can you set flags for individual entities (i.e. the bullet)?
A flag is not necessarily a command-line flag, if that's what you're thinking of. It can also refer to a boolean variable. Or a bit in a bit-field (an integer, where each bit is treated as a separate value).
Nevermind, found a way to do it.
[QUOTE=CommanderPT;40504317]What is the best way of shuffling an array? I have an array holding a bunch of strings representing a bunch of tarotcards and I want to shuffle it. So that if I look at the same index before and after the shuffle it will, naturally, be different.[/QUOTE]
To clarify, you want to guarrantee that no index ever remains the same? As opposed to a normal shuffle where they may or may not do.
[QUOTE=ArgvCompany;40504392]To clarify, you want to guarrantee that no index ever remains the same? As opposed to a normal shuffle where they may or may not do.[/QUOTE]
Oops, didn't see your post before I edited. I found a way of doing it and it was just an ordinary shuffle. No need to guarantee that the indexes are not the same.
[QUOTE=ZeekyHBomb;40504068]A flag is not necessarily a command-line flag, if that's what you're thinking of. It can also refer to a boolean variable. Or a bit in a bit-field (an integer, where each bit is treated as a separate value).[/QUOTE]
Ah. I'm guessing that was java and I don't know java very well (I took a course on it but we didn't even code, we like clicked and dragged pre-written pieces of code wtf)
I think the main problem with my motivation is coding the workbench for my game. I always want to jump right in instead.
Actually, that probably applies to a lot of other things I have trouble with, as well.
Damn it.
Oh, and is it common practice to window->clear and redraw after each frame in SFML? I've seen it in some code but other times not.
Sorry, you need to Log In to post a reply to this thread.