Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Turn Based Game  (Read 2796 times)

0 Members and 2 Guests are viewing this topic.

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Turn Based Game
« on: January 03, 2013, 08:05:27 am »
I am relatively new to c++ and SFML. For the purpose of practice, I figured I would try to complete a blackjack program. The approach I have taken is simply (deal, check-for-blackjacks-player one turn- player two turn, etc..) I have a basic game working; however, when attempting to add an option to split, I have come across a problem. I cannot change the position of the original dealt cards because I do not run the App.Draw for it until the game-loop resets.

Is there a way to delete a single sprite without redrawing? Or a way to hide it behind the background? Or something to get rid of it without needing to make the game one giant loop? any help would be... helpful ;) 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Turn Based Game
« Reply #1 on: January 03, 2013, 10:07:04 am »
If you don't want a sprite to be drawn, then don't call app.Draw(sprite), the simplest way to achieve this, is by having a boolean variable and before drawing, you check against the bool.
bool spriteVisible = true;
// ...
spriteVisible = false;
// ...
App Clear();
if(spriteVisible)
    App.Draw(sprite);
App.Display();
// ...

Obviously if you have to do this for every single sprite, the codebase will get messier every time. That's where OOP comes into play. With a nice entitiy class and a std::vector of entities you can implement a isVisible() function and when iterating over the std::vector to draw the entities call that function first.
If you don't know anything about OOP you should definitely get a good C++ book and read it. ;)

Btw. from App.Draw() I conclude, that you're using SFML 1.6, but I'd strongly advise you to use SFML 2, because the 1.6 version hasn't been touched in around 2.5 years, has many bugs and lacks quite a few nice features (sf::RenderTexture, sf::VertexArray, ...)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Chivos

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Turn Based Game
« Reply #2 on: January 03, 2013, 10:24:19 am »
I have actually been using the boolean method to to show sprites at the correct time. Based on what you are saying, I think I need to take a new approach. My problem is this...

Code: [Select]
Initialize variables....

game loop {

(deal)
{
deal ()...
app.draw // the deal
}

(PlayerOne)
{
different actions...
app.draw //the actions
app.display
}
 

(PlayerTwo
{
different actions...
app.draw
app.display
}

if (n > 30) //n being the number of cards dealt out.
{
shuffle();
{
 } //end loop and go back to top

One of the actions Player One can make is splitting two cards of the same value. In order to split the cards, I need to move one of the app.draw's from the deal. The issue is that I cannot find a way to manipulate the card because it has already been drawn, and the loop will not get back til the next deal.

Thank you for the response by the way. I am in the process of switching back and forth from programming to digging into the book. I have much to learn about OOP.

I am currently using 1.6, but I will try out 2.0. I did not realize there was a release until after I was diving into 1.6.

Anyway, if you have any tips as to how I can approach this problem, that would be great! ;)

 

anything