//
// main.c
// Acey
//
// Created by Patrick Alessi on 3/28/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct card {
char* name;
char* suit;
int value;
};
void shuffle(struct card* deck) {
// Seed the random number generator
srandom( time( NULL ) );
int i=0;
int randomA, randomB;
struct card tempCard;
do {
// Generate 2 random numbers to determine which cards to swap
randomA = random() % 52;
randomB = random() % 52;
// Swap slots A and B
tempCard = deck[randomA];
deck[randomA] = deck[randomB];
deck[randomB] = tempCard;
// Increment the counter
i++;
}
while (i<1000000);
}
int main (int argc, const char * argv[])
{
struct card deck[] =
{
{"ace", "spades",1}, {"two", "spades",2}, {"three", "spades",3},
{"four", "spades",4}, {"five", "spades",5}, {"six", "spades",6},
{"seven", "spades",7}, {"eight", "spades",8}, {"nine", "spades",9},
{"ten", "spades",10}, {"jack", "spades",11}, {"queen", "spades",12},
{"king", "spades",13},
{"ace", "clubs",1}, {"two", "clubs",2}, {"three", "clubs",3},
{"four", "clubs",4}, {"five", "clubs",5}, {"six", "clubs",6},
{"seven", "clubs",7}, {"eight", "clubs",8}, {"nine", "clubs",9},
{"ten", "clubs",10}, {"jack", "clubs",11}, {"queen", "clubs",12},
{"king", "clubs",13},
{"ace", "hearts",1}, {"two", "hearts",2}, {"three", "hearts",3},
{"four", "hearts",4}, {"five", "hearts",5}, {"six", "hearts",6},
{"seven", "hearts",7}, {"eight", "hearts",8}, {"nine", "hearts",9},
{"ten", "hearts",10}, {"jack", "hearts",11}, {"queen", "hearts",12},
{"king", "hearts",13},
{"ace", "diamonds",1}, {"two", "diamonds",2}, {"three", "diamonds",3},
{"four", "diamonds",4}, {"five", "diamonds",5}, {"six", "diamonds",6},
{"seven", "diamonds",7}, {"eight", "diamonds",8},
{"nine", "diamonds",9},{"ten", "diamonds",10}, {"jack", "diamonds",11},
{"queen", "diamonds",12}, {"king", "diamonds",13},
{"sentinel", "null", 0}
};
// Create the player's bank and start it off with 100 credits
int bank=100;
// Create a pointer to the deck
struct card* pDeck = deck;
// Create a variable to hold the bet
int bet=0;
// Run the function to shuffle the deck
shuffle(deck);
// Run the game in a loop. Continue as long as the bank is > and none of
// the next three cards are the sentinel
do {
// Print the amount of credits in the bank
printf("Your bank: %i\n", bank);
// Print the cards
printf("The cards: ");
// First card
printf("%s of %s ", pDeck->name, pDeck->suit);
// Move to the next card
pDeck++;
// Second card
printf("and %s of %s\n", pDeck->name, pDeck->suit);
// Move the pointer to the next card
pDeck++;
// Ask for the bet
// Do this in a loop because we cannot accept bets greater than the
// amount that the player has in the bank and we cannot
// accept a 0 bet
do {
printf("Enter your bet: ");
scanf("%i", &bet);
}
while (bet <= 0 || bet > bank );
// Draw the third card
printf("The third card is %s of %s\n", pDeck->name, pDeck->suit);
// Determine if the player won
// The player is a winner if the third card falls between the first two
// Ties go to the house
if (((pDeck-2)->value < pDeck-> value &&
(pDeck-1)->value > pDeck->value) ||
((pDeck-2)->value > pDeck-> value &&
(pDeck-1)->value < pDeck->value)) {
printf("We have a winner!\n\n");
// Player won, add bet to the bank
bank += bet;
}
else {
printf("Sorry, you lose.\n\n");
// Player lost, subsract bet from the bank
bank -= bet;
}
// Move to the next card
pDeck++;
}
while (bank > 0 &&
pDeck->value!=0 &&
(pDeck+1)->value!=0 &&
(pDeck+2)->value!=0);
// The game is over
printf("The game is over. Your final score is %i\n", bank);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
iOS游戏开发入门经典.rar
共907个文件
m:168个
ds_store:136个
png:134个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 194 浏览量
2022-06-18
14:15:42
上传
评论
收藏 6.01MB RAR 举报
温馨提示
iOS游戏开发入门经典.rar
资源推荐
资源详情
资源评论
收起资源包目录
iOS游戏开发入门经典.rar (907个子文件)
MagicMind.1 3KB
Shapes.1 3KB
CSizes.1 3KB
Houses.1 3KB
Cards.1 3KB
Acey.1 3KB
._Shapes.1 171B
._Houses.1 171B
._CSizes.1 171B
._Cards.1 171B
._MagicMind.1 171B
6b6facda6f2148565f249474fec47fd4660f43 58B
714f9797de77351ad1d992da5fa0182ed10453 1KB
7d69549d68b7a7c2f37b3c9300da3e99350fc0 82B
8fe713ffe923476ba477e02b16a0eaeea9f041 2KB
a4c9c2698e09de27073556c67f1f60860f5f58 83B
BlockerMusic.aiff 2.69MB
BlockerMusic.aiff 2.69MB
0.aiff 86KB
0.aiff 86KB
0.aiff 86KB
2.aiff 84KB
1.aiff 84KB
2.aiff 84KB
2.aiff 84KB
3.aiff 84KB
._0.aiff 82B
._2.aiff 82B
._0.aiff 82B
._2.aiff 82B
._2.aiff 82B
._BlockerMusic.aiff 82B
._1.aiff 82B
._0.aiff 82B
._BlockerMusic.aiff 82B
._3.aiff 82B
main.c 4KB
main.c 3KB
main.c 1KB
main.c 750B
._main.c 171B
._main.c 171B
COMMIT_EDITMSG 15B
config 111B
dd532ac0d889aec75b9859f71ac4e8d332fa60 136B
description 73B
.DS_Store 15KB
.DS_Store 15KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 12KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
共 907 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
BryanDing
- 粉丝: 297
- 资源: 5587
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功