Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
4d976e5
Update .gitignore
gummi-ice Oct 21, 2023
091f61b
Update vcs.xml
gummi-ice Oct 21, 2023
e88a4dc
t
gummi-ice Oct 21, 2023
8b97afc
? to functions
bjornunnar Oct 21, 2023
0e40721
tt
gummi-ice Oct 21, 2023
bb9b6c3
Merge pull request #2 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
dd0f0ca
Merge branch 'master' into Gummi-ice
gummi-ice Oct 21, 2023
c11a6b5
raise to 2.11
bjornunnar Oct 21, 2023
44b49ef
Merge pull request #5 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
d8ca880
t
gummi-ice Oct 21, 2023
f91b85e
shuffle completed
edvaldatli Oct 21, 2023
19f9c78
Deck of Cards tilbúið
OSE-ICE Oct 21, 2023
e7894c1
Merge pull request #6 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
0b174de
Update pubspec.yaml
CCP-2FaceMonkey Oct 21, 2023
f6cd737
Merge branch 'master' into OSE-ICE3
CCP-2FaceMonkey Oct 21, 2023
cadc0a5
Merge pull request #7 from bjornunnar/OSE-ICE3
CCP-2FaceMonkey Oct 21, 2023
965b9d0
Update deal_card.dart
gummi-ice Oct 21, 2023
3fab5a6
shuffled_deck completed
edvaldatli Oct 21, 2023
7b1f380
Merge pull request #8 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
1fc6889
Merge branch 'master' into Gummi-ice
gummi-ice Oct 21, 2023
52021f4
check_if_busted completed
edvaldatli Oct 21, 2023
41ba3f9
Merge pull request #9 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
efde2fc
Create card_namer
Some0ne3lse Oct 21, 2023
24265bb
b
gummi-ice Oct 21, 2023
cc2d98c
Merge pull request #10 from bjornunnar/Thor2
bjornunnar Oct 21, 2023
18fcbd6
Merge pull request #4 from bjornunnar/Gummi-ice
gummi-ice Oct 21, 2023
f25652f
Update draw_card.dart
bjornunnar Oct 21, 2023
81293b2
Merge pull request #11 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
641d4ca
create initial deal, fix draw card and deal card
bjornunnar Oct 21, 2023
cad74bc
Merge pull request #12 from bjornunnar/aron4
bjornunnar Oct 21, 2023
e98876e
Update return_hand.dart
gummi-ice Oct 21, 2023
5ab0de7
Merge pull request #13 from bjornunnar/Gummi-ice
gummi-ice Oct 21, 2023
7c785e5
Create score_function
Some0ne3lse Oct 21, 2023
ee9aebb
Update money_grab.dart
bjornunnar Oct 21, 2023
40602aa
Create null check
Some0ne3lse Oct 21, 2023
7b606ed
Merge pull request #14 from bjornunnar/Thor2
bjornunnar Oct 21, 2023
392f782
hitorstay & optionselect completed
edvaldatli Oct 21, 2023
0e81b6e
Merge pull request #15 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
d7291ee
Merge pull request #16 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
d815a16
removed print from escapefunction
edvaldatli Oct 21, 2023
6ff4cd5
Merge pull request #17 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
7000e4e
added nullEscape to option_select
edvaldatli Oct 21, 2023
846d214
Merge pull request #18 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
aee6cab
Update check_winner.dart
gummi-ice Oct 21, 2023
f46a35d
Merge branch 'master' into Gummi-ice
gummi-ice Oct 21, 2023
334982c
Update check_winner.dart
gummi-ice Oct 21, 2023
0eabc69
Merge pull request #19 from bjornunnar/Gummi-ice
CCP-2FaceMonkey Oct 21, 2023
2ca0901
Update welcome.dart
gummi-ice Oct 21, 2023
50f51a3
Merge pull request #20 from bjornunnar/Gummi-ice
gummi-ice Oct 21, 2023
70d0d35
Update money_grab.dart
bjornunnar Oct 21, 2023
d00e909
Merge pull request #21 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
a0ab072
house_plays completed
edvaldatli Oct 21, 2023
b1e2592
Merge pull request #22 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
d5a4754
Update house_plays.dart
edvaldatli Oct 21, 2023
1a70082
Merge pull request #23 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
aec5537
Update BlackJack.dart
Aronnord Oct 21, 2023
9720b76
Update money_grab.dart
bjornunnar Oct 21, 2023
e79207b
Update money_grab.dart
bjornunnar Oct 21, 2023
c0cf7c7
Merge pull request #24 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
b630db3
Merge remote-tracking branch 'upstream/master' into aron4
Aronnord Oct 21, 2023
e8320a8
Merge remote-tracking branch 'upstream/master' into aron4
Aronnord Oct 21, 2023
ecd9883
status completed
edvaldatli Oct 21, 2023
c50bd55
Merge pull request #25 from bjornunnar/edvalds
edvaldatli Oct 21, 2023
a825ffd
Merge remote-tracking branch 'upstream/master' into aron4
Aronnord Oct 21, 2023
3c5f87f
blackjack
Aronnord Oct 21, 2023
5554b85
Merge pull request #26 from bjornunnar/aron4
Aronnord Oct 21, 2023
33ce955
black jack 2.0
Aronnord Oct 21, 2023
b6fa904
Merge pull request #27 from bjornunnar/aron4
Aronnord Oct 21, 2023
1362ab8
Update check_winner.dart
bjornunnar Oct 21, 2023
7e0df00
Merge pull request #28 from bjornunnar/bjornunnar
bjornunnar Oct 21, 2023
0c0fd56
commit
CCP-2FaceMonkey Oct 21, 2023
0518930
Update BlackJack.dart
CCP-2FaceMonkey Oct 21, 2023
a62a1b2
Update check_winner.dart
CCP-2FaceMonkey Oct 21, 2023
c2b5513
Update score_function.dart
CCP-2FaceMonkey Oct 21, 2023
e142cad
Merge branch 'master' into final
CCP-2FaceMonkey Oct 21, 2023
7b18732
Merge pull request #29 from bjornunnar/final
CCP-2FaceMonkey Oct 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
pubspec.lock
*.xml

