-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
70 lines (56 loc) · 2.04 KB
/
Game.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
using System;
using System.Collections.Generic;
using System.Text;
namespace Scrabble.Game_Logic {
class Game {
public TileSet tileSet;
public Player player1;
public Player player2;
public Board board;
public WordProcessor wp;
public LinkedList mainWord;
public bool isValidPlay = false;
public Game() {
tileSet = new TileSet();
player1 = new Player();
player1.refillHand(tileSet);
player2 = new Player();
player2.refillHand(tileSet);
board = new Board(15);
wp = new WordProcessor();
mainWord = new LinkedList();
}
public bool playTile(Player player, int index, int row, int col) {
// checks if cell is unoccupied
if(board.playTile(player.getTile(index), row, col)) {
// inserts into the main word
mainWord.insertOrder(player.getTile(index), row, col);
// removes from players hand
player.play(index);
return true;
}
return false;
}
public void validPlay() {
isValidPlay = true;
// this section checks for valid words played
foreach (string word in board.getWords(mainWord, board.getDirection(mainWord))) {
if (word.Length > 1) {
if (!wp.isWordAsync(word)) {
Console.WriteLine("Invalid: " + word);
isValidPlay = false;
}
}
}
// this section checks for valid borders on tiles
LinkedList.Node head = new LinkedList.Node();
head = mainWord.Head;
while (head.next != null) {
if (!board.borders(head.next.row, head.next.col)) {
isValidPlay = false;
}
head = head.next;
}
}
}
}