Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 480 481 [482] 483 484 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887449 times)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7215 on: April 18, 2015, 08:09:25 pm »

And while we're at it, if you're planning on making a game I'd probably pick a framework for that too.  OGRE is a fairly popular OpenGL based framework that abstracts out some things (including the GUI I believe), but doesn't serve as a full game engine.
Logged
Through pain, I find wisdom.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7216 on: April 18, 2015, 10:15:34 pm »

If you're doing 2D,allegro is pretty good too.
Logged

highmax28

  • Bay Watcher
  • I think this is what they call a tantrum spiral...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7217 on: April 20, 2015, 11:30:46 am »

I'm having a big problem with my code for my final project for Javascript. Its supposed to be a card counter that is supposed to count how many cards there are and spit out a total, if you're over or under a deck limit, and then spits out all the cards you have, the amount you have and it will tell you and prompt you again if you entered a card amount over the limit (in this case, its 3, though can be changed).

So far, if you enter a double, it enters a loop of "can't do that, enter another amount" even if its a valid amonut. Also, it seems to lose its shit if I enter 0...

On another note, if you somehow bypass the doubles, it seems to take the list and bash the numbers together for the total amonut instead of adding it together
(EX: "You have 03123131213232 cards" instead of "You have 27 cards")

Code: [Select]
<html>
<head>
<script type="text/javascript">
// Program Name: cardcounter.txt
// Purpose: Chris can't tell if he has enough cards in his deck. We're going to fix that
// Author: Spencer Durette & Benjamin Tofflemire
// Date last modified: 04/15/2015

//Declare Global Variables


var daCardTotal = 0; // Total Number of cards added
var daCard; // The card entered
var cardList = []; // The List of cards that will be displayed at the very end
var numbahOCards = []; // The list of the quantity of each card
var cardQty; // The number of cards entered
var index = 0; // The index used for the final loop in the program to display the total number of cards
var cardQtyCheck = false; // Checks if the card quantity is proper
var BR = "<br />";
var checkIndex = 0; // The index used in finding repeat cards
var cardDouble = false // Checks if there is a card double. This is counted as true if the card found is a double and will skip adding a new card
// as well as adding a new card quantity if this is true

//Set the Card Limit (40 for Yu-gi-oh, 60 for Magic: The Gathering)
var cardMax = 40;

//Declare the maximum number of cards per deck (This program doesn't count cards you can have an infinite number of,
//such as land cards and relentless rats in Magic: The Gathering)
var cardQtyMax = 3;

//Count the card total
var cardCount = function(daGrandTotal) {
if (daGrandTotal > cardMax){
alert("Please remove some cards. You are over the card limit");
document.write("Please remove some cards. You are over the card limit" + BR);
document.write("You have " + daCardTotal + " cards total")
} else if (daGrandTotal < cardMax) {
alert("Please add some more cards. You are under the card limit");
document.write("Please add some more cards. You are under the card limit" + BR);
document.write("You have " + daCardTotal + " cards total")
} else {
alert("You have exactly "+cardMax+" cards in your deck. You have the exact number of cards needed" + BR);
document.write("You have exactly "+cardMax+" cards in your deck. You have the exact number of cards needed" + BR);
document.write("You have " + daCardTotal + " cards total")
}
}

var cardRepeat = function(card) {
//Check if the card added has already been added to the list
while (checkIndex < cardList.length){
if (cardList[checkIndex] == card){
cardDouble = true;
cardQty = prompt("The card you have has already been added. Please enter the added amount (You have " + numbahOCards[checkIndex] + " already added)");
cardQty = parseInt(cardQty);
while (cardDouble == true) {
if ((cardQty + numbahOCards[checkIndex]) >= cardQtyMax){
cardQty = prompt("The card amount entered is invalid. Please enter a valid amount (You have " + numbahOCards[checkIndex] + " added already)");
cardQty = parseInt(cardQty);
} else if ((cardQty + numbahOCards[checkIndex]) < cardQtyMax) {
numbahOCards[checkIndex] = numbahOCards[checkIndex]+cardQty;
break;
}
}
break;
}
//Increment the card index for the card list
checkIndex += 1;
}
//Once the check for doubles is finished, reset the card index for the next card
checkIndex = 0;
}

</script>
</head>
<body>
<script type="text/javascript">
//Welcome the user
alert("Welcome to the card counter program!");

//Run the program

//Prompt the User to enter the first card
daCard = prompt("Please enter the first card","");

//Enter the loop that will have the user consistently enter cards until they entered all of the cards needed
while (daCard != "-1") {
//If the user enters -1, the program stops counting cards
if (daCard == "-1") {
break
} else {
//Check if the card is a double
cardRepeat(daCard);

//Run the regular card adding if the card is not a double
if (cardDouble == false) {
//Add the card to the list of cards by name
cardList[cardList.length] = daCard;;
//Prompt the user for how many cards there are
cardQty = prompt("How many "+daCard+"s are there to add?");

//Check if the card quantity is a valid amount (defined by the variables above)
while (cardQtyCheck == false){
if (cardQty > cardQtyMax) {
//Tell the user that the amount of cards they added is invalid if they entered more then the maximum of allowed cards
alert("You cannot have that many cards in a deck, please enter a valid amount");
cardQty = prompt("How many "+daCard+"s are there to add?");
cardQty = parseInt(cardQty);
} else {
cardQtyCheck = true;
//Add the card quantity if the card total is right
numbahOCards[numbahOCards.length] = cardQty;
cardQty = parseInt(cardQty);
}
}
}
//Add to the grand total of cards that will be displayed at the end
daCardTotal = daCardTotal + cardQty;
//Loop the prompts, this time adding the option to exit with -1
daCard = prompt("Please enter the next card (-1 to exit)","-1");
//Changes the check so the next quantity of cards is checked
cardQtyCheck = false;
}
}

//Count the grand total of cards and checks if the cards are over or under the total amount of cards allowed
cardCount(daCardTotal);

//Displays every card with its respectable number, stopping when the list ends
            while (index < (numbahOCards.length)){
if (numbahOCards[index] == "" || cardList[index] == "") {
break;
}
document.write(BR + cardList[index]+" x"+ numbahOCards[index] + BR);
index += 1
            }
</script>
</html>

I know its hard to look at, but please bear with me on this. I'll also take any recommendations to make it look... Cleaner? (is that how I would describe it?). I also would like it if someone can explain to me whats going on...
Logged
just shot him with a balistic arrow, i think he will get stuned from that >.>

"Guardian" and Sigfriend Of Necrothreat
Jee wilikers, I think Highmax is near invulnerable, must have been dunked in the river styx like achilles was.
Just make sure he wears a boot.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7218 on: April 20, 2015, 11:35:21 am »

In Python, "def insertNameHere" is basically defining a structure like in C++ with "struct insertNameHere", right?
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7219 on: April 20, 2015, 11:45:42 am »

No, that is a function declaration/definition.

def max (a, b):
    return a if a > b else b

Would be equivalent to

template <type T>
&T max (T &a, T &b) {
return a>b?a:b;
}

In C++, I think? I am not 100% sure about my reference placement though...
« Last Edit: April 20, 2015, 11:49:49 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7220 on: April 20, 2015, 11:51:14 am »

In Python, "def insertNameHere" is basically defining a structure like in C++ with "struct insertNameHere", right?

If you want something that's "good enough", a dict (or frozenset for extra immutability), NamedTuple, or just about any other data structure would work.

According to StackOverflow, the only difference between a struct and class in C++ is that members in a struct are public. That being the case, a Python class (everything is public by default unless you invoke Python's "wish it was private" name mangling) would work just fine.

Or if you really want to, you could import struct. I'm just including this for the sake of completion. This probably doesn't do what you want.
« Last Edit: April 20, 2015, 11:53:35 am by Mephisto »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7221 on: April 20, 2015, 11:59:30 am »

Right. I've been taking classes focusing on C++ in college. And I just looked at this year old half-finished roguelike I was working on that's coded in python and was referring to a tutorial from RogueBasin. So I was thinking in terms of C++ and trying to apply that to the old Python code that I have half an idea of what it's supposed to do.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7222 on: April 20, 2015, 03:05:22 pm »

Bumping the thread because question.

Let's say I want to draw an ascii roguelike dungeon in the c++ console. Like, the window that prints "cout" statements. Can I do this, draw an ascii map, in the console without constantly printing new lines and having the past lines remain? Like, if I were to do this with basic cout satements and a loop to reprint the map every turn, with each map being 25 lines, the player could scroll up with the mousewheel for example and see each past turn's 25 line map printed out above the current map. This would be a fustercluck of a ui system and look terrible.

I want to achieve the kind of console-esque window Nethack has going for it. I'm guessing Nethack is using more than the basic default console.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7223 on: April 20, 2015, 03:15:06 pm »

I don't really know much, but this isn't the standard console. If you're on Linux you would probably use the curses library (or maybe something based on curses, the interface is awful).
Logged
Taste my Paci-Fist

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #7224 on: April 20, 2015, 03:19:46 pm »

You can do it on Windows using the Windows Console API, though there are also curses-implementations for Windows (allowing for cross-platform).

As for struct vs class, in the C++ language specification it's just public vs protected as the default visibility. However, in practice you tend to see struct used for POD objects, and class for actual classes.
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7225 on: April 20, 2015, 03:30:33 pm »

Googling "c++ curses" and "c++ curses windows" brings up something called "ncurses".
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7226 on: April 20, 2015, 03:43:59 pm »

One of the various curses implementations is probably what you want to use. It's what we use for Cataclysm, for example (though the tiles builds use SDL instead, so you might consider that as well, though it takes a bit more know-how IMO).
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7227 on: April 20, 2015, 04:25:37 pm »

Bumping the thread because question.

Let's say I want to draw an ascii roguelike dungeon in the c++ console. Like, the window that prints "cout" statements. Can I do this, draw an ascii map, in the console without constantly printing new lines and having the past lines remain? Like, if I were to do this with basic cout satements and a loop to reprint the map every turn, with each map being 25 lines, the player could scroll up with the mousewheel for example and see each past turn's 25 line map printed out above the current map. This would be a fustercluck of a ui system and look terrible.

I want to achieve the kind of console-esque window Nethack has going for it. I'm guessing Nethack is using more than the basic default console.
Libcotd is a special graphics library for ascii roguelikes. But curses is the more classic library, and it pays to know how to use it.

pdcurses is the windows port of curses. You really want to find the pre-coded dll version and use that rather from going to source:

http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/

pdc34dllw.zip i think. The trick with visual studio for me was to create a completely "blank" project - not a console application. Then, you use pdcurses (just look up ncurses tutorials) to create a window when the app starts.
« Last Edit: April 20, 2015, 04:27:28 pm by Reelya »
Logged

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7228 on: April 20, 2015, 05:10:02 pm »

pdcurses is the windows port of curses. You really want to find the pre-coded dll version and use that rather from going to source:

http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/

pdc34dllw.zip i think. The trick with visual studio for me was to create a completely "blank" project - not a console application. Then, you use pdcurses (just look up ncurses tutorials) to create a window when the app starts.
Wow, ok. More questions now. I think I'll be posting in this thread regularly.

Using this tutorial thing. Cannot figure out how to include pdcurses. The tutorial gives this code:
Spoiler (click to show/hide)

I don't know what I'm doing wrong. I downloaded pdc34dllw. Exported the zip contents into a folder named "pdc34dllw" in the folder for my roguelike project where the main is. Even copied everything from the zip folder and put it in the same file as the main, in case that matters at all.

Tried these.
Spoiler (click to show/hide)

Compiler continues to give me the fatal error for the #include line, saying "no such file or directory". Using Code::Blocks and the included GNU GCC compiler.
« Last Edit: April 20, 2015, 05:21:04 pm by Spehss _ »
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7229 on: April 20, 2015, 05:20:23 pm »

I don't use C++, but I'd guess that the compiler doesn't know to look in the pdc34dllw folder, seeing as it's not specified at any point that I can see.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.
Pages: 1 ... 480 481 [482] 483 484 ... 796