[1.1] 自分が今行いたい事は何か
簡単なブラックジャックのプログラミングの作成
最初にいくらかけるかを決める。。。プレイヤーが勝てばプラス、負ければ0←ここはたぶんできます
プレイヤーに2枚カードが来る ハートの11、ダイヤの2など。←この部分がわかりません
プレイヤーがカードを引くか決める。←こちらもたぶんできると思います
ディーラー側は16以下なら自動的に21に近づくまで引く←これはWhile loopを使えばOKですか??16以下なら自動的にカードを引くというので。
スコアの大小で勝者決定。。。同点ならディーラー勝利←同点の場合ディーラー勝利にする方法??
最初のもちきん100円が0円になるか1000円こえると終了←こちらもたぶん大丈夫です。
[1.2] どのように取り組んだか(プログラムコードがある場合記載)
いまのところ、Aを1または11と数えるコードと10以上のカードを全部10にするというコードしかできていません。
[1.3] どのようなエラーやトラブルで困っているか(エラーメッセージが解る場合は記載)
困っている部分はランダムナンバーで最初のカード2枚、重複しないようにする方法がわかりません
[3] その他
・どの程度C言語を理解しているか
初心者です、前回OXゲームやループの方法を習いました。
今回はランダムナンバーのところの課題としてこのプログラム作成があります
ステップ別にアシスタントが示してくれたメールも添付しときます
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void draw_card(string& card, int& total);// this is your function declaration.
int main()
{
srand ( time(NULL) ); // this is just initialize the random seed.
/***************step one, declaration **************************/
/* within the main, you first declare the variables player_total,
dealer_total, player_amount, bet and so on... */
while ((player_amount>0)&&(player_amount<1000)) //
{
/* This is where you write the whole game. We do it in 3 steps */
/**************** step one, player's turn *****************/
/* call the function draw_card twice, that will generate the first 2 cards for the player.
* in the mean time, you need to cout the cards. It will be as the following:
cout<<"Your cards are: \n";
draw_card(card, player_total);
cout<<card<<"\n";
draw_card(card, player_total);
* where card and player_total should be declared before.
* then you should define a boolean variable ans, and ask the player "Do you want to draw another card?"
* then you can cin>>ans.
* while ( ans==y), you can keep drawing cards, until player bursts or ans=="n".
*/
/**************** step two, dealer's turn *****************/
/* you can use the same draw_card function and the same variable card for dealer as well.
* The dealer's condition on stop drawing cards is dealer_total>16.
* so you can write a while loop to check that condition, and if dealer_total<16, you can
* keep drawing the cards.
*/
/***************** step three, determine who wins the round ***********/
/* Here you have the sudo code for different cases.
* if (player_total>21){
* player loses;} // if player busts, dealer automatically wins.
* else if (dealer_total>21){
* dealer wins;} // if player hasn't bust, but dealer bust, player wins.
* else if (player_total>dealer_total){
* player wins;} // if both not burst, and player has higher total, player wins.
* else if (player_total<dealer_total){
* dealer wins;} // otherwise the dealer wins.
* else{
* tie;} // or else, you get a tie.
* in each of the cases above, you need to type the message indicating whoever wins,
* and increase or decrease the corresponding amount of money.
*/
}
cout<<"You have "<<player_amount<<" left. Game over. "
return 0;
}
void draw_card(string& card, int& total) // here starts your function defition.
{
/**************step one, randomly draw cards*************************/
/* declear int variables n1, n2, rank and suit.
and then randomly generate a number between 1 and 13, store it as n1;
also randomly generate a number between 1 and 4, store it as n2;
by the way, the way to generate a random integer from 1 to n is the following:
rand()%n+1;
*/
/**************step two, change the int n1 and n2 to strings and store them as card ***********/
/* you can either use switch or if statements.
Here is the syntax for switch:
switch ( n1 ) {
case 1 : // case 1 means n1=1.
// Process for n1 = 1
...
break;
case 5 :
// Process for n2 = 5
...
break;
default :
// Process for all other cases.
...
}
And for the syntax of if statement, I think you guys should already know that.
In each case listed above, you want to set the rank to be the corresponding string.
For example, if n1=2, you want to set the rank to be "2", and if n1=1, you want to set
the rank to be "Ace".
Besides, you also want to update the total in each case.
For example, if n1=2, you should have: total+=2; if n1=5, you should have: total+=5;
if n1=13, that's the case you draw a king, and king is regarded as 10, so you should
have total+=10; if n1=1, you need to check if total+11>21, if so, total+=1, otherwise, total+=11.
***** important: after the statements in each case,
you need to put the command break; to break from the statement*******
You need to have two switches, or two if statements. One for n1, the other for n2.
The first switch sets rank to the corresponding n1, and the second switch sets suite to
the corresponding n2.
*/
}
よろしくお願いします