*.xml
pubspec.lock
.idea/libraries/Dart_SDK.xml
2 changes: 2 additions & 0 deletions .idea/Dart_Functions_BlackJack_Stripped.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions bin/BlackJack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ import 'package:BlackJack/functions/deal_card.dart';
*/

void main() {
Welcome();
int? bankRoll = BuyIn();
while(bankRoll! > 0) {
List<int>?deck = ShuffledDeck();
List<int>?playerHand = [];
List<int>?houseHand = [];
InitialDeal(playerHand, houseHand, deck);
int? bet = PlaceBet(bankRoll);

//DealCard(deck);
HitOrStay(playerHand, houseHand, deck);
if (CheckIfBusted(playerHand) == true) {
CheckWinner(playerHand, houseHand, bankRoll, bet);
} else {
HousePlays(houseHand, deck);
}
// Status(playerHand, houseHand);
bankRoll = CheckWinner(playerHand, houseHand, bankRoll, bet);
print(bankRoll);

//returnHands()
}
}

40 changes: 40 additions & 0 deletions lib/functions/avoidNullChecks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'dart:io';

double nullEscapeAndConvertToDouble() {
String? number;
double? parsedNumber;

while (parsedNumber == null) {
print("Please enter a valid number: ");
number = stdin.readLineSync();

if (number != null) {
parsedNumber = double.tryParse(number);
}

if (parsedNumber == null) {
print("Invalid option");
}
}

return parsedNumber;
}

int nullEscapeAndConvertToInt() {
String? number;
int? parsedNumber;

while (parsedNumber == null) {
number = stdin.readLineSync();

if (number != null) {
parsedNumber = int.tryParse(number);
}

if (parsedNumber == null) {
print("Invalid option");
}
}

return parsedNumber;
}
33 changes: 31 additions & 2 deletions lib/functions/card_namer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ When given an integer between 1-13,
it should return the name of the corresponding card (Ignore the suit)
*/

String CardNamer(int i){

String? CardNamer(int i){
var cardName;
switch (i) {
case 1:
return 'A';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
case 10:
return '10';
case 11:
return 'J';
case 12:
return 'Q';
case 13:
return 'K';
}
return cardName;
}
9 changes: 6 additions & 3 deletions lib/functions/check_if_busted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ Example inputs
if ... true eða false, return true eða false
*/


bool CheckIfBusted(List<int> hand){

}
int? sumOfCards = CalculateScore(hand);
if(sumOfCards! > 21){
return true;
}
return false;
}
22 changes: 20 additions & 2 deletions lib/functions/check_winner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ of the user, which should have decreased/increased based on if he won or not.

import 'package:BlackJack/functions/functions.dart';

int CheckWinner(List<int> playerHand, List<int> houseHand, int currentBankRoll, int currentBet){
int? CheckWinner(List<int> playerHand, List<int> houseHand, int currentBankRoll, int currentBet){

}
int? playerScore = CalculateScore(playerHand);
int? houseScore = CalculateScore(houseHand);

if(CheckIfBusted(houseHand)){
// WIN
currentBankRoll += currentBet;
} else {
if ( playerScore! > houseScore! && CheckIfBusted(playerHand) == false) {
// Win
currentBankRoll += currentBet;
print("You Win!");
} else {
currentBankRoll -= currentBet;
print("You Lose!");
}
}
ShowAllCards(playerHand, houseHand);
return currentBankRoll;
}
4 changes: 4 additions & 0 deletions lib/functions/deal_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ print(deck); // Should print [2, 3, 4]
*/

int DealCard(List<int> deck){
//int cardNumber = 0;

int cardNumber = deck[0];
deck.removeAt(0);
return cardNumber;
}
9 changes: 9 additions & 0 deletions lib/functions/deck_of_cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ List<int> DeckOfCards() {
List<int> Cards = [];
List<int> Deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
List<String> Suits = ["Spaði", "Tígul", "Hjarta", "Lauf"];

for (int i = 0; i < Suits.length; i++) {
for (int j = 0; j < Deck.length; j++) {
Cards.add(Deck[j]);
}
}

return Cards;
}




3 changes: 2 additions & 1 deletion lib/functions/draw_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Add function

*/

void DrawCard(List<int> hand, List<int> deck){

void DrawCard(List<int> hand, List<int> deck){
hand.add(DealCard(deck));
}
8 changes: 7 additions & 1 deletion lib/functions/initial_deal.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:BlackJack/functions/deal_card.dart';

import 'draw_card.dart';

/*
Expand All @@ -22,6 +24,10 @@ print(dealerHand); // Should print [2, 4]

*/

void InitialDeal(List<int> playerHand, List<int> houseHand, List<int> deck){

void InitialDeal(List<int> playerHand, List<int> houseHand, List<int> deck){
DrawCard(playerHand, deck);
DrawCard(houseHand, deck);
DrawCard(playerHand, deck);
DrawCard(houseHand, deck);
}
36 changes: 33 additions & 3 deletions lib/functions/money_grab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,40 @@ Can you design the function such that it will ask the user again if
he doesn't input a integer?
*/

int PlaceBet(int bankRoll) {

int getInteger(){
int number = 0;
try {
number = int.tryParse(stdin.readLineSync()!) !- 0;
} catch (e){
print("You have to input a number!");
getInteger();
}
return number;
}

int BuyIn() {
int PlaceBet(int bankRoll) {
if (bankRoll == 0){
print("Error: no available funds.");
BuyIn();
}
print("Give me an amount you want to bet");
int amount = getInteger();
if (amount > bankRoll){
print("You only have $bankRoll to play with! Pick a lower number.");
PlaceBet(bankRoll);
return amount;
} else if (amount == 0) {
print("You can't bet 0! Try again.");
PlaceBet(bankRoll);
return amount;
} else {
return amount;
}
}

}
int BuyIn() {
print("How large is your buy in?");
int amount = getInteger();
return amount;
}
10 changes: 9 additions & 1 deletion lib/functions/option_select.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'avoidNullChecks.dart';
/*
Create a function called OptionSelect which takes in a list of options,
prints them out to the user and asks for the user to select an option.
Expand All @@ -18,6 +19,13 @@ that the function will simply ask the user again to input an answer?

*/

int OptionSelect(String statement, List<String> options) {
int? OptionSelect(String statement, List<String> options) {
print(statement);
for(int i = 0; i < options.length; i++){
print("${i+1}. ${options[i]}");
}
int userOption;
userOption = nullEscapeAndConvertToInt();

return userOption;
}
14 changes: 12 additions & 2 deletions lib/functions/return_hand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ print(hand); // Should print []


void ReturnHand(List<int> hand, List<int> deck){

for (var item in hand) {
deck.add(item);
}
hand.clear();
}

void ReturnHands(List<int> playerHand, List<int> houseHand, List<int> deck){

for (var item in playerHand) {
deck.add(item);
}
for (var item in houseHand) {
deck.add(item);
}
playerHand.clear();
houseHand.clear();
}
/*
Then create another function called ReturnHands that uses the above function
Expand Down
20 changes: 17 additions & 3 deletions lib/functions/score_function.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
Create a function called CalculateScore that can calculate the score of a given hand of cards.
The score is blackjack score, so the following rules apply
Expand All @@ -21,7 +20,22 @@ gets the score 1. So if the method gets the hand [1, 1] the score would be 12
hand = [7, 1] -> Score 18
*/

int CalculateScore(List<int> hand){

int? CalculateScore(List<int> hand){
int sum = 0;
bool checkIfAce = false;
for (int number in hand) {
if (number == 1 && checkIfAce == false){
checkIfAce = true;
sum += 11;
} else if (number == 1 && checkIfAce == true) {
sum += 1;
} else if(number >= 2 && number <= 10) {
sum += number;
} else if (number >= 11 && number <= 13){
sum += 10;
}
}
print('sum: $sum');
return sum;
}

4 changes: 4 additions & 0 deletions lib/functions/shuffled_deck.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ And when run, returns a shuffled deck of cards. No inputs, only output.
*/

List<int> ShuffledDeck(){
List<int> _shuffledDeck = Shuffler(DeckOfCards())!;

print("A deck of cards has been shuffled");
//print('Log - shuffled-deck: ${_shuffledDeck}');
return _shuffledDeck;
}
4 changes: 3 additions & 1 deletion lib/functions/shuffler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and outputs a shuffled list of integers.
I.e, it should return a RANDOMIZED version of the list.
*/

List<int> Shuffler(List<int> theList){
List<int>? Shuffler(List<int> theList){
theList.shuffle();

return theList;
}
Loading