Note that there are some explanatory texts on larger screens.

plurals
  1. POSeeking advice on Object-Oriented programming
    primarykey
    data
    text
    <p>I'm not sure if I will able to put it in a sensible way.</p> <p>I'm trying to write an easy non-graphical game. User will play a dice game against the computer.</p> <p>(To be more specific, this game: The object of the jeopardy dice game Pig is to be the first player to reach 100 points. Each player’s turn consists of repeatedly rolling a die. After each roll, the player is faced with two choices: roll again, or hold (decline to roll again).</p> <ul> <li>If the player rolls a 1, the player scores nothing and it becomes the opponent’s turn.</li> <li>If the player rolls a number other than 1, the number is added to the player’s turn total and the player’s turn continues.</li> <li>If the player holds, the turn total, the sum of the rolls during the turn, is added to the player’s score, and it becomes the opponent’s turn.)</li> </ul> <hr> <p>I wrote the program but now I want to do it in object-oriented way. This is my problem:</p> <p>I have an abstract Player class. Human_player class and Computer_player class extend the Player class. Another class, called Game_Controller, controls the flow the game. Say that Computer_Player has a certain strategy, that unless the "initial total" is less than 20, he keeps rolling the dice (which means that he is in a certain loop). On the other hand, the Game_Controller keeps rolling the dice for the Computer_Player as long as he wishes and as long as he can (which means that that part of the program is in a certain loop). So when Computer_Player rolls "1", Game_Controller gives the turn to Human_Player. How do I make the Compter_Player end his loop?</p> <p>Moreover, I'm having difficulty at implementing the Computer_Player as a concrete player (because I'm new at programming, and I'm especially new at this kind of interaction). What's the proper way of handling this?---That is, the Game-Controller class interacts with Computer_Player class and Computer_Player class interacts with Game_Controller class.</p> <p>Thanks for sparing your time.</p> <p>Edit 1: Is there good source (website, book) on this type of stuff? I'm not looking for those advanced game-programming sources, just easy and fundamental stuff.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload