Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
alsunj
/
blackjack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6cc6c3b3
authored
a year ago
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
566fea8e
master
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
0 deletions
scripts/C#/Gamescripts/PlayerScript.cs
scripts/C#/Gamescripts/PlayerScript.cs
0 → 100644
View file @
6cc6c3b3
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
PlayerScript
:
MonoBehaviour
{
// Nii mängija kui ka diileri kood
// Kasuta teisi scripte
public
CardScript
cardScript
;
public
DeckScript
deckScript
;
// Total value of player/dealer's hand
public
int
handValue
=
0
;
// Betting money
private
int
money
=
DBmanager
.
bank
;
//public int money = 5000;
// Massiiv kaartidest, mis tekivad ühes käes/hand
public
GameObject
[]
hand
;
// Index uuele kaardile
public
int
cardIndex
=
0
;
// Is ace 1 or 11
List
<
CardScript
>
aceList
=
new
List
<
CardScript
>();
public
void
StartHand
()
{
GetCard
();
GetCard
();
}
// Update is called once per frame
public
int
GetCard
()
{
// Get a card
int
cardValue
=
deckScript
.
DealCard
(
hand
[
cardIndex
].
GetComponent
<
CardScript
>());
// Show card on game screen
hand
[
cardIndex
].
GetComponent
<
Renderer
>().
enabled
=
true
;
// Hand/käe kogu väärtus
handValue
+=
cardValue
;
// Kui väärtus on 1 on tegemist ässaga
if
(
cardValue
==
1
)
{
aceList
.
Add
(
hand
[
cardIndex
].
GetComponent
<
CardScript
>());
}
// Kontroll kas kasutame 1e või 11 ässa väärtusena
AceCheck
();
cardIndex
++;
return
handValue
;
}
// Conversion: is ace 1 or 11
public
void
AceCheck
()
{
// for each ace in the ace list
foreach
(
CardScript
ace
in
aceList
)
{
if
(
handValue
+
10
<
22
&&
ace
.
GetValueOfCard
()
==
1
)
{
// if converting, adjust card object and hand value
ace
.
SetValue
(
11
);
handValue
+=
10
;
}
else
if
(
handValue
>
21
&&
ace
.
GetValueOfCard
()
==
11
)
{
ace
.
SetValue
(
1
);
handValue
-=
10
;
}
}
}
// Add or subtract from money, for bets
public
void
AdjustMoney
(
int
amount
)
{
money
+=
amount
;
}
// Output players current money amount
public
int
GetMoney
()
{
return
money
;
}
// Hides all cards, resets the needed variables
public
void
ResetHand
()
{
for
(
int
i
=
0
;
i
<
hand
.
Length
;
i
++)
{
hand
[
i
].
GetComponent
<
CardScript
>().
ResetCard
();
hand
[
i
].
GetComponent
<
Renderer
>().
enabled
=
false
;
}
cardIndex
=
0
;
handValue
=
0
;
aceList
=
new
List
<
CardScript
>();
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
hand
[
i
].
GetComponent
<
Renderer
>().
enabled
=
true
;
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment