-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
86 lines (76 loc) · 2.43 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Text;
namespace C21_Ex02_Liron_315783852_Maor_315900795
{
public class Player
{
public static int s_Winnings { get; internal set; }
public char m_PlayerSign { get; set; }
public string m_PlayerName { get; set; }
public bool m_IsComputerPlayer { get; set; }
public Player(char sign, string i_PlayerName, bool i_isComputerPlayer = false)
{
this.m_PlayerSign = sign;
m_PlayerName = i_PlayerName;
s_Winnings = 0;
m_IsComputerPlayer = i_isComputerPlayer;
}
public static Player GetCurrentPlayer(int i_MoveCount, Dictionary<Player, int> i_Players)
{
Player currentPlayer = null;
try
{
if (i_MoveCount % 2 == 0)
{
foreach (var player in i_Players)
{
if (player.Key.m_PlayerSign == (char)ePlayerSign.Second)
{
currentPlayer = player.Key;
}
}
}
else
{
foreach (var player in i_Players)
{
if (player.Key.m_PlayerSign == (char)ePlayerSign.First)
{
currentPlayer = player.Key;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Oops, seems there was an exception : {0}", ex));
}
return currentPlayer;
}
public void ComputerPlayerTurn(int[] i_CcolumnsCapacity, int i_MaxCapacity, out int io_ChosenColumn)
{
io_ChosenColumn = 0;
try
{
for (int i = 0; i < i_CcolumnsCapacity.Length; i++)
{
if (i_CcolumnsCapacity[i] < i_MaxCapacity - 1)
{
io_ChosenColumn = i + 1;
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Oops, seems there was an exception : {0}", ex));
}
}
}
public enum ePlayerSign
{
First = 'X',
Second = 'O',
}
}